Browse Source

👣 完成锁屏功能

master
wangxiang 3 years ago
parent
commit
45e9b8f4c9
  1. 4
      kicc-ui/src/api/controller/sys/model/userModel.ts
  2. 10
      kicc-ui/src/api/controller/sys/user.ts
  3. 7
      kicc-ui/src/store/modules/lock.ts
  4. 10
      kicc-ui/src/store/modules/user.ts
  5. 9
      kicc-ui/src/utils/http/axios/axiosTransform.ts
  6. 4
      kicc-ui/src/utils/http/axios/index.ts
  7. 4
      kicc-ui/types/axios.d.ts

4
kicc-ui/src/api/controller/sys/model/userModel.ts

@ -5,8 +5,8 @@
export interface LoginParams { export interface LoginParams {
username: string; username: string;
password: string; password: string;
realKey: string; realKey?: string;
code: string; code?: string;
} }
export interface UserInfo { export interface UserInfo {

10
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 {GetCaptchaModel, GetUserInfoModel, LoginParams, LoginResultModel,} from './model/userModel';
import {encryptionLogin} from '/@/utils/cipher'; import {encryptionLogin} from '/@/utils/cipher';
import qs from 'qs'; import qs from 'qs';
import {RequestOptions} from "/#/axios";
enum Api { enum Api {
Login = '/auth_proxy/oauth/token', Login = '/auth_proxy/oauth/token',
@ -11,11 +12,8 @@ enum Api {
GetCaptcha = '/code', GetCaptcha = '/code',
} }
/** /** 用户登录接口 */
* @description: user login api export function loginApi(params: LoginParams, options?: boolean | RequestOptions) {
*/
export function loginApi(params: LoginParams) {
// 非对称密钥ASE加密处理 // 非对称密钥ASE加密处理
const user = encryptionLogin({ const user = encryptionLogin({
data: params, data: params,
@ -38,7 +36,7 @@ export function loginApi(params: LoginParams) {
}, },
params: { code, realKey, grant_type, scope }, params: { code, realKey, grant_type, scope },
data: data data: data
}); }, <RequestOptions>options);
} }
/** /**

7
kicc-ui/src/store/modules/lock.ts

@ -48,14 +48,13 @@ export const useLockStore = defineStore({
const tryLogin = async () => { const tryLogin = async () => {
try { try {
const username = userStore.getUserInfo.userName; const username = userStore.getUserInfo.userName;
userStore.setAccessToken('');
userStore.setRefreshToken('');
const res = await userStore.login({ const res = await userStore.login({
username, username,
password: password!, password: password!,
goHome: false, goHome: false,
unLock: true
// todo: 锁屏解锁登录,需要验证码,后期完善
realKey: '',
code: '',
}); });
if (res) this.resetLockInfo(); if (res) this.resetLockInfo();
return res; return res;

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

@ -98,10 +98,14 @@ export const useUserStore = defineStore({
this.permissions = []; this.permissions = [];
}, },
/** 登录 */ /** 登录 */
async login(params: LoginParams & { goHome?: boolean; }): Promise<GetUserInfoModel | null> { async login(params: LoginParams & { goHome?: boolean; unLock?: boolean; }): Promise<GetUserInfoModel | null> {
try { try {
const { goHome = true, ...loginParams } = params; const { goHome = true, unLock = false, ...loginParams } = params;
const data = await loginApi(loginParams); const data = await loginApi(loginParams, unLock && {
// 使用微服务提供的专属客户端不需要写验证码进行登录
clientId: 'kicc_lock',
clientSecret: 'kicc_lock'
});
const { access_token, refresh_token } = data; const { access_token, refresh_token } = data;
this.setAccessToken(access_token); this.setAccessToken(access_token);
this.setRefreshToken(refresh_token); this.setRefreshToken(refresh_token);

9
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?: ( requestInterceptors?: (config: CreateAxiosOptions, options: CreateAxiosOptions) => CreateAxiosOptions;
config: AxiosRequestConfig,
options: CreateAxiosOptions
) => AxiosRequestConfig;
/** /**
* *
*/ */
responseInterceptors?: (res: AxiosResponse<any>) => AxiosResponse<any>; responseInterceptors?: (res: AxiosResponse) => AxiosResponse;
/** /**
* *

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

@ -116,6 +116,7 @@ const transform: AxiosTransform = {
// 请求之前处理config // 请求之前处理config
const token = getAccessToken(); const token = getAccessToken();
const { clientId, clientSecret } = globSetting; const { clientId, clientSecret } = globSetting;
const { clientId: customClientId, clientSecret: customClientSecret } = config.requestOptions!;
// 使用token进行请求 // 使用token进行请求
if (token && (config as Recordable)?.requestOptions?.withToken !== false) { if (token && (config as Recordable)?.requestOptions?.withToken !== false) {
(config as Recordable).headers.Authorization = options.authenticationScheme (config as Recordable).headers.Authorization = options.authenticationScheme
@ -123,7 +124,8 @@ const transform: AxiosTransform = {
: token; : token;
} else { } 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; return config;
}, },

4
kicc-ui/types/axios.d.ts vendored

@ -28,6 +28,10 @@ export interface RequestOptions {
ignoreCancelToken?: boolean; ignoreCancelToken?: boolean;
// 是否在header中发送token // 是否在header中发送token
withToken?: boolean; withToken?: boolean;
// 客户端ID
clientId?: string;
// 客户端密钥
clientSecret?: string;
} }
export interface Data<T = any> { export interface Data<T = any> {

Loading…
Cancel
Save