Files
xj-admin/src/views/label/label.api.ts
T
wanghao 9c6680146f feat(resource): 对接急救宣教资源管理 V3 接口
- 审批与上架分离:已通过状态显示「已通过」+「上架」操作
- 分类扁平化:分类表单去掉父级分类字段
- 标签从分类 tags 字段联动取,不再调独立标签接口
- 标签表单加所属分类必填,支持从分类「+标签」按钮预设锁定
- 审核记录字段对齐后端:resourceTitle/auditRejectReason
- 资源表单 footer 隐藏默认按钮,写操作 API 关全局提示避免重复弹
2026-06-25 10:30:22 +08:00

119 lines
5.0 KiB
TypeScript

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<string, any>();
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);
}