瀏覽代碼

feat: 优化报错提示

linwenxin 1 年之前
父節點
當前提交
abbca5bed3
共有 2 個文件被更改,包括 15 次插入18 次删除
  1. 11 14
      src/common/http/index.js
  2. 4 4
      src/mixins/index.js

+ 11 - 14
src/common/http/index.js

@@ -3,6 +3,11 @@ import {
   platform
 } from '../utils/index';
 import store from '@/store/index.js'
+
+import {
+  goLoginPage
+} from "@/mixins/index.js"
+
 const program = {
   H5: "wap",
   APP: "app",
@@ -33,25 +38,17 @@ export const $http = (url, method, data, json) => {
     uni.hideLoading()
     const res = response.data;
     if (whiteCodes.indexOf(res.code) < 0) {
+      if (res.code === 1001) {
+        goLoginPage()
+        return {}
+      }
+
       uni.showToast({
         title: res.message || 'Error',
         icon: 'none',
         duration: 1500
       })
 
-      if (res.code === 1001 || res.code === 7777 || res.code === 8888) {
-
-        // return response.data = await doRequest(response, url)//动态刷新token,并重新完成request请求
-        // store.dispatch('user/resetToken').then(() => {
-        //   uni.navigateTo({
-        //     url: '/pages/login/indexs'
-        //   })
-        // })
-
-        // uni.navigateTo({
-        //   url: '/pages/login/indexs'
-        // })
-      }
       return Promise.reject(new Error(res.message || 'Error'))
     } else {
       return res
@@ -129,4 +126,4 @@ export default {
   post,
   put,
   del
-}
+}

+ 4 - 4
src/mixins/index.js

@@ -14,14 +14,14 @@ import store from '@/store/index.js'
 import wx from 'weixin-js-sdk'
 // #endif
 
-// #ifdef MP-WEIXIN
 // 微信小程序页面劫持
-var goLoginPage = (new firstPerform(1000)).refactor(function() {
+export const goLoginPage = (new firstPerform(1000)).refactor(function() {
   navToPage({
     url: "/pages/login/indexs"
   }, "redirectTo")
 });
-var routerBeforeEach = (new firstPerform(200)).refactor(function() {
+// #ifdef MP-WEIXIN
+export const routerBeforeEach = (new firstPerform(200)).refactor(function() {
   function getrouter() {
     let routes = getCurrentPages();
     if (routes.length) {
@@ -42,7 +42,7 @@ var routerBeforeEach = (new firstPerform(200)).refactor(function() {
 });
 // #endif
 
-var updatePageLay = (new firstPerform(1000)).refactor(function() {
+const updatePageLay = (new firstPerform(1000)).refactor(function() {
   // 去除顶部
   var uni_page_head = document.querySelector("uni-page-head[uni-page-head-type='default']")
   if (uni_page_head) {