From 4b4f0a5057d8962d8b81667cc1d31701f5328bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=8E=89=E9=9C=9E?= Date: Wed, 19 Jun 2024 18:05:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/dasadmin/src/utils/axios.ts | 23 +++++-------- ui/dasadmin/src/views/backend/login.vue | 45 +++++++++++++------------ 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/ui/dasadmin/src/utils/axios.ts b/ui/dasadmin/src/utils/axios.ts index 52bec2ed..e30c7d83 100644 --- a/ui/dasadmin/src/utils/axios.ts +++ b/ui/dasadmin/src/utils/axios.ts @@ -121,7 +121,7 @@ function createAxios>(axiosConfig: AxiosRequest options.loading && closeLoading(options) // 关闭loading if (response.config.responseType == 'json') { - if (response.data && response.data.code !== 200) { + if (response.data && response.data.code == 401) { // if (response.data.code == 409) { // if (!window.tokenRefreshing) { // window.tokenRefreshing = true @@ -161,21 +161,16 @@ function createAxios>(axiosConfig: AxiosRequest // if (response.data.code == 302) { // router.push({ path: response.data.data.routePath ?? '', name: response.data.data.routeName ?? '' }) // } - if (response.data.code == 400) { - let routerPath = adminBaseRoute.path - userInfo.removeToken() - routerPath += '/login' - router.push({ path: routerPath }) - } - if (response.data.code == 401) { - let routerPath = adminBaseRoute.path - userInfo.removeToken() - routerPath += '/login' - router.push({ path: routerPath }) - } + + // if (response.data.code == 401) { + let routerPath = adminBaseRoute.path + userInfo.removeToken() + routerPath += '/login' + router.push({ path: routerPath }) + // } // code不等于1, 页面then内的具体逻辑就不执行了 return Promise.reject(response.data) - } else if (options.showSuccessMessage && response.data && response.data.code == 1) { + } else if (options.showSuccessMessage && response.data && response.data.code == 200) { ElNotification({ message: response.data.msg ? response.data.msg : i18n.global.t('axios.Operation successful'), type: 'success', diff --git a/ui/dasadmin/src/views/backend/login.vue b/ui/dasadmin/src/views/backend/login.vue index d2d8981c..343c1f43 100644 --- a/ui/dasadmin/src/views/backend/login.vue +++ b/ui/dasadmin/src/views/backend/login.vue @@ -52,18 +52,12 @@ - + - + @@ -92,6 +86,7 @@ import { onMounted, onBeforeUnmount, reactive, ref, nextTick } from 'vue' import { getCaptchaData } from '/@/api/common' import * as pageBubble from '/@/utils/pageBubble' import type { FormInstance, InputInstance } from 'element-plus' +import { ElNotification } from 'element-plus' import { useI18n } from 'vue-i18n' import { editDefaultLang } from '/@/lang/index' import { useConfig } from '/@/stores/config' @@ -133,7 +128,7 @@ const { t } = useI18n() const rules = reactive({ username: [buildValidatorData({ name: 'required', message: t('login.Please enter an account') }), buildValidatorData({ name: 'account' })], password: [buildValidatorData({ name: 'required', message: t('login.Please input a password') }), buildValidatorData({ name: 'password' })], - code: [buildValidatorData({ name: 'required', message: t('login.Please input a captcha') }), buildValidatorData({ name: 'required' })], + code: [buildValidatorData({ name: 'required', message: t('login.Please input a captcha') })], }) const focusInput = () => { @@ -189,18 +184,26 @@ const onSubmit = () => { state.submitLoading = true login(form) .then((res) => { - adminInfo.dataFill({ - id: res.data.sysUser.id, - username: res.data.sysUser.account, - nickname: res.data.sysUser.userName, - avatar: '', - last_login_time: '', - token: res.data.token, - refresh_token: '', - // 是否是superAdmin,用于判定是否显示终端按钮等,不做任何权限判断 - super: false, - }) - router.push({ path: adminBaseRoutePath }) + if (res.code == 200) { + adminInfo.dataFill({ + id: res.data.sysUser.id, + username: res.data.sysUser.account, + nickname: res.data.sysUser.userName, + avatar: '', + last_login_time: '', + token: res.data.token, + refresh_token: '', + // 是否是superAdmin,用于判定是否显示终端按钮等,不做任何权限判断 + super: false, + }) + router.push({ path: adminBaseRoutePath }) + } else { + ElNotification({ + message: res.msg, + type: 'error', + }) + load() + } }) .finally(() => { state.submitLoading = false