| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- // src/lib/services/nodeConfigService.ts
- import api from '@/lib/api';
- import {
- NodeConfigEntryType,
- NodeConfigurationItem,
- NodeConfigListParams,
- SparseUpdatePayload,
- RevisionItem,
- } from '@/types';
- export const nodeConfigService = {
- /**
- * 分页查询配置列表
- */
- async getList(
- entryType: NodeConfigEntryType,
- params?: NodeConfigListParams
- ): Promise<{
- code: number;
- message: string;
- data: {
- total: number;
- page: number;
- page_size: number;
- items: NodeConfigurationItem[];
- };
- }> {
- const res = await api.get(`/api/node-configurations/${entryType}`, { params });
- return res.data;
- },
- /**
- * 获取配置详情
- */
- async getDetail(
- entryType: NodeConfigEntryType,
- entryId: number
- ): Promise<{
- code: number;
- message: string;
- data: NodeConfigurationItem;
- }> {
- const res = await api.get(`/api/node-configurations/${entryType}/${entryId}`);
- return res.data;
- },
- /**
- * 新建配置条目
- */
- async create(
- entryType: NodeConfigEntryType,
- payload: Partial<NodeConfigurationItem>
- ): Promise<{
- code: number;
- message: string;
- data: NodeConfigurationItem;
- }> {
- const res = await api.post(`/api/node-configurations/${entryType}`, payload);
- return res.data;
- },
- /**
- * 稀疏更新配置 (Sparse Update)
- */
- async sparseUpdate(
- entryType: NodeConfigEntryType,
- entryId: number,
- payload: SparseUpdatePayload
- ): Promise<{
- code: number;
- message: string;
- data: NodeConfigurationItem;
- }> {
- const res = await api.put(`/api/node-configurations/${entryType}/${entryId}`, payload);
- return res.data;
- },
- /**
- * 启用 / 停用配置
- */
- async toggleEnable(
- entryType: NodeConfigEntryType,
- entryId: number,
- enable: boolean
- ): Promise<{
- code: number;
- message: string;
- data: NodeConfigurationItem;
- }> {
- const res = await api.put(`/api/node-configurations/${entryType}/${entryId}/enable`, {
- enable,
- });
- return res.data;
- },
- /**
- * 删除配置条目 (支持 confirm_purge 保护守卫)
- */
- async delete(
- entryType: NodeConfigEntryType,
- entryId: number,
- confirmPurge: boolean = false
- ): Promise<{
- code: number;
- message: string;
- data: boolean;
- }> {
- const res = await api.delete(`/api/node-configurations/${entryType}/${entryId}`, {
- params: confirmPurge ? { confirm_purge: true } : undefined,
- });
- return res.data;
- },
- /**
- * 查询配置修订历史记录 (Revisions)
- */
- async getRevisions(
- entryType: NodeConfigEntryType,
- entryId: number
- ): Promise<{
- code: number;
- message: string;
- data: RevisionItem[];
- }> {
- const res = await api.get(`/api/node-configurations/${entryType}/${entryId}/revisions`);
- return res.data;
- },
- /**
- * 回滚配置至指定历史版本
- */
- async rollback(
- entryType: NodeConfigEntryType,
- entryId: number,
- revisionId: number
- ): Promise<{
- code: number;
- message: string;
- data: NodeConfigurationItem;
- }> {
- const res = await api.post(`/api/node-configurations/${entryType}/${entryId}/rollback`, {
- revision_id: revisionId,
- });
- return res.data;
- },
- /**
- * 获取 Worker 节点集群实时状态与心跳
- */
- async getRuntimeStatus(params?: {
- role?: string;
- node_id?: string;
- }): Promise<{
- code: number;
- message: string;
- data: {
- nodes: import('@/types').NodeRuntimeStatus[];
- timestamp: string;
- };
- }> {
- const res = await api.get('/api/node-configurations/runtime-status', { params });
- return res.data;
- },
- };
|