Commit 1a8a946d491b69f8112b5172dd3b643cea112163
1 parent
b783cddd
优化代码
Showing
4 changed files
with
156 additions
and
21 deletions
src/components/room/floorUnitRoomShopTree.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="bg-white margin-top-xs padding border-radius tree-div"> | ||
| 3 | + <el-tree | ||
| 4 | + v-if="treeData.length > 0" | ||
| 5 | + :data="treeData" | ||
| 6 | + :props="defaultProps" | ||
| 7 | + node-key="id" | ||
| 8 | + :expand-on-click-node="false" | ||
| 9 | + @node-click="handleNodeClick" | ||
| 10 | + > | ||
| 11 | + <template #default="{ node, data }"> | ||
| 12 | + <span class="custom-tree-node"> | ||
| 13 | + <i :class="data.icon" style="margin-right:5px"></i> | ||
| 14 | + <span>{{ node.label }}</span> | ||
| 15 | + </span> | ||
| 16 | + </template> | ||
| 17 | + </el-tree> | ||
| 18 | + <div v-else class="no-data"> | ||
| 19 | + {{ $t('room.floorUnitTree.noData') }} | ||
| 20 | + </div> | ||
| 21 | + </div> | ||
| 22 | +</template> | ||
| 23 | + | ||
| 24 | +<script> | ||
| 25 | +import { getFloorAndUnits } from '@/api/room/floorUnitTreeApi' | ||
| 26 | + | ||
| 27 | +export default { | ||
| 28 | + name: 'floorUnitRoomShopTree', | ||
| 29 | + props: { | ||
| 30 | + callBackListener: String | ||
| 31 | + }, | ||
| 32 | + data() { | ||
| 33 | + return { | ||
| 34 | + treeData: [], | ||
| 35 | + defaultProps: { | ||
| 36 | + children: 'children', | ||
| 37 | + label: 'text', | ||
| 38 | + }, | ||
| 39 | + currentFloorId: '' | ||
| 40 | + } | ||
| 41 | + }, | ||
| 42 | + mounted() { | ||
| 43 | + this.loadData() | ||
| 44 | + }, | ||
| 45 | + beforeDestroy() { | ||
| 46 | + }, | ||
| 47 | + methods: { | ||
| 48 | + refreshTree(param) { | ||
| 49 | + this.handleRefreshTree(param) | ||
| 50 | + }, | ||
| 51 | + selectFirstUnit(){ | ||
| 52 | + if(this.treeData.length > 0){ | ||
| 53 | + this.handleNodeClick(this.treeData[0].children[0]) | ||
| 54 | + // 并且展开 | ||
| 55 | + | ||
| 56 | + } | ||
| 57 | + }, | ||
| 58 | + handleRefreshTree(param) { | ||
| 59 | + if (param) { | ||
| 60 | + this.currentFloorId = param.floorId | ||
| 61 | + } | ||
| 62 | + this.loadData() | ||
| 63 | + }, | ||
| 64 | + async loadData() { | ||
| 65 | + try { | ||
| 66 | + const communityId = this.getCommunityId() | ||
| 67 | + const response = await getFloorAndUnits(communityId) | ||
| 68 | + this.treeData = this.transformData(response) | ||
| 69 | + } catch (error) { | ||
| 70 | + console.error('加载楼栋单元树失败', error) | ||
| 71 | + } | ||
| 72 | + }, | ||
| 73 | + transformData(units) { | ||
| 74 | + const treeData = [] | ||
| 75 | + const floorMap = {} | ||
| 76 | + | ||
| 77 | + units.forEach(item => { | ||
| 78 | + if (!floorMap[item.floorId]) { | ||
| 79 | + floorMap[item.floorId] = { | ||
| 80 | + id: `f_${item.floorId}`, | ||
| 81 | + floorId: item.floorId, | ||
| 82 | + floorNum: item.floorNum, | ||
| 83 | + icon: 'el-icon-office-building', | ||
| 84 | + text: `${item.floorNum}(${item.floorName})`, | ||
| 85 | + children: [] | ||
| 86 | + } | ||
| 87 | + treeData.push(floorMap[item.floorId]) | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + if (item.unitId ) { | ||
| 91 | + floorMap[item.floorId].children.push({ | ||
| 92 | + id: `u_${item.unitId}`, | ||
| 93 | + unitId: item.unitId, | ||
| 94 | + text: `${item.unitNum}`, | ||
| 95 | + icon: 'el-icon-house' | ||
| 96 | + }) | ||
| 97 | + } | ||
| 98 | + }) | ||
| 99 | + | ||
| 100 | + return treeData | ||
| 101 | + }, | ||
| 102 | + handleNodeClick(data) { | ||
| 103 | + if (data.id.startsWith('f_')) { | ||
| 104 | + this.$emit('switchFloorUnit', { floorId: data.floorId,unitId: '' }) | ||
| 105 | + } else { | ||
| 106 | + this.$emit('switchFloorUnit', { floorId:'',unitId: data.unitId }) | ||
| 107 | + } | ||
| 108 | + }, | ||
| 109 | + } | ||
| 110 | +} | ||
| 111 | +</script> | ||
| 112 | + | ||
| 113 | +<style scoped> | ||
| 114 | +.tree-div { | ||
| 115 | + min-height: 300px; | ||
| 116 | +} | ||
| 117 | +.custom-tree-node { | ||
| 118 | + display: flex; | ||
| 119 | + align-items: center; | ||
| 120 | +} | ||
| 121 | +.no-data { | ||
| 122 | + text-align: center; | ||
| 123 | + padding: 20px; | ||
| 124 | + color: #909399; | ||
| 125 | +} | ||
| 126 | +.custom-tree-node { | ||
| 127 | + white-space: nowrap; | ||
| 128 | + overflow: hidden; | ||
| 129 | + text-overflow: ellipsis; | ||
| 130 | + max-width: 200px; /* 根据你的布局调整 */ | ||
| 131 | +} | ||
| 132 | +</style> | ||
| 0 | \ No newline at end of file | 133 | \ No newline at end of file |
src/views/room/roomList.vue
| @@ -225,7 +225,7 @@ | @@ -225,7 +225,7 @@ | ||
| 225 | <el-table-column v-for="(item, index) in roomInfo.listColumns" :key="index" :label="item" width="120" | 225 | <el-table-column v-for="(item, index) in roomInfo.listColumns" :key="index" :label="item" width="120" |
| 226 | align="center"> | 226 | align="center"> |
| 227 | <template slot-scope="scope"> | 227 | <template slot-scope="scope"> |
| 228 | - <div class="hc-td">{{ scope.row.listValues[index] || '' }}</div> | 228 | + <div class="hc-td" v-if="scope.row.listValues">{{ scope.row.listValues[index] || '' }}</div> |
| 229 | </template> | 229 | </template> |
| 230 | </el-table-column> | 230 | </el-table-column> |
| 231 | <el-table-column :label="$t('roomList.operation')" fixed="right" width="180" align="center" | 231 | <el-table-column :label="$t('roomList.operation')" fixed="right" width="180" align="center" |
| @@ -450,21 +450,20 @@ export default { | @@ -450,21 +450,20 @@ export default { | ||
| 450 | this.roomInfo.total = res.total | 450 | this.roomInfo.total = res.total |
| 451 | this.roomInfo.records = res.records | 451 | this.roomInfo.records = res.records |
| 452 | this.roomInfo.rooms = res.rooms | 452 | this.roomInfo.rooms = res.rooms |
| 453 | - this.dealRoomAttr(res.rooms) | 453 | + await this.dealRoomAttr(res.rooms) |
| 454 | } catch (error) { | 454 | } catch (error) { |
| 455 | console.error('获取房间列表失败:', error) | 455 | console.error('获取房间列表失败:', error) |
| 456 | this.$message.error('获取房间列表失败') | 456 | this.$message.error('获取房间列表失败') |
| 457 | } | 457 | } |
| 458 | }, | 458 | }, |
| 459 | 459 | ||
| 460 | - dealRoomAttr(rooms) { | 460 | + async dealRoomAttr(rooms) { |
| 461 | if (!rooms || !rooms.length) return | 461 | if (!rooms || !rooms.length) return |
| 462 | 462 | ||
| 463 | - // 获取表格列配置 | ||
| 464 | - this.getColumns(rooms, () => { | ||
| 465 | - rooms.forEach(item => { | ||
| 466 | - this.getColumnsValue(item) | ||
| 467 | - }) | 463 | + // 获取表格列配置后再处理每个房屋的属性值 |
| 464 | + await this.getColumns() | ||
| 465 | + rooms.forEach(item => { | ||
| 466 | + this.getColumnsValue(item) | ||
| 468 | }) | 467 | }) |
| 469 | }, | 468 | }, |
| 470 | 469 | ||
| @@ -483,7 +482,7 @@ export default { | @@ -483,7 +482,7 @@ export default { | ||
| 483 | }) | 482 | }) |
| 484 | }, | 483 | }, |
| 485 | 484 | ||
| 486 | - async getColumns(rooms, callback) { | 485 | + async getColumns() { |
| 487 | try { | 486 | try { |
| 488 | const { data } = await getAttrSpecList({ | 487 | const { data } = await getAttrSpecList({ |
| 489 | page: 1, | 488 | page: 1, |
| @@ -493,7 +492,6 @@ export default { | @@ -493,7 +492,6 @@ export default { | ||
| 493 | this.roomInfo.listColumns = data | 492 | this.roomInfo.listColumns = data |
| 494 | .filter(item => item.listShow === 'Y') | 493 | .filter(item => item.listShow === 'Y') |
| 495 | .map(item => item.specName) | 494 | .map(item => item.specName) |
| 496 | - callback() | ||
| 497 | } catch (error) { | 495 | } catch (error) { |
| 498 | console.error('获取房屋属性失败:', error) | 496 | console.error('获取房屋属性失败:', error) |
| 499 | } | 497 | } |
src/views/room/roomStructureList.vue
| @@ -2,13 +2,17 @@ | @@ -2,13 +2,17 @@ | ||
| 2 | <div class="room-structure-container"> | 2 | <div class="room-structure-container"> |
| 3 | <el-row :gutter="20"> | 3 | <el-row :gutter="20"> |
| 4 | <el-col :span="4"> | 4 | <el-col :span="4"> |
| 5 | - <floor-unit-tree ref="floorUnitTree" @switchFloorUnit="switchFloorUnit" /> | 5 | + <floor-unit-room-shop-tree ref="floorUnitRoomShopTree" @switchFloorUnit="switchFloorUnit" /> |
| 6 | </el-col> | 6 | </el-col> |
| 7 | <el-col :span="20"> | 7 | <el-col :span="20"> |
| 8 | - <el-card v-if="roomStructureInfo.layerRoomCount < 5" class="room-list-card"> | 8 | + <el-card v-if="roomStructureInfo.layerRoomCount < 5" class="room-list-card "> |
| 9 | <el-row :gutter="10"> | 9 | <el-row :gutter="10"> |
| 10 | - <el-col v-for="(room, index) in roomStructureInfo.rooms" :key="index" :xs="12" :sm="8" :md="6" :lg="4" | ||
| 11 | - :xl="3" class="room-item"> | 10 | + <el-col |
| 11 | + v-for="(room, index) in roomStructureInfo.rooms" | ||
| 12 | + :key="index" | ||
| 13 | + :span="3" | ||
| 14 | + class="room-item" | ||
| 15 | + > | ||
| 12 | <div class="room-card" :style="{ 'background-color': getBgColor(room) }" | 16 | <div class="room-card" :style="{ 'background-color': getBgColor(room) }" |
| 13 | @dblclick="toSimplifyAcceptance(room)"> | 17 | @dblclick="toSimplifyAcceptance(room)"> |
| 14 | <div class="room-number">{{ room.floorNum }}-{{ room.unitNum }}-{{ room.roomNum }}</div> | 18 | <div class="room-number">{{ room.floorNum }}-{{ room.unitNum }}-{{ room.roomNum }}</div> |
| @@ -23,7 +27,7 @@ | @@ -23,7 +27,7 @@ | ||
| 23 | </el-row> | 27 | </el-row> |
| 24 | </el-card> | 28 | </el-card> |
| 25 | 29 | ||
| 26 | - <el-card v-else class="room-list-card"> | 30 | + <el-card v-else class="room-list-card "> |
| 27 | <div v-for="(val, key, index) in roomStructureInfo.parkRooms" :key="index"> | 31 | <div v-for="(val, key, index) in roomStructureInfo.parkRooms" :key="index"> |
| 28 | <div class="floor-title">{{ key }}F</div> | 32 | <div class="floor-title">{{ key }}F</div> |
| 29 | <el-row :gutter="10" class="floor-row"> | 33 | <el-row :gutter="10" class="floor-row"> |
| @@ -49,14 +53,14 @@ | @@ -49,14 +53,14 @@ | ||
| 49 | </template> | 53 | </template> |
| 50 | 54 | ||
| 51 | <script> | 55 | <script> |
| 52 | -import floorUnitTree from '@/components/room/floorUnitTree' | 56 | +import floorUnitRoomShopTree from '@/components/room/floorUnitRoomShopTree' |
| 53 | import { listRoomStructure } from '@/api/room/roomStructureApi' | 57 | import { listRoomStructure } from '@/api/room/roomStructureApi' |
| 54 | import { getCommunityId } from '@/api/community/communityApi' | 58 | import { getCommunityId } from '@/api/community/communityApi' |
| 55 | 59 | ||
| 56 | export default { | 60 | export default { |
| 57 | name: 'RoomStructureList', | 61 | name: 'RoomStructureList', |
| 58 | components: { | 62 | components: { |
| 59 | - floorUnitTree | 63 | + floorUnitRoomShopTree |
| 60 | }, | 64 | }, |
| 61 | data() { | 65 | data() { |
| 62 | return { | 66 | return { |
| @@ -71,7 +75,7 @@ export default { | @@ -71,7 +75,7 @@ export default { | ||
| 71 | created() { | 75 | created() { |
| 72 | this.communityId = getCommunityId() | 76 | this.communityId = getCommunityId() |
| 73 | setTimeout(() => { | 77 | setTimeout(() => { |
| 74 | - this.$refs.floorUnitTree.selectFirstUnit() | 78 | + this.$refs.floorUnitRoomShopTree.selectFirstUnit() |
| 75 | }, 1500) | 79 | }, 1500) |
| 76 | }, | 80 | }, |
| 77 | methods: { | 81 | methods: { |
| @@ -190,7 +194,8 @@ export default { | @@ -190,7 +194,8 @@ export default { | ||
| 190 | padding: 10px; | 194 | padding: 10px; |
| 191 | cursor: pointer; | 195 | cursor: pointer; |
| 192 | transition: all 0.3s; | 196 | transition: all 0.3s; |
| 193 | - height: 100%; | 197 | + height: 125px; |
| 198 | + box-sizing: border-box; | ||
| 194 | 199 | ||
| 195 | &:hover { | 200 | &:hover { |
| 196 | transform: translateY(-3px); | 201 | transform: translateY(-3px); |
src/views/user/login/Login.vue
| @@ -44,8 +44,8 @@ export default { | @@ -44,8 +44,8 @@ export default { | ||
| 44 | logo: '', | 44 | logo: '', |
| 45 | companyName:'', | 45 | companyName:'', |
| 46 | loginForm: { | 46 | loginForm: { |
| 47 | - username: 'wuxw', | ||
| 48 | - passwd: 'admin', | 47 | + username: '', |
| 48 | + passwd: '', | ||
| 49 | validateCode: '' | 49 | validateCode: '' |
| 50 | }, | 50 | }, |
| 51 | captchaUrl: '', | 51 | captchaUrl: '', |