zhengnaiwen_citu 1 年之前
父节点
当前提交
18d3b63006
共有 3 个文件被更改,包括 16 次插入16 次删除
  1. 3 2
      src/config/axios/service.js
  2. 11 11
      src/plugins/snackbar/index.js
  3. 2 3
      src/views/login/index.vue

+ 3 - 2
src/config/axios/service.js

@@ -165,10 +165,11 @@ service.interceptors.response.use(
       if (msg === '无效的刷新令牌') {
         // hard coding:忽略这个提示,直接登出
         console.log(msg)
-      } else {
+      }
+       else {
         Snackbar.error(msg)
       }
-      return Promise.reject('error')
+      return Promise.reject(msg)
     } else {
       return data
     }

+ 11 - 11
src/plugins/snackbar/index.js

@@ -2,7 +2,7 @@ import { createApp } from 'vue'
 import ToastMessage from './message.vue'
 import vuetify from '@/plugins/vuetify'
 
-var timeId
+// var timeId
 const toastMessage  = (options)  => {
   const rootNode = document.createElement("div")
   document.querySelector('.v-application').appendChild(rootNode)
@@ -10,23 +10,23 @@ const toastMessage  = (options)  => {
   app.use(vuetify)
   app.mount(rootNode)
   const { timeout } = options || {}
-  clearTimeout(timeId)
-  timeId = setTimeout(() => {
+  // clearTimeout(timeId)
+  setTimeout(() => {
       app.unmount()
       rootNode.remove()
   }, timeout || 3000)
 }
-toastMessage.success = (message, variant) => {
-  toastMessage({ message, color: 'success', variant })
+toastMessage.success = (message, variant, timeout) => {
+  toastMessage({ message, color: 'success', variant, timeout })
 }
-toastMessage.error = (message, variant) => {
-  toastMessage({ message, color: 'error', variant })
+toastMessage.error = (message, variant, timeout) => {
+  toastMessage({ message, color: 'error', variant, timeout })
 }
-toastMessage.info = (message, variant) => {
-  toastMessage({ message, color: 'info', variant })
+toastMessage.info = (message, variant, timeout) => {
+  toastMessage({ message, color: 'info', variant, timeout })
 }
-toastMessage.warning = (message, variant) => {
-  toastMessage({ message, color: 'warning', variant })
+toastMessage.warning = (message, variant, timeout) => {
+  toastMessage({ message, color: 'warning', variant, timeout })
 }
 // 注册插件app.use()会自动执行install函数
 toastMessage.install = (app) => {

+ 2 - 3
src/views/login/index.vue

@@ -86,9 +86,8 @@ const handleLogin = async () => {
     }
     Snackbar.success('登录成功')
     router.push({ path: '/home' })
-  } catch (error) {
-    Snackbar.error(error.msg)
-  } finally {
+  }
+  finally {
     loginLoading.value = false
   }
 }