main.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. var rsing=0
  32. rs()
  33. function rs(){
  34. const nowTime = new Date().getTime()
  35. if (rsing==0 && nowTime > (getExpiresTime()-10*1000)) {
  36. rsing=1
  37. console.log("===rs call")
  38. refreshToken({
  39. refreshToken: getRefreshToken()
  40. }).then((res) => {
  41. console.log(res.data, 'ressss')
  42. setToken(res.data)
  43. rsing=0
  44. }).catch(() => {
  45. /*
  46. showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
  47. if (res.confirm) {
  48. uni.navigateTo({
  49. url: '/pages/login'
  50. })
  51. }
  52. })*/
  53. })
  54. }
  55. setTimeout(function(){
  56. rs()
  57. },1*1000)
  58. }
  59. // #ifdef H5
  60. Vue.mixin({
  61. mounted() {
  62. if (this.isWeiXinBrowser() && !this.isCustomNav()) {
  63. this.navTitle()
  64. }
  65. },
  66. methods: {
  67. isWeiXinBrowser() {
  68. let ua = navigator.userAgent.toLowerCase()
  69. return ua.indexOf('micromessenger') != -1
  70. },
  71. isCustomNav() {
  72. return this.$mp && this.$mp.appOptions && this.$mp.appOptions.window && this.$mp.appOptions.window.navigationStyle === 'custom';
  73. },
  74. navTitle() {
  75. this.$nextTick(() => {
  76. let navTitleDom = document.getElementsByTagName('uni-page-head')
  77. if (navTitleDom.length) {
  78. navTitleDom[0].style.display = 'none'
  79. if (typeof wx !== 'undefined' && wx.hideNavigationBarLoading) {
  80. wx.hideNavigationBarLoading()
  81. }
  82. }
  83. })
  84. }
  85. }
  86. })
  87. // #endif