2025-06-10 12:07:14 +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-03 09:29:33 +00:00
|
|
|
|
2025-06-06 01:39:01 +00:00
|
|
|
const prefix = '/workspace/' + localStorage.getItem('workspace_id') + '/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,
|
|
|
|
|
) => {
|
|
|
|
|
return get(`${prefix}`, 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-10 12:07:14 +00:00
|
|
|
return get(`${prefix}/${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) => {
|
|
|
|
|
return post(`${prefix}`, 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) => {
|
|
|
|
|
return put(`${prefix}/${application_id}`, data, undefined, loading)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除应用
|
|
|
|
|
* @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) => {
|
|
|
|
|
return del(`${prefix}/${application_id}`, undefined, {}, loading)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 应用详情
|
|
|
|
|
* @param 参数 application_id
|
|
|
|
|
*/
|
|
|
|
|
const getApplicationDetail: (
|
|
|
|
|
application_id: string,
|
|
|
|
|
loading?: Ref<boolean>,
|
|
|
|
|
) => Promise<Result<any>> = (application_id, loading) => {
|
|
|
|
|
return get(`${prefix}/${application_id}`, undefined, loading)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取AccessToken
|
|
|
|
|
* @param 参数 application_id
|
|
|
|
|
*/
|
|
|
|
|
const getAccessToken: (application_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
|
|
|
|
application_id,
|
|
|
|
|
loading,
|
|
|
|
|
) => {
|
|
|
|
|
return get(`${prefix}/${application_id}/access_token`, undefined, loading)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改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) => {
|
|
|
|
|
return put(`${prefix}/${application_id}/access_token`, data, 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 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',
|
|
|
|
|
`${prefix}/${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-10 12:07:14 +00:00
|
|
|
return post(`${prefix}/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-11 08:38:48 +00:00
|
|
|
return get(`${prefix}/${application_id}/application_stats`, data, loading)
|
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-03 09:29:33 +00:00
|
|
|
}
|