From 883f1087d74a2b92bda50209af031595e9407e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E5=AE=8F=E6=9D=B0?= <1943105267@qq.com> Date: Tue, 3 Sep 2024 14:03:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E6=A5=BC?= =?UTF-8?q?=E5=B1=82=E6=88=BF=E9=97=B4=E6=95=B0=E4=B8=8D=E5=AF=B9=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/xiaoqu/ColorCell/index.vue | 2 +- src/views/components/xiaoqu/building.vue | 79 ++++++++++--------- 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/views/components/xiaoqu/ColorCell/index.vue b/src/views/components/xiaoqu/ColorCell/index.vue index 53e43d2..6fe4218 100644 --- a/src/views/components/xiaoqu/ColorCell/index.vue +++ b/src/views/components/xiaoqu/ColorCell/index.vue @@ -9,7 +9,7 @@ v-show="item.color == 'HF' || item.color == 'NF'" > -
{{ item.name }}
+
{{ item.name.replace("室", "") }}
{{ info.deptname }}{{ info.name }}
-
+
@@ -49,6 +49,29 @@ export default { "rightTopColor", "houseItem", ]), + groupedRooms() { + // 初始化每层楼的数组 + let floors = Array.from({ length: this.info.floor }, () => []); + + // 遍历房间数据 + this.list.forEach((room) => { + // 提取房间号前几位作为楼层号 + let floor = (parseInt(room.name) / 100) | 0; + room.keyId = uuidv4(); + // 将房间加入对应楼层数组 + if (floor > 0 && floor <= this.info.floor) { + floors[floor - 1].push(this.handleColor(room)); + } + }); + + // 对每层楼的房间进行排序 + floors.forEach((floorRooms) => { + floorRooms.sort((a, b) => parseInt(a.name) - parseInt(b.name)); + }); + + // 返回对象,键为楼层号(从1开始),值为对应的房间数组 + return floors; + }, }, components: { colorCell, @@ -95,7 +118,6 @@ export default { rightTopColor: item.rightTopColor, }); this.currentIndex = keyId; - console.log(this.currentIndex); }, async getBuildingInfo() { let info = await getBuilding(this.queryParamsXiaoqu.buildingId); @@ -106,53 +128,32 @@ export default { let res = await getNum({ buildingId: this.queryParamsXiaoqu.buildingId, }); + this.list = res.data; - this.list = this.filterFloor(res.data); + // this.list = this.groupedRooms(res.data); + // let num = 0; + // this.list.forEach((item) => { + // num = num + item.length; + // }); + // console.log(num, res.data.length); }, + // 颜色处理 handleColor(item) { if (!item.color) { item.leftColor = "#7b75ff"; item.rightTopColor = "#7b75ff"; - return; - } - for (let key in this.leftColor) { - if (item.color == key) { - item.leftColor = this.leftColor[key]; - item.rightTopColor = this.rightTopColor[key]; + } else { + for (let key in this.leftColor) { + if (item.color == key) { + item.leftColor = this.leftColor[key]; + item.rightTopColor = this.rightTopColor[key]; + } } } return item; }, - filterFloor(list) { - const categorizedRooms = {}; - list.forEach((room) => { - room.name = room.name.replace("室", ""); - room.keyId = uuidv4(); - const floor = (parseInt(room.name, 10) / 100) | 0; - if (!categorizedRooms[floor]) { - categorizedRooms[floor] = []; - } - - categorizedRooms[floor].push(this.handleColor(room)); - }); - - const totalFloors = this.info.floor; - const sortedRoomsByFloor = []; - for (let floor = 1; floor <= totalFloors; floor++) { - const roomsForFloor = (categorizedRooms[floor] || []).sort((a, b) => { - return a.name - b.name; - }); - - const filteredArray = roomsForFloor.filter( - (element) => element !== undefined - ); - sortedRoomsByFloor.push(filteredArray); - } - - return sortedRoomsByFloor.reverse(); - }, }, };