fix:修复设备管理页面全选功能失效问题

This commit is contained in:
3030332422
2025-08-19 14:45:14 +08:00
parent e8bfe9850e
commit 372dc8ecb0
+14 -13
View File
@@ -74,7 +74,7 @@
<div class="table_bottom"> <div class="table_bottom">
<div class="ctrl_btn"> <div class="ctrl_btn">
<el-button size="mini" type="primary" class="select-all-btn" @click="handleSelectAll"> <el-button size="mini" type="primary" class="select-all-btn" @click="handleSelectAll">
{{ isAllSelected ? '取消全选' : '全选' }} {{ isCurrentPageAllSelected ? '取消全选' : '全选' }}
</el-button> </el-button>
<el-button type="success" size="mini" class="add-device-btn" @click="handleAddDevice"> <el-button type="success" size="mini" class="add-device-btn" @click="handleAddDevice">
验证码绑定 验证码绑定
@@ -128,8 +128,6 @@ export default {
return { return {
addDeviceDialogVisible: false, addDeviceDialogVisible: false,
manualAddDeviceDialogVisible: false, manualAddDeviceDialogVisible: false,
selectedDevices: [],
isAllSelected: false,
searchKeyword: "", searchKeyword: "",
activeSearchKeyword: "", activeSearchKeyword: "",
currentAgentId: this.$route.query.agentId || '', currentAgentId: this.$route.query.agentId || '',
@@ -160,6 +158,11 @@ export default {
pageCount() { pageCount() {
return Math.ceil(this.filteredDeviceList.length / this.pageSize); return Math.ceil(this.filteredDeviceList.length / this.pageSize);
}, },
// 计算当前页是否全选
isCurrentPageAllSelected() {
return this.paginatedDeviceList.length > 0 &&
this.paginatedDeviceList.every(device => device.selected);
},
visiblePages() { visiblePages() {
const pages = []; const pages = [];
const maxVisible = 3; const maxVisible = 3;
@@ -205,16 +208,15 @@ export default {
}, },
handleSelectAll() { handleSelectAll() {
this.isAllSelected = !this.isAllSelected; const shouldSelectAll = !this.isCurrentPageAllSelected;
this.paginatedDeviceList.forEach(row => { this.paginatedDeviceList.forEach(row => {
row.selected = this.isAllSelected; row.selected = shouldSelectAll;
}); });
this.selectedDevices = this.paginatedDeviceList.filter(device => device.selected);
}, },
deleteSelected() { deleteSelected() {
this.selectedDevices = this.paginatedDeviceList.filter(device => device.selected); const selectedDevices = this.paginatedDeviceList.filter(device => device.selected);
if (this.selectedDevices.length === 0) { if (selectedDevices.length === 0) {
this.$message.warning({ this.$message.warning({
message: '请至少选择一条记录', message: '请至少选择一条记录',
showClose: true showClose: true
@@ -222,12 +224,12 @@ export default {
return; return;
} }
this.$confirm(`确认要解绑选中的 ${this.selectedDevices.length} 台设备吗?`, '警告', { this.$confirm(`确认要解绑选中的 ${selectedDevices.length} 台设备吗?`, '警告', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
const deviceIds = this.selectedDevices.map(device => device.device_id); const deviceIds = selectedDevices.map(device => device.device_id);
this.batchUnbindDevices(deviceIds); this.batchUnbindDevices(deviceIds);
}); });
}, },
@@ -250,8 +252,6 @@ export default {
showClose: true showClose: true
}); });
this.fetchBindDevices(this.currentAgentId); this.fetchBindDevices(this.currentAgentId);
this.selectedDevices = [];
this.isAllSelected = false;
}) })
.catch(error => { .catch(error => {
this.$message.error({ this.$message.error({
@@ -355,7 +355,8 @@ export default {
isEdit: false, isEdit: false,
_submitting: false, _submitting: false,
otaSwitch: device.autoUpdate === 1, otaSwitch: device.autoUpdate === 1,
rawBindTime: new Date(device.createDate).getTime() rawBindTime: new Date(device.createDate).getTime(),
selected: false
}; };
}) })
.sort((a, b) => a.rawBindTime - b.rawBindTime); .sort((a, b) => a.rawBindTime - b.rawBindTime);