productService.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // src/lib/services/productService.ts
  2. import api from '@/lib/api';
  3. export interface ProductListParams {
  4. page?: number;
  5. size?: number;
  6. page_size?: number;
  7. keyword?: string;
  8. is_active?: boolean;
  9. category?: string;
  10. [key: string]: any;
  11. }
  12. export const productService = {
  13. /**
  14. * 获取已启用的产品列表 (客户端前台)
  15. */
  16. async listEnabled(params?: ProductListParams) {
  17. const res = await api.get('/api/vas/product/list-enable', { params });
  18. return res.data;
  19. },
  20. /**
  21. * 分页查询产品列表 (后台)
  22. */
  23. async listAll(params?: ProductListParams) {
  24. const res = await api.get('/api/vas/product/list', { params });
  25. return res.data;
  26. },
  27. /**
  28. * 获取产品详情
  29. */
  30. async getDetail(productId: number) {
  31. const res = await api.get('/api/vas/product/detail', {
  32. params: { product_id: productId },
  33. });
  34. return res.data;
  35. },
  36. /**
  37. * 新建产品
  38. */
  39. async create(payload: Record<string, any>) {
  40. const res = await api.post('/api/vas/product/create', payload);
  41. return res.data;
  42. },
  43. /**
  44. * 更新产品
  45. */
  46. async update(productId: number, payload: Record<string, any>) {
  47. const res = await api.post('/api/vas/product/update', payload, {
  48. params: { product_id: productId },
  49. });
  50. return res.data;
  51. },
  52. /**
  53. * 删除产品
  54. */
  55. async delete(productId: number) {
  56. const res = await api.delete('/api/vas/product/delete', {
  57. params: { product_id: productId },
  58. });
  59. return res.data;
  60. },
  61. /**
  62. * 查询所有表单 Schema 列表
  63. */
  64. async listSchemas(params?: { page?: number; size?: number; page_size?: number; keyword?: string }) {
  65. const res = await api.get('/api/vas/schema/list', { params });
  66. return res.data;
  67. },
  68. /**
  69. * 获取指定 Schema 详情
  70. */
  71. async getSchemaDetail(schemaId: number) {
  72. const res = await api.get('/api/vas/schema/detail', {
  73. params: { schema_id: schemaId },
  74. });
  75. return res.data;
  76. },
  77. /**
  78. * 新增动态表单 Schema
  79. */
  80. async createSchema(payload: Record<string, any>) {
  81. const res = await api.post('/api/vas/schema/create', payload);
  82. return res.data;
  83. },
  84. /**
  85. * 更新动态表单 Schema
  86. */
  87. async updateSchema(schemaId: number, payload: Record<string, any>) {
  88. const res = await api.post('/api/vas/schema/update', payload, {
  89. params: { schema_id: schemaId },
  90. });
  91. return res.data;
  92. },
  93. /**
  94. * 删除表单 Schema
  95. */
  96. async deleteSchema(schemaId: number) {
  97. const res = await api.delete('/api/vas/schema/delete', {
  98. params: { id: schemaId, schema_id: schemaId },
  99. });
  100. return res.data;
  101. },
  102. /**
  103. * 获取产品的路由配置列表
  104. */
  105. async listRoutings(productId: number) {
  106. const res = await api.get('/api/vas/product_routing/list_by_product', {
  107. params: { product_id: productId },
  108. });
  109. return res.data;
  110. },
  111. /**
  112. * 创建产品路由配置
  113. */
  114. async createRouting(payload: Record<string, any>) {
  115. const res = await api.post('/api/vas/product_routing/create', payload);
  116. return res.data;
  117. },
  118. /**
  119. * 更新产品路由配置
  120. */
  121. async updateRouting(id: number, payload: Record<string, any>) {
  122. const res = await api.post('/api/vas/product_routing/update', payload, {
  123. params: { id },
  124. });
  125. return res.data;
  126. },
  127. /**
  128. * 删除产品路由配置
  129. */
  130. async deleteRouting(id: number) {
  131. const res = await api.delete('/api/vas/product_routing/delete', {
  132. params: { id },
  133. });
  134. return res.data;
  135. },
  136. };