App.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. console.log('App Launch')
  5. this.$u.func.checkLogin()
  6. //this.refreshToken()
  7. },
  8. onShow: function() {
  9. console.log('App Show')
  10. },
  11. onHide: function() {
  12. console.log('App Hide')
  13. },
  14. onShareAppMessage(res) { //发送给朋友
  15. return {
  16. title: '警地融合小程序',
  17. path:'/pages/index/index',
  18. imageUrl: '',
  19. }
  20. },
  21. onShareTimeline(res) { //分享到朋友圈
  22. return {
  23. title: '警地融合小程序',
  24. imageUrl: '',
  25. }
  26. },
  27. methods:{
  28. // 检测token
  29. refreshToken() {
  30. const tokenValidPeriod = 20000;
  31. // 如果token为空或者已经超过有效期,需要生成新的token
  32. if (this.token!=undefined && Number(Date.now() - this.userInfo.tokenGeneratedTime) > Number(tokenValidPeriod)) {
  33. console.log(this.token,Date.now() - this.userInfo.tokenGeneratedTime);
  34. this.$u.vuex('userInfo', {
  35. avatar: '',
  36. nick_name: '游客',
  37. tenant_id: '暂无'
  38. })
  39. this.$u.vuex('accessToken', '')
  40. this.$u.vuex('isLogin', false)
  41. }
  42. }
  43. }
  44. }
  45. </script>
  46. <style lang="scss">
  47. /*每个页面公共css */
  48. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  49. @import "@/uni_modules/uview-ui/index.scss";
  50. </style>