vue2-client 1.19.40 → 1.19.41

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue2-client",
3
- "version": "1.19.40",
3
+ "version": "1.19.41",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve --no-eslint",
@@ -1041,41 +1041,38 @@ export default {
1041
1041
  result.then(res => {
1042
1042
  this.totalCount = res.totalCount || 0
1043
1043
 
1044
- // 在数据加载完成后,立即检查并更新选中状态
1044
+ // 查询后保留跨页选中行的相关逻辑
1045
1045
  if (this.selectRowMode !== 'disabled' && !this.clearSelectRowAfterQuery) {
1046
1046
  const primaryKeyName = this.primaryKey || this.rowKey
1047
+ // 获取当前页所有行的key
1048
+ const currentPageKeys = res.data.map(row => row[primaryKeyName])
1047
1049
  // 找出当前页中应该被选中的行
1048
1050
  const currentPageSelectedRows = res.data.filter(row =>
1049
1051
  this.selectedRowKeys.includes(row[primaryKeyName])
1050
1052
  )
1051
- // 更新表格的选中状态
1053
+
1052
1054
  this.$nextTick(() => {
1053
- // 更新内部选中状态
1055
+ // 更新当前页选中状态
1054
1056
  this.innerSelectedRowKeys = currentPageSelectedRows.map(row => row[primaryKeyName])
1055
1057
  this.innerSelectedRows = currentPageSelectedRows
1056
- // 更新表格显示
1058
+
1057
1059
  if (this.$refs.table) {
1058
1060
  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 => {
1061
+
1062
+ // 合并跨页选中数据:保留其他页 + 当前页最新数据
1063
+ const rowsMap = new Map()
1064
+ // 先保留其他页的选中行
1065
+ this.selectedRows.forEach(row => {
1066
+ if (!currentPageKeys.includes(row[primaryKeyName])) {
1075
1067
  rowsMap.set(row[primaryKeyName], row)
1076
- })
1077
- this.selectedRows = Array.from(rowsMap.values())
1078
- }
1068
+ }
1069
+ })
1070
+ // 再添加当前页的选中行(覆盖重复项,确保数据最新)
1071
+ currentPageSelectedRows.forEach(row => {
1072
+ rowsMap.set(row[primaryKeyName], row)
1073
+ })
1074
+ this.selectedRows = Array.from(rowsMap.values())
1075
+
1079
1076
  // 触发选择事件
1080
1077
  this.$emit('selectRow', this.selectedRowKeys, this.selectedRows)
1081
1078
  }
@@ -1147,62 +1144,68 @@ export default {
1147
1144
  * @param currentPageSelectedRows 被选择的列集合
1148
1145
  */
1149
1146
  onSelectChange (currentPageSelectedKeys, currentPageSelectedRows) {
1150
- if (this.selectRowMode === 'listView' && !this.clearSelectRowAfterQuery) {
1151
- const primaryKeyName = this.primaryKey || this.rowKey
1152
- if (primaryKeyName) {
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
- }
1147
+ // 跨页选中模式:需要合并多页数据
1148
+ if (this.selectRowMode === 'listView' && !this.clearSelectRowAfterQuery && (this.primaryKey || this.rowKey)) {
1149
+ this.mergeMultiPageSelection(currentPageSelectedKeys, currentPageSelectedRows)
1183
1150
  } else {
1184
- // 非 listView 模式或 clearSelectRowAfterQuery 为 true,直接使用当前页的选中状态作为总状态
1151
+ // 单页选中模式:直接使用当前页数据
1185
1152
  this.selectedRowKeys = currentPageSelectedKeys
1186
1153
  this.selectedRows = currentPageSelectedRows
1187
1154
  }
1188
1155
 
1189
- // 更新内部状态和表格显示
1156
+ // 更新当前页选中状态
1190
1157
  this.innerSelectedRowKeys = currentPageSelectedKeys
1191
1158
  this.innerSelectedRows = currentPageSelectedRows
1192
1159
 
1193
- // 确保在DOM更新后调用 updateSelect,以正确反映当前页的选中状态
1160
+ // 更新表格显示
1194
1161
  this.$nextTick(() => {
1195
- this.$refs.table.updateSelect(this.innerSelectedRowKeys, this.innerSelectedRows)
1162
+ this.$refs.table?.updateSelect(this.innerSelectedRowKeys, this.innerSelectedRows)
1196
1163
  })
1197
1164
 
1198
- // 更新按钮状态基于总选中数量
1199
- this.isModify = this.selectedRowKeys.length === 1
1200
- this.isDelete = this.selectedRowKeys.length > 0
1201
- this.isChoose = this.allowSelectRowNum === 0 ? this.selectedRowKeys.length > 0 : this.selectedRowKeys.length === this.allowSelectRowNum
1165
+ // 更新按钮状态
1166
+ this.updateButtonState()
1202
1167
 
1203
- // 触发选择事件,传递总的选中数据
1168
+ // 触发选择事件
1204
1169
  this.$emit('selectRow', this.selectedRowKeys, this.selectedRows)
1205
1170
  },
1171
+
1172
+ /**
1173
+ * 合并多页选中数据
1174
+ */
1175
+ mergeMultiPageSelection (currentPageSelectedKeys, currentPageSelectedRows) {
1176
+ const primaryKeyName = this.primaryKey || this.rowKey
1177
+ const currentPageAllKeys = this.$refs.table.localDataSource.map(row => row[primaryKeyName])
1178
+
1179
+ // 使用 Map 统一处理 keys 和 rows 的合并
1180
+ const rowsMap = new Map()
1181
+
1182
+ // 1. 保留其他页的选中行
1183
+ this.selectedRows.forEach(row => {
1184
+ if (!currentPageAllKeys.includes(row[primaryKeyName])) {
1185
+ rowsMap.set(row[primaryKeyName], row)
1186
+ }
1187
+ })
1188
+
1189
+ // 2. 添加当前页的选中行(覆盖重复项)
1190
+ currentPageSelectedRows.forEach(row => {
1191
+ rowsMap.set(row[primaryKeyName], row)
1192
+ })
1193
+
1194
+ // 3. 更新结果
1195
+ this.selectedRows = Array.from(rowsMap.values())
1196
+ this.selectedRowKeys = Array.from(rowsMap.keys())
1197
+ },
1198
+
1199
+ /**
1200
+ * 更新按钮状态
1201
+ */
1202
+ updateButtonState () {
1203
+ this.isModify = this.selectedRowKeys.length === 1
1204
+ this.isDelete = this.selectedRowKeys.length > 0
1205
+ this.isChoose = this.allowSelectRowNum === 0
1206
+ ? this.selectedRowKeys.length > 0
1207
+ : this.selectedRowKeys.length === this.allowSelectRowNum
1208
+ },
1206
1209
  /**
1207
1210
  * 清除表格选中项
1208
1211
  */
@@ -1435,6 +1438,11 @@ export default {
1435
1438
  this.localEditModeDataSource = this.getLocalData().filter(item => !this.selectedRowKeys.includes(item[this.rowKey]))
1436
1439
  resolve(200)
1437
1440
  this.$message.success('删除成功!')
1441
+ // 清空选中状态
1442
+ this.selectedRowKeys = []
1443
+ this.selectedRows = []
1444
+ this.innerSelectedRowKeys = []
1445
+ this.innerSelectedRows = []
1438
1446
  this.refresh(true)
1439
1447
  // afterDelete
1440
1448
  this.$emit('afterDelete', requestParameters)
@@ -1444,6 +1452,11 @@ export default {
1444
1452
  remove(requestParameters, this.serviceName, this.env === 'dev').then(res => {
1445
1453
  resolve(res)
1446
1454
  this.$message.success('删除成功!')
1455
+ // 清空选中状态
1456
+ this.selectedRowKeys = []
1457
+ this.selectedRows = []
1458
+ this.innerSelectedRowKeys = []
1459
+ this.innerSelectedRows = []
1447
1460
  this.refresh(true)
1448
1461
  // afterDelete
1449
1462
  this.$emit('afterDelete', requestParameters)