From c698c8240e25164ebaaf4c19bee69b7516b0eed3 Mon Sep 17 00:00:00 2001 From: wangxiang <1827945911@qq.com> Date: Fri, 11 Aug 2023 11:30:14 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=99=BB=E9=99=86=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/platform/common/entity/pushType.ts | 2 +- src/api/platform/core/controller/user.ts | 4 ++-- src/api/platform/core/entity/user.ts | 3 +++ src/store/modules/lock.ts | 2 +- src/store/modules/user.ts | 19 ++++++++++++------- src/utils/index.ts | 20 +++++++++++++------- src/views/system/file/file.data.ts | 2 ++ 7 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/api/platform/common/entity/pushType.ts b/src/api/platform/common/entity/pushType.ts index 7b2ba0e..13ee38e 100644 --- a/src/api/platform/common/entity/pushType.ts +++ b/src/api/platform/common/entity/pushType.ts @@ -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; diff --git a/src/api/platform/core/controller/user.ts b/src/api/platform/core/controller/user.ts index c87f37a..5d26a8b 100644 --- a/src/api/platform/core/controller/user.ts +++ b/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加密处理 const user = encryptionLogin({ data: params, @@ -42,7 +42,7 @@ export const login = (params: LoginParams, options?: boolean | RequestOptions) = }, params: { code, realKey, grant_type, scope }, data: data - }, options); + }, params?.options); }; /** 获取当前用户信息 */ diff --git a/src/api/platform/core/entity/user.ts b/src/api/platform/core/entity/user.ts index b990adc..fcbff0a 100644 --- a/src/api/platform/core/entity/user.ts +++ b/src/api/platform/core/entity/user.ts @@ -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 { password: string; realKey?: string; code?: string; + clientId?: string; + options?: RequestOptions; [key: string]: any; } diff --git a/src/store/modules/lock.ts b/src/store/modules/lock.ts index 1c3d59d..7ac50e9 100644 --- a/src/store/modules/lock.ts +++ b/src/store/modules/lock.ts @@ -54,7 +54,7 @@ export const useLockStore = defineStore({ username, password: password!, goHome: false, - unLock: true + clientId: 'kicc_lock' }); if (res) this.resetLockInfo(); return res; diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index e9fa8ee..15d45fd 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -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; @@ -110,12 +111,16 @@ export const useUserStore = defineStore({ /** 登录 */ async login(params: LoginParams): Promise { 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); diff --git a/src/utils/index.ts b/src/utils/index.ts index e3e600f..060e9f1 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -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 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 { /** 获取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) || []; +} diff --git a/src/views/system/file/file.data.ts b/src/views/system/file/file.data.ts index bb9f5d0..768e4dc 100644 --- a/src/views/system/file/file.data.ts +++ b/src/views/system/file/file.data.ts @@ -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',