From 00a83cfd7703420ccd89b98581b0862680efb906 Mon Sep 17 00:00:00 2001 From: mk <2403457699@qq.com> Date: Tue, 20 May 2025 13:56:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=BF=E5=B1=8B=E7=BB=84=E7=BB=87=E6=A0=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9=20=E6=A5=BC=E6=A0=8B?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E6=88=BF=E5=B1=8B=E5=8A=9F=E8=83=BD=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/dept.js | 7 +++ src/layout/components/Navbar.vue | 4 +- src/utils/ruoyi.js | 13 +++-- src/views/mz/building/index.vue | 11 +++- src/views/mz/house/index.vue | 88 ++++++++++++++++++++++++++------ 5 files changed, 101 insertions(+), 22 deletions(-) diff --git a/src/api/system/dept.js b/src/api/system/dept.js index fc943cd..ed3b08f 100644 --- a/src/api/system/dept.js +++ b/src/api/system/dept.js @@ -49,4 +49,11 @@ export function delDept(deptId) { url: '/system/dept/' + deptId, method: 'delete' }) +} +// 房屋专属左侧组织树 +export function getdeptList() { + return request({ + url: '/mz/building/getdeptList', + method: 'get' + }) } \ No newline at end of file diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index 9369b06..311faea 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -88,7 +88,9 @@ export default { type: 'warning' }).then(() => { this.$store.dispatch('LogOut').then(() => { - location.href = '/index'; + this.$router.replace({ + path: "/login" + }); }) }).catch(() => {}); } diff --git a/src/utils/ruoyi.js b/src/utils/ruoyi.js index 44bf9c4..0cf3799 100644 --- a/src/utils/ruoyi.js +++ b/src/utils/ruoyi.js @@ -157,7 +157,7 @@ export function mergeRecursive(source, target) { * @param {*} parentId 父节点字段 默认 'parentId' * @param {*} children 孩子节点字段 默认 'children' */ -export function handleTree(data, id, parentId, children) { +export function handleTree(data, id, parentId, children, maxLevel) { let config = { id: id || 'id', parentId: parentId || 'parentId', @@ -185,16 +185,21 @@ export function handleTree(data, id, parentId, children) { } for (let t of tree) { - adaptToChildrenList(t); + adaptToChildrenList(t, 1); } - function adaptToChildrenList(o) { + function adaptToChildrenList(o, level) { if (childrenListMap[o[config.id]] !== null) { + if (maxLevel && level >= maxLevel) { + // 当达到最大层级时,清除子节点数据 + o[config.childrenList] = []; + return; + } o[config.childrenList] = childrenListMap[o[config.id]]; } if (o[config.childrenList]) { for (let c of o[config.childrenList]) { - adaptToChildrenList(c); + adaptToChildrenList(c, level + 1); } } } diff --git a/src/views/mz/building/index.vue b/src/views/mz/building/index.vue index 4ae3c65..d1b164f 100644 --- a/src/views/mz/building/index.vue +++ b/src/views/mz/building/index.vue @@ -50,7 +50,13 @@ - + + + @@ -200,6 +206,9 @@ export default { this.getApartmentList(); }, methods: { + toHouse(row) { + this.$router.push({ path: "/mz/house", query: { deptId: row.id } }); + }, /** 转换组织数据结构 */ handleNodeClick(node, data) { this.queryParams.apartmentId = node.deptId; diff --git a/src/views/mz/house/index.vue b/src/views/mz/house/index.vue index 0565824..6592bb8 100644 --- a/src/views/mz/house/index.vue +++ b/src/views/mz/house/index.vue @@ -2,7 +2,9 @@
- +
- - - - - - - + @@ -240,7 +236,6 @@ export default { remark: null, floor: 0, hire:'1', - days:null, }, // 表单校验 rules: { @@ -265,9 +260,7 @@ export default { hire: [ { required: true, message: '请选择长租房/短租房', trigger: 'change' } ], - days: [ - { validator: validateDays, trigger: 'blur' } - ], + }, deptList: [], defaultProps: { @@ -280,7 +273,10 @@ export default { buildingOption: [], unitOptions: [], disabled:false, - treeList:[] + treeList:[], + expandedKeys: [],// 展开的节点的 key 数组 + checkedKeys: [],// 选中的节点的 key 数组 + showTree: true, }; }, components: { @@ -378,7 +374,6 @@ export default { remark: null, floor: 0, hire:'1', - days:null, }; this.resetForm("form"); }, @@ -493,9 +488,70 @@ export default { this.form.unitId = ''; this.unitOptions = []; await this.getUnitbyBuddingId(this.form.buildingId) - } + }, + // 新增方法:处理树展开逻辑 + handleExpandTree(apartmentId) { + if (!apartmentId) return; + const targetId = Number(apartmentId); + const findParents = (node, targetId, parents = []) => { + if (Number(node.deptId) === targetId) { + return [...parents, node.deptId]; + } + if (node.children) { + for (let child of node.children) { + const result = findParents(child, targetId, [...parents, node.deptId]); + if (result) return result; + } + } + return null; + }; + + let path = null; + for (let node of this.treeList) { + path = findParents(node, targetId); + if (path) break; + } + + if (path) { + // 直接设置展开路径,由于 :accordion="true",其他节点会自动收起 + this.expandedKeys = path; + this.checkedKeys = [path[path.length - 1]]; + } else { + console.warn('未找到匹配的节点路径'); + } + }, }, - watch:{} + watch:{ + $route: { + handler: function (newVal, oldVal) { + if (newVal.query) { + this.queryParams = { + ...this.queryParams, + ...newVal.query, + }; + this.treeList = []; + this.showTree = false; + this.$nextTick(() => { + // 重新渲染 el-tree 实例 + this.showTree = true; + this.getList(); + // 等待 deptList 加载完成 + if (this.treeList.length === 0) { + this.getDeptList().then(() => { + this.handleExpandTree(newVal.query.deptId); + }); + } else { + this.handleExpandTree(newVal.query.deptId); + } + }); + } else { + this.getDeptList() + } + }, + immediate: true, + deep: true, + }, + } };