Browse Source

chore: 支持自定义登陆客户端

master
wangxiang 2 years ago
parent
commit
c698c8240e
No known key found for this signature in database
GPG Key ID: 1BA7946AB6B232E4
  1. 2
      src/api/platform/common/entity/pushType.ts
  2. 4
      src/api/platform/core/controller/user.ts
  3. 3
      src/api/platform/core/entity/user.ts
  4. 2
      src/store/modules/lock.ts
  5. 17
      src/store/modules/user.ts
  6. 20
      src/utils/index.ts
  7. 2
      src/views/system/file/file.data.ts

2
src/api/platform/common/entity/pushType.ts

@ -12,7 +12,7 @@ export interface PushType extends CommonEntity { @@ -12,7 +12,7 @@ export interface PushType extends CommonEntity {
playToText: string;
onlineRingtone: string;
offlineRingtone: string;
[key:string]: string;
[key:string]: any;
}
export type PushTypeResult = R<PushType[]>;

4
src/api/platform/core/controller/user.ts

@ -19,7 +19,7 @@ export enum Api { @@ -19,7 +19,7 @@ export enum Api {
}
/** 用户登录接口 */
export const login = (params: LoginParams, options?: boolean | RequestOptions) => {
export const login = (params: LoginParams) => {
// 非对称密钥AES加密处理
const user = encryptionLogin({
data: params,
@ -42,7 +42,7 @@ export const login = (params: LoginParams, options?: boolean | RequestOptions) = @@ -42,7 +42,7 @@ export const login = (params: LoginParams, options?: boolean | RequestOptions) =
},
params: { code, realKey, grant_type, scope },
data: data
}, <RequestOptions>options);
}, params?.options);
};
/** 获取当前用户信息 */

3
src/api/platform/core/entity/user.ts

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
*/
import type { CommonEntity } from '/@/api/common/data/entity';
import type { KiccUser } from '/@/api/common/base/entity';
import type { RequestOptions } from '/#/axios';
/** 登录参数对象 */
export interface LoginParams {
@ -14,6 +15,8 @@ export interface LoginParams { @@ -14,6 +15,8 @@ export interface LoginParams {
password: string;
realKey?: string;
code?: string;
clientId?: string;
options?: RequestOptions;
[key: string]: any;
}

2
src/store/modules/lock.ts

@ -54,7 +54,7 @@ export const useLockStore = defineStore({ @@ -54,7 +54,7 @@ export const useLockStore = defineStore({
username,
password: password!,
goHome: false,
unLock: true
clientId: 'kicc_lock'
});
if (res) this.resetLockInfo();
return res;

17
src/store/modules/user.ts

@ -20,8 +20,9 @@ import { RouteRecordRaw } from 'vue-router'; @@ -20,8 +20,9 @@ import { RouteRecordRaw } from 'vue-router';
import defaultAvatar from '/@/assets/images/defaultAvatar.svg';
import { urlToBase64 } from '/@/utils/file/base64Conver';
import { useGlobSetting } from '/@/hooks/setting';
import { isUrl } from '/@/utils/is';
import { isUrl, isEmpty } from '/@/utils/is';
import { h } from 'vue';
import { getAuthClient } from '/@/utils';
interface UserState {
userInfo: Nullable<User>;
@ -110,12 +111,16 @@ export const useUserStore = defineStore({ @@ -110,12 +111,16 @@ export const useUserStore = defineStore({
/** 登录 */
async login(params: LoginParams): Promise<User | null> {
try {
const { goHome = true, unLock = false, ...loginParams } = params;
const data = await login(loginParams, unLock && {
// 使用微服务提供的锁屏专属客户端不需要写验证码进行登录
clientId: 'kicc_lock',
clientSecret: 'kicc_lock'
const { goHome = true, clientId = '', ...loginParams } = params;
// 处理自定义授权客户端
if (clientId) {
const client = getAuthClient(clientId);
!isEmpty(client) && Object.assign({}, loginParams.options, {
clientId: client[0],
clientSecret: client[1]
});
}
const data = await login(loginParams);
const { access_token, refresh_token } = data;
this.setAccessToken(access_token);
this.setRefreshToken(refresh_token);

20
src/utils/index.ts

@ -6,13 +6,13 @@ @@ -6,13 +6,13 @@
* @create: 2022/4/8
*/
import type { RouteLocationNormalized, RouteRecordNormalized } from 'vue-router';
import type { App, Component } from 'vue';
import { unref } from 'vue';
import type {RouteLocationNormalized, RouteRecordNormalized} from 'vue-router';
import type {App, Component} from 'vue';
import {unref} from 'vue';
import {isObject, isUrl} from '/@/utils/is';
import { isEmpty, cloneDeep } from 'lodash-es';
import { isDevMode } from '/@/utils/env';
import { useGlobSetting } from '/@/hooks/setting';
import {cloneDeep, isEmpty} from 'lodash-es';
import {isDevMode} from '/@/utils/env';
import {useGlobSetting} from '/@/hooks/setting';
const { apiUrl } = useGlobSetting();
export const noop = () => {};
@ -134,11 +134,11 @@ export const findListNameById = (id: string, list: any[], options: Partial<{ idF @@ -134,11 +134,11 @@ export const findListNameById = (id: string, list: any[], options: Partial<{ idF
return '';
};
/** 获取后端微服务代理地址 */
export function getCloudProxyUrl(): string {
let baseUrl = `${window.location.origin}${apiUrl}`;
if (isDevMode()) {
// 开发环境支持公网地址,确保开发环境下支持多人共享文件预览
const proxy: [string[]] = JSON.parse(import.meta.env.VITE_PROXY);
const api = proxy.find(item => item[0] == apiUrl) || [];
baseUrl = api[1];
@ -148,3 +148,9 @@ export function getCloudProxyUrl(): string { @@ -148,3 +148,9 @@ export function getCloudProxyUrl(): string {
/** 获取OSS代理地址 */
export const getOSSProxyUrl = (url: string) => isUrl(url) ? url : `${apiUrl}${url}`;
/** 获取授权客户端 */
export function getAuthClient(clientId: string): string[] {
const authClient: [string[]] = JSON.parse(import.meta.env['VITE_AUTH_CLIENT']);
return authClient.find(item => item[0] == clientId) || [];
}

2
src/views/system/file/file.data.ts

@ -33,6 +33,8 @@ export const columns: BasicColumn[] = [ @@ -33,6 +33,8 @@ export const columns: BasicColumn[] = [
ellipsis: true,
width: 380,
customRender: ({ record }) => {
//debugger
console.log(`${getCloudProxyUrl()}${Api.get}/${record.bucketName}/${record.fileName}`)
const url = encodeURL(`${getCloudProxyUrl()}${Api.get}/${record.bucketName}/${record.fileName}`);
return h(Button, {
type: 'link',

Loading…
Cancel
Save