xunlian_codes.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import axios from 'axios';
  2. import type { XunlianCode } from '../../share/types_stock.ts';
  3. // 训练代码列表响应
  4. interface XunlianCodeListResponse {
  5. data: XunlianCode[];
  6. pagination: {
  7. current: number;
  8. pageSize: number;
  9. total: number;
  10. totalPages: number;
  11. };
  12. }
  13. interface XunlianCodeResponse {
  14. data: XunlianCode;
  15. message?: string;
  16. }
  17. interface XunlianCodeCreateResponse {
  18. message: string;
  19. data: XunlianCode;
  20. }
  21. interface XunlianCodeUpdateResponse {
  22. message: string;
  23. data: XunlianCode;
  24. }
  25. interface XunlianCodeDeleteResponse {
  26. message: string;
  27. id: number;
  28. }
  29. export const XunlianCodeAPI = {
  30. getXunlianCodes: async (params: {
  31. page?: number;
  32. pageSize?: number;
  33. code?: string;
  34. stock_name?: string;
  35. }): Promise<XunlianCodeListResponse> => {
  36. try {
  37. const response = await axios.get('/xunlian-codes', { params });
  38. return response.data;
  39. } catch (error) {
  40. throw error;
  41. }
  42. },
  43. getXunlianCode: async (id: number): Promise<XunlianCodeResponse> => {
  44. try {
  45. const response = await axios.get(`/xunlian-codes/${id}`);
  46. return response.data;
  47. } catch (error) {
  48. throw error;
  49. }
  50. },
  51. createXunlianCode: async (data: Partial<XunlianCode>): Promise<XunlianCodeCreateResponse> => {
  52. try {
  53. const response = await axios.post('/xunlian-codes', data);
  54. return response.data;
  55. } catch (error) {
  56. throw error;
  57. }
  58. },
  59. updateXunlianCode: async (id: number, data: Partial<XunlianCode>): Promise<XunlianCodeUpdateResponse> => {
  60. try {
  61. const response = await axios.put(`/xunlian-codes/${id}`, data);
  62. return response.data;
  63. } catch (error) {
  64. throw error;
  65. }
  66. },
  67. deleteXunlianCode: async (id: number): Promise<XunlianCodeDeleteResponse> => {
  68. try {
  69. const response = await axios.delete(`/xunlian-codes/${id}`);
  70. return response.data;
  71. } catch (error) {
  72. throw error;
  73. }
  74. }
  75. };