main.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. store.commit("m_business/saveCurrentHotelToStorage", "{}")
  35. uni.$showMsg("令牌过期,请重新登录");
  36. uni.reLaunch({
  37. url: "/pages/login/login",
  38. })
  39. return
  40. }
  41. // uni.$showMsg('加载成功')
  42. // uni.hideLoading()
  43. };
  44. // 封装弹框的方法
  45. uni.$showMsg = function (title = "数据请求失败!", duration = 1500) {
  46. uni.showToast({
  47. title,
  48. duration,
  49. icon: "none",
  50. });
  51. };
  52. Vue.config.productionTip = false;
  53. App.mpType = "app";
  54. const app = new Vue({
  55. ...App,
  56. store,
  57. });
  58. app.$mount();
  59. // #endif
  60. // #ifdef VUE3
  61. import {
  62. createSSRApp
  63. } from "vue";
  64. import App from "./App.vue";
  65. import Log from "./mp_ecard_sdk/constants/log";
  66. export function createApp() {
  67. const app = createSSRApp(App);
  68. return {
  69. app,
  70. };
  71. }
  72. // #endif