Files
37duAutomation/desktop/controlplane-next/frontend/src/api/business.ts
T
puddy 9873eb1963 restore: 恢复 11-06~11-09 本地未提交改动
- libs: 新增 hr_sdk / hotel_report / dingtalk,更新 desktopauto
- controlplane-next: SDK 管理模块(controller/entity/migrations)与前端视图
- electron-shell: 插件同步、注册表、runner 调整
- plugins: XQ0035/XQ0041/XQ0042/XQ0045_XQ0046/XQ0048/XQ0076/XQ0078 等版本更新
- tests/tools: 新增 SDK 兼容性检查与打包工具(sdk_pack.py、sdk_compat_check.py)
2026-11-09 17:27:10 +08:00

308 lines
11 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import request from '@/utils/http'
/**
* 37du 控制台业务 API(对接 cool-admin 后端 /api/admin/*)
* 响应统一由请求层归一:cool-admin 信封 / 裸数据均返回业务数据本体
*/
/** 概览 */
export function fetchOverview() {
return request.get<any>({ url: '/api/admin/overview' })
}
/** 数据看板 */
export function fetchStats() {
return request.get<any>({ url: '/api/admin/stats' })
}
/** 插件列表(支持关键字/分类/状态多选/快捷标记/排序) */
export function fetchPlugins(params: {
page?: number
page_size?: number
q?: string
status?: string
category?: string
flags?: string
sort?: string
order?: string
}) {
return request.get<{ items: any[]; total: number; stats?: Record<string, number> }>({
url: '/api/admin/plugins',
params
})
}
/** 上传发布插件包(multipart;channel=test 进测试通道,仅管理员可见) */
export function uploadPlugin(file: File, params: { plugin_id: string; name?: string; version: string; channel?: string }) {
const fd = new FormData()
fd.append('file', file)
return request.post<any>({ url: '/api/admin/pkg', data: fd, params, timeout: 300000 })
}
/** 删除插件 */
export function deletePlugin(plugin_id: string) {
return request.post<any>({ url: '/api/admin/plugin/delete', data: { plugin_id } })
}
/** 更新插件元信息/状态/强制更新 */
export function patchPlugin(plugin_id: string, body: any) {
return request.post<any>({ url: '/api/admin/plugin/patch', params: { plugin_id }, data: body })
}
// ==================== SDK(挂载到执行机的纯 Python 运行库) ====================
/** SDK 列表(含版本历史与当前可用版本) */
export function fetchSdks() {
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/sdks' })
}
/** 上传发布 SDK 包(multipart;channel=test 进测试通道,仅管理员账号可同步) */
export function uploadSdk(file: File, params: { sdk_id: string; name?: string; version: string; channel?: string }) {
const fd = new FormData()
fd.append('file', file)
return request.post<any>({ url: '/api/admin/sdk-pkg', data: fd, params, timeout: 300000 })
}
/** 更新 SDK 状态(published=把在测版本转正) */
export function patchSdk(sdk_id: string, body: any) {
return request.post<any>({ url: '/api/admin/sdk/patch', params: { sdk_id }, data: body })
}
/** 撤回某个 SDK 版本(执行机下次同步回落到最高可用版本) */
export function yankSdk(sdk_id: string, version: string) {
return request.post<any>({ url: '/api/admin/sdk-yank', data: { sdk_id, version } })
}
/** 删除 SDK(连带版本与磁盘包文件) */
export function deleteSdk(sdk_id: string) {
return request.post<any>({ url: '/api/admin/sdk/delete', data: { sdk_id } })
}
// ==================== 字典(可维护枚举,如场景分类 plugin_category) ====================
/** 字典项列表(sort,id 升序) */
export function fetchDictItems(key: string) {
return request.get<{ items: { id: number; label: string; sort: number }[] }>({ url: `/api/admin/dict/${key}/items` })
}
/** 新增字典项 */
export function addDictItem(key: string, label: string) {
return request.post<any>({ url: `/api/admin/dict/${key}/items`, data: { label } })
}
/** 改名 / 上移下移 */
export function updateDictItem(key: string, id: number, body: { label?: string; move?: 'up' | 'down' }) {
return request.put<any>({ url: `/api/admin/dict/${key}/items/${id}`, data: body })
}
/** 删除字典项(不影响已引用该值的业务数据) */
export function deleteDictItem(key: string, id: number) {
return request.del<any>({ url: `/api/admin/dict/${key}/items/${id}` })
}
/** 账号列表 */
export function fetchAccounts(params: { page?: number; page_size?: number; q?: string }) {
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/accounts', params })
}
/** 新建账号 */
export function createAccount(body: any) {
return request.post<any>({ url: '/api/admin/account', data: body })
}
/** 更新账号 */
export function updateAccount(body: any) {
return request.post<any>({ url: '/api/admin/account/update', data: body })
}
/** 重置密码 */
export function resetAccountPwd(body: { account: string; new_password: string }) {
return request.post<any>({ url: '/api/admin/account/reset_pwd', data: body })
}
/** 删除账号 */
export function deleteAccount(account: string) {
return request.post<any>({ url: '/api/admin/account/delete', data: { account } })
}
/** 授权页数据(插件 + 账号) */
export function fetchGrantData() {
return request.get<{ plugins: any[]; accounts: any[] }>({ url: '/api/admin/grant_data' })
}
/** 某账号授权明细 */
export function fetchAccountGrants(account: string) {
return request.get<any>({ url: '/api/admin/account_grants', params: { account } })
}
/** 授予/撤销插件(granted=false 即撤销整行) */
export function grantPlugin(body: any) {
return request.post<any>({ url: '/api/admin/account_plugins', data: body })
}
/** 授予/撤销平台 */
export function grantPlatform(body: any) {
return request.post<any>({ url: '/api/admin/account_platforms', data: body })
}
// ==================== 双向批量授权(新授权工作台) ====================
/** 授权矩阵总览(账号 × 插件 + 平台白名单,一次拉全量) */
export function fetchGrantsMatrix() {
return request.get<any>({ url: '/api/admin/grants/matrix' })
}
/** 插件维度:该插件已授权账号列表 */
export function fetchPluginGrants(pluginId: string) {
return request.get<any>({ url: '/api/admin/plugin_grants', params: { plugin_id: pluginId } })
}
/** 批量授权/更新(事务 upsert) */
export function batchPluginGrants(body: { plugin_id: string; items: { account: string; can_download: boolean; can_run: boolean }[] }) {
return request.post<any>({ url: '/api/admin/plugin_grants/batch', data: body, timeout: 60000 })
}
/** 批量撤销 */
export function revokePluginGrants(body: { plugin_id: string; accounts: string[] }) {
return request.post<any>({ url: '/api/admin/plugin_grants/revoke', data: body, timeout: 60000 })
}
/** 审计日志 */
export function fetchAudit(params: { page?: number; page_size?: number; action?: string; q?: string }) {
return request.get<{ items: any[]; total: number; today: number }>({ url: '/api/admin/audit', params })
}
/** 运行记录 */
export function fetchReports(params: { page?: number; page_size?: number; status?: string; q?: string }) {
return request.get<{ items: any[]; total: number; today: number; failed: number }>({ url: '/api/admin/reports', params })
}
/** 设备列表 */
export function fetchDevices(params: { page?: number; page_size?: number }) {
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/devices', params })
}
/** 设备汇总(升级进度) */
export function fetchDevicesSummary() {
return request.get<any>({ url: '/api/admin/devices/summary' })
}
/** 通知列表(管理) */
export function fetchNotifications(params: { page?: number; page_size?: number; q?: string }) {
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/notifications', params })
}
/** 最新有效通知(页眉通知中心,active 且未过期) */
export function fetchLatestNotifications(limit: number = 30) {
return request.get<{ items: any[] }>({ url: '/api/admin/notifications/latest', params: { limit } })
}
/** 创建通知 */
export function createNotification(body: any) {
return request.post<any>({ url: '/api/admin/notifications', data: body })
}
/** 启停通知 */
export function toggleNotification(id: number, active: boolean) {
return request.put<any>({ url: `/api/admin/notifications/${id}`, params: { active } })
}
/** 删除通知 */
export function deleteNotification(id: number) {
return request.del<any>({ url: `/api/admin/notifications/${id}` })
}
/** 凭证管理列表 */
export function fetchCredsManage(params: { page?: number; page_size?: number }) {
return request.get<any>({ url: '/api/admin/creds/manage', params })
}
/** 录入凭证明文源 */
export function seedCreds(body: any) {
return request.post<any>({ url: '/api/admin/creds/seed', data: body })
}
/** 大文件源列表 */
export function fetchFileSources(params: { category?: string; page?: number; page_size?: number }) {
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/file-sources', params })
}
/** 登记/覆盖大文件源 */
export function upsertFileSource(body: any) {
return request.post<any>({ url: '/api/admin/file-sources', data: body })
}
/** 启停/改说明 */
export function patchFileSource(id: number, body: any) {
return request.put<any>({ url: `/api/admin/file-sources/${id}`, data: body })
}
/** 删除大文件源 */
export function deleteFileSource(id: number) {
return request.del<any>({ url: `/api/admin/file-sources/${id}` })
}
// ==================== 个人中心(自助) ====================
/** 自助修改密码(旧密码校验,新密码≥8位,成功后 must_change_pwd 清零) */
export function changePassword(body: { account: string; old_password: string; new_password: string }) {
return request.post<any>({ url: '/api/admin/password', data: body })
}
/** 上传头像(multipart,file 字段) */
export function uploadAvatar(file: File, account: string) {
const fd = new FormData()
fd.append('file', file)
return request.post<any>({ url: '/api/admin/avatar', data: fd, params: { account }, timeout: 30000 })
}
// ==================== 集中日志(运行日志 / 客户端壳日志) ====================
/** 运行日志列表(分页 + 账号/设备/插件/状态/关键字/近N天筛选) */
export function fetchRunLogs(params: {
page?: number; page_size?: number; account?: string; device?: string;
plugin?: string; status?: string; q?: string; days?: number;
}) {
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/run-logs', params })
}
/** 单次运行日志详情(含日志正文) */
export function fetchRunLogDetail(runId: string) {
return request.get<any>({ url: `/api/admin/run-logs/${encodeURIComponent(runId)}` })
}
/** 客户端壳日志设备列表 */
export function fetchDeviceLogs(params: { page?: number; page_size?: number; account?: string; q?: string }) {
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/device-logs', params })
}
/** 设备壳日志尾部内容 */
export function fetchDeviceLogDetail(deviceId: string) {
return request.get<any>({ url: `/api/admin/device-logs/${encodeURIComponent(deviceId)}` })
}
/** 壳日志全文下载(需鉴权头,用 fetch 取 blob 触发浏览器下载) */
export async function downloadDeviceLog(deviceId: string, filename?: string) {
const { useUserStore } = await import('@/store/modules/user')
const token = useUserStore().accessToken
const base = (import.meta.env.VITE_API_URL as string) || ''
const res = await fetch(`${base}/api/admin/device-logs/${encodeURIComponent(deviceId)}/download`, {
headers: { 'X-Admin-Token': token || '' },
})
if (!res.ok) throw new Error(`下载失败 HTTP ${res.status}`)
const blob = await res.blob()
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = filename || `shell-${deviceId}.log`
document.body.appendChild(a)
a.click()
a.remove()
setTimeout(() => URL.revokeObjectURL(url), 5000)
}
/** 手动触发一次保留期清理 */
export function cleanupLogs() {
return request.post<any>({ url: '/api/admin/logs/cleanup' })
}