2026-02-06 10:10:24 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="dictiontary-list-detail child-router">
|
|
|
|
|
|
<!-- 主体区域:左侧树 + 右侧表格 -->
|
|
|
|
|
|
<el-row :gutter="20" class="main-content">
|
|
|
|
|
|
<!-- 左侧树 -->
|
|
|
|
|
|
<el-col :span="6">
|
|
|
|
|
|
<div class="tree-container">
|
|
|
|
|
|
<el-tree
|
2026-02-27 08:49:57 +08:00
|
|
|
|
@node-click="(node, data, event) => handleNodeClick(node, data)"
|
2026-02-06 10:10:24 +08:00
|
|
|
|
:expand-on-click-node="false"
|
|
|
|
|
|
:highlight-current="true"
|
|
|
|
|
|
:data="TreeData"
|
|
|
|
|
|
node-key="id"
|
|
|
|
|
|
:default-expanded-keys="treeExpandData"
|
|
|
|
|
|
:props="defaultProps"
|
|
|
|
|
|
ref="tree"
|
|
|
|
|
|
></el-tree>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 右侧表格 -->
|
|
|
|
|
|
<el-col :span="18">
|
|
|
|
|
|
<TableHeader>
|
|
|
|
|
|
<template #select>
|
|
|
|
|
|
<el-form-item label="">
|
|
|
|
|
|
<el-page-header @back="$emit('close')">
|
|
|
|
|
|
<template #content>
|
|
|
|
|
|
<span class="text-large font-600 mr-3">报告字典管理</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-page-header>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="过滤筛选">
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
style="width: 240px"
|
|
|
|
|
|
v-model="tableStore.table.params.searchValue"
|
|
|
|
|
|
clearable
|
|
|
|
|
|
placeholder="请输入筛选数据"
|
|
|
|
|
|
maxlength="32"
|
|
|
|
|
|
show-word-limit
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template #operation>
|
|
|
|
|
|
<el-button :icon="Plus" type="primary" @click="addTemplate">新增配置项</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</TableHeader>
|
|
|
|
|
|
<Table ref="tableRef" />
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 新增 -->
|
|
|
|
|
|
<el-dialog
|
|
|
|
|
|
:title="dialogTitle"
|
|
|
|
|
|
v-model="dialogVisible"
|
|
|
|
|
|
width="30%"
|
|
|
|
|
|
@close="closeDialog"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-form ref="formRef" :rules="rules" :model="form" label-width="80px">
|
|
|
|
|
|
<el-form-item label="父节点:" prop="pid">
|
|
|
|
|
|
<el-select v-model="form.pid" style="width: 100%" placeholder="请选择父节点" clearable>
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
v-for="item in secondLevelNode"
|
|
|
|
|
|
:key="item.id"
|
|
|
|
|
|
:label="item.reportDescribe"
|
|
|
|
|
|
:value="item.id"
|
|
|
|
|
|
></el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="名称:" prop="name" class="top">
|
|
|
|
|
|
<el-input v-model.trim="form.name" placeholder="请输入名称"></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="描述:" prop="reportDescribe" class="top">
|
|
|
|
|
|
<el-input type="textarea" placeholder="请输入描述" v-model.trim="form.reportDescribe"></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
<el-button @click="closeDialog">取 消</el-button>
|
|
|
|
|
|
<el-button type="primary" @click="addFn">确 定</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { Plus } from '@element-plus/icons-vue'
|
|
|
|
|
|
import { ref, onMounted, provide } from 'vue'
|
|
|
|
|
|
import TableStore from '@/utils/tableStore'
|
|
|
|
|
|
import Table from '@/components/table/index.vue'
|
|
|
|
|
|
import TableHeader from '@/components/table/header/index.vue'
|
|
|
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
|
|
|
import {
|
|
|
|
|
|
getReportDictList,
|
|
|
|
|
|
addDict,
|
|
|
|
|
|
deleteDict
|
|
|
|
|
|
} from '@/api/system-boot/ReportTemplate'
|
|
|
|
|
|
|
2026-02-27 08:49:57 +08:00
|
|
|
|
|
2026-02-06 10:10:24 +08:00
|
|
|
|
// 弹出框是否可见
|
|
|
|
|
|
const dialogVisible = ref<boolean>(false)
|
|
|
|
|
|
const dialogTitle = ref('新增配置项')
|
|
|
|
|
|
const formRef = ref()
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
|
type: {
|
|
|
|
|
|
type: Number,
|
|
|
|
|
|
default: undefined
|
2026-02-27 08:49:57 +08:00
|
|
|
|
},
|
|
|
|
|
|
treeData: {
|
|
|
|
|
|
type: Array,
|
|
|
|
|
|
default: () => []
|
2026-02-06 10:10:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
2026-02-27 08:49:57 +08:00
|
|
|
|
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)
|
2026-02-06 10:10:24 +08:00
|
|
|
|
|
|
|
|
|
|
const formData = reactive({
|
|
|
|
|
|
searchValue: '',
|
2026-02-27 08:49:57 +08:00
|
|
|
|
id: 0,
|
2026-02-06 10:10:24 +08:00
|
|
|
|
type: props.type
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const form = reactive({
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
reportDescribe: '',
|
|
|
|
|
|
pid: '',
|
|
|
|
|
|
sort: 0,
|
|
|
|
|
|
type: props.type
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-02-27 08:49:57 +08:00
|
|
|
|
const defaultProps = {
|
|
|
|
|
|
children: 'children',
|
|
|
|
|
|
label: 'reportDescribe'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 10:10:24 +08:00
|
|
|
|
const rules = {
|
|
|
|
|
|
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
|
|
|
|
|
|
reportDescribe: [{ required: true, message: '描述不能为空', trigger: 'blur' }],
|
|
|
|
|
|
pid: [{ required: true, message: '请选择父节点', trigger: 'change' }]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const tableStore = new TableStore({
|
2026-02-27 08:49:57 +08:00
|
|
|
|
url: getReportDictList(formData),
|
2026-02-06 10:10:24 +08:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
column: [
|
|
|
|
|
|
{ title: '配置项名称', field: 'name' },
|
|
|
|
|
|
{ title: '配置项描述', field: 'reportDescribe' },
|
|
|
|
|
|
{ title: '上级节点', field: 'pidName' },
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '操作',fixed: 'right',
|
|
|
|
|
|
width: '180',
|
|
|
|
|
|
render: 'buttons',
|
|
|
|
|
|
|
|
|
|
|
|
buttons: [
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '编辑',
|
|
|
|
|
|
type: 'primary',
|
|
|
|
|
|
icon: 'el-icon-EditPen',
|
|
|
|
|
|
render: 'basicButton',
|
|
|
|
|
|
click: row => {
|
|
|
|
|
|
popupEditRef.value.open('编辑', {
|
|
|
|
|
|
...row,
|
|
|
|
|
|
openDescribe: props.detail.openDescribe,
|
|
|
|
|
|
openLevel: props.detail.openLevel,
|
|
|
|
|
|
typeName: props.detail.name + row.name,
|
|
|
|
|
|
typeId: props.detail.id
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '删除',
|
|
|
|
|
|
type: 'danger',
|
|
|
|
|
|
icon: 'el-icon-Delete',
|
|
|
|
|
|
render: 'confirmButton',
|
|
|
|
|
|
popconfirm: {
|
|
|
|
|
|
confirmButtonText: '确认',
|
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
|
confirmButtonType: 'danger',
|
|
|
|
|
|
title: '确定删除该字典类型吗?'
|
|
|
|
|
|
},
|
|
|
|
|
|
click: row => {
|
|
|
|
|
|
deleteDict([row.id]).then(() => {
|
|
|
|
|
|
ElMessage.success('删除成功')
|
|
|
|
|
|
tableStore.index()
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
loadCallback: () => {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
provide('tableStore', tableStore)
|
2026-02-27 08:49:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 存储当前选中节点的路径(包括自身)
|
|
|
|
|
|
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 = []; // 清空选项
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-02-06 10:10:24 +08:00
|
|
|
|
const addTemplate = () => {
|
|
|
|
|
|
dialogTitle.value = '新增配置项'
|
|
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
|
Object.assign(form, {
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
reportDescribe: '',
|
|
|
|
|
|
pid: '',
|
|
|
|
|
|
sort: 0,
|
|
|
|
|
|
type: props.type
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const addFn = () => {
|
|
|
|
|
|
formRef.value.validate(async (valid: boolean) => {
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await addDict(form)
|
|
|
|
|
|
ElMessage.success('新增成功')
|
|
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
ElMessage.error('新增失败')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const closeDialog = () => {
|
|
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
|
formRef.value?.resetFields()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
2026-02-27 08:49:57 +08:00
|
|
|
|
//tableStore.index()
|
2026-02-06 10:10:24 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.back {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: 15px;
|
|
|
|
|
|
right: 15px;
|
|
|
|
|
|
font-size: 29px;
|
|
|
|
|
|
color: #409eff;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|