import { defHttp } from '/@/utils/http/axios'; import { useMessage } from '/@/hooks/web/useMessage'; const { createConfirm } = useMessage(); enum Api { // 分类 categoryList = '/health-emergency/emergency/firstAid/category/list', categoryListAll = '/health-emergency/emergency/firstAid/category/listAll', categoryListRoot = '/health-emergency/emergency/firstAid/category/listRoot', categoryListChildren = '/health-emergency/emergency/firstAid/category/listChildren', categoryQueryById = '/health-emergency/emergency/firstAid/category/queryById', categoryAdd = '/health-emergency/emergency/firstAid/category/add', categoryEdit = '/health-emergency/emergency/firstAid/category/edit', categoryDelete = '/health-emergency/emergency/firstAid/category/delete', categoryDeleteBatch = '/health-emergency/emergency/firstAid/category/deleteBatch', // 标签 tagList = '/health-emergency/emergency/firstAid/tag/list', tagListAll = '/health-emergency/emergency/firstAid/tag/listAll', tagQueryById = '/health-emergency/emergency/firstAid/tag/queryById', tagAdd = '/health-emergency/emergency/firstAid/tag/add', tagEdit = '/health-emergency/emergency/firstAid/tag/edit', tagDelete = '/health-emergency/emergency/firstAid/tag/delete', tagDeleteBatch = '/health-emergency/emergency/firstAid/tag/deleteBatch', } // ============ 分类 ============ export const categoryListApi = (params: any) => defHttp.get({ url: Api.categoryList, params }); export const categoryListAllApi = (params?: any) => defHttp.get({ url: Api.categoryListAll, params }); export const categoryListRootApi = (params?: any) => defHttp.get({ url: Api.categoryListRoot, params }); export const categoryListChildrenApi = (params: any) => defHttp.get({ url: Api.categoryListChildren, params }); export const categoryQueryByIdApi = (params: any) => defHttp.get({ url: Api.categoryQueryById, params }); export const categoryAddApi = (params: any) => defHttp.post({ url: Api.categoryAdd, params }, { successNeedMessage: false }); export const categoryEditApi = (params: any) => defHttp.post({ url: Api.categoryEdit, params }, { successNeedMessage: false }); export const categoryDeleteApi = (params: any, handleSuccess: any) => { createConfirm({ iconType: 'warning', title: '确认删除', content: '是否删除该分类?', onOk: async () => { await defHttp.post({ url: Api.categoryDelete, params }, { successNeedMessage: false }); handleSuccess(); }, }); }; export const categoryDeleteBatchApi = (params: any, handleSuccess: any) => { createConfirm({ iconType: 'warning', title: '批量删除', content: `是否删除选中的 ${params?.length || 0} 个分类?`, onOk: async () => { await defHttp.post({ url: Api.categoryDeleteBatch, params }, { successNeedMessage: false }); handleSuccess(); }, }); }; // ============ 标签 ============ export const tagListApi = (params: any) => defHttp.get({ url: Api.tagList, params }); export const tagListAllApi = (params?: any) => defHttp.get({ url: Api.tagListAll, params }); export const tagQueryByIdApi = (params: any) => defHttp.get({ url: Api.tagQueryById, params }); export const tagAddApi = (params: any) => defHttp.post({ url: Api.tagAdd, params }, { successNeedMessage: false }); export const tagEditApi = (params: any) => defHttp.post({ url: Api.tagEdit, params }, { successNeedMessage: false }); export const tagDeleteApi = (params: any, handleSuccess: any) => { createConfirm({ iconType: 'warning', title: '确认删除', content: '是否删除该标签?', onOk: async () => { await defHttp.post({ url: Api.tagDelete, params }, { successNeedMessage: false }); handleSuccess(); }, }); }; export const tagDeleteBatchApi = (params: any, handleSuccess: any) => { createConfirm({ iconType: 'warning', title: '批量删除', content: `是否删除选中的 ${params?.length || 0} 个标签?`, onOk: async () => { await defHttp.post({ url: Api.tagDeleteBatch, params }, { successNeedMessage: false }); handleSuccess(); }, }); }; // ============ 工具:扁平列表转树 ============ export function buildTree(list: any[]): any[] { const map = new Map(); const roots: any[] = []; list.forEach((item) => { map.set(item.id, { ...item, children: [] }); }); list.forEach((item) => { const node = map.get(item.id); if (item.parentId && map.has(item.parentId)) { map.get(item.parentId).children.push(node); } else { roots.push(node); } }); // 移除空 children const clean = (nodes: any[]) => { nodes.forEach((n) => { if (n.children.length === 0) { delete n.children; } else { clean(n.children); } }); return nodes; }; return clean(roots); }