base.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // 基础服务 - 对应 supermart-mini/service/base.js
  2. import { get, post } from './http';
  3. const apis = {
  4. PAGE_CONFIG: '/api/app/page/getByPageId',
  5. MESSAGE: '/api/app/message',
  6. TRACK: '/api/track',
  7. FEEDBACK: '/api/app/feedback/submit',
  8. PARAM_CONFIG: '/param/paramConfig',
  9. };
  10. export interface BannerItem {
  11. id: string;
  12. cover: string;
  13. path?: { url: string };
  14. }
  15. export interface TabItem {
  16. title: string;
  17. cover: string;
  18. path?: { url: string };
  19. }
  20. export interface PageConfig {
  21. components: Array<{
  22. elements: any[];
  23. }>;
  24. }
  25. // 获取页面配置
  26. export const getPageConfig = async (pageId: string): Promise<PageConfig | null> => {
  27. const res = await get<PageConfig>(apis.PAGE_CONFIG, { pageId });
  28. return res.data;
  29. };
  30. // 获取消息列表
  31. export const getMessages = async (current: number, size: number, type?: string) => {
  32. const params: any = { current, size };
  33. if (type) params.type = type;
  34. const res = await get(apis.MESSAGE, params);
  35. return res.success ? res.data : null;
  36. };
  37. // 获取消息列表(分页)
  38. export const getMessageList = async (current: number, size: number, type?: string) => {
  39. const params: any = { current, size };
  40. if (type) params.type = type;
  41. const res = await get(apis.MESSAGE, params);
  42. return res.success ? res.data : { records: [], total: 0 };
  43. };
  44. // 获取参数配置
  45. export const getParamConfig = async (code: string) => {
  46. const res = await get(apis.PARAM_CONFIG, { code });
  47. return res.data;
  48. };
  49. // 提交反馈
  50. export const submitFeedback = async (data: any) => {
  51. const res = await post(apis.FEEDBACK, data);
  52. return res.data;
  53. };
  54. // 追踪
  55. export const track = async () => {
  56. const res = await get(apis.TRACK);
  57. return res.data;
  58. };
  59. export default {
  60. getPageConfig,
  61. getMessages,
  62. getMessageList,
  63. getParamConfig,
  64. submitFeedback,
  65. track,
  66. };