From 66606bcaec289280f682ccfde84bf3e91bad96fe Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Fri, 20 Jun 2025 17:13:01 +0800 Subject: [PATCH] refactor: add application access --- ui/src/api/application/application.ts | 43 ++++++++++++++++--- .../views/application/ApplicationAccess.vue | 14 +++--- .../component/AccessSettingDrawer.vue | 12 +++--- 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/ui/src/api/application/application.ts b/ui/src/api/application/application.ts index 8811cf5e4..dd1daadc6 100644 --- a/ui/src/api/application/application.ts +++ b/ui/src/api/application/application.ts @@ -1,14 +1,14 @@ -import { Result } from '@/request/Result' -import { get, post, postStream, del, put, request, download, exportFile } from '@/request/index' -import type { pageRequest } from '@/api/type/common' -import type { ApplicationFormType } from '@/api/type/application' -import { type Ref } from 'vue' +import {Result} from '@/request/Result' +import {get, post, postStream, del, put, request, download, exportFile} from '@/request/index' +import type {pageRequest} from '@/api/type/common' +import type {ApplicationFormType} from '@/api/type/application' +import {type Ref} from 'vue' import useStore from '@/stores' -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' }, }) @@ -187,6 +187,32 @@ const chat: (chat_id: string, data: any) => Promise = (chat_id, data) => { const getChatUserAuthType: (loading?: Ref) => Promise = (loading) => { return get(`/chat_user/auth/types`, {}, loading) } + +/** + * 获取平台状态 + */ +const getPlatformStatus: (application_id: string) => Promise> = (application_id) => { + return get(`${prefix.value}/${application_id}/platform/status`) +} +/** + * 更新平台状态 + */ +const updatePlatformStatus: (application_id: string, data: any) => Promise> = ( + application_id, + data +) => { + return post(`${prefix.value}/${application_id}/platform/status`, data) +} +/** + * 获取平台配置 + */ +const getPlatformConfig: (application_id: string, type: string) => Promise> = ( + application_id, + type +) => { + return get(`${prefix.value}/${application_id}/platform/${type}`) +} + export default { getAllApplication, getApplication, @@ -203,4 +229,7 @@ export default { chat, getChatUserAuthType, getApplicationSetting, + getPlatformStatus, + updatePlatformStatus, + getPlatformConfig } diff --git a/ui/src/views/application/ApplicationAccess.vue b/ui/src/views/application/ApplicationAccess.vue index f6c9784f8..a30182854 100644 --- a/ui/src/views/application/ApplicationAccess.vue +++ b/ui/src/views/application/ApplicationAccess.vue @@ -116,13 +116,13 @@ function refresh() { function getPlatformStatus() { loading.value = true - // applicationApi.getPlatformStatus(id).then((res: any) => { - // platforms.forEach((platform) => { - // platform.isActive = res.data[platform.key][1] - // platform.exists = res.data[platform.key][0] - // }) - // loading.value = false - // }) + applicationApi.getPlatformStatus(id).then((res: any) => { + platforms.forEach((platform) => { + platform.isActive = res.data[platform.key][1] + platform.exists = res.data[platform.key][0] + }) + loading.value = false + }) } function changeStatus(type: string, value: boolean) { diff --git a/ui/src/views/application/component/AccessSettingDrawer.vue b/ui/src/views/application/component/AccessSettingDrawer.vue index 64a89a101..72206e219 100644 --- a/ui/src/views/application/component/AccessSettingDrawer.vue +++ b/ui/src/views/application/component/AccessSettingDrawer.vue @@ -383,16 +383,16 @@ const open = async (id: string, type: PlatformType) => { dataLoaded.value = false formRef.value?.resetFields() try { - // const res = await applicationApi.getPlatformConfig(id, type) - // if (res.data) { - // form[configType.value] = res.data - // } - // dataLoaded.value = true + const res = await applicationApi.getPlatformConfig(id, type) + if (res.data) { + form[configType.value] = res.data + } + dataLoaded.value = true } catch { MsgError(t('views.application.tip.loadingErrorMessage')) } finally { loading.value = false - form[configType.value].callback_url = `${window.location.origin}/api/${type}/${id}` + form[configType.value].callback_url = `${window.location.origin}/api/chat/${type}/${id}` } }