main.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. })
  19. // console.log(options);
  20. options.header = {
  21. Token: uni.getStorageSync('Token')
  22. }
  23. }
  24. // 响应拦截器
  25. $http.afterRequest = function(err) {
  26. if (err.data.code === 2000) {
  27. uni.removeStorage('userId')
  28. uni.removeStorage('Token')
  29. uni.removeStorage('testProjectId')
  30. uni.showToast({
  31. title: '令牌过期,请重新登录',
  32. icon: 'none',
  33. duration: 2000
  34. })
  35. uni.hideLoading()
  36. uni.redirectTo({
  37. url: "/pages/login/login"
  38. })
  39. return
  40. }
  41. uni.hideLoading()
  42. }
  43. // 封装弹框的方法
  44. uni.$showMsg = function(title = '数据请求失败!', duration = 1500) {
  45. uni.showToast({
  46. title,
  47. duration,
  48. icon: 'none',
  49. mask: true
  50. })
  51. }
  52. Vue.use(uView);
  53. Vue.config.productionTip = false
  54. App.mpType = 'app'
  55. const app = new Vue({
  56. ...App,
  57. store
  58. })
  59. app.$mount()
  60. // #endif
  61. // #ifdef VUE3
  62. import {
  63. createSSRApp
  64. } from 'vue'
  65. export function createApp() {
  66. const app = createSSRApp(App)
  67. return {
  68. app
  69. }
  70. }
  71. // #endif