From f744e8b1091115ba120c98f67f1991082e8e2b30 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Fri, 25 Jul 2025 17:53:54 +0800 Subject: [PATCH] feat: add platform authentication methods and improve QR code handling --- ui/src/api/chat-user/auth-setting.ts | 24 ++++++- ui/src/api/chat/chat.ts | 48 +++++++------- ui/src/api/system/chat-user.ts | 11 +++- ui/src/stores/modules/chat-user.ts | 49 ++++++++++++-- ui/src/views/chat/user-login/index.vue | 66 ++++++++++++------- .../user-login/scanCompinents/QrCodeTab.vue | 6 +- .../scanCompinents/dingtalkQrCode.vue | 31 +++++---- .../user-login/scanCompinents/larkQrCode.vue | 19 ++++-- .../user-login/scanCompinents/wecomQrCode.vue | 11 ++-- .../authentication/component/EditModal.vue | 2 +- .../authentication/component/SCAN.vue | 4 +- .../system-chat-user/authentication/index.vue | 12 ++-- .../chat-user/component/SyncUsersDialog.vue | 33 ++++++++-- ui/src/views/system/role/index.ts | 15 +++-- 14 files changed, 231 insertions(+), 100 deletions(-) diff --git a/ui/src/api/chat-user/auth-setting.ts b/ui/src/api/chat-user/auth-setting.ts index f4f0042dc..7612dd436 100644 --- a/ui/src/api/chat-user/auth-setting.ts +++ b/ui/src/api/chat-user/auth-setting.ts @@ -31,8 +31,30 @@ const putAuthSetting: (auth_type: string, data: any, loading?: Ref) => return put(`${prefix}/${auth_type}/info`, data, undefined, loading) } +const platformPrefix = '/chat_user/auth/platform' +const getPlatformInfo: (loading?: Ref) => Promise> = (loading) => { + return get(`${platformPrefix}/source`, undefined, loading) +} + +const updateConfig: (data: any, loading?: Ref) => Promise> = ( + data, + loading +) => { + return post(`${platformPrefix}/source`, data, undefined, loading) +} + +const validateConnection: (data: any, loading?: Ref) => Promise> = ( + data, + loading +) => { + return put(`${platformPrefix}/source`, data, undefined, loading) +} + export default { getAuthSetting, postAuthSetting, - putAuthSetting + putAuthSetting, + getPlatformInfo, + updateConfig, + validateConnection } diff --git a/ui/src/api/chat/chat.ts b/ui/src/api/chat/chat.ts index 81ea72ac6..bd1e8f554 100644 --- a/ui/src/api/chat/chat.ts +++ b/ui/src/api/chat/chat.ts @@ -1,4 +1,4 @@ -import { Result } from '@/request/Result' +import {Result} from '@/request/Result' import { get, post, @@ -9,17 +9,17 @@ import { download, exportFile, } from '@/request/chat/index' -import { type ChatProfile } from '@/api/type/chat' -import { type Ref } from 'vue' -import type { ResetPasswordRequest } from '@/api/type/user.ts' +import {type ChatProfile} from '@/api/type/chat' +import {type Ref} from 'vue' +import type {ResetPasswordRequest} from '@/api/type/user.ts' import useStore from '@/stores' -import type { LoginRequest } from '@/api/type/user' +import type {LoginRequest} from '@/api/type/user' -const prefix: any = { _value: '/workspace/' } +const prefix: any = {_value: '/workspace/'} Object.defineProperty(prefix, 'value', { get: function () { - const { user } = useStore() + const {user} = useStore() return this._value + user.getWorkspaceId() + '/application' }, }) @@ -51,7 +51,7 @@ const chatProfile: (assessToken: string, loading?: Ref) => Promise { - return get('/profile', { access_token: assessToken }, loading) + return get('/profile', {access_token: assessToken}, loading) } /** * 匿名认证 @@ -63,7 +63,7 @@ const anonymousAuthentication: ( assessToken: string, loading?: Ref, ) => Promise> = (assessToken, loading) => { - return post('/auth/anonymous', { access_token: assessToken }, {}, loading) + return post('/auth/anonymous', {access_token: assessToken}, {}, loading) } /** * 密码认证 @@ -77,7 +77,7 @@ const passwordAuthentication: ( password: string, loading?: Ref, ) => Promise> = (assessToken, password, loading) => { - return post('auth/password', { access_token: assessToken, password: password }, {}, loading) + return post('auth/password', {access_token: assessToken, password: password}, {}, loading) } /** * 获取应用相关信息 @@ -122,38 +122,40 @@ const getCaptcha: (loading?: Ref) => Promise> = (loading) = * 获取二维码类型 */ const getQrType: (loading?: Ref) => Promise> = (loading) => { - return get('qr_type', undefined, loading) + return get('auth/qr_type', undefined, loading) } const getQrSource: (loading?: Ref) => Promise> = (loading) => { - return get('qr_type/source', undefined, loading) + return get('auth/qr_type/source', undefined, loading) } -const getDingCallback: (code: string, loading?: Ref) => Promise> = ( +const getDingCallback: (code: string, accessToken: string, loading?: Ref) => Promise> = ( code, + accessToken, loading, ) => { - return get('dingtalk', { code }, loading) + return get('auth/dingtalk', {code, accessToken: accessToken}, loading) } const getDingOauth2Callback: (code: string, loading?: Ref) => Promise> = ( code, loading, ) => { - return get('dingtalk/oauth2', { code }, loading) + return get('auth/dingtalk/oauth2', {code}, loading) } -const getWecomCallback: (code: string, loading?: Ref) => Promise> = ( +const getWecomCallback: (code: string, accessToken: string, loading?: Ref) => Promise> = ( code, + accessToken, loading, ) => { - return get('wecom', { code }, loading) + return get('auth/wecom', {code, accessToken: accessToken}, loading) } const getLarkCallback: (code: string, loading?: Ref) => Promise> = ( code, loading, ) => { - return get('lark/oauth2', { code }, loading) + return get('auth/lark/oauth2', {code}, loading) } /** @@ -274,17 +276,17 @@ const deleteChat: (chat_id: string, loading?: Ref) => Promise { - return del(`historical_conversation/${chat_id}`,undefined,undefined ,loading) + return del(`historical_conversation/${chat_id}`, undefined, undefined, loading) } /** - * - * @param loading - * @returns + * + * @param loading + * @returns */ const clearChat: (loading?: Ref) => Promise> = ( loading ) => { - return del(`historical_conversation/clear`,undefined,undefined, loading) + return del(`historical_conversation/clear`, undefined, undefined, loading) } /** * diff --git a/ui/src/api/system/chat-user.ts b/ui/src/api/system/chat-user.ts index c8b4c54b3..fcbf36b32 100644 --- a/ui/src/api/system/chat-user.ts +++ b/ui/src/api/system/chat-user.ts @@ -103,6 +103,14 @@ const batchSync: (sync_type: string, loading?: Ref) => Promise { return post(`${prefix}/sync/${sync_type}`, undefined, undefined, loading) } + +/** + * 获取同步类型 + */ +const getSyncType: (loading?: Ref) => Promise> = (loading) => { + return get(`${prefix}/sync_types`, undefined, loading) +} + export default { getUserManage, putUserManage, @@ -112,5 +120,6 @@ export default { getChatUserList, batchAddGroup, batchDelete, - batchSync + batchSync, + getSyncType } diff --git a/ui/src/stores/modules/chat-user.ts b/ui/src/stores/modules/chat-user.ts index e825595dc..6ee648cf2 100644 --- a/ui/src/stores/modules/chat-user.ts +++ b/ui/src/stores/modules/chat-user.ts @@ -1,14 +1,17 @@ -import { defineStore } from 'pinia' +import {defineStore} from 'pinia' import ChatAPI from '@/api/chat/chat' -import type { ChatProfile, ChatUserProfile } from '@/api/type/chat' -import type { LoginRequest } from '@/api/type/user' -import type { Ref } from 'vue' -import { getBrowserLang } from '@/locales/index' +import type {ChatProfile, ChatUserProfile} from '@/api/type/chat' +import type {LoginRequest} from '@/api/type/user' +import type {Ref} from 'vue' +import {getBrowserLang} from '@/locales/index' +import LoginApi from "@/api/user/login.ts"; +import useUserStore from "@/stores/modules/user.ts"; interface ChatUser { // 用户id id: string } + interface Chat { chat_profile?: ChatProfile application?: any @@ -16,6 +19,7 @@ interface Chat { token?: string accessToken?: string } + const useChatUserStore = defineStore('chat-user', { state: (): Chat => ({ chat_profile: undefined, @@ -111,6 +115,41 @@ const useChatUserStore = defineStore('chat-user', { return true }) }, + async dingCallback(code: string, accessToken: string) { + return ChatAPI.getDingCallback(code, accessToken).then((ok) => { + this.setToken(ok.data.token) + return this.token + }) + }, + async dingOauth2Callback(code: string) { + return ChatAPI.getDingOauth2Callback(code).then((ok) => { + this.setToken(ok.data.token) + return this.token + }) + }, + async wecomCallback(code: string, accessToken: string) { + return ChatAPI.getWecomCallback(code, accessToken).then((ok) => { + this.setToken(ok.data.token) + return this.token + }) + }, + async larkCallback(code: string) { + return ChatAPI.getLarkCallback(code).then((ok) => { + this.setToken(ok.data.token) + return this.token + }) + }, + async getQrType() { + return ChatAPI.getQrType().then((ok) => { + return ok.data + }) + }, + async getQrSource() { + return ChatAPI.getQrSource().then((ok) => { + return ok.data + }) + }, + }, }) diff --git a/ui/src/views/chat/user-login/index.vue b/ui/src/views/chat/user-login/index.vue index d074e08f7..b7571398b 100644 --- a/ui/src/views/chat/user-login/index.vue +++ b/ui/src/views/chat/user-login/index.vue @@ -10,9 +10,9 @@ class="mr-8" style="background: none" > - + - +

{{ chatUser.chat_profile?.application_name }}

@@ -29,9 +29,9 @@ class="mr-8" style="background: none" > - + - +

{{ chatUser.chat_profile?.application_name }}

@@ -104,7 +104,7 @@
- +