登录报错

This commit is contained in:
刘玉霞 2024-06-19 18:05:52 +08:00
parent 43c6a2c92f
commit 4b4f0a5057
2 changed files with 33 additions and 35 deletions

View File

@ -121,7 +121,7 @@ function createAxios<Data = any, T = ApiPromise<Data>>(axiosConfig: AxiosRequest
options.loading && closeLoading(options) // 关闭loading options.loading && closeLoading(options) // 关闭loading
if (response.config.responseType == 'json') { 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 (response.data.code == 409) {
// if (!window.tokenRefreshing) { // if (!window.tokenRefreshing) {
// window.tokenRefreshing = true // window.tokenRefreshing = true
@ -161,21 +161,16 @@ function createAxios<Data = any, T = ApiPromise<Data>>(axiosConfig: AxiosRequest
// if (response.data.code == 302) { // if (response.data.code == 302) {
// router.push({ path: response.data.data.routePath ?? '', name: response.data.data.routeName ?? '' }) // router.push({ path: response.data.data.routePath ?? '', name: response.data.data.routeName ?? '' })
// } // }
if (response.data.code == 400) {
let routerPath = adminBaseRoute.path // if (response.data.code == 401) {
userInfo.removeToken() let routerPath = adminBaseRoute.path
routerPath += '/login' userInfo.removeToken()
router.push({ path: routerPath }) 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内的具体逻辑就不执行了 // code不等于1, 页面then内的具体逻辑就不执行了
return Promise.reject(response.data) 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({ ElNotification({
message: response.data.msg ? response.data.msg : i18n.global.t('axios.Operation successful'), message: response.data.msg ? response.data.msg : i18n.global.t('axios.Operation successful'),
type: 'success', type: 'success',

View File

@ -52,18 +52,12 @@
</el-form-item> </el-form-item>
<el-form-item v-if="state.showCaptcha" prop="captcha"> <el-form-item v-if="state.showCaptcha" prop="captcha">
<el-space> <el-space>
<el-input <el-input ref="captchaRef" v-model="form.code" type="text" :placeholder="t('login.Please input a captcha')">
ref="captchaRef"
v-model="form.code"
type="text"
:placeholder="t('login.Please input a captcha')"
clearable
>
<template #prefix> <template #prefix>
<Icon name="fa fa-unlock-alt" class="form-item-icon" size="16" color="var(--el-input-icon-color)" /> <Icon name="fa fa-unlock-alt" class="form-item-icon" size="16" color="var(--el-input-icon-color)" />
</template> </template>
</el-input> </el-input>
<img class="captcha-img" @click.prevent="load()" :src="state.captcha" /> <img @click.prevent="load()" :src="state.captcha" />
</el-space> </el-space>
</el-form-item> </el-form-item>
<!-- <el-checkbox v-model="form.keep" :label="t('login.Hold session')" size="default"></el-checkbox> --> <!-- <el-checkbox v-model="form.keep" :label="t('login.Hold session')" size="default"></el-checkbox> -->
@ -92,6 +86,7 @@ import { onMounted, onBeforeUnmount, reactive, ref, nextTick } from 'vue'
import { getCaptchaData } from '/@/api/common' import { getCaptchaData } from '/@/api/common'
import * as pageBubble from '/@/utils/pageBubble' import * as pageBubble from '/@/utils/pageBubble'
import type { FormInstance, InputInstance } from 'element-plus' import type { FormInstance, InputInstance } from 'element-plus'
import { ElNotification } from 'element-plus'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { editDefaultLang } from '/@/lang/index' import { editDefaultLang } from '/@/lang/index'
import { useConfig } from '/@/stores/config' import { useConfig } from '/@/stores/config'
@ -133,7 +128,7 @@ const { t } = useI18n()
const rules = reactive({ const rules = reactive({
username: [buildValidatorData({ name: 'required', message: t('login.Please enter an account') }), buildValidatorData({ name: 'account' })], 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' })], 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 = () => { const focusInput = () => {
@ -189,18 +184,26 @@ const onSubmit = () => {
state.submitLoading = true state.submitLoading = true
login(form) login(form)
.then((res) => { .then((res) => {
adminInfo.dataFill({ if (res.code == 200) {
id: res.data.sysUser.id, adminInfo.dataFill({
username: res.data.sysUser.account, id: res.data.sysUser.id,
nickname: res.data.sysUser.userName, username: res.data.sysUser.account,
avatar: '', nickname: res.data.sysUser.userName,
last_login_time: '', avatar: '',
token: res.data.token, last_login_time: '',
refresh_token: '', token: res.data.token,
// superAdmin refresh_token: '',
super: false, // superAdmin
}) super: false,
router.push({ path: adminBaseRoutePath }) })
router.push({ path: adminBaseRoutePath })
} else {
ElNotification({
message: res.msg,
type: 'error',
})
load()
}
}) })
.finally(() => { .finally(() => {
state.submitLoading = false state.submitLoading = false