|
@@ -131,12 +131,30 @@
|
|
|
/>
|
|
|
|
|
|
<!-- 添加或修改目录模板对话框 -->
|
|
|
- <el-dialog :title="title" v-model="open" width="500px" append-to-body>
|
|
|
+ <el-dialog :title="title" v-model="open" width="500px" append-to-body @close="cancelAddTemp">
|
|
|
<el-form ref="dirTemplateRef" :model="form" :rules="rules" label-width="80px">
|
|
|
<el-form-item label="模板名称" prop="tmplName">
|
|
|
- <el-input v-model="form.tmplName" placeholder="请输入模板名称"/>
|
|
|
+ <el-input v-model="tempTitle" placeholder="请输入模板名称"/>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="模板内容" prop="tmplContent">
|
|
|
+ <el-tree
|
|
|
+ :data="tempData"
|
|
|
+ default-expand-all
|
|
|
+ node-key="id"
|
|
|
+ style="width:100%;height:300px;overflow-y: auto;"
|
|
|
+ :expand-on-click-node="false"
|
|
|
+ >
|
|
|
+ <template #default="{ node, data }">
|
|
|
+ <span class="custom-tree-node">
|
|
|
+ <span>{{ node.label }}</span>
|
|
|
+ <span>
|
|
|
+ <a class="btm" @click="append(data)"> 增加 </a>
|
|
|
+ <a class="btm" v-if="data.id != 1" @click="updataNode(data)"> 修改 </a>
|
|
|
+ <a class="btm" v-if="data.id != 1" style="margin-left: 8px" @click="remove(node, data)"> 删除 </a>
|
|
|
+ </span>
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+ </el-tree>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="备注" prop="remark">
|
|
|
<el-input v-model="form.remark" placeholder="请输入备注"/>
|
|
@@ -145,10 +163,20 @@
|
|
|
<template #footer>
|
|
|
<div class="dialog-footer">
|
|
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
|
|
- <el-button @click="cancel">取 消</el-button>
|
|
|
+ <el-button @click="cancelAddTemp">取 消</el-button>
|
|
|
</div>
|
|
|
</template>
|
|
|
</el-dialog>
|
|
|
+ <el-dialog title="目录名称" v-model="showMenuName" width="500px">
|
|
|
+ <el-input v-model="newName" maxlength="32" placeholder="请输入目录名称"/>
|
|
|
+ <template #footer>
|
|
|
+ <div class="dialog-footer">
|
|
|
+ <el-button type="primary" @click="submitMenuName">确 定</el-button>
|
|
|
+ <el-button @click="cancelMenuName">取 消</el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -160,6 +188,7 @@ import {
|
|
|
listDirTemplate,
|
|
|
updateDirTemplate
|
|
|
} from "@/api/biz/dirTemplate";
|
|
|
+import { ElMessage} from 'element-plus'
|
|
|
|
|
|
const {proxy} = getCurrentInstance();
|
|
|
|
|
@@ -172,6 +201,16 @@ const single = ref(true);
|
|
|
const multiple = ref(true);
|
|
|
const total = ref(0);
|
|
|
const title = ref("");
|
|
|
+const showMenuName = ref(false)
|
|
|
+const newName = ref()
|
|
|
+const tempId = ref(1000)
|
|
|
+const upNodeData = ref()
|
|
|
+const tempTitle = ref('')
|
|
|
+const tempData = ref([
|
|
|
+ {id:1,label:tempTitle || '请输入模板名称',children:[
|
|
|
+
|
|
|
+ ]}
|
|
|
+])
|
|
|
|
|
|
const data = reactive({
|
|
|
form: {},
|
|
@@ -251,7 +290,25 @@ function handleUpdate(row) {
|
|
|
reset();
|
|
|
const _tmplId = row.tmplId || ids.value
|
|
|
getDirTemplate(_tmplId).then(response => {
|
|
|
+ console.log('response',response);
|
|
|
form.value = response.data;
|
|
|
+ const arr = JSON.parse(response.data.tmplContent)
|
|
|
+ const getNewtempId = (arr)=>{
|
|
|
+ arr.map(item=>{
|
|
|
+ if(item.id >= tempId.value){
|
|
|
+ console.log('1',item.id);
|
|
|
+ tempId.value = item.id +1
|
|
|
+ }
|
|
|
+ if(item.children?.length>0){
|
|
|
+ getNewtempId(item.children)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ getNewtempId(arr)
|
|
|
+ tempTitle.value = response.data.tmplName
|
|
|
+
|
|
|
+ tempData.value = [{id:1,label:tempTitle,children:[]}]
|
|
|
+ tempData.value[0].children = arr
|
|
|
open.value = true;
|
|
|
title.value = "修改目录模板";
|
|
|
});
|
|
@@ -260,6 +317,15 @@ function handleUpdate(row) {
|
|
|
/** 提交按钮 */
|
|
|
function submitForm() {
|
|
|
proxy.$refs["dirTemplateRef"].validate(valid => {
|
|
|
+ if(!tempTitle.value){
|
|
|
+ return ElMessage({
|
|
|
+ message: "模板名不能为空",
|
|
|
+ type: "error"
|
|
|
+ })
|
|
|
+ }
|
|
|
+ const str = JSON.stringify(tempData.value[0].children)
|
|
|
+ form.value.tmplContent = str
|
|
|
+ form.value.tmplName = tempTitle.value
|
|
|
if (valid) {
|
|
|
if (form.value.tmplId != null) {
|
|
|
updateDirTemplate(form.value).then(response => {
|
|
@@ -296,6 +362,92 @@ function handleExport() {
|
|
|
...queryParams.value
|
|
|
}, `dirTemplate_${new Date().getTime()}.xlsx`)
|
|
|
}
|
|
|
+// 新增目录节点
|
|
|
+const append = (data)=>{
|
|
|
+ // console.log('data',data);
|
|
|
+
|
|
|
+ const newChild = {id: tempId.value, label: 'newMenu', children: [] }
|
|
|
+ tempId.value = tempId.value+1
|
|
|
+ if (!data.children) {
|
|
|
+ data.children = []
|
|
|
+ }
|
|
|
+ data.children.push(newChild)
|
|
|
+ tempData.value = [...tempData.value]
|
|
|
+}
|
|
|
+// 移除目录节点
|
|
|
+const remove = (node, data)=>{
|
|
|
+ const parent = node.parent
|
|
|
+ const children = parent.data.children || parent.data
|
|
|
+ const index = children.findIndex((d) => d.id === data.id)
|
|
|
+ children.splice(index, 1)
|
|
|
+ tempData.value = [...tempData.value]
|
|
|
+}
|
|
|
+// 修改目录节点
|
|
|
+const updataNode = (data)=>{
|
|
|
+ newName.value = ''
|
|
|
+ newName.value = data.label
|
|
|
+ showMenuName.value = true
|
|
|
+ upNodeData.value = data
|
|
|
+}
|
|
|
+const submitMenuName = ()=>{
|
|
|
+ if(!newName.value){
|
|
|
+ return ElMessage({
|
|
|
+ message: "目录名不能为空",
|
|
|
+ type: "error"
|
|
|
+ })
|
|
|
+ }
|
|
|
+const oldArr = tempData.value
|
|
|
+ const getNewData = (data)=>{
|
|
|
+ data.map(item=>{
|
|
|
+ if(item.id == upNodeData.value.id){
|
|
|
+ // console.log(1);
|
|
|
+ item.label = newName.value
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(item.children?.length>0){
|
|
|
+ getNewData(item.children)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ getNewData(oldArr)
|
|
|
+ tempData.value= JSON.parse(JSON.stringify(oldArr))
|
|
|
+ setTimeout(() => {
|
|
|
+ showMenuName.value = false
|
|
|
+ // console.log('tempData.value',tempData.value);
|
|
|
+ // console.log('upNodeData.value',upNodeData.value);
|
|
|
+ }, 200);
|
|
|
+}
|
|
|
+const submitAddTemp = ()=>{
|
|
|
+
|
|
|
+}
|
|
|
+const cancelMenuName = ()=>{
|
|
|
+ newName.value = ''
|
|
|
+ showMenuName.value = false
|
|
|
+}
|
|
|
+const cancelAddTemp = ()=>{
|
|
|
+ open.value = false
|
|
|
+ newName.value = ''
|
|
|
+ tempTitle.value = ''
|
|
|
+ tempData.value = [
|
|
|
+ {id:1,label:tempTitle || '请输入模板名称',children:[
|
|
|
+
|
|
|
+ ]}
|
|
|
+]
|
|
|
+}
|
|
|
|
|
|
getList();
|
|
|
</script>
|
|
|
+<style lang="scss" scoped>
|
|
|
+.custom-tree-node {
|
|
|
+ width: 100%;
|
|
|
+ flex: 1;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+ font-size: 14px;
|
|
|
+ padding-right: 8px;
|
|
|
+}
|
|
|
+.btm{
|
|
|
+ color: skyblue;
|
|
|
+}
|
|
|
+</style>
|