系统相关配置

This commit is contained in:
sjl
2026-02-27 08:49:57 +08:00
parent bfa061fb03
commit b25515b5db
21 changed files with 1403 additions and 142 deletions

View File

@@ -7,7 +7,7 @@
<el-col :span="6">
<div class="tree-container">
<el-tree
@node-click="clickNode"
@node-click="(node, data, event) => handleNodeClick(node, data)"
:expand-on-click-node="false"
:highlight-current="true"
:data="TreeData"
@@ -92,13 +92,12 @@ import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import { ElMessage } from 'element-plus'
import {
getDictTree,
getReportDictList,
addDict,
updateDict,
deleteDict
} from '@/api/system-boot/ReportTemplate'
// 弹出框是否可见
const dialogVisible = ref<boolean>(false)
const dialogTitle = ref('新增配置项')
@@ -107,12 +106,50 @@ const props = defineProps({
type: {
type: Number,
default: undefined
},
treeData: {
type: Array,
default: () => []
}
})
const TreeData = computed(() => props.treeData)
const secondLevelNode = ref<any[]>([]);
const treeExpandData = ref([])
const setDefaultExpandedKeys = (treeData: any[]) => {
const firstLevelIds = treeData.map(item => item.id)
treeExpandData.value = firstLevelIds
}
// 默认选中第一个节点
const selectFirstNode = () => {
if (props.treeData.length > 0 && tree.value) {
const firstNodeId = props.treeData[0].id
tree.value.setCurrentKey(firstNodeId)
formData.id = firstNodeId
}
}
// 监听 treeData 变化,自动设置默认展开
watch(
() => props.treeData,
(newVal) => {
if (newVal.length > 0) {
setDefaultExpandedKeys(newVal)
nextTick(() => {
selectFirstNode()
})
}
},
{ immediate: true }
)
const tree = ref(null)
const formData = reactive({
searchValue: '',
id: '0',
id: 0,
type: props.type
})
@@ -124,6 +161,11 @@ const form = reactive({
type: props.type
})
const defaultProps = {
children: 'children',
label: 'reportDescribe'
}
const rules = {
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
reportDescribe: [{ required: true, message: '描述不能为空', trigger: 'blur' }],
@@ -131,7 +173,7 @@ const rules = {
}
const tableStore = new TableStore({
url: '/system-boot/reportDict/getReportDictList',
url: getReportDictList(formData),
method: 'POST',
column: [
{ title: '配置项名称', field: 'name' },
@@ -185,6 +227,45 @@ const tableStore = new TableStore({
})
provide('tableStore', tableStore)
// 存储当前选中节点的路径(包括自身)
const selectedNodePath = ref<any[]>([]);
// 处理节点点击事件
const handleNodeClick = (node: any) => {
// 获取当前节点的完整路径
const nodePath = tree.value?.getNodePath(node);
// 更新当前选中节点的路径
selectedNodePath.value = nodePath || [];
// 设置当前节点 ID 到 formData
formData.id = node.id;
// 动态生成父节点选项(排除当前节点本身)
secondLevelNode.value = (nodePath || []).slice(0, -1).map((item: any) => ({
id: item.id,
reportDescribe: item.reportDescribe
}));
// 调用 tableStore.index()
tableStore.index();
};
// 监听 selectedNodePath 变化
watch(selectedNodePath, (newPath) => {
if (Array.isArray(newPath)) {
secondLevelNode.value = newPath.slice(0, -1).map((item: any) => ({
id: item.id,
reportDescribe: item.reportDescribe
}));
} else {
console.warn('selectedNodePath is not an array:', newPath);
secondLevelNode.value = []; // 清空选项
}
});
const addTemplate = () => {
dialogTitle.value = '新增配置项'
dialogVisible.value = true
@@ -218,7 +299,7 @@ const closeDialog = () => {
}
onMounted(() => {
tableStore.index()
//tableStore.index()
})
</script>