diff --git a/kicc-ui/src/api/sys/user.ts b/kicc-ui/src/api/sys/user.ts index 52f6b0ab..a0bce66e 100644 --- a/kicc-ui/src/api/sys/user.ts +++ b/kicc-ui/src/api/sys/user.ts @@ -21,7 +21,7 @@ enum Api { /** * @description: user login api */ -export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') { +export function loginApi(params: LoginParams) { // 非对称密钥ASE加密处理 const user = encryptionLogin({ @@ -38,18 +38,14 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') const scope = 'server'; const data = qs.stringify({'username': username, 'password': password}); - return defHttp.post( - { - url: Api.Login, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' - }, - params: { code, realKey, grant_type, scope }, - data: data - }, { - errorMessageMode: mode - } - ); + return defHttp.post({ + url: Api.Login, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' + }, + params: { code, realKey, grant_type, scope }, + data: data + }); } /** diff --git a/kicc-ui/src/store/modules/user.ts b/kicc-ui/src/store/modules/user.ts index 6208b8a2..55165176 100644 --- a/kicc-ui/src/store/modules/user.ts +++ b/kicc-ui/src/store/modules/user.ts @@ -6,7 +6,6 @@ */ import type { UserInfo } from '/#/store'; -import type { ErrorMessageMode } from '/#/axios'; import { defineStore } from 'pinia'; import { store } from '/@/store'; import { PageEnum } from '/@/enums/pageEnum'; @@ -75,13 +74,10 @@ export const useUserStore = defineStore({ /** * 登录 */ - async login(params: LoginParams & { - goHome?: boolean; - mode?: ErrorMessageMode; - }): Promise { + async login(params: LoginParams & { goHome?: boolean; }): Promise { try { - const { goHome = true, mode, ...loginParams } = params; - const data = await loginApi(loginParams, mode); + const { goHome = true, ...loginParams } = params; + const data = await loginApi(loginParams); const { accessToken } = data; // 保存令牌 diff --git a/kicc-ui/src/utils/http/axios/checkStatus.ts b/kicc-ui/src/utils/http/axios/checkStatus.ts index 312d22fe..0a65f222 100644 --- a/kicc-ui/src/utils/http/axios/checkStatus.ts +++ b/kicc-ui/src/utils/http/axios/checkStatus.ts @@ -80,8 +80,6 @@ export function checkStatus(status: number, msg: string, errorMessageMode: Error case 505: errMessage = t('sys.api.errMsg505'); break; - default: - errMessage = t('sys.api.errMsgDefault'); } if (errMessage) { diff --git a/kicc-ui/src/utils/http/axios/index.ts b/kicc-ui/src/utils/http/axios/index.ts index 3c643972..6281fa89 100644 --- a/kicc-ui/src/utils/http/axios/index.ts +++ b/kicc-ui/src/utils/http/axios/index.ts @@ -133,7 +133,7 @@ const transform: AxiosTransform = { const { t } = useI18n(); const { response, code, message, config } = error || {}; const errorMessageMode = config?.requestOptions?.errorMessageMode || 'none'; - const err: string = response.data.msg?.toString?.() ?? ''; + const err: string = response?.data?.msg?.toString?.() ?? ''; let errMessage = err; // 优先使用预设错误提示 const status = error?.response?.status || 200; @@ -142,9 +142,11 @@ const transform: AxiosTransform = { // 扩展预设异常处理 if (code === 'ECONNABORTED' && message.indexOf('timeout') !== -1) { errMessage = t('sys.api.apiTimeoutMessage'); - } - if (err?.includes('Network Error')) { + } else if (err?.includes('Network Error')) { errMessage = t('sys.api.networkExceptionMsg'); + // 扩展默认消息,如果都状态码都匹配不到,并且不想获取服务器错误消息,最终会进入到默认错误提示消息 + } else if (errorMessageMode !== 'none') { + errMessage = t('sys.api.errMsgDefault'); } if (errMessage) { if (errorMessageMode === 'modal') { @@ -169,13 +171,9 @@ function createAxios(opt?: Partial) { // 其他方案: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes authenticationScheme: '', timeout: 10 * 1000, - // 基础接口地址 - // baseURL: globSetting.apiUrl, // 接口可能会有通用的地址部分,可以统一抽取出来 urlPrefix: urlPrefix, headers: { 'Content-Type': ContentTypeEnum.JSON }, - // 如果是form-data格式 - // headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED }, // 数据处理方式 transform, // 配置项,下面的选项都可以在独立的接口请求中覆盖 diff --git a/kicc-ui/src/views/sys/login/LoginForm.vue b/kicc-ui/src/views/sys/login/LoginForm.vue index 514385d0..af0eb6ab 100644 --- a/kicc-ui/src/views/sys/login/LoginForm.vue +++ b/kicc-ui/src/views/sys/login/LoginForm.vue @@ -37,7 +37,6 @@ - @@ -56,14 +55,10 @@ - - @@ -82,9 +77,7 @@ }} - {{ t('sys.login.otherSignIn') }} -
@@ -139,13 +132,17 @@ const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN); - async function getCode() { - const codeModel = await getCaptcha(); - codeUrl.value = codeModel.img ?? captchaDefImg; - formData.realKey = codeModel.realKey; + function getCode() { + getCaptcha().then(codeModel =>{ + codeUrl.value = codeModel.img ?? captchaDefImg; + formData.realKey = codeModel.realKey; + }).catch(() => { + codeUrl.value = captchaDefImg; + }); } async function handleLogin() { + debugger const data = await validForm(); if (!data) return; try { @@ -156,8 +153,6 @@ username: data.account, realKey: data.realKey, code: data.code, - // 不要默认的错误提示 - mode: 'none', }) ); if (userInfo) { @@ -167,12 +162,6 @@ duration: 3, }); } - } catch (error) { - createErrorModal({ - title: t('sys.api.errorTip'), - content: String(error) || t('sys.api.networkExceptionMsg'), - getContainer: () => document.body.querySelector(`.${prefixCls}`) || document.body, - }); } finally { loading.value = false; }