Browse Source

新增token过期登录提示

dev
马远东 2 days ago
parent
commit
62a6585027
  1. 15
      src/axios.js
  2. 10
      src/views/distribution/deliverylist/distributionDeliveryList.vue
  3. 11
      src/views/distribution/deliverylist/distributionDeliveryListmar.vue

15
src/axios.js

@ -10,7 +10,7 @@ import router from '@/router/'; // Vue路由
import { serialize } from 'utils/util'; // 序列化工具函数,通常用于处理请求参数
import { getToken } from 'utils/auth'; // 用于获取存储的Token
import { isURL } from 'utils/validate'; // 验证字符串是否为URL的函数
import { ElMessage } from 'element-plus'; // Element-Plus中的消息提示组件
import { ElMessage,ElMessageBox } from 'element-plus'; // Element-Plus中的消息提示组件
import website from '@/config/website'; // 站点配置文件,可以配置一些通用信息如clientId、clientSecret
import NProgress from 'nprogress'; // 页面顶部进度条
import 'nprogress/nprogress.css'; // 进度条样式
@ -19,6 +19,7 @@ import { baseUrl } from '@/config/env'; // API基础URL
import crypto from '@/utils/crypto'; // 加密工具,可能用于加密Token等
import {ref} from 'vue';
let msg = ref(''); // 错误信息
let isAlertShowing = false; // 新增的标志变量
// 存储待取消的HTTP请求的键值对,用于取消重复的请求
const pendingRequests = new Map();
@ -135,7 +136,17 @@ axios.interceptors.response.use(
if (statusWhiteList.includes(status)) return Promise.reject(res);
// 如果状态码为401,则表示用户未认证,需跳转到登录页
if (status === 401) store.dispatch('FedLogOut').then(() => router.push({ path: '/login' }));
if (status === 401 && !isAlertShowing){
isAlertShowing = true; // 设置为 true 表示弹窗正在显示
ElMessageBox.alert('长时间未操作,登录已过期,请重新登录', '提示', {
confirmButtonText: '确定',
callback: (action) => {
isAlertShowing = false; // 恢复为 false 表示弹窗已经关闭
store.dispatch('FedLogOut').then(() => router.push({ path: '/login' }));
},
});
}
// 如果response的状态码不是200,则显示消息提示,并返回Promise的reject状态
if (status !== 200 && status !== '0' && status !== '1') {

10
src/views/distribution/deliverylist/distributionDeliveryList.vue

@ -1009,9 +1009,17 @@ export default {
this.title = '查看';
this.view = true;
this.box = true;
getDetail(row.id).then(res => {
if(row.id){
getDetail(row.id).then(res => {
this.form = res.data.data;
});
}else{
ElMessage({
message: '数据错误,刷新页面重新尝试',
type: 'warning',
})
}
},
handleViewBlank(row) {
this.$router.push({

11
src/views/distribution/deliverylist/distributionDeliveryListmar.vue

@ -697,9 +697,18 @@ export default {
this.title = '查看';
this.view = true;
this.box = true;
getDetail(row.id).then(res => {
if(row.id){
getDetail(row.id).then(res => {
this.form = res.data.data;
});
}else{
ElMessage({
message: '数据错误,刷新页面重新尝试',
type: 'warning',
})
}
},
// handleViewBlank (row) {
// this.$router.push({

Loading…
Cancel
Save