新增分类搜索功能,支持关键词查询并优化状态字段显示逻辑
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<el-form-item label="排序">
|
||||
<el-input-number v-model="ruleForm.sort" :min="0" :max="999" controls-position="right" placeholder="请输入排序" class="w100" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" v-if="!isEdit">
|
||||
<!-- <el-form-item label="状态" v-if="!isEdit">
|
||||
<el-switch
|
||||
v-model="ruleForm.status"
|
||||
active-value="1"
|
||||
@@ -28,7 +28,7 @@
|
||||
active-text="显示"
|
||||
inactive-text="隐藏"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form-item> -->
|
||||
<!-- 自定义属性 -->
|
||||
<el-form-item label="自定义属性">
|
||||
<div class="custom-attrs-container">
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<el-input size="default" v-model="tableData.param.name" placeholder="请输入分类名称" clearable style="width: 200px" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button size="default" type="primary" @click="getCategoryList">
|
||||
<el-button size="default" type="primary" @click="AlistCategories">
|
||||
<el-icon><ele-Search /></el-icon>
|
||||
查询
|
||||
</el-button>
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user