diff --git a/kicc-ui/src/api/controller/sys/model/userModel.ts b/kicc-ui/src/api/controller/sys/model/userModel.ts index a98cc8ac..36d29593 100644 --- a/kicc-ui/src/api/controller/sys/model/userModel.ts +++ b/kicc-ui/src/api/controller/sys/model/userModel.ts @@ -5,8 +5,8 @@ export interface LoginParams { username: string; password: string; - realKey: string; - code: string; + realKey?: string; + code?: string; } export interface UserInfo { diff --git a/kicc-ui/src/api/controller/sys/user.ts b/kicc-ui/src/api/controller/sys/user.ts index f862c3eb..efca2638 100644 --- a/kicc-ui/src/api/controller/sys/user.ts +++ b/kicc-ui/src/api/controller/sys/user.ts @@ -2,6 +2,7 @@ import {defHttp} from '/@/utils/http/axios'; import {GetCaptchaModel, GetUserInfoModel, LoginParams, LoginResultModel,} from './model/userModel'; import {encryptionLogin} from '/@/utils/cipher'; import qs from 'qs'; +import {RequestOptions} from "/#/axios"; enum Api { Login = '/auth_proxy/oauth/token', @@ -11,11 +12,8 @@ enum Api { GetCaptcha = '/code', } -/** - * @description: user login api - */ -export function loginApi(params: LoginParams) { - +/** 用户登录接口 */ +export function loginApi(params: LoginParams, options?: boolean | RequestOptions) { // 非对称密钥ASE加密处理 const user = encryptionLogin({ data: params, @@ -38,7 +36,7 @@ export function loginApi(params: LoginParams) { }, params: { code, realKey, grant_type, scope }, data: data - }); + }, options); } /** diff --git a/kicc-ui/src/store/modules/lock.ts b/kicc-ui/src/store/modules/lock.ts index 5ae85abc..78ae17b1 100644 --- a/kicc-ui/src/store/modules/lock.ts +++ b/kicc-ui/src/store/modules/lock.ts @@ -48,14 +48,13 @@ export const useLockStore = defineStore({ const tryLogin = async () => { try { const username = userStore.getUserInfo.userName; + userStore.setAccessToken(''); + userStore.setRefreshToken(''); const res = await userStore.login({ username, password: password!, goHome: false, - - // todo: 锁屏解锁登录,需要验证码,后期完善 - realKey: '', - code: '', + unLock: true }); if (res) this.resetLockInfo(); return res; diff --git a/kicc-ui/src/store/modules/user.ts b/kicc-ui/src/store/modules/user.ts index 7187b7ab..55cc8ea0 100644 --- a/kicc-ui/src/store/modules/user.ts +++ b/kicc-ui/src/store/modules/user.ts @@ -98,10 +98,14 @@ export const useUserStore = defineStore({ this.permissions = []; }, /** 登录 */ - async login(params: LoginParams & { goHome?: boolean; }): Promise { + async login(params: LoginParams & { goHome?: boolean; unLock?: boolean; }): Promise { try { - const { goHome = true, ...loginParams } = params; - const data = await loginApi(loginParams); + const { goHome = true, unLock = false, ...loginParams } = params; + const data = await loginApi(loginParams, unLock && { + // 使用微服务提供的专属客户端不需要写验证码进行登录 + clientId: 'kicc_lock', + clientSecret: 'kicc_lock' + }); const { access_token, refresh_token } = data; this.setAccessToken(access_token); this.setRefreshToken(refresh_token); diff --git a/kicc-ui/src/utils/http/axios/axiosTransform.ts b/kicc-ui/src/utils/http/axios/axiosTransform.ts index 71cc78cc..34ae7332 100644 --- a/kicc-ui/src/utils/http/axios/axiosTransform.ts +++ b/kicc-ui/src/utils/http/axios/axiosTransform.ts @@ -19,7 +19,7 @@ export abstract class AxiosTransform { /** * 请求前的流程配置 */ - beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig; + beforeRequestHook?: (config: CreateAxiosOptions, options: RequestOptions) => CreateAxiosOptions; /** * 请求成功处理 @@ -34,15 +34,12 @@ export abstract class AxiosTransform { /** * 请求之前的拦截器 */ - requestInterceptors?: ( - config: AxiosRequestConfig, - options: CreateAxiosOptions - ) => AxiosRequestConfig; + requestInterceptors?: (config: CreateAxiosOptions, options: CreateAxiosOptions) => CreateAxiosOptions; /** * 请求之后的拦截器 */ - responseInterceptors?: (res: AxiosResponse) => AxiosResponse; + responseInterceptors?: (res: AxiosResponse) => AxiosResponse; /** * 请求之前的拦截器错误处理 diff --git a/kicc-ui/src/utils/http/axios/index.ts b/kicc-ui/src/utils/http/axios/index.ts index 9fb280c4..7fd4150f 100644 --- a/kicc-ui/src/utils/http/axios/index.ts +++ b/kicc-ui/src/utils/http/axios/index.ts @@ -116,6 +116,7 @@ const transform: AxiosTransform = { // 请求之前处理config const token = getAccessToken(); const { clientId, clientSecret } = globSetting; + const { clientId: customClientId, clientSecret: customClientSecret } = config.requestOptions!; // 使用token进行请求 if (token && (config as Recordable)?.requestOptions?.withToken !== false) { (config as Recordable).headers.Authorization = options.authenticationScheme @@ -123,7 +124,8 @@ const transform: AxiosTransform = { : token; } else { // 使用客户端信息密钥请求 - (config as Recordable).headers.Authorization = `Basic ${Base64.encode(`${clientId}:${clientSecret}`)}`; + (config as Recordable).headers.Authorization = + `Basic ${Base64.encode(`${customClientId || clientId}:${customClientSecret || clientSecret}`)}`; } return config; }, diff --git a/kicc-ui/types/axios.d.ts b/kicc-ui/types/axios.d.ts index b3ed0fd7..72e71bb7 100644 --- a/kicc-ui/types/axios.d.ts +++ b/kicc-ui/types/axios.d.ts @@ -28,6 +28,10 @@ export interface RequestOptions { ignoreCancelToken?: boolean; // 是否在header中发送token withToken?: boolean; + // 客户端ID + clientId?: string; + // 客户端密钥 + clientSecret?: string; } export interface Data {