api.ts 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734
  1. import axios from 'axios';
  2. import type { MinioUploadPolicy, OSSUploadPolicy } from '@d8d-appcontainer/types';
  3. import 'dayjs/locale/zh-cn';
  4. import type {
  5. User, FileLibrary, FileCategory, KnowInfo,
  6. AuthContextType, ThemeContextType, Attachment, ThemeSettings,
  7. SystemSetting, SystemSettingGroupData
  8. } from '../share/types.ts';
  9. // 定义API基础URL
  10. const API_BASE_URL = '/api';
  11. // 获取OSS完整URL
  12. export const getOssUrl = (path: string): string => {
  13. // 获取全局配置中的OSS_HOST,如果不存在使用默认值
  14. const ossHost = (window.CONFIG?.OSS_BASE_URL) || '';
  15. // 确保path不以/开头
  16. const ossPath = path.startsWith('/') ? path.substring(1) : path;
  17. return `${ossHost}/${ossPath}`;
  18. };
  19. // ===================
  20. // Auth API 定义部分
  21. // ===================
  22. // 定义API返回数据类型
  23. interface AuthLoginResponse {
  24. message: string;
  25. token: string;
  26. refreshToken?: string;
  27. user: User;
  28. }
  29. interface AuthResponse {
  30. message: string;
  31. [key: string]: any;
  32. }
  33. // 定义Auth API接口类型
  34. interface AuthAPIType {
  35. login: (username: string, password: string) => Promise<AuthLoginResponse>;
  36. register: (username: string, email: string, password: string) => Promise<AuthResponse>;
  37. logout: () => Promise<AuthResponse>;
  38. getCurrentUser: () => Promise<User>;
  39. updateUser: (userId: number, userData: Partial<User>) => Promise<User>;
  40. changePassword: (oldPassword: string, newPassword: string) => Promise<AuthResponse>;
  41. requestPasswordReset: (email: string) => Promise<AuthResponse>;
  42. resetPassword: (token: string, newPassword: string) => Promise<AuthResponse>;
  43. }
  44. // Auth相关API
  45. export const AuthAPI: AuthAPIType = {
  46. // 登录API
  47. login: async (username: string, password: string) => {
  48. try {
  49. const response = await axios.post(`${API_BASE_URL}/auth/login`, { username, password });
  50. return response.data;
  51. } catch (error) {
  52. throw error;
  53. }
  54. },
  55. // 注册API
  56. register: async (username: string, email: string, password: string) => {
  57. try {
  58. const response = await axios.post(`${API_BASE_URL}/auth/register`, { username, email, password });
  59. return response.data;
  60. } catch (error) {
  61. throw error;
  62. }
  63. },
  64. // 登出API
  65. logout: async () => {
  66. try {
  67. const response = await axios.post(`${API_BASE_URL}/auth/logout`);
  68. return response.data;
  69. } catch (error) {
  70. throw error;
  71. }
  72. },
  73. // 获取当前用户信息
  74. getCurrentUser: async () => {
  75. try {
  76. const response = await axios.get(`${API_BASE_URL}/auth/me`);
  77. return response.data;
  78. } catch (error) {
  79. throw error;
  80. }
  81. },
  82. // 更新用户信息
  83. updateUser: async (userId: number, userData: Partial<User>) => {
  84. try {
  85. const response = await axios.put(`${API_BASE_URL}/auth/users/${userId}`, userData);
  86. return response.data;
  87. } catch (error) {
  88. throw error;
  89. }
  90. },
  91. // 修改密码
  92. changePassword: async (oldPassword: string, newPassword: string) => {
  93. try {
  94. const response = await axios.post(`${API_BASE_URL}/auth/change-password`, { oldPassword, newPassword });
  95. return response.data;
  96. } catch (error) {
  97. throw error;
  98. }
  99. },
  100. // 请求重置密码
  101. requestPasswordReset: async (email: string) => {
  102. try {
  103. const response = await axios.post(`${API_BASE_URL}/auth/request-password-reset`, { email });
  104. return response.data;
  105. } catch (error) {
  106. throw error;
  107. }
  108. },
  109. // 重置密码
  110. resetPassword: async (token: string, newPassword: string) => {
  111. try {
  112. const response = await axios.post(`${API_BASE_URL}/auth/reset-password`, { token, newPassword });
  113. return response.data;
  114. } catch (error) {
  115. throw error;
  116. }
  117. }
  118. };
  119. // 为UserAPI添加的接口响应类型
  120. interface UsersResponse {
  121. data: User[];
  122. pagination: {
  123. total: number;
  124. current: number;
  125. pageSize: number;
  126. totalPages: number;
  127. };
  128. }
  129. interface UserResponse {
  130. data: User;
  131. message?: string;
  132. }
  133. interface UserCreateResponse {
  134. message: string;
  135. data: User;
  136. }
  137. interface UserUpdateResponse {
  138. message: string;
  139. data: User;
  140. }
  141. interface UserDeleteResponse {
  142. message: string;
  143. id: number;
  144. }
  145. // 用户管理API
  146. export const UserAPI = {
  147. // 获取用户列表
  148. getUsers: async (params?: { page?: number, limit?: number, search?: string }): Promise<UsersResponse> => {
  149. try {
  150. const response = await axios.get(`${API_BASE_URL}/users`, { params });
  151. return response.data;
  152. } catch (error) {
  153. throw error;
  154. }
  155. },
  156. // 获取单个用户详情
  157. getUser: async (userId: number): Promise<UserResponse> => {
  158. try {
  159. const response = await axios.get(`${API_BASE_URL}/users/${userId}`);
  160. return response.data;
  161. } catch (error) {
  162. throw error;
  163. }
  164. },
  165. // 创建用户
  166. createUser: async (userData: Partial<User>): Promise<UserCreateResponse> => {
  167. try {
  168. const response = await axios.post(`${API_BASE_URL}/users`, userData);
  169. return response.data;
  170. } catch (error) {
  171. throw error;
  172. }
  173. },
  174. // 更新用户信息
  175. updateUser: async (userId: number, userData: Partial<User>): Promise<UserUpdateResponse> => {
  176. try {
  177. const response = await axios.put(`${API_BASE_URL}/users/${userId}`, userData);
  178. return response.data;
  179. } catch (error) {
  180. throw error;
  181. }
  182. },
  183. // 删除用户
  184. deleteUser: async (userId: number): Promise<UserDeleteResponse> => {
  185. try {
  186. const response = await axios.delete(`${API_BASE_URL}/users/${userId}`);
  187. return response.data;
  188. } catch (error) {
  189. throw error;
  190. }
  191. }
  192. };
  193. // 资产管理API
  194. export const ZichanAPI = {
  195. // 获取资产列表
  196. getZichanList: async (params?: {
  197. page?: number,
  198. limit?: number,
  199. asset_name?: string,
  200. device_category?: DeviceCategory,
  201. device_status?: DeviceStatus
  202. }) => {
  203. try {
  204. const response = await axios.get(`${API_BASE_URL}/zichan`, { params });
  205. return response.data;
  206. } catch (error) {
  207. throw error;
  208. }
  209. },
  210. // 获取单个资产
  211. getZichan: async (id: number) => {
  212. try {
  213. const response = await axios.get(`${API_BASE_URL}/zichan/${id}`);
  214. return response.data;
  215. } catch (error) {
  216. throw error;
  217. }
  218. },
  219. // 创建资产
  220. createZichan: async (data: Partial<ZichanInfo>) => {
  221. try {
  222. const response = await axios.post(`${API_BASE_URL}/zichan`, data);
  223. return response.data;
  224. } catch (error) {
  225. throw error;
  226. }
  227. },
  228. // 更新资产
  229. updateZichan: async (id: number, data: Partial<ZichanInfo>) => {
  230. try {
  231. const response = await axios.put(`${API_BASE_URL}/zichan/${id}`, data);
  232. return response.data;
  233. } catch (error) {
  234. throw error;
  235. }
  236. },
  237. // 删除资产
  238. deleteZichan: async (id: number) => {
  239. try {
  240. const response = await axios.delete(`${API_BASE_URL}/zichan/${id}`);
  241. return response.data;
  242. } catch (error) {
  243. throw error;
  244. }
  245. }
  246. };
  247. // 资产流转API接口定义
  248. export const ZichanTransferAPI = {
  249. // 获取资产流转记录列表
  250. getTransferList: async (params?: { page?: number, limit?: number, asset_id?: number, asset_transfer?: AssetTransferType }) => {
  251. try {
  252. const response = await axios.get(`${API_BASE_URL}/zichan-transfer`, { params });
  253. return response.data;
  254. } catch (error) {
  255. throw error;
  256. }
  257. },
  258. // 获取资产流转记录详情
  259. getTransfer: async (id: number) => {
  260. try {
  261. const response = await axios.get(`${API_BASE_URL}/zichan-transfer/${id}`);
  262. return response.data;
  263. } catch (error) {
  264. throw error;
  265. }
  266. },
  267. // 创建资产流转记录
  268. createTransfer: async (data: Partial<ZichanTransLog>) => {
  269. try {
  270. const response = await axios.post(`${API_BASE_URL}/zichan-transfer`, data);
  271. return response.data;
  272. } catch (error) {
  273. throw error;
  274. }
  275. },
  276. // 更新资产流转记录
  277. updateTransfer: async (id: number, data: Partial<ZichanTransLog>) => {
  278. try {
  279. const response = await axios.put(`${API_BASE_URL}/zichan-transfer/${id}`, data);
  280. return response.data;
  281. } catch (error) {
  282. throw error;
  283. }
  284. },
  285. // 删除资产流转记录
  286. deleteTransfer: async (id: number) => {
  287. try {
  288. const response = await axios.delete(`${API_BASE_URL}/zichan-transfer/${id}`);
  289. return response.data;
  290. } catch (error) {
  291. throw error;
  292. }
  293. }
  294. };
  295. // 设备实例API接口定义
  296. interface DeviceInstancesResponse {
  297. data: DeviceInstance[];
  298. pagination: {
  299. total: number;
  300. current: number;
  301. pageSize: number;
  302. totalPages: number;
  303. };
  304. }
  305. interface DeviceInstanceResponse {
  306. data: DeviceInstance;
  307. asset_info?: ZichanInfo;
  308. type_info?: DeviceType;
  309. message?: string;
  310. }
  311. interface DeviceInstanceCreateResponse {
  312. message: string;
  313. data: DeviceInstance;
  314. }
  315. interface DeviceInstanceUpdateResponse {
  316. message: string;
  317. data: DeviceInstance;
  318. }
  319. interface DeviceInstanceDeleteResponse {
  320. message: string;
  321. id: number;
  322. }
  323. // 设备类型API接口定义
  324. interface DeviceTypeResponse {
  325. data: DeviceType[];
  326. pagination: {
  327. total: number;
  328. current: number;
  329. pageSize: number;
  330. totalPages: number;
  331. };
  332. }
  333. interface DeviceTypeDetailResponse {
  334. data: DeviceType;
  335. message?: string;
  336. }
  337. interface DeviceTypeCreateResponse {
  338. message: string;
  339. data: DeviceType;
  340. }
  341. interface DeviceTypeUpdateResponse {
  342. message: string;
  343. data: DeviceType;
  344. }
  345. interface DeviceTypeDeleteResponse {
  346. message: string;
  347. id: number;
  348. }
  349. export const DeviceTypeAPI = {
  350. // 获取设备类型列表
  351. getDeviceTypes: async (params?: {
  352. page?: number,
  353. pageSize?: number,
  354. code?: string,
  355. name?: string,
  356. is_enabled?: boolean
  357. }): Promise<DeviceTypeResponse> => {
  358. try {
  359. const response = await axios.get('/api/device/types', { params });
  360. return response.data;
  361. } catch (error) {
  362. throw error;
  363. }
  364. },
  365. // 获取单个设备类型信息
  366. getDeviceType: async (id: number): Promise<DeviceTypeDetailResponse> => {
  367. try {
  368. const response = await axios.get(`/api/device/types/${id}`);
  369. return response.data;
  370. } catch (error) {
  371. throw error;
  372. }
  373. },
  374. // 创建设备类型
  375. createDeviceType: async (data: Partial<DeviceType>): Promise<DeviceTypeCreateResponse> => {
  376. try {
  377. const response = await axios.post('/api/device/types', data);
  378. return response.data;
  379. } catch (error) {
  380. throw error;
  381. }
  382. },
  383. // 更新设备类型
  384. updateDeviceType: async (id: number, data: Partial<DeviceType>): Promise<DeviceTypeUpdateResponse> => {
  385. try {
  386. const response = await axios.put(`/api/device/types/${id}`, data);
  387. return response.data;
  388. } catch (error) {
  389. throw error;
  390. }
  391. },
  392. // 删除设备类型
  393. deleteDeviceType: async (id: number): Promise<DeviceTypeDeleteResponse> => {
  394. try {
  395. const response = await axios.delete(`/api/device/types/${id}`);
  396. return response.data;
  397. } catch (error) {
  398. throw error;
  399. }
  400. },
  401. // 获取设备类型图标
  402. getTypeIcons: async (): Promise<{data: Record<string, string>, success: boolean}> => {
  403. try {
  404. const response = await axios.get('/api/device/types/icons');
  405. return response.data;
  406. } catch (error) {
  407. throw error;
  408. }
  409. }
  410. };
  411. export const DeviceInstanceAPI = {
  412. // 获取设备实例列表
  413. getDeviceInstances: async (params?: {
  414. page?: number,
  415. limit?: number,
  416. type_id?: number,
  417. protocol?: string,
  418. status?: number
  419. }): Promise<DeviceInstancesResponse> => {
  420. try {
  421. const response = await axios.get('/api/device/instances', { params });
  422. return response.data;
  423. } catch (error) {
  424. throw error;
  425. }
  426. },
  427. // 获取单个设备实例信息
  428. getDeviceInstance: async (id: number): Promise<DeviceInstanceResponse> => {
  429. try {
  430. const response = await axios.get(`/api/device/instances/${id}`);
  431. return response.data;
  432. } catch (error) {
  433. throw error;
  434. }
  435. },
  436. // 创建设备实例
  437. createDeviceInstance: async (data: Partial<DeviceInstance>): Promise<DeviceInstanceCreateResponse> => {
  438. try {
  439. const response = await axios.post('/api/device/instances', data);
  440. return response.data;
  441. } catch (error) {
  442. throw error;
  443. }
  444. },
  445. // 更新设备实例
  446. updateDeviceInstance: async (id: number, data: Partial<DeviceInstance>): Promise<DeviceInstanceUpdateResponse> => {
  447. try {
  448. const response = await axios.put(`/api/device/instances/${id}`, data);
  449. return response.data;
  450. } catch (error) {
  451. throw error;
  452. }
  453. },
  454. // 删除设备实例
  455. deleteDeviceInstance: async (id: number): Promise<DeviceInstanceDeleteResponse> => {
  456. try {
  457. const response = await axios.delete(`/api/device/instances/${id}`);
  458. return response.data;
  459. } catch (error) {
  460. throw error;
  461. }
  462. }
  463. };
  464. // 机柜管理API接口定义
  465. export const RackAPI = {
  466. // 获取机柜列表
  467. getRackList: async (params?: {
  468. page?: number,
  469. limit?: number,
  470. rack_name?: string,
  471. rack_code?: string,
  472. area?: string
  473. }) => {
  474. try {
  475. const response = await axios.get(`${API_BASE_URL}/racks`, { params });
  476. return response.data;
  477. } catch (error) {
  478. throw error;
  479. }
  480. },
  481. // 获取单个机柜信息
  482. getRack: async (id: number) => {
  483. try {
  484. const response = await axios.get(`${API_BASE_URL}/racks/${id}`);
  485. return response.data;
  486. } catch (error) {
  487. throw error;
  488. }
  489. },
  490. // 创建机柜
  491. createRack: async (data: Partial<RackInfo>) => {
  492. try {
  493. const response = await axios.post(`${API_BASE_URL}/racks`, data);
  494. return response.data;
  495. } catch (error) {
  496. throw error;
  497. }
  498. },
  499. // 更新机柜
  500. updateRack: async (id: number, data: Partial<RackInfo>) => {
  501. try {
  502. const response = await axios.put(`${API_BASE_URL}/racks/${id}`, data);
  503. return response.data;
  504. } catch (error) {
  505. throw error;
  506. }
  507. },
  508. // 删除机柜
  509. deleteRack: async (id: number) => {
  510. try {
  511. const response = await axios.delete(`${API_BASE_URL}/racks/${id}`);
  512. return response.data;
  513. } catch (error) {
  514. throw error;
  515. }
  516. }
  517. };
  518. // 机柜服务器API接口定义
  519. export const RackServerAPI = {
  520. // 获取机柜服务器列表
  521. getRackServerList: async (params?: {
  522. page?: number,
  523. limit?: number,
  524. rack_id?: number,
  525. asset_id?: number,
  526. server_type?: string
  527. }) => {
  528. try {
  529. const response = await axios.get(`${API_BASE_URL}/rack-servers`, { params });
  530. return response.data;
  531. } catch (error) {
  532. throw error;
  533. }
  534. },
  535. // 获取单个机柜服务器信息
  536. getRackServer: async (id: number) => {
  537. try {
  538. const response = await axios.get(`${API_BASE_URL}/rack-servers/${id}`);
  539. return response.data;
  540. } catch (error) {
  541. throw error;
  542. }
  543. },
  544. // 创建机柜服务器
  545. createRackServer: async (data: Partial<RackServer>) => {
  546. try {
  547. const response = await axios.post(`${API_BASE_URL}/rack-servers`, data);
  548. return response.data;
  549. } catch (error) {
  550. throw error;
  551. }
  552. },
  553. // 更新机柜服务器
  554. updateRackServer: async (id: number, data: Partial<RackServer>) => {
  555. try {
  556. const response = await axios.put(`${API_BASE_URL}/rack-servers/${id}`, data);
  557. return response.data;
  558. } catch (error) {
  559. throw error;
  560. }
  561. },
  562. // 删除机柜服务器
  563. deleteRackServer: async (id: number) => {
  564. try {
  565. const response = await axios.delete(`${API_BASE_URL}/rack-servers/${id}`);
  566. return response.data;
  567. } catch (error) {
  568. throw error;
  569. }
  570. }
  571. };
  572. interface DeviceMonitorDataResponse {
  573. data: DeviceMonitorData[];
  574. total: number;
  575. page: number;
  576. pageSize: number;
  577. }
  578. interface DeviceMonitorResponse {
  579. data: DeviceMonitorData;
  580. message?: string;
  581. }
  582. interface MonitorCreateResponse {
  583. data: DeviceMonitorData;
  584. message: string;
  585. }
  586. interface MonitorUpdateResponse {
  587. data: DeviceMonitorData;
  588. message: string;
  589. }
  590. interface MonitorDeleteResponse {
  591. message: string;
  592. }
  593. // 告警相关响应类型
  594. interface DeviceAlertDataResponse {
  595. data: DeviceAlert[];
  596. total: number;
  597. page: number;
  598. pageSize: number;
  599. }
  600. interface DeviceAlertResponse {
  601. data: DeviceAlert;
  602. message?: string;
  603. }
  604. interface AlertCreateResponse {
  605. data: DeviceAlert;
  606. message: string;
  607. }
  608. interface AlertUpdateResponse {
  609. data: DeviceAlert;
  610. message: string;
  611. }
  612. interface AlertDeleteResponse {
  613. message: string;
  614. }
  615. // 告警处理相关响应类型
  616. interface AlertHandleDataResponse {
  617. data: AlertHandleLog[];
  618. total: number;
  619. page: number;
  620. pageSize: number;
  621. }
  622. interface AlertHandleResponse {
  623. data: AlertHandleLog;
  624. message?: string;
  625. }
  626. // 告警通知配置相关响应类型
  627. interface AlertNotifyConfigDataResponse {
  628. data: AlertNotifyConfig[];
  629. total: number;
  630. page: number;
  631. pageSize: number;
  632. }
  633. interface AlertNotifyConfigResponse {
  634. data: AlertNotifyConfig;
  635. message?: string;
  636. }
  637. // 监控API接口定义
  638. export const MonitorAPI = {
  639. // 获取监控数据
  640. getMonitorData: async (params?: {
  641. page?: number,
  642. limit?: number,
  643. device_id?: number,
  644. device_type?: string,
  645. start_time?: string,
  646. end_time?: string
  647. }): Promise<DeviceMonitorDataResponse> => {
  648. try {
  649. const response = await axios.get(`${API_BASE_URL}/monitor/data`, { params });
  650. return response.data;
  651. } catch (error) {
  652. throw error;
  653. }
  654. },
  655. // 获取设备树数据
  656. getDeviceTree: async (params?: {
  657. status?: string,
  658. keyword?: string
  659. }): Promise<{ data: DeviceTreeNode[] }> => {
  660. try {
  661. const response = await axios.get(`${API_BASE_URL}/monitor/devices/tree`, { params });
  662. return response.data;
  663. } catch (error) {
  664. throw error;
  665. }
  666. },
  667. // 获取设备树统计数据
  668. getDeviceTreeStats: async (): Promise<{ data: DeviceTreeStats }> => {
  669. try {
  670. const response = await axios.get(`${API_BASE_URL}/monitor/devices/tree/statistics`);
  671. return response.data;
  672. } catch (error) {
  673. throw error;
  674. }
  675. },
  676. // 获取设备地图数据
  677. getDeviceMapData: async (params?: {
  678. type_code?: string,
  679. device_status?: DeviceStatus,
  680. keyword?: string,
  681. device_id?: number
  682. }): Promise<{ data: MapViewDevice[], stats: DeviceMapStats }> => {
  683. try {
  684. const response = await axios.get(`${API_BASE_URL}/monitor/devices/map`, { params });
  685. return response.data;
  686. } catch (error) {
  687. throw error;
  688. }
  689. },
  690. // 获取单个监控数据
  691. getMonitor: async (id: number): Promise<DeviceMonitorResponse> => {
  692. try {
  693. const response = await axios.get(`${API_BASE_URL}/monitor/data/${id}`);
  694. return response.data;
  695. } catch (error) {
  696. throw error;
  697. }
  698. },
  699. // 创建监控数据
  700. createMonitor: async (data: Partial<DeviceMonitorData>): Promise<MonitorCreateResponse> => {
  701. try {
  702. const response = await axios.post(`${API_BASE_URL}/monitor/data`, data);
  703. return response.data;
  704. } catch (error) {
  705. throw error;
  706. }
  707. },
  708. // 更新监控数据
  709. updateMonitor: async (id: number, data: Partial<DeviceMonitorData>): Promise<MonitorUpdateResponse> => {
  710. try {
  711. const response = await axios.put(`${API_BASE_URL}/monitor/data/${id}`, data);
  712. return response.data;
  713. } catch (error) {
  714. throw error;
  715. }
  716. },
  717. // 删除监控数据
  718. deleteMonitor: async (id: number): Promise<MonitorDeleteResponse> => {
  719. try {
  720. const response = await axios.delete(`${API_BASE_URL}/monitor/data/${id}`);
  721. return response.data;
  722. } catch (error) {
  723. throw error;
  724. }
  725. }
  726. };
  727. // 告警API接口定义
  728. export const AlertAPI = {
  729. // 获取告警数据
  730. getAlertData: async (params?: {
  731. page?: number,
  732. limit?: number,
  733. alert_type?: string,
  734. alert_level?: string,
  735. start_time?: string,
  736. end_time?: string
  737. }): Promise<DeviceAlertDataResponse> => {
  738. try {
  739. const response = await axios.get(`${API_BASE_URL}/alerts`, { params });
  740. return response.data;
  741. } catch (error) {
  742. throw error;
  743. }
  744. },
  745. // 获取单个告警数据
  746. getAlert: async (id: number): Promise<DeviceAlert> => {
  747. try {
  748. const response = await axios.get(`${API_BASE_URL}/alerts/${id}`);
  749. return response.data;
  750. } catch (error) {
  751. throw error;
  752. }
  753. },
  754. // 创建告警数据
  755. createAlert: async (data: Partial<DeviceAlert>): Promise<AlertCreateResponse> => {
  756. try {
  757. const response = await axios.post(`${API_BASE_URL}/alerts`, data);
  758. return response.data;
  759. } catch (error) {
  760. throw error;
  761. }
  762. },
  763. // 更新告警数据
  764. updateAlert: async (id: number, data: Partial<DeviceAlert>): Promise<AlertUpdateResponse> => {
  765. try {
  766. const response = await axios.put(`${API_BASE_URL}/alerts/${id}`, data);
  767. return response.data;
  768. } catch (error) {
  769. throw error;
  770. }
  771. },
  772. // 删除告警数据
  773. deleteAlert: async (id: number): Promise<AlertDeleteResponse> => {
  774. try {
  775. const response = await axios.delete(`${API_BASE_URL}/alerts/${id}`);
  776. return response.data;
  777. } catch (error) {
  778. throw error;
  779. }
  780. }
  781. };
  782. // 告警处理API接口定义
  783. export const AlertHandleAPI = {
  784. // 获取告警处理数据
  785. getAlertHandleData: async (params?: {
  786. page?: number,
  787. limit?: number,
  788. alert_id?: number,
  789. handle_type?: string,
  790. start_time?: string,
  791. end_time?: string
  792. }): Promise<AlertHandleDataResponse> => {
  793. try {
  794. const response = await axios.get(`${API_BASE_URL}/alert-handles`, { params });
  795. return response.data;
  796. } catch (error) {
  797. throw error;
  798. }
  799. },
  800. // 获取单个告警处理数据
  801. getAlertHandle: async (id: number): Promise<AlertHandleResponse> => {
  802. try {
  803. const response = await axios.get(`${API_BASE_URL}/alert-handles/${id}`);
  804. return response.data;
  805. } catch (error) {
  806. throw error;
  807. }
  808. },
  809. // 创建告警处理数据
  810. createAlertHandle: async (data: Partial<AlertHandleLog>) => {
  811. try {
  812. const response = await axios.post(`${API_BASE_URL}/alert-handles`, data);
  813. return response.data;
  814. } catch (error) {
  815. throw error;
  816. }
  817. },
  818. // 更新告警处理数据
  819. updateAlertHandle: async (id: number, data: Partial<AlertHandleLog>) => {
  820. try {
  821. const response = await axios.put(`${API_BASE_URL}/alert-handles/${id}`, data);
  822. return response.data;
  823. } catch (error) {
  824. throw error;
  825. }
  826. },
  827. // 删除告警处理数据
  828. deleteAlertHandle: async (id: number) => {
  829. try {
  830. const response = await axios.delete(`${API_BASE_URL}/alert-handles/${id}`);
  831. return response.data;
  832. } catch (error) {
  833. throw error;
  834. }
  835. }
  836. };
  837. // 告警通知配置API接口定义
  838. export const AlertNotifyConfigAPI = {
  839. // 获取告警通知配置
  840. getAlertNotifyConfig: async (params?: {
  841. page?: number,
  842. limit?: number,
  843. device_id?: number,
  844. alert_level?: string
  845. }): Promise<AlertNotifyConfigDataResponse> => {
  846. try {
  847. const response = await axios.get(`${API_BASE_URL}/alert-notify-configs`, { params });
  848. return response.data;
  849. } catch (error) {
  850. throw error;
  851. }
  852. },
  853. // 创建告警通知配置
  854. createAlertNotifyConfig: async (data: Partial<AlertNotifyConfig>): Promise<AlertNotifyConfigResponse> => {
  855. try {
  856. const response = await axios.post(`${API_BASE_URL}/alert-notify-configs`, data);
  857. return response.data;
  858. } catch (error) {
  859. throw error;
  860. }
  861. },
  862. // 更新告警通知配置
  863. updateAlertNotifyConfig: async (id: number, data: Partial<AlertNotifyConfig>): Promise<AlertNotifyConfigResponse> => {
  864. try {
  865. const response = await axios.put(`${API_BASE_URL}/alert-notify-configs/${id}`, data);
  866. return response.data;
  867. } catch (error) {
  868. throw error;
  869. }
  870. },
  871. // 删除告警通知配置
  872. deleteAlertNotifyConfig: async (id: number): Promise<AlertNotifyConfigResponse> => {
  873. try {
  874. const response = await axios.delete(`${API_BASE_URL}/alert-notify-configs/${id}`);
  875. return response.data;
  876. } catch (error) {
  877. throw error;
  878. }
  879. }
  880. };
  881. // 设备告警规则API接口定义
  882. export const DeviceAlertRuleAPI = {
  883. // 获取设备告警规则
  884. getDeviceAlertRules: async (params?: {
  885. page?: number,
  886. limit?: number,
  887. device_id?: number,
  888. rule_type?: string
  889. }): Promise<DeviceAlertDataResponse> => {
  890. try {
  891. const response = await axios.get(`${API_BASE_URL}/device-alert-rules`, { params });
  892. return response.data;
  893. } catch (error) {
  894. throw error;
  895. }
  896. },
  897. // 获取单个设备告警规则
  898. getDeviceAlertRule: async (id: number): Promise<DeviceAlertResponse> => {
  899. try {
  900. const response = await axios.get(`${API_BASE_URL}/device-alert-rules/${id}`);
  901. return response.data;
  902. } catch (error) {
  903. throw error;
  904. }
  905. },
  906. // 创建设备告警规则
  907. createDeviceAlertRule: async (data: Partial<DeviceAlertRule>): Promise<DeviceAlertResponse> => {
  908. try {
  909. const response = await axios.post(`${API_BASE_URL}/device-alert-rules`, data);
  910. return response.data;
  911. } catch (error) {
  912. throw error;
  913. }
  914. },
  915. // 更新设备告警规则
  916. updateDeviceAlertRule: async (id: number, data: Partial<DeviceAlertRule>): Promise<DeviceAlertResponse> => {
  917. try {
  918. const response = await axios.put(`${API_BASE_URL}/device-alert-rules/${id}`, data);
  919. return response.data;
  920. } catch (error) {
  921. throw error;
  922. }
  923. },
  924. // 删除设备告警规则
  925. deleteDeviceAlertRule: async (id: number): Promise<AlertDeleteResponse> => {
  926. try {
  927. const response = await axios.delete(`${API_BASE_URL}/device-alert-rules/${id}`);
  928. return response.data;
  929. } catch (error) {
  930. throw error;
  931. }
  932. }
  933. };
  934. // 资产分类API响应类型
  935. interface ZichanCategoryResponse {
  936. data: ZichanCategory[];
  937. pagination: {
  938. total: number;
  939. current: number;
  940. pageSize: number;
  941. };
  942. }
  943. // 资产归属区域API响应类型
  944. interface ZichanAreaResponse {
  945. data: ZichanArea[];
  946. pagination: {
  947. total: number;
  948. current: number;
  949. pageSize: number;
  950. };
  951. }
  952. // 机柜服务器类型API响应类型
  953. interface RackServerTypeResponse {
  954. data: RackServerType[];
  955. pagination: {
  956. total: number;
  957. current: number;
  958. pageSize: number;
  959. };
  960. }
  961. // 资产分类API接口定义
  962. export const ZichanCategoryAPI = {
  963. // 获取资产分类列表
  964. getZichanCategoryList: async (params?: {
  965. page?: number,
  966. limit?: number,
  967. name?: string,
  968. code?: string
  969. }) => {
  970. try {
  971. const response = await axios.get(`${API_BASE_URL}/zichan-categories`, { params });
  972. return response.data;
  973. } catch (error) {
  974. throw error;
  975. }
  976. },
  977. // 获取单个资产分类信息
  978. getZichanCategory: async (id: number) => {
  979. try {
  980. const response = await axios.get(`${API_BASE_URL}/zichan-categories/${id}`);
  981. return response.data;
  982. } catch (error) {
  983. throw error;
  984. }
  985. },
  986. // 创建资产分类
  987. createZichanCategory: async (data: Partial<ZichanCategory>) => {
  988. try {
  989. const response = await axios.post(`${API_BASE_URL}/zichan-categories`, data);
  990. return response.data;
  991. } catch (error) {
  992. throw error;
  993. }
  994. },
  995. // 更新资产分类
  996. updateZichanCategory: async (id: number, data: Partial<ZichanCategory>) => {
  997. try {
  998. const response = await axios.put(`${API_BASE_URL}/zichan-categories/${id}`, data);
  999. return response.data;
  1000. } catch (error) {
  1001. throw error;
  1002. }
  1003. },
  1004. // 删除资产分类
  1005. deleteZichanCategory: async (id: number) => {
  1006. try {
  1007. const response = await axios.delete(`${API_BASE_URL}/zichan-categories/${id}`);
  1008. return response.data;
  1009. } catch (error) {
  1010. throw error;
  1011. }
  1012. }
  1013. };
  1014. // 资产归属区域API接口定义
  1015. export const ZichanAreaAPI = {
  1016. // 获取资产归属区域列表
  1017. getZichanAreaList: async (params?: {
  1018. page?: number,
  1019. limit?: number,
  1020. name?: string,
  1021. code?: string
  1022. }) => {
  1023. try {
  1024. const response = await axios.get(`${API_BASE_URL}/zichan-areas`, { params });
  1025. return response.data;
  1026. } catch (error) {
  1027. throw error;
  1028. }
  1029. },
  1030. // 获取单个资产归属区域信息
  1031. getZichanArea: async (id: number) => {
  1032. try {
  1033. const response = await axios.get(`${API_BASE_URL}/zichan-areas/${id}`);
  1034. return response.data;
  1035. } catch (error) {
  1036. throw error;
  1037. }
  1038. },
  1039. // 创建资产归属区域
  1040. createZichanArea: async (data: Partial<ZichanArea>) => {
  1041. try {
  1042. const response = await axios.post(`${API_BASE_URL}/zichan-areas`, data);
  1043. return response.data;
  1044. } catch (error) {
  1045. throw error;
  1046. }
  1047. },
  1048. // 更新资产归属区域
  1049. updateZichanArea: async (id: number, data: Partial<ZichanArea>) => {
  1050. try {
  1051. const response = await axios.put(`${API_BASE_URL}/zichan-areas/${id}`, data);
  1052. return response.data;
  1053. } catch (error) {
  1054. throw error;
  1055. }
  1056. },
  1057. // 删除资产归属区域
  1058. deleteZichanArea: async (id: number) => {
  1059. try {
  1060. const response = await axios.delete(`${API_BASE_URL}/zichan-areas/${id}`);
  1061. return response.data;
  1062. } catch (error) {
  1063. throw error;
  1064. }
  1065. }
  1066. };
  1067. // 机柜服务器类型API接口定义
  1068. export const RackServerTypeAPI = {
  1069. // 获取机柜服务器类型列表
  1070. getRackServerTypeList: async (params?: {
  1071. page?: number,
  1072. limit?: number,
  1073. name?: string,
  1074. code?: string
  1075. }): Promise<RackServerTypeResponse> => {
  1076. try {
  1077. const response = await axios.get(`${API_BASE_URL}/rack-server-types`, { params });
  1078. return response.data;
  1079. } catch (error) {
  1080. throw error;
  1081. }
  1082. },
  1083. // 获取单个机柜服务器类型信息
  1084. getRackServerType: async (id: number) => {
  1085. try {
  1086. const response = await axios.get(`${API_BASE_URL}/rack-server-types/${id}`);
  1087. return response.data;
  1088. } catch (error) {
  1089. throw error;
  1090. }
  1091. },
  1092. // 创建机柜服务器类型
  1093. createRackServerType: async (data: Partial<RackServerType>) => {
  1094. try {
  1095. const response = await axios.post(`${API_BASE_URL}/rack-server-types`, data);
  1096. return response.data;
  1097. } catch (error) {
  1098. throw error;
  1099. }
  1100. },
  1101. // 更新机柜服务器类型
  1102. updateRackServerType: async (id: number, data: Partial<RackServerType>) => {
  1103. try {
  1104. const response = await axios.put(`${API_BASE_URL}/rack-server-types/${id}`, data);
  1105. return response.data;
  1106. } catch (error) {
  1107. throw error;
  1108. }
  1109. },
  1110. // 删除机柜服务器类型
  1111. deleteRackServerType: async (id: number) => {
  1112. try {
  1113. const response = await axios.delete(`${API_BASE_URL}/rack-server-types/${id}`);
  1114. return response.data;
  1115. } catch (error) {
  1116. throw error;
  1117. }
  1118. }
  1119. };
  1120. // 定义文件相关接口类型
  1121. interface FileUploadPolicyResponse {
  1122. message: string;
  1123. data: MinioUploadPolicy | OSSUploadPolicy;
  1124. }
  1125. interface FileListResponse {
  1126. message: string;
  1127. data: {
  1128. list: FileLibrary[];
  1129. pagination: {
  1130. current: number;
  1131. pageSize: number;
  1132. total: number;
  1133. };
  1134. };
  1135. }
  1136. interface FileSaveResponse {
  1137. message: string;
  1138. data: FileLibrary;
  1139. }
  1140. interface FileInfoResponse {
  1141. message: string;
  1142. data: FileLibrary;
  1143. }
  1144. interface FileDeleteResponse {
  1145. message: string;
  1146. }
  1147. interface FileCategoryListResponse {
  1148. data: FileCategory[];
  1149. total: number;
  1150. page: number;
  1151. pageSize: number;
  1152. }
  1153. interface FileCategoryCreateResponse {
  1154. message: string;
  1155. data: FileCategory;
  1156. }
  1157. interface FileCategoryUpdateResponse {
  1158. message: string;
  1159. data: FileCategory;
  1160. }
  1161. interface FileCategoryDeleteResponse {
  1162. message: string;
  1163. }
  1164. // 文件API接口定义
  1165. export const FileAPI = {
  1166. // 获取文件上传策略
  1167. getUploadPolicy: async (filename: string, prefix: string = 'uploads/', maxSize: number = 10 * 1024 * 1024): Promise<FileUploadPolicyResponse> => {
  1168. try {
  1169. const response = await axios.get(`${API_BASE_URL}/upload/policy`, {
  1170. params: { filename, prefix, maxSize }
  1171. });
  1172. return response.data;
  1173. } catch (error) {
  1174. throw error;
  1175. }
  1176. },
  1177. // 保存文件信息
  1178. saveFileInfo: async (fileData: Partial<FileLibrary>): Promise<FileSaveResponse> => {
  1179. try {
  1180. const response = await axios.post(`${API_BASE_URL}/upload/save`, fileData);
  1181. return response.data;
  1182. } catch (error) {
  1183. throw error;
  1184. }
  1185. },
  1186. // 获取文件列表
  1187. getFileList: async (params?: {
  1188. page?: number,
  1189. pageSize?: number,
  1190. category_id?: number,
  1191. fileType?: string,
  1192. keyword?: string
  1193. }): Promise<FileListResponse> => {
  1194. try {
  1195. const response = await axios.get(`${API_BASE_URL}/upload/list`, { params });
  1196. return response.data;
  1197. } catch (error) {
  1198. throw error;
  1199. }
  1200. },
  1201. // 获取单个文件信息
  1202. getFileInfo: async (id: number): Promise<FileInfoResponse> => {
  1203. try {
  1204. const response = await axios.get(`${API_BASE_URL}/upload/${id}`);
  1205. return response.data;
  1206. } catch (error) {
  1207. throw error;
  1208. }
  1209. },
  1210. // 更新文件下载计数
  1211. updateDownloadCount: async (id: number): Promise<FileDeleteResponse> => {
  1212. try {
  1213. const response = await axios.post(`${API_BASE_URL}/upload/${id}/download`);
  1214. return response.data;
  1215. } catch (error) {
  1216. throw error;
  1217. }
  1218. },
  1219. // 删除文件
  1220. deleteFile: async (id: number): Promise<FileDeleteResponse> => {
  1221. try {
  1222. const response = await axios.delete(`${API_BASE_URL}/upload/${id}`);
  1223. return response.data;
  1224. } catch (error) {
  1225. throw error;
  1226. }
  1227. },
  1228. // 获取文件分类列表
  1229. getCategories: async (params?: {
  1230. page?: number,
  1231. pageSize?: number,
  1232. search?: string
  1233. }): Promise<FileCategoryListResponse> => {
  1234. try {
  1235. const response = await axios.get(`${API_BASE_URL}/file-categories`, { params });
  1236. return response.data;
  1237. } catch (error) {
  1238. throw error;
  1239. }
  1240. },
  1241. // 创建文件分类
  1242. createCategory: async (data: Partial<FileCategory>): Promise<FileCategoryCreateResponse> => {
  1243. try {
  1244. const response = await axios.post(`${API_BASE_URL}/file-categories`, data);
  1245. return response.data;
  1246. } catch (error) {
  1247. throw error;
  1248. }
  1249. },
  1250. // 更新文件分类
  1251. updateCategory: async (id: number, data: Partial<FileCategory>): Promise<FileCategoryUpdateResponse> => {
  1252. try {
  1253. const response = await axios.put(`${API_BASE_URL}/file-categories/${id}`, data);
  1254. return response.data;
  1255. } catch (error) {
  1256. throw error;
  1257. }
  1258. },
  1259. // 删除文件分类
  1260. deleteCategory: async (id: number): Promise<FileCategoryDeleteResponse> => {
  1261. try {
  1262. const response = await axios.delete(`${API_BASE_URL}/file-categories/${id}`);
  1263. return response.data;
  1264. } catch (error) {
  1265. throw error;
  1266. }
  1267. }
  1268. };
  1269. // // 添加图表类型定义(从大屏移植)
  1270. // interface CategoryChartData {
  1271. // 设备分类: string;
  1272. // 设备数: number;
  1273. // }
  1274. // interface CategoryChartDataWithPercent extends CategoryChartData {
  1275. // 百分比: string;
  1276. // }
  1277. // interface OnlineRateChartData {
  1278. // time_interval: string;
  1279. // online_devices: number;
  1280. // total_devices: number;
  1281. // }
  1282. // interface StateChartData {
  1283. // 资产流转: string;
  1284. // 设备数: number;
  1285. // }
  1286. // interface StateChartDataWithPercent extends StateChartData {
  1287. // 百分比: string;
  1288. // }
  1289. // interface AlarmChartData {
  1290. // time_interval: string;
  1291. // total_devices: number;
  1292. // }
  1293. // 统一图表数据查询函数
  1294. export const chartQueryFns = {
  1295. // 资产分类数据查询
  1296. fetchCategoryData: async (): Promise<CategoryChartDataWithPercent[]> => {
  1297. const res = await axios.get<CategoryChartData[]>(`${API_BASE_URL}/big/zichan_category_chart`);
  1298. // 预先计算百分比
  1299. const data = res.data;
  1300. const total = data.reduce((sum: number, item: CategoryChartData) => sum + item['设备数'], 0);
  1301. // 为每个数据项添加百分比字段
  1302. return data.map(item => ({
  1303. ...item,
  1304. 百分比: total > 0 ? (item['设备数'] / total * 100).toFixed(1) : '0'
  1305. }));
  1306. },
  1307. // 在线率变化数据查询
  1308. fetchOnlineRateData: async (params?: {
  1309. created_at_gte?: string;
  1310. created_at_lte?: string;
  1311. dimension?: string;
  1312. }): Promise<OnlineRateChartData[]> => {
  1313. // 可选参数
  1314. // const params = {
  1315. // created_at_gte: dayjs().subtract(7, 'day').format('YYYY-MM-DD HH:mm:ss'),
  1316. // created_at_lte: dayjs().format('YYYY-MM-DD HH:mm:ss'),
  1317. // dimension: 'day'
  1318. // };
  1319. const res = await axios.get<OnlineRateChartData[]>(`${API_BASE_URL}/big/zichan_online_rate_chart`, { params });
  1320. return res.data;
  1321. },
  1322. // 资产流转状态数据查询
  1323. fetchStateData: async (): Promise<StateChartDataWithPercent[]> => {
  1324. const res = await axios.get<StateChartData[]>(`${API_BASE_URL}/big/zichan_state_chart`);
  1325. // 预先计算百分比
  1326. const data = res.data;
  1327. const total = data.reduce((sum: number, item: StateChartData) => sum + item['设备数'], 0);
  1328. // 为每个数据项添加百分比字段
  1329. return data.map(item => ({
  1330. ...item,
  1331. 百分比: total > 0 ? (item['设备数'] / total * 100).toFixed(1) : '0'
  1332. }));
  1333. },
  1334. // 告警数据变化查询
  1335. fetchAlarmData: async (params?: {
  1336. created_at_gte?: string;
  1337. created_at_lte?: string;
  1338. dimension?: string;
  1339. }): Promise<AlarmChartData[]> => {
  1340. // 可选参数
  1341. // const params = {
  1342. // created_at_gte: dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
  1343. // created_at_lte: dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss'),
  1344. // dimension: 'hour'
  1345. // };
  1346. const res = await axios.get<AlarmChartData[]>(`${API_BASE_URL}/big/zichan_alarm_chart`, { params });
  1347. return res.data;
  1348. }
  1349. };
  1350. // Theme API 响应类型
  1351. export interface ThemeSettingsResponse {
  1352. message: string;
  1353. data: ThemeSettings;
  1354. }
  1355. // Theme API 定义
  1356. export const ThemeAPI = {
  1357. // 获取主题设置
  1358. getThemeSettings: async (): Promise<ThemeSettings> => {
  1359. try {
  1360. const response = await axios.get(`${API_BASE_URL}/theme`);
  1361. return response.data.data;
  1362. } catch (error) {
  1363. throw error;
  1364. }
  1365. },
  1366. // 更新主题设置
  1367. updateThemeSettings: async (themeData: Partial<ThemeSettings>): Promise<ThemeSettings> => {
  1368. try {
  1369. const response = await axios.put(`${API_BASE_URL}/theme`, themeData);
  1370. return response.data.data;
  1371. } catch (error) {
  1372. throw error;
  1373. }
  1374. },
  1375. // 重置主题设置
  1376. resetThemeSettings: async (): Promise<ThemeSettings> => {
  1377. try {
  1378. const response = await axios.post(`${API_BASE_URL}/theme/reset`);
  1379. return response.data.data;
  1380. } catch (error) {
  1381. throw error;
  1382. }
  1383. }
  1384. };
  1385. // 图表数据API接口类型
  1386. interface ChartDataResponse<T> {
  1387. message: string;
  1388. data: T;
  1389. }
  1390. interface UserActivityData {
  1391. date: string;
  1392. count: number;
  1393. }
  1394. interface FileUploadsData {
  1395. month: string;
  1396. count: number;
  1397. }
  1398. interface FileTypesData {
  1399. type: string;
  1400. value: number;
  1401. }
  1402. interface DashboardOverviewData {
  1403. userCount: number;
  1404. fileCount: number;
  1405. articleCount: number;
  1406. todayLoginCount: number;
  1407. }
  1408. // 图表数据API
  1409. export const ChartAPI = {
  1410. // 获取用户活跃度数据
  1411. getUserActivity: async (): Promise<ChartDataResponse<UserActivityData[]>> => {
  1412. try {
  1413. const response = await axios.get(`${API_BASE_URL}/charts/user-activity`);
  1414. return response.data;
  1415. } catch (error) {
  1416. throw error;
  1417. }
  1418. },
  1419. // 获取文件上传统计数据
  1420. getFileUploads: async (): Promise<ChartDataResponse<FileUploadsData[]>> => {
  1421. try {
  1422. const response = await axios.get(`${API_BASE_URL}/charts/file-uploads`);
  1423. return response.data;
  1424. } catch (error) {
  1425. throw error;
  1426. }
  1427. },
  1428. // 获取文件类型分布数据
  1429. getFileTypes: async (): Promise<ChartDataResponse<FileTypesData[]>> => {
  1430. try {
  1431. const response = await axios.get(`${API_BASE_URL}/charts/file-types`);
  1432. return response.data;
  1433. } catch (error) {
  1434. throw error;
  1435. }
  1436. },
  1437. // 获取仪表盘概览数据
  1438. getDashboardOverview: async (): Promise<ChartDataResponse<DashboardOverviewData>> => {
  1439. try {
  1440. const response = await axios.get(`${API_BASE_URL}/charts/dashboard-overview`);
  1441. return response.data;
  1442. } catch (error) {
  1443. throw error;
  1444. }
  1445. }
  1446. };
  1447. // 地图相关API的接口类型定义
  1448. export interface LoginLocationResponse {
  1449. message: string;
  1450. data: LoginLocation[];
  1451. }
  1452. export interface LoginLocationDetailResponse {
  1453. message: string;
  1454. data: LoginLocationDetail;
  1455. }
  1456. export interface LoginLocationUpdateResponse {
  1457. message: string;
  1458. data: LoginLocationDetail;
  1459. }
  1460. // 地图相关API
  1461. export const MapAPI = {
  1462. // 获取地图标记点数据
  1463. getMarkers: async (params?: {
  1464. startTime?: string;
  1465. endTime?: string;
  1466. userId?: number
  1467. }): Promise<LoginLocationResponse> => {
  1468. try {
  1469. const response = await axios.get(`${API_BASE_URL}/map/markers`, { params });
  1470. return response.data;
  1471. } catch (error) {
  1472. throw error;
  1473. }
  1474. },
  1475. // 获取登录位置详情
  1476. getLocationDetail: async (locationId: number): Promise<LoginLocationDetailResponse> => {
  1477. try {
  1478. const response = await axios.get(`${API_BASE_URL}/map/location/${locationId}`);
  1479. return response.data;
  1480. } catch (error) {
  1481. throw error;
  1482. }
  1483. },
  1484. // 更新登录位置信息
  1485. updateLocation: async (locationId: number, data: {
  1486. longitude: number;
  1487. latitude: number;
  1488. location_name?: string;
  1489. }): Promise<LoginLocationUpdateResponse> => {
  1490. try {
  1491. const response = await axios.put(`${API_BASE_URL}/map/location/${locationId}`, data);
  1492. return response.data;
  1493. } catch (error) {
  1494. throw error;
  1495. }
  1496. }
  1497. };
  1498. // 系统设置API响应类型
  1499. interface SystemSettingsResponse {
  1500. message: string;
  1501. data: SystemSetting[];
  1502. }
  1503. // 系统设置API
  1504. export const SystemAPI = {
  1505. // 获取所有系统设置
  1506. getSettings: async (): Promise<SystemSettingGroupData[]> => {
  1507. try {
  1508. const response = await axios.get(`${API_BASE_URL}/settings`);
  1509. return response.data.data;
  1510. } catch (error) {
  1511. throw error;
  1512. }
  1513. },
  1514. // 获取指定分组的系统设置
  1515. getSettingsByGroup: async (group: string): Promise<SystemSetting[]> => {
  1516. try {
  1517. const response = await axios.get(`${API_BASE_URL}/settings/group/${group}`);
  1518. return response.data.data;
  1519. } catch (error) {
  1520. throw error;
  1521. }
  1522. },
  1523. // 更新系统设置
  1524. updateSettings: async (settings: Partial<SystemSetting>[]): Promise<SystemSetting[]> => {
  1525. try {
  1526. const response = await axios.put(`${API_BASE_URL}/settings`, settings);
  1527. return response.data.data;
  1528. } catch (error) {
  1529. throw error;
  1530. }
  1531. },
  1532. // 重置系统设置
  1533. resetSettings: async (): Promise<SystemSetting[]> => {
  1534. try {
  1535. const response = await axios.post(`${API_BASE_URL}/settings/reset`);
  1536. return response.data.data;
  1537. } catch (error) {
  1538. throw error;
  1539. }
  1540. }
  1541. };