api.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  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, ThemeSettings,
  6. SystemSetting, SystemSettingGroupData,
  7. LoginLocation, LoginLocationDetail,
  8. MessageType, MessageStatus, UserMessage,
  9. KnowInfo
  10. } from '../share/types.ts';
  11. // 定义API基础URL
  12. const API_BASE_URL = '/api';
  13. // 获取OSS完整URL
  14. export const getOssUrl = (path: string): string => {
  15. // 获取全局配置中的OSS_HOST,如果不存在使用默认值
  16. const ossHost = (window.CONFIG?.OSS_BASE_URL) || '';
  17. // 确保path不以/开头
  18. const ossPath = path.startsWith('/') ? path.substring(1) : path;
  19. return `${ossHost}/${ossPath}`;
  20. };
  21. // ===================
  22. // Auth API 定义部分
  23. // ===================
  24. // 定义API返回数据类型
  25. interface AuthLoginResponse {
  26. message: string;
  27. token: string;
  28. refreshToken?: string;
  29. user: User;
  30. }
  31. interface AuthResponse {
  32. message: string;
  33. [key: string]: any;
  34. }
  35. // 定义Auth API接口类型
  36. interface AuthAPIType {
  37. login: (username: string, password: string, latitude?: number, longitude?: number) => Promise<AuthLoginResponse>;
  38. register: (data: {
  39. username: string;
  40. email: string;
  41. password: string;
  42. organizationId?: number;
  43. }) => Promise<AuthResponse>;
  44. logout: () => Promise<AuthResponse>;
  45. getCurrentUser: () => Promise<User>;
  46. updateUser: (userId: number, userData: Partial<User>) => Promise<User>;
  47. changePassword: (oldPassword: string, newPassword: string) => Promise<AuthResponse>;
  48. requestPasswordReset: (email: string) => Promise<AuthResponse>;
  49. resetPassword: (token: string, newPassword: string) => Promise<AuthResponse>;
  50. }
  51. // Auth相关API
  52. export const AuthAPI: AuthAPIType = {
  53. // 登录API
  54. login: async (username: string, password: string, latitude?: number, longitude?: number) => {
  55. try {
  56. const response = await axios.post(`${API_BASE_URL}/auth/login`, {
  57. username,
  58. password,
  59. latitude,
  60. longitude
  61. });
  62. return response.data;
  63. } catch (error) {
  64. throw error;
  65. }
  66. },
  67. // 注册API
  68. register: async (data: {
  69. username: string;
  70. email: string;
  71. password: string;
  72. organizationId?: number;
  73. }) => {
  74. try {
  75. const response = await axios.post(`${API_BASE_URL}/auth/register`, data);
  76. return response.data;
  77. } catch (error) {
  78. throw error;
  79. }
  80. },
  81. // 登出API
  82. logout: async () => {
  83. try {
  84. const response = await axios.post(`${API_BASE_URL}/auth/logout`);
  85. return response.data;
  86. } catch (error) {
  87. throw error;
  88. }
  89. },
  90. // 获取当前用户信息
  91. getCurrentUser: async () => {
  92. try {
  93. const response = await axios.get(`${API_BASE_URL}/auth/me`);
  94. return response.data;
  95. } catch (error) {
  96. throw error;
  97. }
  98. },
  99. // 更新用户信息
  100. updateUser: async (userId: number, userData: Partial<User>) => {
  101. try {
  102. const response = await axios.put(`${API_BASE_URL}/auth/users/${userId}`, userData);
  103. return response.data;
  104. } catch (error) {
  105. throw error;
  106. }
  107. },
  108. // 修改密码
  109. changePassword: async (oldPassword: string, newPassword: string) => {
  110. try {
  111. const response = await axios.post(`${API_BASE_URL}/auth/change-password`, { oldPassword, newPassword });
  112. return response.data;
  113. } catch (error) {
  114. throw error;
  115. }
  116. },
  117. // 请求重置密码
  118. requestPasswordReset: async (email: string) => {
  119. try {
  120. const response = await axios.post(`${API_BASE_URL}/auth/request-password-reset`, { email });
  121. return response.data;
  122. } catch (error) {
  123. throw error;
  124. }
  125. },
  126. // 重置密码
  127. resetPassword: async (token: string, newPassword: string) => {
  128. try {
  129. const response = await axios.post(`${API_BASE_URL}/auth/reset-password`, { token, newPassword });
  130. return response.data;
  131. } catch (error) {
  132. throw error;
  133. }
  134. }
  135. };
  136. // 首页相关接口响应类型
  137. interface HomeBannersResponse {
  138. message: string;
  139. data: KnowInfo[];
  140. }
  141. interface HomeNewsResponse {
  142. message: string;
  143. data: KnowInfo[];
  144. pagination: {
  145. total: number;
  146. current: number;
  147. pageSize: number;
  148. totalPages: number;
  149. };
  150. }
  151. interface HomeNoticesResponse {
  152. message: string;
  153. data: {
  154. id: number;
  155. title: string;
  156. content: string;
  157. created_at: string;
  158. }[];
  159. pagination: {
  160. total: number;
  161. current: number;
  162. pageSize: number;
  163. totalPages: number;
  164. };
  165. }
  166. export interface LoginLocationResponse {
  167. message: string;
  168. data: LoginLocation[];
  169. }
  170. export interface LoginLocationUpdateResponse {
  171. message: string;
  172. data: LoginLocationDetail;
  173. }
  174. export interface LoginLocationDetailResponse {
  175. message: string;
  176. data: LoginLocationDetail;
  177. }
  178. // 为UserAPI添加的接口响应类型
  179. interface UsersResponse {
  180. data: User[];
  181. pagination: {
  182. total: number;
  183. current: number;
  184. pageSize: number;
  185. totalPages: number;
  186. };
  187. }
  188. export interface UserResponse {
  189. data: User;
  190. message?: string;
  191. }
  192. interface UserCreateResponse {
  193. message: string;
  194. data: User;
  195. }
  196. interface UserUpdateResponse {
  197. message: string;
  198. data: User;
  199. }
  200. interface UserDeleteResponse {
  201. message: string;
  202. id: number;
  203. }
  204. // 用户管理API
  205. export const UserAPI = {
  206. // 获取用户列表
  207. getUsers: async (params?: { page?: number, limit?: number, search?: string }): Promise<UsersResponse> => {
  208. try {
  209. const response = await axios.get(`${API_BASE_URL}/users`, { params });
  210. return response.data;
  211. } catch (error) {
  212. throw error;
  213. }
  214. },
  215. // 获取单个用户详情
  216. getUser: async (userId: number): Promise<UserResponse> => {
  217. try {
  218. const response = await axios.get(`${API_BASE_URL}/users/${userId}`);
  219. return response.data;
  220. } catch (error) {
  221. throw error;
  222. }
  223. },
  224. // 创建用户
  225. createUser: async (userData: Partial<User>): Promise<UserCreateResponse> => {
  226. try {
  227. const response = await axios.post(`${API_BASE_URL}/users`, userData);
  228. return response.data;
  229. } catch (error) {
  230. throw error;
  231. }
  232. },
  233. // 更新用户信息
  234. updateUser: async (userId: number, userData: Partial<User>): Promise<UserUpdateResponse> => {
  235. try {
  236. const response = await axios.put(`${API_BASE_URL}/users/${userId}`, userData);
  237. return response.data;
  238. } catch (error) {
  239. throw error;
  240. }
  241. },
  242. // 删除用户
  243. deleteUser: async (userId: number): Promise<UserDeleteResponse> => {
  244. try {
  245. const response = await axios.delete(`${API_BASE_URL}/users/${userId}`);
  246. return response.data;
  247. } catch (error) {
  248. throw error;
  249. }
  250. },
  251. // 获取当前用户信息
  252. getCurrentUser: async (): Promise<UserResponse> => {
  253. try {
  254. const response = await axios.get(`${API_BASE_URL}/users/me/profile`);
  255. return response.data;
  256. } catch (error) {
  257. throw error;
  258. }
  259. },
  260. // 更新当前用户信息
  261. updateCurrentUser: async (userData: Partial<User>): Promise<UserUpdateResponse> => {
  262. try {
  263. const response = await axios.put(`${API_BASE_URL}/users/me/profile`, userData);
  264. return response.data;
  265. } catch (error) {
  266. throw error;
  267. }
  268. }
  269. };
  270. // 定义文件相关接口类型
  271. interface FileUploadPolicyResponse {
  272. message: string;
  273. data: MinioUploadPolicy | OSSUploadPolicy;
  274. }
  275. interface FileListResponse {
  276. message: string;
  277. data: {
  278. list: FileLibrary[];
  279. pagination: {
  280. current: number;
  281. pageSize: number;
  282. total: number;
  283. };
  284. };
  285. }
  286. interface FileSaveResponse {
  287. message: string;
  288. data: FileLibrary;
  289. }
  290. interface FileInfoResponse {
  291. message: string;
  292. data: FileLibrary;
  293. }
  294. interface FileDeleteResponse {
  295. message: string;
  296. }
  297. interface FileCategoryListResponse {
  298. data: FileCategory[];
  299. total: number;
  300. page: number;
  301. pageSize: number;
  302. }
  303. interface FileCategoryCreateResponse {
  304. message: string;
  305. data: FileCategory;
  306. }
  307. interface FileCategoryUpdateResponse {
  308. message: string;
  309. data: FileCategory;
  310. }
  311. interface FileCategoryDeleteResponse {
  312. message: string;
  313. }
  314. // 文件API接口定义
  315. export const FileAPI = {
  316. // 获取文件上传策略
  317. getUploadPolicy: async (filename: string, prefix: string = 'uploads/', maxSize: number = 10 * 1024 * 1024): Promise<FileUploadPolicyResponse> => {
  318. try {
  319. const response = await axios.get(`${API_BASE_URL}/upload/policy`, {
  320. params: { filename, prefix, maxSize }
  321. });
  322. return response.data;
  323. } catch (error) {
  324. throw error;
  325. }
  326. },
  327. // 保存文件信息
  328. saveFileInfo: async (fileData: Partial<FileLibrary>): Promise<FileSaveResponse> => {
  329. try {
  330. const response = await axios.post(`${API_BASE_URL}/upload/save`, fileData);
  331. return response.data;
  332. } catch (error) {
  333. throw error;
  334. }
  335. },
  336. // 获取文件列表
  337. getFileList: async (params?: {
  338. page?: number,
  339. pageSize?: number,
  340. category_id?: number,
  341. fileType?: string,
  342. keyword?: string
  343. }): Promise<FileListResponse> => {
  344. try {
  345. const response = await axios.get(`${API_BASE_URL}/upload/list`, { params });
  346. return response.data;
  347. } catch (error) {
  348. throw error;
  349. }
  350. },
  351. // 获取单个文件信息
  352. getFileInfo: async (id: number): Promise<FileInfoResponse> => {
  353. try {
  354. const response = await axios.get(`${API_BASE_URL}/upload/${id}`);
  355. return response.data;
  356. } catch (error) {
  357. throw error;
  358. }
  359. },
  360. // 更新文件下载计数
  361. updateDownloadCount: async (id: number): Promise<FileDeleteResponse> => {
  362. try {
  363. const response = await axios.post(`${API_BASE_URL}/upload/${id}/download`);
  364. return response.data;
  365. } catch (error) {
  366. throw error;
  367. }
  368. },
  369. // 删除文件
  370. deleteFile: async (id: number): Promise<FileDeleteResponse> => {
  371. try {
  372. const response = await axios.delete(`${API_BASE_URL}/upload/${id}`);
  373. return response.data;
  374. } catch (error) {
  375. throw error;
  376. }
  377. },
  378. // 获取文件分类列表
  379. getCategories: async (params?: {
  380. page?: number,
  381. pageSize?: number,
  382. search?: string
  383. }): Promise<FileCategoryListResponse> => {
  384. try {
  385. const response = await axios.get(`${API_BASE_URL}/file-categories`, { params });
  386. return response.data;
  387. } catch (error) {
  388. throw error;
  389. }
  390. },
  391. // 创建文件分类
  392. createCategory: async (data: Partial<FileCategory>): Promise<FileCategoryCreateResponse> => {
  393. try {
  394. const response = await axios.post(`${API_BASE_URL}/file-categories`, data);
  395. return response.data;
  396. } catch (error) {
  397. throw error;
  398. }
  399. },
  400. // 更新文件分类
  401. updateCategory: async (id: number, data: Partial<FileCategory>): Promise<FileCategoryUpdateResponse> => {
  402. try {
  403. const response = await axios.put(`${API_BASE_URL}/file-categories/${id}`, data);
  404. return response.data;
  405. } catch (error) {
  406. throw error;
  407. }
  408. },
  409. // 删除文件分类
  410. deleteCategory: async (id: number): Promise<FileCategoryDeleteResponse> => {
  411. try {
  412. const response = await axios.delete(`${API_BASE_URL}/file-categories/${id}`);
  413. return response.data;
  414. } catch (error) {
  415. throw error;
  416. }
  417. }
  418. };
  419. // Theme API 定义
  420. export const ThemeAPI = {
  421. // 获取主题设置
  422. getThemeSettings: async (): Promise<ThemeSettings> => {
  423. try {
  424. const response = await axios.get(`${API_BASE_URL}/theme`);
  425. return response.data.data;
  426. } catch (error) {
  427. throw error;
  428. }
  429. },
  430. // 更新主题设置
  431. updateThemeSettings: async (themeData: Partial<ThemeSettings>): Promise<ThemeSettings> => {
  432. try {
  433. const response = await axios.put(`${API_BASE_URL}/theme`, themeData);
  434. return response.data.data;
  435. } catch (error) {
  436. throw error;
  437. }
  438. },
  439. // 重置主题设置
  440. resetThemeSettings: async (): Promise<ThemeSettings> => {
  441. try {
  442. const response = await axios.post(`${API_BASE_URL}/theme/reset`);
  443. return response.data.data;
  444. } catch (error) {
  445. throw error;
  446. }
  447. }
  448. };
  449. // 图表数据API接口类型
  450. interface ChartDataResponse<T> {
  451. message: string;
  452. data: T;
  453. }
  454. interface UserActivityData {
  455. date: string;
  456. count: number;
  457. }
  458. interface FileUploadsData {
  459. month: string;
  460. count: number;
  461. }
  462. interface FileTypesData {
  463. type: string;
  464. value: number;
  465. }
  466. interface DashboardOverviewData {
  467. userCount: number;
  468. fileCount: number;
  469. articleCount: number;
  470. todayLoginCount: number;
  471. }
  472. // 图表数据API
  473. export const ChartAPI = {
  474. // 获取用户活跃度数据
  475. getUserActivity: async (): Promise<ChartDataResponse<UserActivityData[]>> => {
  476. try {
  477. const response = await axios.get(`${API_BASE_URL}/charts/user-activity`);
  478. return response.data;
  479. } catch (error) {
  480. throw error;
  481. }
  482. },
  483. // 获取文件上传统计数据
  484. getFileUploads: async (): Promise<ChartDataResponse<FileUploadsData[]>> => {
  485. try {
  486. const res = await axios.get(`${API_BASE_URL}/charts/file-uploads`);
  487. return res.data;
  488. } catch (error) {
  489. throw error;
  490. }
  491. },
  492. // 获取文件类型统计数据
  493. getFileTypes: async (): Promise<ChartDataResponse<FileTypesData[]>> => {
  494. try {
  495. const res = await axios.get(`${API_BASE_URL}/charts/file-types`);
  496. return res.data;
  497. } catch (error) {
  498. throw error;
  499. }
  500. },
  501. // 获取仪表板概览数据
  502. getDashboardOverview: async (): Promise<ChartDataResponse<DashboardOverviewData>> => {
  503. try {
  504. const res = await axios.get(`${API_BASE_URL}/charts/dashboard-overview`);
  505. return res.data;
  506. } catch (error) {
  507. throw error;
  508. }
  509. }
  510. };
  511. // 系统管理API
  512. export const SysAPI = {
  513. // 获取机构树形列表
  514. getOrganizations: async (): Promise<{ data: any[] }> => {
  515. try {
  516. const res = await axios.get(`${API_BASE_URL}/sys/organizations/tree`);
  517. return res.data;
  518. } catch (error) {
  519. throw error;
  520. }
  521. },
  522. // 创建机构
  523. createOrganization: async (data: {
  524. name: string;
  525. parentId?: number;
  526. code?: string;
  527. description?: string;
  528. }) => {
  529. try {
  530. const res = await axios.post(`${API_BASE_URL}/sys/organizations`, data);
  531. return res.data;
  532. } catch (error) {
  533. throw error;
  534. }
  535. },
  536. // 更新机构
  537. updateOrganization: async (id: number, data: {
  538. name?: string;
  539. parentId?: number;
  540. code?: string;
  541. description?: string;
  542. }) => {
  543. try {
  544. const res = await axios.put(`${API_BASE_URL}/sys/organizations/${id}`, data);
  545. return res.data;
  546. } catch (error) {
  547. throw error;
  548. }
  549. },
  550. // 删除机构
  551. deleteOrganization: async (id: number) => {
  552. try {
  553. const res = await axios.delete(`${API_BASE_URL}/sys/organizations/${id}`);
  554. return res.data;
  555. } catch (error) {
  556. throw error;
  557. }
  558. }
  559. }
  560. // 首页API
  561. export const HomeAPI = {
  562. // 获取轮播图
  563. getBanners: async (): Promise<HomeBannersResponse> => {
  564. try {
  565. const response = await axios.get(`${API_BASE_URL}/home/banners`);
  566. return response.data;
  567. } catch (error) {
  568. throw error;
  569. }
  570. },
  571. // 获取新闻列表
  572. getNews: async (params?: {
  573. page?: number,
  574. pageSize?: number,
  575. category?: string
  576. }): Promise<HomeNewsResponse> => {
  577. try {
  578. const response = await axios.get(`${API_BASE_URL}/home/news`, { params });
  579. return response.data;
  580. } catch (error) {
  581. throw error;
  582. }
  583. },
  584. // 获取通知列表
  585. getNotices: async (params?: {
  586. page?: number,
  587. pageSize?: number
  588. }): Promise<HomeNoticesResponse> => {
  589. try {
  590. const response = await axios.get(`${API_BASE_URL}/home/notices`, { params });
  591. return response.data;
  592. } catch (error) {
  593. throw error;
  594. }
  595. }
  596. };
  597. // 地图相关API的接口类型定义
  598. // 地图相关API
  599. export const MapAPI = {
  600. // 获取地图标记点数据
  601. getMarkers: async (params?: {
  602. startTime?: string;
  603. endTime?: string;
  604. userId?: number
  605. }): Promise<LoginLocationResponse> => {
  606. try {
  607. const response = await axios.get(`${API_BASE_URL}/map/markers`, { params });
  608. return response.data;
  609. } catch (error) {
  610. throw error;
  611. }
  612. },
  613. // 获取登录位置详情
  614. getLocationDetail: async (locationId: number): Promise<LoginLocationDetailResponse> => {
  615. try {
  616. const response = await axios.get(`${API_BASE_URL}/map/location/${locationId}`);
  617. return response.data;
  618. } catch (error) {
  619. throw error;
  620. }
  621. },
  622. // 更新登录位置信息
  623. updateLocation: async (locationId: number, data: {
  624. longitude: number;
  625. latitude: number;
  626. location_name?: string;
  627. }): Promise<LoginLocationUpdateResponse> => {
  628. try {
  629. const response = await axios.put(`${API_BASE_URL}/map/location/${locationId}`, data);
  630. return response.data;
  631. } catch (error) {
  632. throw error;
  633. }
  634. }
  635. };
  636. // 系统设置API
  637. export const SystemAPI = {
  638. // 获取所有系统设置
  639. getSettings: async (): Promise<SystemSettingGroupData[]> => {
  640. try {
  641. const response = await axios.get(`${API_BASE_URL}/settings`);
  642. return response.data.data;
  643. } catch (error) {
  644. throw error;
  645. }
  646. },
  647. // 获取指定分组的系统设置
  648. getSettingsByGroup: async (group: string): Promise<SystemSetting[]> => {
  649. try {
  650. const response = await axios.get(`${API_BASE_URL}/settings/group/${group}`);
  651. return response.data.data;
  652. } catch (error) {
  653. throw error;
  654. }
  655. },
  656. // 更新系统设置
  657. updateSettings: async (settings: Partial<SystemSetting>[]): Promise<SystemSetting[]> => {
  658. try {
  659. const response = await axios.put(`${API_BASE_URL}/settings`, settings);
  660. return response.data.data;
  661. } catch (error) {
  662. throw error;
  663. }
  664. },
  665. // 重置系统设置
  666. resetSettings: async (): Promise<SystemSetting[]> => {
  667. try {
  668. const response = await axios.post(`${API_BASE_URL}/settings/reset`);
  669. return response.data.data;
  670. } catch (error) {
  671. throw error;
  672. }
  673. }
  674. };
  675. // 消息API响应类型
  676. export interface MessageResponse {
  677. message: string;
  678. data?: any;
  679. }
  680. export interface MessagesResponse {
  681. data: UserMessage[];
  682. pagination: {
  683. total: number;
  684. current: number;
  685. pageSize: number;
  686. totalPages: number;
  687. };
  688. }
  689. export interface UnreadCountResponse {
  690. count: number;
  691. }
  692. // 消息API
  693. export const MessageAPI = {
  694. // 获取消息列表
  695. getMessages: async (params?: {
  696. page?: number,
  697. pageSize?: number,
  698. type?: MessageType,
  699. status?: MessageStatus
  700. }): Promise<MessagesResponse> => {
  701. try {
  702. const response = await axios.get(`${API_BASE_URL}/messages`, { params });
  703. return response.data;
  704. } catch (error) {
  705. throw error;
  706. }
  707. },
  708. // 获取消息详情
  709. getMessage: async (id: number): Promise<MessageResponse> => {
  710. try {
  711. const response = await axios.get(`${API_BASE_URL}/messages/${id}`);
  712. return response.data;
  713. } catch (error) {
  714. throw error;
  715. }
  716. },
  717. // 发送消息
  718. sendMessage: async (data: {
  719. title: string,
  720. content: string,
  721. type: MessageType,
  722. receiver_ids: number[]
  723. }): Promise<MessageResponse> => {
  724. try {
  725. const response = await axios.post(`${API_BASE_URL}/messages`, data);
  726. return response.data;
  727. } catch (error) {
  728. throw error;
  729. }
  730. },
  731. // 删除消息(软删除)
  732. deleteMessage: async (id: number): Promise<MessageResponse> => {
  733. try {
  734. const response = await axios.delete(`${API_BASE_URL}/messages/${id}`);
  735. return response.data;
  736. } catch (error) {
  737. throw error;
  738. }
  739. },
  740. // 获取未读消息数量
  741. getUnreadCount: async (): Promise<UnreadCountResponse> => {
  742. try {
  743. const response = await axios.get(`${API_BASE_URL}/messages/count/unread`);
  744. return response.data;
  745. } catch (error) {
  746. throw error;
  747. }
  748. },
  749. // 标记消息为已读
  750. markAsRead: async (id: number): Promise<MessageResponse> => {
  751. try {
  752. const response = await axios.post(`${API_BASE_URL}/messages/${id}/read`);
  753. return response.data;
  754. } catch (error) {
  755. throw error;
  756. }
  757. }
  758. };