提交代码
This commit is contained in:
1 parent
b5e6ca3cce
commit
40d4bcdc3a
5 files changed
+226
-10
No files matched your search
@@ -0,0 +1,24 @@
|
||||
# 代码调整记录 2025-07-01
|
||||
|
||||
## 房间编号格式变更
|
||||
|
||||
### 调整时间
|
||||
2025-07-01 13:45:30
|
||||
|
||||
### 变更内容
|
||||
将宿舍房间编号格式从固定的"3+楼层+房间号"调整为"楼栋首字符+楼层+房间号"。
|
||||
|
||||
### 变更文件
|
||||
- `web/src/views/xgss/xsssfjgl/index.vue`
|
||||
|
||||
### 详细说明
|
||||
1. 原有格式为 `3${floor}${paddedRoomNumber}`,如3201表示2楼01号房
|
||||
2. 现调整为 `${buildingFirstChar}${floor}${paddedRoomNumber}`,如A201表示A栋2楼01号房
|
||||
3. 楼栋首字符通过 `selectedBuilding.value.label.charAt(0)` 获取
|
||||
|
||||
### 相关业务场景
|
||||
宿舍管理模块中的批量添加房间功能,现在能够更准确地反映不同楼栋的房间编号。
|
||||
|
||||
### 待优化事项
|
||||
- 考虑未来将房间编号规则配置化,以适应不同校区和宿舍楼的编号需求
|
||||
- 需要评估此变更对已有数据的影响,目前仅影响新添加的房间
|
||||
@@ -18,8 +18,8 @@
|
||||
<el-radio-group v-model="form.bedType">
|
||||
<el-radio label="1">下铺</el-radio>
|
||||
<el-radio label="2">上铺</el-radio>
|
||||
<el-radio label="3">中铺</el-radio>
|
||||
<el-radio label="4">独立床</el-radio>
|
||||
<!-- <el-radio label="3">中铺</el-radio> -->
|
||||
<!-- <el-radio label="4">独立床</el-radio> -->
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
@@ -60,7 +60,7 @@ const initFormData: DormBedForm = {
|
||||
bedName: '',
|
||||
roomId: '',
|
||||
bedStatus: '0',
|
||||
bedType: '4',
|
||||
bedType: '1',
|
||||
remark: ''
|
||||
};
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ const initFormData: DormRoomForm = {
|
||||
roomName: '',
|
||||
floorNum: 1,
|
||||
buildingId: '',
|
||||
actualBeds: 4,
|
||||
actualBeds: 8,
|
||||
roomArea: 0,
|
||||
roomType: '1',
|
||||
roomStatus: '0',
|
||||
|
||||
@@ -80,7 +80,13 @@
|
||||
<template #header>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<span class="font-bold">{{ selectedBuilding?.label }} - 房间管理</span>
|
||||
<span class="font-bold"
|
||||
>{{ selectedBuilding?.label }}
|
||||
<span :class="selectedBuilding?.buildingType === '1' ? 'male-building' : 'female-building'">
|
||||
{{ selectedBuilding?.buildingType === '1' ? '(男生楼)' : '(女生楼)' }}
|
||||
</span>
|
||||
- 房间管理</span
|
||||
>
|
||||
</el-col>
|
||||
<el-col :span="12" class="text-right">
|
||||
<right-toolbar
|
||||
@@ -96,6 +102,7 @@
|
||||
<div v-for="floor in floorList" :key="floor" class="mb-4">
|
||||
<el-divider>
|
||||
<el-tag type="success" effect="dark" class="mr-2">{{ floor }}层</el-tag>
|
||||
<el-button type="primary" icon="Plus" size="small" @click="handleAddAllRoom(floor)">自动添加房间</el-button>
|
||||
<el-button type="primary" icon="Plus" size="small" @click="handleAddRoom(floor)">添加房间</el-button>
|
||||
</el-divider>
|
||||
|
||||
@@ -156,6 +163,7 @@
|
||||
<!-- 床位管理对话框 -->
|
||||
<el-dialog v-model="bedManageDialog.visible" :title="`${bedManageDialog.roomName} - 床位管理`" width="800px">
|
||||
<div class="mb-4 text-right">
|
||||
<el-button v-if="!isBedLimitReached" type="primary" icon="Plus" size="small" @click="handleAddALlBed">自动添加床位</el-button>
|
||||
<el-button v-if="!isBedLimitReached" type="primary" icon="Plus" size="small" @click="handleAddBed">添加床位</el-button>
|
||||
<el-tag v-else type="info">已达到床位上限 ({{ bedList.length }}/{{ bedManageDialog.maxBeds }})</el-tag>
|
||||
<!-- <el-button type="success" icon="Check" size="small" @click="handleSaveBeds">保存</el-button> -->
|
||||
@@ -205,12 +213,12 @@
|
||||
import { ref, computed, reactive, onMounted, nextTick, watch } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { InfoFilled, Search } from '@element-plus/icons-vue';
|
||||
import { DormTreeNode, BedInfo, DormQuery } from '@/api/xgss/xsssfjgl/types';
|
||||
import { DormTreeNode, BedInfo, DormQuery, BedForm } from '@/api/xgss/xsssfjgl/types';
|
||||
import { DormRoomVO, DormRoomQuery } from '@/api/xgss/dormRoom/types';
|
||||
import { getDormTree } from '@/api/xgss/xsssfjgl';
|
||||
import { listDormBed, delDormBed } from '@/api/xgss/dormBed';
|
||||
import { listDormBed, delDormBed, addDormBed } from '@/api/xgss/dormBed';
|
||||
import type { DormBedQuery } from '@/api/xgss/dormBed/types';
|
||||
import { listDormRoom, delDormRoom } from '@/api/xgss/dormRoom';
|
||||
import { listDormRoom, delDormRoom, addDormRoom } from '@/api/xgss/dormRoom';
|
||||
|
||||
// 引入子组件
|
||||
import RoomDialog from './components/RoomDialog.vue';
|
||||
@@ -247,7 +255,7 @@ const floorList = computed(() => {
|
||||
// 查询参数
|
||||
const queryParams = reactive<DormRoomQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 100,
|
||||
pageSize: 10000,
|
||||
buildingId: undefined,
|
||||
roomName: '',
|
||||
roomStatus: undefined
|
||||
@@ -389,6 +397,87 @@ const resetQuery = () => {
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
/** 批量自动添加房间 */
|
||||
const handleAddAllRoom = (floor: number) => {
|
||||
if (!selectedBuilding.value) return;
|
||||
|
||||
// 使用Element Plus的对话框提示用户输入寝室数量
|
||||
ElMessageBox.prompt('请输入要添加的寝室数量', '批量添加房间', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
inputPattern: /^[1-9]\d*$/,
|
||||
inputErrorMessage: '请输入正整数',
|
||||
inputValue: '10' // 默认值
|
||||
})
|
||||
.then(async ({ value }) => {
|
||||
const roomCount = parseInt(value);
|
||||
|
||||
try {
|
||||
// 先获取当前楼层的房间列表,确定起始房间号
|
||||
const floorRooms = getRoomsByFloor(floor);
|
||||
let startRoomNumber = 1;
|
||||
|
||||
// 如果已有房间,确定起始编号(避免房间号重复)
|
||||
if (floorRooms.length > 0) {
|
||||
// 提取现有房间号中的数字部分
|
||||
const existingRoomNumbers = floorRooms
|
||||
.map((room) => {
|
||||
// 假设房间名称格式为:楼层+编号,如"3201"
|
||||
const match = room.roomName.match(/\d+$/);
|
||||
return match ? parseInt(match[0].substring(floor.toString().length), 10) : 0;
|
||||
})
|
||||
.filter((num) => !isNaN(num));
|
||||
|
||||
// 找出最大编号并加1作为起始编号
|
||||
if (existingRoomNumbers.length > 0) {
|
||||
startRoomNumber = Math.max(...existingRoomNumbers) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 显示加载提示
|
||||
ElMessage.info(`正在添加 ${roomCount} 个房间,请稍候...`);
|
||||
|
||||
// 批量添加房间
|
||||
for (let i = 0; i < roomCount; i++) {
|
||||
const roomNumber = startRoomNumber + i;
|
||||
// 房间号格式:楼栋首字符+楼层+编号(如A栋2层1号房间为A201)
|
||||
// 补零确保房间号长度一致
|
||||
const paddedRoomNumber = roomNumber.toString().padStart(2, '0');
|
||||
const buildingFirstChar = selectedBuilding.value.label.charAt(0);
|
||||
const roomCode = `${buildingFirstChar}${floor}${paddedRoomNumber}`;
|
||||
|
||||
const roomData = {
|
||||
buildingId: selectedBuilding.value.id,
|
||||
floorNum: floor,
|
||||
roomCode: `${roomCode}`,
|
||||
roomName: `${roomCode}`,
|
||||
roomType: '1', // 1: 标准间
|
||||
actualBeds: 6, // 默认6个床位
|
||||
roomArea: 0, // 默认面积为0
|
||||
roomStatus: '0' // 0: 正常
|
||||
};
|
||||
|
||||
// 调用添加房间API
|
||||
await addDormRoom(roomData);
|
||||
|
||||
// 添加延迟避免请求过快
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
}
|
||||
|
||||
ElMessage.success(`成功添加 ${roomCount} 个房间`);
|
||||
// 重新加载房间数据
|
||||
loadRoomData();
|
||||
} catch (error) {
|
||||
console.error('批量添加房间失败', error);
|
||||
ElMessage.error('添加房间失败,请重试');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// 用户取消操作
|
||||
ElMessage.info('已取消添加房间');
|
||||
});
|
||||
};
|
||||
|
||||
/** 添加房间 */
|
||||
const handleAddRoom = (floor: number) => {
|
||||
if (!selectedBuilding.value) return;
|
||||
@@ -528,6 +617,103 @@ const handleSaveBeds = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
/** 自动添加床位 */
|
||||
const handleAddALlBed = async () => {
|
||||
// 计算需要添加的床位数量
|
||||
const maxBeds = bedManageDialog.maxBeds;
|
||||
const currentBeds = bedList.value.length;
|
||||
|
||||
if (currentBeds >= maxBeds) {
|
||||
ElMessage.warning(`已达到床位上限 (${currentBeds}/${maxBeds})`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算要添加的床位数量,床位按成对添加(上铺和下铺)
|
||||
const needToAdd = maxBeds - currentBeds;
|
||||
const pairCount = Math.ceil(needToAdd / 2); // 需要添加的床位对数
|
||||
|
||||
try {
|
||||
bedLoading.value = true;
|
||||
|
||||
// 计算起始编号(基于已有床位计算)
|
||||
let startIndex = 1;
|
||||
if (bedList.value.length > 0) {
|
||||
// 尝试从现有床位编号中提取最大数字
|
||||
const existingNumbers = bedList.value
|
||||
.map((bed) => {
|
||||
// 假设bedName中包含数字,如"1上"中的1
|
||||
const match = bed.bedName.match(/^(\d+)/);
|
||||
return match ? parseInt(match[1], 10) : 0;
|
||||
})
|
||||
.filter((num) => !isNaN(num));
|
||||
|
||||
if (existingNumbers.length > 0) {
|
||||
startIndex = Math.max(...existingNumbers) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 添加床位计数
|
||||
let addedCount = 0;
|
||||
|
||||
// 创建延迟函数
|
||||
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
for (let i = 0; i < pairCount; i++) {
|
||||
const bedIndex = startIndex + i;
|
||||
|
||||
// 如果当前床位数 + 已添加的床位数 < 最大床位数,则添加上铺
|
||||
if (currentBeds + addedCount < maxBeds) {
|
||||
// 使用API需要的格式
|
||||
const upperBed = {
|
||||
id: '', // 新增时为空
|
||||
bedCode: `${addedCount + 1}`,
|
||||
bedName: `${addedCount + 1}`,
|
||||
roomId: bedManageDialog.roomId,
|
||||
bedStatus: '0', // 空闲
|
||||
bedType: '2', // 上铺
|
||||
remark: ''
|
||||
};
|
||||
await addDormBed(upperBed);
|
||||
addedCount++;
|
||||
|
||||
// 添加0.5秒延迟
|
||||
await delay(100);
|
||||
}
|
||||
|
||||
// 如果当前床位数 + 已添加的床位数 < 最大床位数,则添加下铺
|
||||
if (currentBeds + addedCount < maxBeds) {
|
||||
// 使用API需要的格式
|
||||
const lowerBed = {
|
||||
id: '', // 新增时为空
|
||||
bedCode: `${addedCount + 1}`,
|
||||
bedName: `${addedCount + 1}`,
|
||||
roomId: bedManageDialog.roomId,
|
||||
bedStatus: '0', // 空闲
|
||||
bedType: '1', // 下铺
|
||||
remark: ''
|
||||
};
|
||||
await addDormBed(lowerBed);
|
||||
addedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (addedCount > 0) {
|
||||
ElMessage.success(`成功添加 ${addedCount} 个床位`);
|
||||
// 重新加载床位数据
|
||||
await loadBedData(bedManageDialog.roomId);
|
||||
// 更新房间的当前床位数
|
||||
if (selectedBuilding.value) {
|
||||
loadRoomData();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('批量添加床位失败', error);
|
||||
ElMessage.error('添加床位失败,请重试');
|
||||
} finally {
|
||||
bedLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getDormTreeData();
|
||||
});
|
||||
|
||||
@@ -129,7 +129,13 @@
|
||||
<div class="mb-4">
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<span class="font-bold">{{ selectedBuilding?.label }} - 房间管理</span>
|
||||
<span class="font-bold"
|
||||
>{{ selectedBuilding?.label }}
|
||||
<span :class="selectedBuilding?.buildingType === '1' ? 'male-building' : 'female-building'">
|
||||
{{ selectedBuilding?.buildingType === '1' ? '(男生楼)' : '(女生楼)' }}
|
||||
</span>
|
||||
- 房间管理</span
|
||||
>
|
||||
<span class="ml-4 text-blue-500">已选择: {{ selectedRoomCount }}个房间 / {{ selectedBedCount }}个床位</span>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
Reference in new issue
Block a user