From 09216aadbd19a98fad24afb921c165cef8c7f661 Mon Sep 17 00:00:00 2001 From: xuhuajiao <13476289682@163.com> Date: Tue, 2 Sep 2025 17:06:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9C=BA=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/inquiryMachine/form.vue | 29 +-- src/views/inquiryMachine/menu.vue | 226 +++++++++++++++++------- src/views/inquiryMachine/sortDialog.vue | 2 +- 3 files changed, 180 insertions(+), 77 deletions(-) diff --git a/src/views/inquiryMachine/form.vue b/src/views/inquiryMachine/form.vue index dd7bc26..a1a6a19 100644 --- a/src/views/inquiryMachine/form.vue +++ b/src/views/inquiryMachine/form.vue @@ -16,12 +16,11 @@ - - + - + @@ -80,7 +79,13 @@ export default { // { required: true, message: '编码不可为空', trigger: 'blur' } // ], queryTopicList: [ - { required: true, message: '栏目绑定不可为空', trigger: 'change' } + { + required: () => { + return this.form.type === 2 || this.form.type === 3 + }, + message: '栏目绑定不可为空', + trigger: 'change' + } ] }, selectOptions: [ @@ -102,6 +107,14 @@ export default { watch: { selectedMenu: function(newValue, oldValue) { // console.log('newValue', newValue) + }, + 'form.type': function(newType) { + if (newType !== 2 && newType !== 3) { + this.form.queryTopicList = null + } + this.$nextTick(() => { + this.$forceUpdate() + }) } }, created() { @@ -127,11 +140,6 @@ export default { // } // }) // }, - beforeToAdd() { - this.form.type = null - }, - [CRUD.HOOK.beforeSubmit]() { - }, // 提交前的验证 [CRUD.HOOK.afterValidateCU](crud) { delete crud.form.parentName @@ -144,7 +152,8 @@ export default { console.log(crud.form) return true }, - changeType() { + changeType(val) { + console.log('val', val) // this.isAdd = this.form.type === 2 }, normalizer(node) { diff --git a/src/views/inquiryMachine/menu.vue b/src/views/inquiryMachine/menu.vue index c073772..7969e1b 100644 --- a/src/views/inquiryMachine/menu.vue +++ b/src/views/inquiryMachine/menu.vue @@ -8,23 +8,23 @@ @@ -36,7 +36,7 @@ - + {{ data.title }} @@ -75,14 +75,14 @@

栏目列表

新书推荐

-

+
仅1级菜单可生成链接地址!
所属父级 -

{{ selectedMenu.parentId ? selectedMenu.parentName : '-' }}

+

{{ selectedMenu.parentId===null && selectedMenu.id ===0 ? '-' : selectedMenu.parentName }}

备注 @@ -90,7 +90,7 @@
-
+
@@ -111,12 +111,13 @@
- - + + + + + @@ -127,12 +128,11 @@ - + - + - @@ -241,14 +241,30 @@ export default { form: { queryMenu: { id: '', parentId: '', parentName: '', title: '', code: '', type: 1, remarks: '' }, queryTopicList: [] - } + }, + btnType: 'add', + currentNodeLevel: 0 // 存储当前节点层级 } }, computed: { ...mapGetters([ 'baseApi', 'user' - ]) + ]), + filteredSelectOptions() { + if (this.btnType === 'edit') { + return this.selectOptions.map(item => ({ + ...item, + disabled: this.currentNodeLevel === 3 && !([2, 3].includes(item.value)) + })) + } + + if (this.currentNodeLevel === 3) { + return this.selectOptions.filter(item => [2, 3].includes(item.value)) + } + + return this.selectOptions + } }, created() { this.getInitQueryTopic() @@ -282,72 +298,151 @@ export default { this.expandParents(node.parent) } }, + expandAllChildren(node) { + if (node && node.childNodes && node.childNodes.length > 0) { + node.expanded = true + } + }, + // [CRUD.HOOK.afterRefresh]() { + // if (this.crud.data.length > 0 && (this.crud.data[0].id === null || this.crud.data[0].id === undefined)) { + // this.crud.data[0].type = 1 + // } + // console.log('this.crud.data', this.crud.data) + + // this.$nextTick(() => { + // let currentKey + // if (localStorage.getItem('currentMenuKey')) { + // currentKey = JSON.parse(localStorage.getItem('currentMenuKey')) + // } else { + // currentKey = this.crud.data[0] + // } + // console.log('currentKey', currentKey) + // this.$refs.tree.setCurrentKey(currentKey.id) + + // const selectedKey = this.$refs.tree.getCurrentNode() + // console.log('selectedKey', selectedKey) + // if (this.$refs.tree.getNode(selectedKey) && this.$refs.tree.getNode(selectedKey).parent) { + // this.expandParents(this.$refs.tree.getNode(selectedKey).parent) + // } + // // 选中节点的门类详情 + // this.handleNodeClick(selectedKey, this.$refs.tree.getNode(selectedKey)) + // }) + // }, + checkNodeExists(nodeId) { + if (nodeId === '0') return true + + const check = (nodes) => { + if (!nodes || !nodes.length) return false + for (const node of nodes) { + if (node.id === nodeId) return true + if (node.children && node.children.length > 0) { + if (check(node.children)) return true + } + } + return false + } + return check(this.crud.data) + }, [CRUD.HOOK.afterRefresh]() { - let currentKey - if (localStorage.getItem('currentMenuKey')) { - currentKey = JSON.parse(localStorage.getItem('currentMenuKey')) - } else { - currentKey = this.crud.data[0] + if (this.crud.data && this.crud.data.length > 0) { + const newFirstNode = { + ...this.crud.data[0], + id: 0, + type: 1, + parentId: null + } + this.crud.data.splice(0, 1, newFirstNode) } - this.$refs.tree.setCurrentKey(currentKey.id) + this.$nextTick(() => { - const selectedKey = this.$refs.tree.getCurrentNode() - if (this.$refs.tree.getNode(selectedKey) && this.$refs.tree.getNode(selectedKey).parent) { - this.expandParents(this.$refs.tree.getNode(selectedKey).parent) + let currentKey + const storedKey = localStorage.getItem('currentMenuKey') + + if (storedKey) { + const parsedKey = JSON.parse(storedKey) + if (parsedKey && parsedKey.id && this.checkNodeExists(parsedKey.id)) { + currentKey = parsedKey + } else { + currentKey = this.crud.data[0] + } + } else { + currentKey = this.crud.data[0] } - // 选中节点的门类详情 - this.handleNodeClick(selectedKey) + + this.$refs.tree.setCurrentKey(currentKey.id) + + this.$nextTick(() => { + const selectedNode = this.$refs.tree.getCurrentNode() + console.log('实际选中的节点:', selectedNode ? selectedNode.id : '未选中任何节点') + if (selectedNode) { + const node = this.$refs.tree.getNode(selectedNode) + if (node && node.parent) this.expandParents(node.parent) + // this.expandAllChildren(node) + + this.handleNodeClick(selectedNode, node) + } + }) }) }, - // 选中门类后,设置门类详情数据 handleNodeClick(val, node) { - if (val) { - this.crud.selectionChangeHandler([val]) - // this.$refs.eform.parentId = val.id - this.selectedMenu = val + if (!val || !node) return + localStorage.setItem('currentMenuKey', JSON.stringify(val)) + this.crud.selectionChangeHandler([val]) + this.selectedMenu = val - if (this.selectedMenu.queryMenuTopics.length !== 0) { - const queryTopics = this.selectedMenu.queryMenuTopics.map(item => item.queryTopic) - this.selectedMenu.queryTopicList = queryTopics - } else { - this.selectedMenu.queryTopicList = [] - } - if (val.parentId) { - Vue.set(this.selectedMenu, 'parentName', this.$refs.tree.getNode(val.parentId).data.title) - this.brotherNodeNum = this.$refs.tree.getNode(val.parentId).childNodes.length - } + this.currentNodeLevel = node.level + this.selectedMenu.queryTopicList = val.queryMenuTopics + ? val.queryMenuTopics.map(item => item.queryTopic) + : [] - console.log('当前节点层级:', node.level) + if (val.parentId === null) { + const parentNode = this.crud.data[0] + this.brotherNodeNum = parentNode.children ? parentNode.children.length : 0 + } else { + const parentNode = this.$refs.tree.getNode(val.parentId) + this.brotherNodeNum = parentNode.childNodes ? parentNode.childNodes.length : 0 + } - // 可以根据层级执行不同操作 - if (node.level === 1) { - console.log('这是一级节点') - } else if (node.level === 2) { - console.log('这是二级节点') + if (val.parentId) { + const parentNode = this.$refs.tree.getNode(val.parentId) + if (parentNode && parentNode.data?.title) { + Vue.set(this.selectedMenu, 'parentName', parentNode.data.title) } else { - console.log(`这是第${node.level}级节点`) + Vue.set(this.selectedMenu, 'parentName', '-') + } + } else { + if (val.id !== '0') { + Vue.set(this.selectedMenu, 'parentName', '查询机') } - - // if (val.id !== '0') { - // Vue.set(this.selectedMenu, 'parentName', this.$refs.tree.getNode(val.id).data.title) - // } - // if (this.$refs.tree.getNode(val.pid) && this.$refs.tree.getNode(val.pid).childNodes) { - // this.brotherNodeNum = this.$refs.tree.getNode(val.pid).childNodes.length - // } } + console.log('brotherNodeNum', this.brotherNodeNum) + console.log(`当前节点层级:${node.level}`) + // switch (node.level) { + // case 1: + // console.log('这是顶级节点(一级节点)') + // break + // case 2: + // console.log('这是二级节点(顶级节点的子节点)') + // break + // default: + // console.log(`这是第${node.level}级节点`) + // } }, + toAddOrEdit(type) { + this.btnType = type if (type === 'add') { this.dialogTilte = '新增菜单' if (this.$refs['form']) { this.$refs['form'].clearValidate() } + console.log('新增菜单this.selectedMenu.title', this.selectedMenu.title) this.form = { queryMenu: { id: '', libcode: this.user.fonds.fondsNo, - parentId: '', - parentName: '', + parentId: this.selectedMenu.id === '0' ? null : this.selectedMenu.id, + parentName: this.selectedMenu.title, title: '', code: '', type: '', @@ -355,20 +450,17 @@ export default { }, queryTopicList: [] } - if (this.selectedMenu.type === 1) { - this.form.queryMenu.parentName = this.selectedMenu.title - this.form.queryMenu.parentId = this.selectedMenu.id - } console.log('this.selectedMenu', this.selectedMenu) console.log('brotherNodeNum', this.brotherNodeNum) } else { + console.log('this.selectedMenu编辑', this.selectedMenu) this.dialogTilte = '编辑菜单' this.form = { queryMenu: { id: this.selectedMenu.id, parentId: this.selectedMenu.parentId, libcode: this.user.fonds.fondsNo, - parentName: this.selectedMenu.parentName || null, + parentName: this.selectedMenu.parentName, title: this.selectedMenu.title, code: null, type: this.selectedMenu.type, @@ -376,9 +468,10 @@ export default { }, queryTopicList: [...this.selectedMenu.queryTopicList] } - console.log('编辑时的表单数据', this.form) } this.formVisible = true + + console.log('form', this.form) }, handleComfired() { this.$refs.form.validate((valid) => { @@ -455,7 +548,8 @@ export default { }) }, toSort(data) { - this.$refs.sort.sortTableData = this.$refs.tree.getNode(data[0].pid).data.children + console.log('data', data) + this.$refs.sort.sortTableData = this.$refs.tree.getNode(data[0].parentId).data.children this.$refs.sort.sortVisible = true }, handleDblClick(formName, field) { diff --git a/src/views/inquiryMachine/sortDialog.vue b/src/views/inquiryMachine/sortDialog.vue index 23b3569..7479013 100644 --- a/src/views/inquiryMachine/sortDialog.vue +++ b/src/views/inquiryMachine/sortDialog.vue @@ -5,7 +5,7 @@ 提示:使用鼠标拖动调整顺序 - +