2025-06-20 09:13:01 +00:00
|
|
|
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'
|
2025-06-16 04:08:09 +00:00
|
|
|
import useStore from '@/stores'
|
2025-06-03 09:29:33 +00:00
|
|
|
|
2025-06-20 09:13:01 +00:00
|
|
|
const prefix: any = {_value: '/workspace/'}
|
2025-06-16 04:08:09 +00:00
|
|
|
Object.defineProperty(prefix, 'value', {
|
|
|
|
|
get: function () {
|
2025-06-20 09:13:01 +00:00
|
|
|
const {user} = useStore()
|
2025-06-16 04:08:09 +00:00
|
|
|
return this._value + user.getWorkspaceId() + '/application'
|
|
|
|
|
},
|
|
|
|
|
})
|
2025-06-03 09:29:33 +00:00
|
|
|
/**
|
|
|
|
|
* 获取全部应用
|
|
|
|
|
* @param 参数
|
|
|
|
|
*/
|
2025-06-10 12:07:14 +00:00
|
|
|
const getAllApplication: (param?: any, loading?: Ref<boolean>) => Promise<Result<any[]>> = (
|
|
|
|
|
param,
|
|
|
|
|
loading,
|
|
|
|
|
) => {
|
2025-06-16 04:08:09 +00:00
|
|
|
return get(`${prefix.value}`, param, loading)
|
2025-06-03 09:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取分页应用
|
|
|
|
|
* param {
|
|
|
|
|
"name": "string",
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
const getApplication: (
|
|
|
|
|
page: pageRequest,
|
|
|
|
|
param: any,
|
|
|
|
|
loading?: Ref<boolean>,
|
2025-06-06 01:39:01 +00:00
|
|
|
) => Promise<Result<any>> = (page, param, loading) => {
|
2025-06-16 04:08:09 +00:00
|
|
|
return get(`${prefix.value}/${page.current_page}/${page.page_size}`, param, loading)
|
2025-06-03 09:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建应用
|
|
|
|
|
* @param 参数
|
|
|
|
|
*/
|
|
|
|
|
const postApplication: (
|
|
|
|
|
data: ApplicationFormType,
|
|
|
|
|
loading?: Ref<boolean>,
|
2025-06-06 01:39:01 +00:00
|
|
|
) => Promise<Result<any>> = (data, loading) => {
|
2025-06-16 04:08:09 +00:00
|
|
|
return post(`${prefix.value}`, data, undefined, loading)
|
2025-06-03 09:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改应用
|
|
|
|
|
* @param 参数
|
|
|
|
|
*/
|
|
|
|
|
const putApplication: (
|
2025-06-06 04:31:30 +00:00
|
|
|
application_id: string,
|
2025-06-03 09:29:33 +00:00
|
|
|
data: ApplicationFormType,
|
|
|
|
|
loading?: Ref<boolean>,
|
|
|
|
|
) => Promise<Result<any>> = (application_id, data, loading) => {
|
2025-06-16 04:08:09 +00:00
|
|
|
return put(`${prefix.value}/${application_id}`, data, undefined, loading)
|
2025-06-03 09:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除应用
|
|
|
|
|
* @param 参数 application_id
|
|
|
|
|
*/
|
|
|
|
|
const delApplication: (
|
2025-06-06 04:31:30 +00:00
|
|
|
application_id: string,
|
2025-06-03 09:29:33 +00:00
|
|
|
loading?: Ref<boolean>,
|
|
|
|
|
) => Promise<Result<boolean>> = (application_id, loading) => {
|
2025-06-16 04:08:09 +00:00
|
|
|
return del(`${prefix.value}/${application_id}`, undefined, {}, loading)
|
2025-06-03 09:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 应用详情
|
|
|
|
|
* @param 参数 application_id
|
|
|
|
|
*/
|
|
|
|
|
const getApplicationDetail: (
|
|
|
|
|
application_id: string,
|
|
|
|
|
loading?: Ref<boolean>,
|
|
|
|
|
) => Promise<Result<any>> = (application_id, loading) => {
|
2025-06-16 04:08:09 +00:00
|
|
|
return get(`${prefix.value}/${application_id}`, undefined, loading)
|
2025-06-03 09:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取AccessToken
|
|
|
|
|
* @param 参数 application_id
|
|
|
|
|
*/
|
|
|
|
|
const getAccessToken: (application_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
|
|
|
|
application_id,
|
|
|
|
|
loading,
|
|
|
|
|
) => {
|
2025-06-16 04:08:09 +00:00
|
|
|
return get(`${prefix.value}/${application_id}/access_token`, undefined, loading)
|
2025-06-03 09:29:33 +00:00
|
|
|
}
|
2025-06-19 09:25:46 +00:00
|
|
|
/**
|
|
|
|
|
* 获取应用设置
|
|
|
|
|
* @param application_id 应用id
|
|
|
|
|
* @param loading 加载器
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
const getApplicationSetting: (
|
|
|
|
|
application_id: string,
|
|
|
|
|
loading?: Ref<boolean>,
|
|
|
|
|
) => Promise<Result<any>> = (application_id, loading) => {
|
|
|
|
|
return get(`${prefix.value}/${application_id}/setting`, undefined, loading)
|
|
|
|
|
}
|
2025-06-03 09:29:33 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改AccessToken
|
|
|
|
|
* @param 参数 application_id
|
|
|
|
|
* data {
|
|
|
|
|
* "is_active": true
|
|
|
|
|
* }
|
|
|
|
|
*/
|
|
|
|
|
const putAccessToken: (
|
|
|
|
|
application_id: string,
|
|
|
|
|
data: any,
|
|
|
|
|
loading?: Ref<boolean>,
|
|
|
|
|
) => Promise<Result<any>> = (application_id, data, loading) => {
|
2025-06-16 04:08:09 +00:00
|
|
|
return put(`${prefix.value}/${application_id}/access_token`, data, undefined, loading)
|
2025-06-03 09:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-06-10 12:07:14 +00:00
|
|
|
* 导出应用
|
2025-06-03 09:29:33 +00:00
|
|
|
*/
|
|
|
|
|
|
2025-06-10 12:07:14 +00:00
|
|
|
const exportApplication = (
|
2025-06-03 09:29:33 +00:00
|
|
|
application_id: string,
|
2025-06-10 12:07:14 +00:00
|
|
|
application_name: string,
|
2025-06-03 09:29:33 +00:00
|
|
|
loading?: Ref<boolean>,
|
2025-06-10 12:07:14 +00:00
|
|
|
) => {
|
|
|
|
|
return exportFile(
|
|
|
|
|
application_name + '.mk',
|
2025-06-16 04:08:09 +00:00
|
|
|
`${prefix.value}/${application_id}/export`,
|
2025-06-03 09:29:33 +00:00
|
|
|
undefined,
|
|
|
|
|
loading,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-06-10 12:07:14 +00:00
|
|
|
* 导入应用
|
2025-06-03 09:29:33 +00:00
|
|
|
*/
|
2025-06-10 12:07:14 +00:00
|
|
|
const importApplication: (data: any, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
2025-06-03 09:29:33 +00:00
|
|
|
data,
|
|
|
|
|
loading,
|
|
|
|
|
) => {
|
2025-06-16 04:08:09 +00:00
|
|
|
return post(`${prefix.value}/import`, data, undefined, loading)
|
2025-06-03 09:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-06-10 12:07:14 +00:00
|
|
|
* 统计
|
|
|
|
|
* @param 参数 application_id, data
|
2025-06-03 09:29:33 +00:00
|
|
|
*/
|
2025-06-10 12:07:14 +00:00
|
|
|
const getStatistics: (
|
2025-06-06 04:31:30 +00:00
|
|
|
application_id: string,
|
2025-06-03 09:29:33 +00:00
|
|
|
data: any,
|
|
|
|
|
loading?: Ref<boolean>,
|
|
|
|
|
) => Promise<Result<any>> = (application_id, data, loading) => {
|
2025-06-16 04:08:09 +00:00
|
|
|
return get(`${prefix.value}/${application_id}/application_stats`, data, loading)
|
2025-06-03 09:29:33 +00:00
|
|
|
}
|
2025-06-12 12:07:31 +00:00
|
|
|
/**
|
|
|
|
|
* 打开调试对话id
|
|
|
|
|
* @param application_id 应用id
|
|
|
|
|
* @param loading 加载器
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
const open: (application_id: string, loading?: Ref<boolean>) => Promise<Result<string>> = (
|
|
|
|
|
application_id,
|
|
|
|
|
loading,
|
|
|
|
|
) => {
|
2025-06-16 04:08:09 +00:00
|
|
|
return get(`${prefix.value}/${application_id}/open`, {}, loading)
|
2025-06-12 12:07:31 +00:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 对话
|
|
|
|
|
* @param 参数
|
|
|
|
|
* chat_id: string
|
|
|
|
|
* data
|
|
|
|
|
*/
|
|
|
|
|
const chat: (chat_id: string, data: any) => Promise<any> = (chat_id, data) => {
|
|
|
|
|
return postStream(`/api/chat_message/${chat_id}`, data)
|
|
|
|
|
}
|
2025-06-19 09:25:46 +00:00
|
|
|
/**
|
|
|
|
|
* 获取对话用户认证类型
|
|
|
|
|
* @param loading 加载器
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
const getChatUserAuthType: (loading?: Ref<boolean>) => Promise<any> = (loading) => {
|
|
|
|
|
return get(`/chat_user/auth/types`, {}, loading)
|
|
|
|
|
}
|
2025-06-20 09:13:01 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取平台状态
|
|
|
|
|
*/
|
|
|
|
|
const getPlatformStatus: (application_id: string) => Promise<Result<any>> = (application_id) => {
|
|
|
|
|
return get(`${prefix.value}/${application_id}/platform/status`)
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 更新平台状态
|
|
|
|
|
*/
|
|
|
|
|
const updatePlatformStatus: (application_id: string, data: any) => Promise<Result<any>> = (
|
|
|
|
|
application_id,
|
|
|
|
|
data
|
|
|
|
|
) => {
|
|
|
|
|
return post(`${prefix.value}/${application_id}/platform/status`, data)
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取平台配置
|
|
|
|
|
*/
|
|
|
|
|
const getPlatformConfig: (application_id: string, type: string) => Promise<Result<any>> = (
|
|
|
|
|
application_id,
|
|
|
|
|
type
|
|
|
|
|
) => {
|
|
|
|
|
return get(`${prefix.value}/${application_id}/platform/${type}`)
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-03 09:29:33 +00:00
|
|
|
export default {
|
2025-06-10 12:07:14 +00:00
|
|
|
getAllApplication,
|
2025-06-03 09:29:33 +00:00
|
|
|
getApplication,
|
|
|
|
|
postApplication,
|
|
|
|
|
putApplication,
|
|
|
|
|
delApplication,
|
|
|
|
|
getApplicationDetail,
|
|
|
|
|
getAccessToken,
|
|
|
|
|
putAccessToken,
|
|
|
|
|
exportApplication,
|
|
|
|
|
importApplication,
|
2025-06-10 12:07:14 +00:00
|
|
|
getStatistics,
|
2025-06-12 12:07:31 +00:00
|
|
|
open,
|
|
|
|
|
chat,
|
2025-06-19 09:25:46 +00:00
|
|
|
getChatUserAuthType,
|
|
|
|
|
getApplicationSetting,
|
2025-06-20 09:13:01 +00:00
|
|
|
getPlatformStatus,
|
|
|
|
|
updatePlatformStatus,
|
|
|
|
|
getPlatformConfig
|
2025-06-03 09:29:33 +00:00
|
|
|
}
|