标签管理修改

This commit is contained in:
夕阳微笑1 2024-12-16 13:44:16 +08:00
parent 3ad716ba12
commit 91f4cd1487

View File

@ -18,7 +18,24 @@
添加标签 添加标签
</el-button> </el-button>
</div> </div>
<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%" :header-cell-style="{ backgroundColor: '#fafafa', height: '40px' }"> <!-- <el-tree
:data="treeData"
:props="defaultProps"
node-key="id"
default-expand-all
:highlight-current="true"
@node-click="handleNodeClick"
>
<span class="custom-tree-node" slot-scope="{ node, data }">
<span>{{ data.name }}</span>
<span>
<el-button size="mini" type="text" @click="toShowDetail(data.id)">查看详情</el-button>
<el-button size="mini" type="text" @click="toEditArticle(data.id)">编辑</el-button>
<el-button size="mini" type="text" @click="deleteArticle(data.id)">删除</el-button>
</span>
</span>
</el-tree> -->
<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%" :header-cell-style="{ backgroundColor: '#fafafa', height: '40px' }">
<el-table-column prop="moduleName" label="模块名称" show-overflow-tooltip></el-table-column> <el-table-column prop="moduleName" label="模块名称" show-overflow-tooltip></el-table-column>
<el-table-column prop="parentName" label="父标签" show-overflow-tooltip></el-table-column> <el-table-column prop="parentName" label="父标签" show-overflow-tooltip></el-table-column>
<el-table-column prop="name" label="标签名称" show-overflow-tooltip></el-table-column> <el-table-column prop="name" label="标签名称" show-overflow-tooltip></el-table-column>
@ -72,6 +89,11 @@ const addLabelDialogRef = ref();
const editLabelDialog = defineAsyncComponent(() => import('/@/views/label/editDialog.vue')); const editLabelDialog = defineAsyncComponent(() => import('/@/views/label/editDialog.vue'));
const editLabelDialogRef = ref(); const editLabelDialogRef = ref();
interface Tree {
label: string
children?: Tree[]
}
// //
const state = reactive({ const state = reactive({
tableData: { tableData: {
@ -93,6 +115,13 @@ const moduleList = ref([]);
// //
const labelList = ref([]); const labelList = ref([]);
//
const treeData = ref([]);
const defaultProps = {
children: 'children',
label: 'name'
};
// api // api
const labelapi = labelApi(); const labelapi = labelApi();
@ -119,6 +148,7 @@ const getTableData = async() => {
if(res?.success){ if(res?.success){
state.tableData.data = res.data.records; state.tableData.data = res.data.records;
state.tableData.total = res.data.total; state.tableData.total = res.data.total;
buildTreeData();
}else{ }else{
ElMessage.error('标签列表获取失败!'); ElMessage.error('标签列表获取失败!');
} }
@ -128,6 +158,27 @@ const getTableData = async() => {
} }
}; };
const buildTreeData = () => {
const moduleMap = {};
//
state.tableData.data.forEach(item => {
if (!moduleMap[item.moduleName]) {
moduleMap[item.moduleName] = {
name: item.moduleName,
children: []
};
}
moduleMap[item.moduleName].children.push({ ...item });
});
treeData.value = Object.values(moduleMap);
console.log(treeData.value); //
};
const handleNodeClick = (data: Tree) => {
console.log(data)
}
// //
const handleChangeModule = async(val: any) => { const handleChangeModule = async(val: any) => {
@ -147,24 +198,6 @@ const handleChangeModule = async(val: any) => {
} }
}; };
// //
// const handleChangeModule = async(val) => {
// try {
// if (!val) {
// labelList.value = [];
// state.tableData.data = [];
// state.tableData.total = 0;
// return;
// }
// const op = moduleList.value.find(item => item.moduleName === val);
// if (op) {
// state.tableData.param.moduleid = op.id;
// await getTableData();
// }
// } catch (error) {
// ElMessage.error('');
// }
// }
// //
const reset = (index = 0) =>{ const reset = (index = 0) =>{
@ -233,13 +266,13 @@ const dateFormatter = (row: any, column: TableColumnCtx<String>) => {
// return row.articletype === 1 ? '' : ''; // return row.articletype === 1 ? '' : '';
// } // }
// //
const onHandleSizeChange = (val: number) => { const onHandleSizeChange = (val: number) => {
state.tableData.param.size = val; state.tableData.param.size = val;
getTableData(); getTableData();
}; };
// //
const onHandleCurrentChange = (val: number) => { const onHandleCurrentChange = (val: number) => {
state.tableData.param.current = val; state.tableData.param.current = val;
getTableData(); getTableData();
@ -250,76 +283,19 @@ onMounted(() => {
getTableData(); getTableData();
}); });
// const totalData = ref([]); //
// //
// const getModuleList = async () => {
// try {
// let res = await labelapi.getModuleList();
// if (res?.success) {
// moduleList.value = res.data;
// await getAllData(); //
// } else {
// ElMessage.error('');
// }
// } catch (error) {
// ElMessage.error('');
// }
// };
// //
// const getAllData = async () => {
// try {
// const requests = moduleList.value.map(module => labelapi.getLabelList({ moduleid: module.id, current: 1, size: 10 })); //
// const results = await Promise.all(requests);
// totalData.value = results
// .filter(res => res?.success) //
// .flatMap(res => res.data.records || []); //
// state.tableData.total = totalData.value.length;
// updatePageData(); //
// } catch (error) {
// ElMessage.error('');
// } finally {
// state.tableData.loading = false;
// }
// };
// //
// const updatePageData = () => {
// const start = (state.tableData.param.current - 1) * state.tableData.param.size;
// const end = start + state.tableData.param.size;
// state.tableData.data = totalData.value.slice(start, end);
// };
// //
// const onHandleSizeChange = (val) => {
// state.tableData.param.size = val;
// updatePageData(); //
// };
// const onHandleCurrentChange = (val) => {
// state.tableData.param.current = val;
// updatePageData(); //
// };
// onMounted(() => {
// getModuleList();
// });
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.system-dept-container { .system-dept-container {
:deep(.el-card__body) { :deep(.el-card__body) {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
flex: 1;
overflow: auto;
.el-table {
flex: 1; flex: 1;
overflow: auto;
.el-tree {
flex: 1;
}
} }
} }
}
</style> </style>