main.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import Vue from 'vue'
  2. import App from './App'
  3. import store from './store' // store
  4. import plugins from './plugins' // plugins
  5. import './permission' // permission
  6. import {refreshToken} from "@/api/login";
  7. // import uView from 'uview-ui'
  8. import uView from '@/uni_modules/uview-ui'
  9. import $ from '@/pages/common/fun.js'
  10. import {
  11. getRefreshToken,
  12. getExpiresTime,
  13. setToken
  14. } from '@/utils/auth'
  15. // 在main.js中注册全局组件
  16. import isLodingModel from './components/loading/loading.vue'
  17. Vue.component('isLodingModel', isLodingModel)
  18. // import navInfo from "@/pagesA/components/my-nav/nav.vue"
  19. // Vue.component('navInfo', navInfo)
  20. Vue.use(uView)
  21. Vue.use(plugins)
  22. Vue.config.productionTip = false
  23. Vue.prototype.$store = store
  24. Vue.prototype.$ = $
  25. Vue.prototype.$screenHeight = uni.getSystemInfoSync().windowHeight
  26. App.mpType = 'app'
  27. const app = new Vue({
  28. ...App
  29. })
  30. app.$mount()
  31. console.log(getExpiresTime(),'getExpiresTime()');
  32. var rsing=0
  33. rs()
  34. let isrefresh=false
  35. function rs(){
  36. const nowTime = new Date().getTime()
  37. if (rsing==0 && nowTime > (getExpiresTime()-10*1000)&& !isrefresh) {
  38. console.log("===rs call",)
  39. refreshToken({
  40. refreshToken: getRefreshToken()
  41. }).then((res) => {
  42. console.log(res.data, 'ressss')
  43. setToken(res.data)
  44. isrefresh = true; // 设置标志变量为 true
  45. rsing=0
  46. setTimeout(function() {
  47. isrefresh = false;
  48. }, 11 * 1000)
  49. }).catch(() => {
  50. // showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
  51. // if (res.confirm) {
  52. // uni.navigateTo({
  53. // url: '/pages/login'
  54. // })
  55. // }
  56. // })
  57. })
  58. }
  59. setTimeout(function(){
  60. rs()
  61. },1*1000)
  62. }
  63. // #ifdef H5
  64. Vue.mixin({
  65. mounted() {
  66. if (this.isWeiXinBrowser() && !this.isCustomNav()) {
  67. this.navTitle()
  68. }
  69. },
  70. methods: {
  71. isWeiXinBrowser() {
  72. let ua = navigator.userAgent.toLowerCase()
  73. return ua.indexOf('micromessenger') != -1
  74. },
  75. isCustomNav() {
  76. return this.$mp && this.$mp.appOptions && this.$mp.appOptions.window && this.$mp.appOptions.window.navigationStyle === 'custom';
  77. },
  78. navTitle() {
  79. this.$nextTick(() => {
  80. let navTitleDom = document.getElementsByTagName('uni-page-head')
  81. if (navTitleDom.length) {
  82. navTitleDom[0].style.display = 'none'
  83. if (typeof wx !== 'undefined' && wx.hideNavigationBarLoading) {
  84. wx.hideNavigationBarLoading()
  85. }
  86. }
  87. })
  88. }
  89. }
  90. })
  91. // #endif