main.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. // 判断是否断网的函数
  64. function isOffline() {
  65. return !navigator.onLine;
  66. }
  67. // 监听断网事件
  68. window.addEventListener('offline', function() {
  69. if (isOffline()) {
  70. showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then((res) => {
  71. if (res.confirm) {
  72. uni.navigateTo({
  73. url: '/pages/login',
  74. });
  75. }
  76. });
  77. }
  78. });
  79. // #ifdef H5
  80. Vue.mixin({
  81. mounted() {
  82. if (this.isWeiXinBrowser() && !this.isCustomNav()) {
  83. this.navTitle()
  84. }
  85. },
  86. methods: {
  87. isWeiXinBrowser() {
  88. let ua = navigator.userAgent.toLowerCase()
  89. return ua.indexOf('micromessenger') != -1
  90. },
  91. isCustomNav() {
  92. return this.$mp && this.$mp.appOptions && this.$mp.appOptions.window && this.$mp.appOptions.window.navigationStyle === 'custom';
  93. },
  94. navTitle() {
  95. this.$nextTick(() => {
  96. let navTitleDom = document.getElementsByTagName('uni-page-head')
  97. if (navTitleDom.length) {
  98. navTitleDom[0].style.display = 'none'
  99. if (typeof wx !== 'undefined' && wx.hideNavigationBarLoading) {
  100. wx.hideNavigationBarLoading()
  101. }
  102. }
  103. })
  104. }
  105. }
  106. })
  107. // #endif