nodeConfigService.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // src/lib/services/nodeConfigService.ts
  2. import api from '@/lib/api';
  3. import {
  4. NodeConfigEntryType,
  5. NodeConfigurationItem,
  6. NodeConfigListParams,
  7. SparseUpdatePayload,
  8. RevisionItem,
  9. } from '@/types';
  10. export const nodeConfigService = {
  11. /**
  12. * 分页查询配置列表
  13. */
  14. async getList(
  15. entryType: NodeConfigEntryType,
  16. params?: NodeConfigListParams
  17. ): Promise<{
  18. code: number;
  19. message: string;
  20. data: {
  21. total: number;
  22. page: number;
  23. page_size: number;
  24. items: NodeConfigurationItem[];
  25. };
  26. }> {
  27. const res = await api.get(`/api/node-configurations/${entryType}`, { params });
  28. return res.data;
  29. },
  30. /**
  31. * 获取配置详情
  32. */
  33. async getDetail(
  34. entryType: NodeConfigEntryType,
  35. entryId: number
  36. ): Promise<{
  37. code: number;
  38. message: string;
  39. data: NodeConfigurationItem;
  40. }> {
  41. const res = await api.get(`/api/node-configurations/${entryType}/${entryId}`);
  42. return res.data;
  43. },
  44. /**
  45. * 新建配置条目
  46. */
  47. async create(
  48. entryType: NodeConfigEntryType,
  49. payload: Partial<NodeConfigurationItem>
  50. ): Promise<{
  51. code: number;
  52. message: string;
  53. data: NodeConfigurationItem;
  54. }> {
  55. const res = await api.post(`/api/node-configurations/${entryType}`, payload);
  56. return res.data;
  57. },
  58. /**
  59. * 稀疏更新配置 (Sparse Update)
  60. */
  61. async sparseUpdate(
  62. entryType: NodeConfigEntryType,
  63. entryId: number,
  64. payload: SparseUpdatePayload
  65. ): Promise<{
  66. code: number;
  67. message: string;
  68. data: NodeConfigurationItem;
  69. }> {
  70. const res = await api.put(`/api/node-configurations/${entryType}/${entryId}`, payload);
  71. return res.data;
  72. },
  73. /**
  74. * 启用 / 停用配置
  75. */
  76. async toggleEnable(
  77. entryType: NodeConfigEntryType,
  78. entryId: number,
  79. enable: boolean
  80. ): Promise<{
  81. code: number;
  82. message: string;
  83. data: NodeConfigurationItem;
  84. }> {
  85. const res = await api.put(`/api/node-configurations/${entryType}/${entryId}/enable`, {
  86. enable,
  87. });
  88. return res.data;
  89. },
  90. /**
  91. * 删除配置条目 (支持 confirm_purge 保护守卫)
  92. */
  93. async delete(
  94. entryType: NodeConfigEntryType,
  95. entryId: number,
  96. confirmPurge: boolean = false
  97. ): Promise<{
  98. code: number;
  99. message: string;
  100. data: boolean;
  101. }> {
  102. const res = await api.delete(`/api/node-configurations/${entryType}/${entryId}`, {
  103. params: confirmPurge ? { confirm_purge: true } : undefined,
  104. });
  105. return res.data;
  106. },
  107. /**
  108. * 查询配置修订历史记录 (Revisions)
  109. */
  110. async getRevisions(
  111. entryType: NodeConfigEntryType,
  112. entryId: number
  113. ): Promise<{
  114. code: number;
  115. message: string;
  116. data: RevisionItem[];
  117. }> {
  118. const res = await api.get(`/api/node-configurations/${entryType}/${entryId}/revisions`);
  119. return res.data;
  120. },
  121. /**
  122. * 回滚配置至指定历史版本
  123. */
  124. async rollback(
  125. entryType: NodeConfigEntryType,
  126. entryId: number,
  127. revisionId: number
  128. ): Promise<{
  129. code: number;
  130. message: string;
  131. data: NodeConfigurationItem;
  132. }> {
  133. const res = await api.post(`/api/node-configurations/${entryType}/${entryId}/rollback`, {
  134. revision_id: revisionId,
  135. });
  136. return res.data;
  137. },
  138. /**
  139. * 获取 Worker 节点集群实时状态与心跳
  140. */
  141. async getRuntimeStatus(params?: {
  142. role?: string;
  143. node_id?: string;
  144. }): Promise<{
  145. code: number;
  146. message: string;
  147. data: {
  148. nodes: import('@/types').NodeRuntimeStatus[];
  149. timestamp: string;
  150. };
  151. }> {
  152. const res = await api.get('/api/node-configurations/runtime-status', { params });
  153. return res.data;
  154. },
  155. };