main.js 1.5 KB

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