diff --git a/src/api/assets/category/index.ts b/src/api/assets/category/index.ts index a309d87..f9f491b 100644 --- a/src/api/assets/category/index.ts +++ b/src/api/assets/category/index.ts @@ -29,6 +29,15 @@ export function addCategory(data: object) { }); } +// 查询获取列表 +export function listCategories(keyword: string) { + return newService({ + url: '/assets/category/listCategories', + method: 'get', + params: {keyword}, + }); +} + // 修改分类 export function updateCategory(data: object) { return newService({ diff --git a/src/views/assets/category/component/editCategory.vue b/src/views/assets/category/component/editCategory.vue index 81bfbe8..552b395 100644 --- a/src/views/assets/category/component/editCategory.vue +++ b/src/views/assets/category/component/editCategory.vue @@ -19,7 +19,7 @@ - +
diff --git a/src/views/assets/category/index.vue b/src/views/assets/category/index.vue index 73058e5..e0a605e 100644 --- a/src/views/assets/category/index.vue +++ b/src/views/assets/category/index.vue @@ -7,7 +7,7 @@ - + 查询 @@ -67,7 +67,7 @@ export default { import { ref, reactive, onMounted } from 'vue'; import { ElMessageBox, ElMessage } from 'element-plus'; import EditCategory from './component/editCategory.vue'; -import { getCategoryTree, deleteCategory, updateCategoryStatus } from '/@/api/assets/category'; +import { getCategoryTree, deleteCategory, updateCategoryStatus,listCategories } from '/@/api/assets/category'; interface CategoryRow { id: string; @@ -108,6 +108,29 @@ const getCategoryList = () => { }); }; +// 查询功能 +const AlistCategories = () => { + const keyword = tableData.param.name?.trim(); + // 如果没有输入关键词,则获取完整树形结构 + if (!keyword) { + getCategoryList(); + return; + } + // 有关键词时进行搜索 + tableData.loading = true; + listCategories(keyword) + .then((res: any) => { + // 搜索结果直接展示为列表 + tableData.data = res.data?.list ?? res.data ?? []; + }) + .catch(() => { + tableData.data = []; + ElMessage.error('查询失败'); + }) + .finally(() => { + tableData.loading = false; + }); +} // 打开新增弹窗 const onOpenAddCategory = (row?: CategoryRow) => { editCategoryRef.value.openDialog(row?.id);