Browse Source

⚗ 修改用户登录

master
wangxiang 3 years ago
parent
commit
2cd774dc15
  1. 10
      kicc-ui/src/api/sys/user.ts
  2. 10
      kicc-ui/src/store/modules/user.ts
  3. 2
      kicc-ui/src/utils/http/axios/checkStatus.ts
  4. 12
      kicc-ui/src/utils/http/axios/index.ts
  5. 23
      kicc-ui/src/views/sys/login/LoginForm.vue

10
kicc-ui/src/api/sys/user.ts

@ -21,7 +21,7 @@ enum Api { @@ -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') @@ -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<LoginResultModel>(
{
return defHttp.post<LoginResultModel>({
url: Api.Login,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
},
params: { code, realKey, grant_type, scope },
data: data
}, {
errorMessageMode: mode
}
);
});
}
/**

10
kicc-ui/src/store/modules/user.ts

@ -6,7 +6,6 @@ @@ -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({ @@ -75,13 +74,10 @@ export const useUserStore = defineStore({
/**
*
*/
async login(params: LoginParams & {
goHome?: boolean;
mode?: ErrorMessageMode;
}): Promise<GetUserInfoModel | null> {
async login(params: LoginParams & { goHome?: boolean; }): Promise<GetUserInfoModel | null> {
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;
// 保存令牌

2
kicc-ui/src/utils/http/axios/checkStatus.ts

@ -80,8 +80,6 @@ export function checkStatus(status: number, msg: string, errorMessageMode: Error @@ -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) {

12
kicc-ui/src/utils/http/axios/index.ts

@ -133,7 +133,7 @@ const transform: AxiosTransform = { @@ -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 = { @@ -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<CreateAxiosOptions>) { @@ -169,13 +171,9 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
// 其他方案: 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,
// 配置项,下面的选项都可以在独立的接口请求中覆盖

23
kicc-ui/src/views/sys/login/LoginForm.vue

@ -37,7 +37,6 @@ @@ -37,7 +37,6 @@
<img :src="codeUrl" @click="getCode" />
</ACol>
</ARow>
<ARow class="enter-x">
<ACol :span="12">
<FormItem>
@ -56,14 +55,10 @@ @@ -56,14 +55,10 @@
</FormItem>
</ACol>
</ARow>
<FormItem class="enter-x">
<Button type="primary" size="large" block @click="handleLogin" :loading="loading">{{
t('sys.login.loginButton')
}}</Button>
<!-- <Button size="large" class="mt-4 enter-x" block @click="handleRegister">
{{ t('sys.login.registerButton') }}
</Button>-->
</FormItem>
<ARow class="enter-x">
<ACol :md="8" :xs="24">
@ -82,9 +77,7 @@ @@ -82,9 +77,7 @@
}}</Button>
</ACol>
</ARow>
<Divider class="enter-x">{{ t('sys.login.otherSignIn') }}</Divider>
<div class="flex justify-evenly enter-x" :class="`${prefixCls}-sign-in-way`">
<GithubFilled />
<WechatFilled />
@ -139,13 +132,17 @@ @@ -139,13 +132,17 @@
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN);
async function getCode() {
const codeModel = await getCaptcha();
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 @@ @@ -156,8 +153,6 @@
username: data.account,
realKey: data.realKey,
code: data.code,
//
mode: 'none',
})
);
if (userInfo) {
@ -167,12 +162,6 @@ @@ -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;
}

Loading…
Cancel
Save