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. 10
      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 {
playToText: string; playToText: string;
onlineRingtone: string; onlineRingtone: string;
offlineRingtone: string; offlineRingtone: string;
[key:string]: string; [key:string]: any;
} }
export type PushTypeResult = R<PushType[]>; export type PushTypeResult = R<PushType[]>;

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

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

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

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

2
src/store/modules/lock.ts

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

17
src/store/modules/user.ts

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

10
src/utils/index.ts

@ -10,7 +10,7 @@ import type { RouteLocationNormalized, RouteRecordNormalized } from 'vue-router'
import type {App, Component} from 'vue'; import type {App, Component} from 'vue';
import {unref} from 'vue'; import {unref} from 'vue';
import {isObject, isUrl} from '/@/utils/is'; import {isObject, isUrl} from '/@/utils/is';
import { isEmpty, cloneDeep } from 'lodash-es'; import {cloneDeep, isEmpty} from 'lodash-es';
import {isDevMode} from '/@/utils/env'; import {isDevMode} from '/@/utils/env';
import {useGlobSetting} from '/@/hooks/setting'; import {useGlobSetting} from '/@/hooks/setting';
@ -134,11 +134,11 @@ export const findListNameById = (id: string, list: any[], options: Partial<{ idF
return ''; return '';
}; };
/** 获取后端微服务代理地址 */ /** 获取后端微服务代理地址 */
export function getCloudProxyUrl(): string { export function getCloudProxyUrl(): string {
let baseUrl = `${window.location.origin}${apiUrl}`; let baseUrl = `${window.location.origin}${apiUrl}`;
if (isDevMode()) { if (isDevMode()) {
// 开发环境支持公网地址,确保开发环境下支持多人共享文件预览
const proxy: [string[]] = JSON.parse(import.meta.env.VITE_PROXY); const proxy: [string[]] = JSON.parse(import.meta.env.VITE_PROXY);
const api = proxy.find(item => item[0] == apiUrl) || []; const api = proxy.find(item => item[0] == apiUrl) || [];
baseUrl = api[1]; baseUrl = api[1];
@ -148,3 +148,9 @@ export function getCloudProxyUrl(): string {
/** 获取OSS代理地址 */ /** 获取OSS代理地址 */
export const getOSSProxyUrl = (url: string) => isUrl(url) ? url : `${apiUrl}${url}`; 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[] = [
ellipsis: true, ellipsis: true,
width: 380, width: 380,
customRender: ({ record }) => { customRender: ({ record }) => {
//debugger
console.log(`${getCloudProxyUrl()}${Api.get}/${record.bucketName}/${record.fileName}`)
const url = encodeURL(`${getCloudProxyUrl()}${Api.get}/${record.bucketName}/${record.fileName}`); const url = encodeURL(`${getCloudProxyUrl()}${Api.get}/${record.bucketName}/${record.fileName}`);
return h(Button, { return h(Button, {
type: 'link', type: 'link',

Loading…
Cancel
Save