From 32700aee17e3df8369738e9fc834429a097eb57e Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Mon, 3 Nov 2025 10:28:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E8=BF=87=E6=9C=9F=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E6=B6=88=E9=99=A4=E4=BB=A3=E7=A0=81=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/http/helpers.js | 57 ++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/src/utils/http/helpers.js b/src/utils/http/helpers.js index b7de8bb..0057319 100644 --- a/src/utils/http/helpers.js +++ b/src/utils/http/helpers.js @@ -10,45 +10,34 @@ import { useAuthStore } from '@/store' let isConfirming = false + +function handleAuthExpired(content, needTip) { + if (isConfirming || !needTip) + return + isConfirming = true + $dialog.confirm({ + title: '提示', + type: 'info', + content, + confirm() { + useAuthStore().logout() + window.$message?.success('已退出登录') + isConfirming = false + }, + cancel() { + isConfirming = false + }, + }) + return false +} + export function resolveResError(code, message, needTip = true) { switch (code) { case 401: - if (isConfirming || !needTip) - return - isConfirming = true - $dialog.confirm({ - title: '提示', - type: 'info', - content: '登录已过期,是否重新登录?', - confirm() { - useAuthStore().logout() - window.$message?.success('已退出登录') - isConfirming = false - }, - cancel() { - isConfirming = false - }, - }) - return false + return handleAuthExpired('登录已过期,是否重新登录?', needTip) case 11007: case 11008: - if (isConfirming || !needTip) - return - isConfirming = true - $dialog.confirm({ - title: '提示', - type: 'info', - content: `${message},是否重新登录?`, - confirm() { - useAuthStore().logout() - window.$message?.success('已退出登录') - isConfirming = false - }, - cancel() { - isConfirming = false - }, - }) - return false + return handleAuthExpired(`${message},是否重新登录?`, needTip) case 403: message = '请求被拒绝' break