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 @@ @@ -5,8 +5,8 @@
export interface LoginParams {
username: string;
password: string;
realKey: string;
code: string;
realKey?: string;
code?: string;
}
export interface UserInfo {

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

@ -2,6 +2,7 @@ import {defHttp} from '/@/utils/http/axios'; @@ -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 { @@ -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) { @@ -38,7 +36,7 @@ export function loginApi(params: LoginParams) {
},
params: { code, realKey, grant_type, scope },
data: data
});
}, <RequestOptions>options);
}
/**

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

@ -48,14 +48,13 @@ export const useLockStore = defineStore({ @@ -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;

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

@ -98,10 +98,14 @@ export const useUserStore = defineStore({ @@ -98,10 +98,14 @@ export const useUserStore = defineStore({
this.permissions = [];
},
/** 登录 */
async login(params: LoginParams & { goHome?: boolean; }): Promise<GetUserInfoModel | null> {
async login(params: LoginParams & { goHome?: boolean; unLock?: boolean; }): Promise<GetUserInfoModel | null> {
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);

9
kicc-ui/src/utils/http/axios/axiosTransform.ts

@ -19,7 +19,7 @@ export abstract class AxiosTransform { @@ -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 { @@ -34,15 +34,12 @@ export abstract class AxiosTransform {
/**
*
*/
requestInterceptors?: (
config: AxiosRequestConfig,
options: CreateAxiosOptions
) => AxiosRequestConfig;
requestInterceptors?: (config: CreateAxiosOptions, options: CreateAxiosOptions) => CreateAxiosOptions;
/**
*
*/
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 = { @@ -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 = { @@ -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;
},

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

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

Loading…
Cancel
Save