main.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 {
  7. refreshToken
  8. } from "@/api/login";
  9. // import uView from 'uview-ui'
  10. import uView from '@/uni_modules/uview-ui'
  11. import $ from '@/pages/common/fun.js'
  12. import {
  13. showConfirm,
  14. } from '@/utils/common'
  15. import {
  16. getRefreshToken,
  17. getExpiresTime,
  18. setToken
  19. } from '@/utils/auth'
  20. // 在main.js中注册全局组件
  21. import isLodingModel from './components/loading/loading.vue'
  22. Vue.component('isLodingModel', isLodingModel)
  23. // import navInfo from "@/pagesA/components/my-nav/nav.vue"
  24. // Vue.component('navInfo', navInfo)
  25. Vue.use(uView)
  26. Vue.use(plugins)
  27. Vue.config.productionTip = false
  28. Vue.prototype.$store = store
  29. Vue.prototype.$ = $
  30. Vue.prototype.$screenHeight = uni.getSystemInfoSync().windowHeight
  31. App.mpType = 'app'
  32. const app = new Vue({
  33. ...App
  34. })
  35. app.$mount()
  36. var rsing = 0
  37. // rs()
  38. // let isrefresh=false
  39. // function rs(){
  40. // const nowTime = new Date().getTime()
  41. // if (rsing==0 && nowTime > (getExpiresTime()-10*1000)&& !isrefresh) {
  42. // refreshToken({
  43. // refreshToken: getRefreshToken()
  44. // }).then((res) => {
  45. // setToken(res.data)
  46. // isrefresh = true; // 设置标志变量为 true
  47. // rsing=0
  48. // setTimeout(function() {
  49. // isrefresh = false;
  50. // }, 11 * 1000)
  51. // }).catch(() => {
  52. // showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
  53. // if (res.confirm) {
  54. // uni.navigateTo({
  55. // url: '/pages/login'
  56. // })
  57. // }
  58. // })
  59. // })
  60. // }
  61. // setTimeout(function(){
  62. // rs()
  63. // },1*1000)
  64. // }
  65. // 判断是否断网的函数
  66. function isOffline() {
  67. return !navigator.onLine;
  68. }
  69. // 监听断网事件
  70. window.addEventListener('offline', function() {
  71. if (isOffline()) {
  72. showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then((res) => {
  73. if (res.confirm) {
  74. uni.navigateTo({
  75. url: '/pages/login',
  76. });
  77. }
  78. });
  79. }
  80. });
  81. // #ifdef H5
  82. Vue.mixin({
  83. mounted() {
  84. if (this.isWeiXinBrowser() && !this.isCustomNav()) {
  85. this.navTitle()
  86. }
  87. },
  88. methods: {
  89. isWeiXinBrowser() {
  90. let ua = navigator.userAgent.toLowerCase()
  91. return ua.indexOf('micromessenger') != -1
  92. },
  93. isCustomNav() {
  94. return this.$mp && this.$mp.appOptions && this.$mp.appOptions.window && this.$mp.appOptions.window
  95. .navigationStyle === 'custom';
  96. },
  97. navTitle() {
  98. const currentPath = this.$route.path;
  99. this.$nextTick(() => {
  100. let navTitleDom = document.getElementsByClassName('uni-page-head__title');
  101. // let navTitleDoms = navTitleDom.getElementsByTagName('');
  102. if (navTitleDom.length) {
  103. if(currentPath == '/'||currentPath == '/pages/index' ||currentPath == '/pages/work/index'||currentPath == '/pages/mine/index'){
  104. navTitleDom[0].style.display = 'none';
  105. }else{
  106. navTitleDom[0].innerText = '返回';
  107. }
  108. if (typeof wx !== 'undefined' && wx.hideNavigationBarLoading) {
  109. wx.hideNavigationBarLoading()
  110. }
  111. }
  112. })
  113. }
  114. }
  115. })
  116. // #endif