vue2-client 1.19.40 → 1.19.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -590,7 +590,17 @@ export default {
|
|
|
590
590
|
}
|
|
591
591
|
},
|
|
592
592
|
...mapState('account', { currUser: 'user', curRoles: 'roles', curPermissions: 'permissions' }),
|
|
593
|
-
...mapState('setting', ['compatible'])
|
|
593
|
+
...mapState('setting', ['compatible']),
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* 是否启用跨页选中模式
|
|
597
|
+
* 条件:selectRowMode 为 listView 且不在查询后清空选中 且有主键
|
|
598
|
+
*/
|
|
599
|
+
isMultiPageSelectionEnabled () {
|
|
600
|
+
return this.selectRowMode === 'listView'
|
|
601
|
+
&& !this.clearSelectRowAfterQuery
|
|
602
|
+
&& (this.primaryKey || this.rowKey)
|
|
603
|
+
}
|
|
594
604
|
},
|
|
595
605
|
watch: {
|
|
596
606
|
pageMaxSize: {
|
|
@@ -1041,45 +1051,9 @@ export default {
|
|
|
1041
1051
|
result.then(res => {
|
|
1042
1052
|
this.totalCount = res.totalCount || 0
|
|
1043
1053
|
|
|
1044
|
-
//
|
|
1054
|
+
// 数据加载完成后,恢复选中状态
|
|
1045
1055
|
if (this.selectRowMode !== 'disabled' && !this.clearSelectRowAfterQuery) {
|
|
1046
|
-
|
|
1047
|
-
// 找出当前页中应该被选中的行
|
|
1048
|
-
const currentPageSelectedRows = res.data.filter(row =>
|
|
1049
|
-
this.selectedRowKeys.includes(row[primaryKeyName])
|
|
1050
|
-
)
|
|
1051
|
-
// 更新表格的选中状态
|
|
1052
|
-
this.$nextTick(() => {
|
|
1053
|
-
// 更新内部选中状态
|
|
1054
|
-
this.innerSelectedRowKeys = currentPageSelectedRows.map(row => row[primaryKeyName])
|
|
1055
|
-
this.innerSelectedRows = currentPageSelectedRows
|
|
1056
|
-
// 更新表格显示
|
|
1057
|
-
if (this.$refs.table) {
|
|
1058
|
-
this.$refs.table.updateSelect(this.innerSelectedRowKeys, this.innerSelectedRows)
|
|
1059
|
-
// 更新总选中状态
|
|
1060
|
-
if (currentPageSelectedRows.length > 0) {
|
|
1061
|
-
// 保留不在当前页面的已选中行
|
|
1062
|
-
const otherPageSelectedRows = this.selectedRows.filter(row =>
|
|
1063
|
-
!currentPageSelectedRows.some(currentRow =>
|
|
1064
|
-
currentRow[primaryKeyName] === row[primaryKeyName]
|
|
1065
|
-
)
|
|
1066
|
-
)
|
|
1067
|
-
// 合并当前页面和其他页面的选中行
|
|
1068
|
-
const rowsMap = new Map()
|
|
1069
|
-
// 先添加其他页面的行
|
|
1070
|
-
otherPageSelectedRows.forEach(row => {
|
|
1071
|
-
rowsMap.set(row[primaryKeyName], row)
|
|
1072
|
-
})
|
|
1073
|
-
// 再添加当前页面的行(会覆盖重复的)
|
|
1074
|
-
currentPageSelectedRows.forEach(row => {
|
|
1075
|
-
rowsMap.set(row[primaryKeyName], row)
|
|
1076
|
-
})
|
|
1077
|
-
this.selectedRows = Array.from(rowsMap.values())
|
|
1078
|
-
}
|
|
1079
|
-
// 触发选择事件
|
|
1080
|
-
this.$emit('selectRow', this.selectedRowKeys, this.selectedRows)
|
|
1081
|
-
}
|
|
1082
|
-
})
|
|
1056
|
+
this.restoreSelectionAfterQuery(res.data)
|
|
1083
1057
|
}
|
|
1084
1058
|
}).catch(() => {
|
|
1085
1059
|
this.$message.error('查询超时!')
|
|
@@ -1111,7 +1085,6 @@ export default {
|
|
|
1111
1085
|
* @param nativeEvent 原生事件
|
|
1112
1086
|
*/
|
|
1113
1087
|
onSelect (record, selected, selectedRows, nativeEvent) {
|
|
1114
|
-
console.log('onSelect', record, selected, selectedRows)
|
|
1115
1088
|
if (this.selectRowMode === 'listView') {
|
|
1116
1089
|
const primaryKeyName = this.primaryKey || this.rowKey
|
|
1117
1090
|
// 获取主键数据
|
|
@@ -1130,7 +1103,6 @@ export default {
|
|
|
1130
1103
|
* @param changeRows 改变的行集合
|
|
1131
1104
|
*/
|
|
1132
1105
|
onSelectAll (selected, selectedRows, changeRows) {
|
|
1133
|
-
console.log('onSelectAll', selected, selectedRows, changeRows)
|
|
1134
1106
|
if (this.selectRowMode === 'listView') {
|
|
1135
1107
|
if (!selected) {
|
|
1136
1108
|
const primaryKeyName = this.primaryKey || this.rowKey
|
|
@@ -1141,67 +1113,180 @@ export default {
|
|
|
1141
1113
|
}
|
|
1142
1114
|
}
|
|
1143
1115
|
},
|
|
1116
|
+
|
|
1144
1117
|
/**
|
|
1145
|
-
*
|
|
1146
|
-
*
|
|
1147
|
-
*
|
|
1118
|
+
* 【用户交互】选择列数据改变事件(用户手动勾选复选框时触发)
|
|
1119
|
+
*
|
|
1120
|
+
* 功能:处理用户勾选/取消勾选复选框的操作
|
|
1121
|
+
*
|
|
1122
|
+
* 逻辑:
|
|
1123
|
+
* - 跨页模式(listView):合并多页选中数据,保留其他页的选中状态
|
|
1124
|
+
* - 单页模式:直接使用当前页选中数据,切换页面会清空选中
|
|
1125
|
+
*
|
|
1126
|
+
* @param {Array} currentPageSelectedKeys - 当前页被选中的行keys
|
|
1127
|
+
* @param {Array} currentPageSelectedRows - 当前页被选中的行数据
|
|
1148
1128
|
*/
|
|
1149
1129
|
onSelectChange (currentPageSelectedKeys, currentPageSelectedRows) {
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
// 获取当前页面所有行的key
|
|
1154
|
-
const currentPageAllKeys = this.$refs.table.localDataSource.map(row => row[primaryKeyName])
|
|
1155
|
-
// 1. 保留不在当前页的已选中keys,并去重
|
|
1156
|
-
const otherPageSelectedKeys = [...new Set(this.selectedRowKeys.filter(key => !currentPageAllKeys.includes(key)))]
|
|
1157
|
-
console.log('其他页的keys', otherPageSelectedKeys)
|
|
1158
|
-
// 2. 添加当前页新选中的keys,并去重
|
|
1159
|
-
this.selectedRowKeys = [...new Set([...otherPageSelectedKeys, ...currentPageSelectedKeys])]
|
|
1160
|
-
console.log('onSelectChange - updated selectedRowKeys:', this.selectedRowKeys)
|
|
1161
|
-
// 更新总的 selectedRows
|
|
1162
|
-
// 1. 保留不在当前页的已选中行,并去重
|
|
1163
|
-
const otherPageSelectedRows = this.selectedRows.filter(row =>
|
|
1164
|
-
!currentPageAllKeys.includes(row[primaryKeyName])
|
|
1165
|
-
)
|
|
1166
|
-
// 2. 合并结果,使用 Map 去重
|
|
1167
|
-
const rowsMap = new Map()
|
|
1168
|
-
// 先添加其他页面的行
|
|
1169
|
-
otherPageSelectedRows.forEach(row => {
|
|
1170
|
-
rowsMap.set(row[primaryKeyName], row)
|
|
1171
|
-
})
|
|
1172
|
-
// 再添加当前页面的行(会覆盖重复的)
|
|
1173
|
-
currentPageSelectedRows.forEach(row => {
|
|
1174
|
-
rowsMap.set(row[primaryKeyName], row)
|
|
1175
|
-
})
|
|
1176
|
-
this.selectedRows = Array.from(rowsMap.values())
|
|
1177
|
-
console.log('onSelectChange - updated selectedRows:', this.selectedRows)
|
|
1178
|
-
} else {
|
|
1179
|
-
// 如果没有主键,则直接使用当前选中的行(此情况可能无法跨页选中,但为了兼容保留)
|
|
1180
|
-
this.selectedRowKeys = currentPageSelectedKeys
|
|
1181
|
-
this.selectedRows = currentPageSelectedRows
|
|
1182
|
-
}
|
|
1130
|
+
// 跨页选中模式:需要合并多页数据
|
|
1131
|
+
if (this.isMultiPageSelectionEnabled) {
|
|
1132
|
+
this.mergeMultiPageSelection(currentPageSelectedRows)
|
|
1183
1133
|
} else {
|
|
1184
|
-
//
|
|
1134
|
+
// 单页选中模式:直接使用当前页数据
|
|
1185
1135
|
this.selectedRowKeys = currentPageSelectedKeys
|
|
1186
1136
|
this.selectedRows = currentPageSelectedRows
|
|
1187
1137
|
}
|
|
1188
1138
|
|
|
1189
|
-
//
|
|
1139
|
+
// 同步内部状态并更新UI
|
|
1140
|
+
this.syncSelectionState(currentPageSelectedKeys, currentPageSelectedRows)
|
|
1141
|
+
},
|
|
1142
|
+
|
|
1143
|
+
/**
|
|
1144
|
+
* 【跨页选中】合并多页选中数据(核心合并逻辑)
|
|
1145
|
+
*
|
|
1146
|
+
* 功能:在跨页选中模式下,合并当前页和其他页的选中数据
|
|
1147
|
+
*
|
|
1148
|
+
* 逻辑:
|
|
1149
|
+
* 1. 获取当前页所有行的keys
|
|
1150
|
+
* 2. 保留不在当前页的已选中行(其他页的选中数据)
|
|
1151
|
+
* 3. 添加当前页的选中行(覆盖重复项,确保数据最新)
|
|
1152
|
+
* 4. 使用 Map 去重,key为主键,value为行数据
|
|
1153
|
+
*
|
|
1154
|
+
* 结果:
|
|
1155
|
+
* - selectedRowKeys: 所有页面选中的keys
|
|
1156
|
+
* - selectedRows: 所有页面选中的行数据
|
|
1157
|
+
*
|
|
1158
|
+
* @param {Array} currentPageSelectedRows - 当前页被选中的行数据
|
|
1159
|
+
*/
|
|
1160
|
+
mergeMultiPageSelection (currentPageSelectedRows) {
|
|
1161
|
+
const primaryKeyName = this.primaryKey || this.rowKey
|
|
1162
|
+
const currentPageAllKeys = this.$refs.table.localDataSource.map(row => row[primaryKeyName])
|
|
1163
|
+
|
|
1164
|
+
// 使用 Map 统一处理 keys 和 rows 的合并
|
|
1165
|
+
const rowsMap = new Map()
|
|
1166
|
+
|
|
1167
|
+
// 1. 保留其他页的选中行
|
|
1168
|
+
this.selectedRows.forEach(row => {
|
|
1169
|
+
if (!currentPageAllKeys.includes(row[primaryKeyName])) {
|
|
1170
|
+
rowsMap.set(row[primaryKeyName], row)
|
|
1171
|
+
}
|
|
1172
|
+
})
|
|
1173
|
+
|
|
1174
|
+
// 2. 添加当前页的选中行(覆盖重复项)
|
|
1175
|
+
currentPageSelectedRows.forEach(row => {
|
|
1176
|
+
rowsMap.set(row[primaryKeyName], row)
|
|
1177
|
+
})
|
|
1178
|
+
|
|
1179
|
+
// 3. 更新结果
|
|
1180
|
+
this.selectedRows = Array.from(rowsMap.values())
|
|
1181
|
+
this.selectedRowKeys = Array.from(rowsMap.keys())
|
|
1182
|
+
},
|
|
1183
|
+
|
|
1184
|
+
/**
|
|
1185
|
+
* 【UI同步】同步选中状态到UI(内部公共方法)
|
|
1186
|
+
*
|
|
1187
|
+
* 功能:统一处理选中状态的UI更新逻辑
|
|
1188
|
+
*
|
|
1189
|
+
* 执行步骤:
|
|
1190
|
+
* 1. 更新当前页选中状态(innerSelectedRowKeys/innerSelectedRows)
|
|
1191
|
+
* 2. 更新表格复选框显示
|
|
1192
|
+
* 3. 更新按钮状态(修改/删除/选择按钮的启用/禁用)
|
|
1193
|
+
* 4. 触发选择事件,通知父组件
|
|
1194
|
+
*
|
|
1195
|
+
* 调用场景:
|
|
1196
|
+
* - onSelectChange: 用户勾选复选框后
|
|
1197
|
+
* - restoreSelectionAfterQuery: 数据加载后恢复选中状态
|
|
1198
|
+
* - doUpdateTableSelection: 外部传入keys更新选中状态
|
|
1199
|
+
*
|
|
1200
|
+
* @param {Array} currentPageSelectedKeys - 当前页被选中的行keys
|
|
1201
|
+
* @param {Array} currentPageSelectedRows - 当前页被选中的行数据
|
|
1202
|
+
*/
|
|
1203
|
+
syncSelectionState (currentPageSelectedKeys, currentPageSelectedRows) {
|
|
1204
|
+
// 更新当前页选中状态
|
|
1190
1205
|
this.innerSelectedRowKeys = currentPageSelectedKeys
|
|
1191
1206
|
this.innerSelectedRows = currentPageSelectedRows
|
|
1192
1207
|
|
|
1193
|
-
//
|
|
1208
|
+
// 更新表格显示
|
|
1194
1209
|
this.$nextTick(() => {
|
|
1195
|
-
this.$refs.table
|
|
1210
|
+
this.$refs.table?.updateSelect(this.innerSelectedRowKeys, this.innerSelectedRows)
|
|
1196
1211
|
})
|
|
1197
1212
|
|
|
1198
|
-
//
|
|
1213
|
+
// 更新按钮状态
|
|
1214
|
+
this.updateButtonState()
|
|
1215
|
+
|
|
1216
|
+
// 触发选择事件
|
|
1217
|
+
this.$emit('selectRow', this.selectedRowKeys, this.selectedRows)
|
|
1218
|
+
},
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* 【数据加载】数据加载后恢复选中状态
|
|
1222
|
+
*
|
|
1223
|
+
* 功能:在表格数据重新加载后,恢复之前的选中状态
|
|
1224
|
+
*
|
|
1225
|
+
* 使用场景:
|
|
1226
|
+
* - 翻页后,恢复当前页应该被选中的行
|
|
1227
|
+
* - 刷新数据后,保持选中状态不丢失
|
|
1228
|
+
*
|
|
1229
|
+
* 逻辑:
|
|
1230
|
+
* 1. 从新加载的数据中,筛选出应该被选中的行(根据 selectedRowKeys)
|
|
1231
|
+
* 2. 合并跨页选中数据(复用 mergeMultiPageSelection)
|
|
1232
|
+
* 3. 同步UI状态
|
|
1233
|
+
*
|
|
1234
|
+
* @param {Array} currentPageData - 当前页加载的数据
|
|
1235
|
+
*/
|
|
1236
|
+
restoreSelectionAfterQuery (currentPageData) {
|
|
1237
|
+
const primaryKeyName = this.primaryKey || this.rowKey
|
|
1238
|
+
|
|
1239
|
+
// 找出当前页中应该被选中的行
|
|
1240
|
+
const currentPageSelectedRows = currentPageData.filter(row =>
|
|
1241
|
+
this.selectedRowKeys.includes(row[primaryKeyName])
|
|
1242
|
+
)
|
|
1243
|
+
const currentPageSelectedKeys = currentPageSelectedRows.map(row => row[primaryKeyName])
|
|
1244
|
+
|
|
1245
|
+
this.$nextTick(() => {
|
|
1246
|
+
if (!this.$refs.table) return
|
|
1247
|
+
|
|
1248
|
+
// 合并跨页选中数据(复用合并逻辑)
|
|
1249
|
+
this.mergeMultiPageSelection(currentPageSelectedRows)
|
|
1250
|
+
|
|
1251
|
+
// 同步UI状态
|
|
1252
|
+
this.syncSelectionState(currentPageSelectedKeys, currentPageSelectedRows)
|
|
1253
|
+
})
|
|
1254
|
+
},
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* 【按钮状态】更新按钮状态
|
|
1258
|
+
*
|
|
1259
|
+
* 功能:根据选中数量,更新操作按钮的启用/禁用状态
|
|
1260
|
+
*
|
|
1261
|
+
* 按钮规则:
|
|
1262
|
+
* - isModify: 修改按钮,仅选中1条时启用
|
|
1263
|
+
* - isDelete: 删除按钮,选中至少1条时启用
|
|
1264
|
+
* - isChoose: 选择按钮,根据 allowSelectRowNum 配置判断
|
|
1265
|
+
* - allowSelectRowNum = 0: 选中任意数量即可
|
|
1266
|
+
* - allowSelectRowNum > 0: 必须选中指定数量
|
|
1267
|
+
*/
|
|
1268
|
+
updateButtonState () {
|
|
1199
1269
|
this.isModify = this.selectedRowKeys.length === 1
|
|
1200
1270
|
this.isDelete = this.selectedRowKeys.length > 0
|
|
1201
|
-
this.isChoose = this.allowSelectRowNum === 0
|
|
1271
|
+
this.isChoose = this.allowSelectRowNum === 0
|
|
1272
|
+
? this.selectedRowKeys.length > 0
|
|
1273
|
+
: this.selectedRowKeys.length === this.allowSelectRowNum
|
|
1274
|
+
},
|
|
1202
1275
|
|
|
1203
|
-
|
|
1204
|
-
|
|
1276
|
+
/**
|
|
1277
|
+
* 【清空选中】清空所有选中状态
|
|
1278
|
+
*
|
|
1279
|
+
* 功能:清空全局和当前页的选中状态
|
|
1280
|
+
*
|
|
1281
|
+
* 使用场景:
|
|
1282
|
+
* - 删除操作成功后
|
|
1283
|
+
* - 需要重置选中状态时
|
|
1284
|
+
*/
|
|
1285
|
+
clearSelection () {
|
|
1286
|
+
this.selectedRowKeys = []
|
|
1287
|
+
this.selectedRows = []
|
|
1288
|
+
this.innerSelectedRowKeys = []
|
|
1289
|
+
this.innerSelectedRows = []
|
|
1205
1290
|
},
|
|
1206
1291
|
/**
|
|
1207
1292
|
* 清除表格选中项
|
|
@@ -1435,6 +1520,8 @@ export default {
|
|
|
1435
1520
|
this.localEditModeDataSource = this.getLocalData().filter(item => !this.selectedRowKeys.includes(item[this.rowKey]))
|
|
1436
1521
|
resolve(200)
|
|
1437
1522
|
this.$message.success('删除成功!')
|
|
1523
|
+
// 清空选中状态
|
|
1524
|
+
this.clearSelection()
|
|
1438
1525
|
this.refresh(true)
|
|
1439
1526
|
// afterDelete
|
|
1440
1527
|
this.$emit('afterDelete', requestParameters)
|
|
@@ -1444,6 +1531,8 @@ export default {
|
|
|
1444
1531
|
remove(requestParameters, this.serviceName, this.env === 'dev').then(res => {
|
|
1445
1532
|
resolve(res)
|
|
1446
1533
|
this.$message.success('删除成功!')
|
|
1534
|
+
// 清空选中状态
|
|
1535
|
+
this.clearSelection()
|
|
1447
1536
|
this.refresh(true)
|
|
1448
1537
|
// afterDelete
|
|
1449
1538
|
this.$emit('afterDelete', requestParameters)
|
|
@@ -1608,13 +1697,11 @@ export default {
|
|
|
1608
1697
|
onExpand (expanded, record) {
|
|
1609
1698
|
this.$emit('expand', expanded, record)
|
|
1610
1699
|
},
|
|
1611
|
-
//
|
|
1700
|
+
// 添加新方法处理表格选中状态(外部调用)
|
|
1612
1701
|
updateTableSelection (selectedKeys) {
|
|
1613
|
-
console.log('selectedKeys', selectedKeys)
|
|
1614
1702
|
if (!this.$refs.table) {
|
|
1615
1703
|
return
|
|
1616
1704
|
}
|
|
1617
|
-
|
|
1618
1705
|
// 检查数据是否已加载
|
|
1619
1706
|
if (!this.$refs.table.localDataSource || this.$refs.table.localDataSource.length === 0) {
|
|
1620
1707
|
// 等待数据加载完成后再处理
|
|
@@ -1636,30 +1723,18 @@ export default {
|
|
|
1636
1723
|
doUpdateTableSelection (selectedKeys) {
|
|
1637
1724
|
const primaryKeyName = this.primaryKey || this.rowKey
|
|
1638
1725
|
|
|
1639
|
-
//
|
|
1640
|
-
this.
|
|
1641
|
-
this.innerSelectedRowKeys = this.$refs.table.localDataSource
|
|
1642
|
-
.filter(row => selectedKeys.includes(row[primaryKeyName]))
|
|
1643
|
-
.map(row => row[primaryKeyName])
|
|
1644
|
-
|
|
1645
|
-
// 更新选中行数据
|
|
1646
|
-
this.selectedRows = this.$refs.table.localDataSource.filter(row =>
|
|
1726
|
+
// 从当前页数据中筛选出应该被选中的行
|
|
1727
|
+
const currentPageSelectedRows = this.$refs.table.localDataSource.filter(row =>
|
|
1647
1728
|
selectedKeys.includes(row[primaryKeyName])
|
|
1648
1729
|
)
|
|
1649
|
-
|
|
1730
|
+
const currentPageSelectedKeys = currentPageSelectedRows.map(row => row[primaryKeyName])
|
|
1650
1731
|
|
|
1651
|
-
//
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
// 更新按钮状态
|
|
1657
|
-
this.isModify = this.selectedRowKeys.length === 1
|
|
1658
|
-
this.isDelete = this.selectedRowKeys.length > 0
|
|
1659
|
-
this.isChoose = this.allowSelectRowNum === 0 ? this.selectedRowKeys.length > 0 : this.selectedRowKeys.length === this.allowSelectRowNum
|
|
1732
|
+
// 更新总选中状态(外部传入的keys)
|
|
1733
|
+
this.selectedRowKeys = [...selectedKeys]
|
|
1734
|
+
this.selectedRows = currentPageSelectedRows
|
|
1660
1735
|
|
|
1661
|
-
//
|
|
1662
|
-
this
|
|
1736
|
+
// 同步内部状态并更新UI(复用方法)
|
|
1737
|
+
this.syncSelectionState(currentPageSelectedKeys, currentPageSelectedRows)
|
|
1663
1738
|
},
|
|
1664
1739
|
/**
|
|
1665
1740
|
* 处理进度更新事件
|