main.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import App from './App'
  2. // #ifndef VUE3
  3. import Vue from 'vue'
  4. import store from "@/store/index.js"
  5. import './uni.promisify.adaptor'
  6. import uView from '@/uni_modules/uview-ui'
  7. import "./utils/permission.js"
  8. import {
  9. $http
  10. } from "@escook/request-miniprogram"
  11. uni.$http = $http
  12. // 请求的根路径
  13. $http.baseUrl = "http://test.cloud.boyuantech.net:9001"
  14. // 请求拦截器
  15. $http.beforeRequest = function(options) {
  16. // uni.showLoading({
  17. // title: '数据加载中...',
  18. // mask: true,
  19. // })
  20. // console.log(options);
  21. options.header = {
  22. Token: uni.getStorageSync('Token')
  23. }
  24. }
  25. // 响应拦截器
  26. $http.afterRequest = function(err) {
  27. if (err.data.code === 2000) {
  28. uni.removeStorage('userId')
  29. uni.removeStorage('Token')
  30. uni.removeStorage('testProjectId')
  31. uni.showToast({
  32. title: '令牌过期,请重新登录',
  33. icon: 'none',
  34. duration: 2000
  35. })
  36. // uni.hideLoading()
  37. uni.redirectTo({
  38. url: "/pages/login/login"
  39. })
  40. return
  41. }
  42. // uni.hideLoading()
  43. }
  44. // 封装弹框的方法
  45. uni.$showMsg = function(title = '数据请求失败!', duration = 1500) {
  46. uni.showToast({
  47. title,
  48. duration,
  49. icon: 'none',
  50. mask: true
  51. })
  52. }
  53. Vue.use(uView);
  54. Vue.config.productionTip = false
  55. App.mpType = 'app'
  56. const app = new Vue({
  57. ...App,
  58. store
  59. })
  60. app.$mount()
  61. // #endif
  62. // #ifdef VUE3
  63. import {
  64. createSSRApp
  65. } from 'vue'
  66. export function createApp() {
  67. const app = createSSRApp(App)
  68. return {
  69. app
  70. }
  71. }
  72. // #endif