|
@@ -288,6 +288,10 @@ export default {
|
|
|
/** @type {Array<string|number>} */
|
|
|
selectedRowKeys: [],
|
|
|
|
|
|
+ // 程序化同步选择的守卫标记,避免回调环
|
|
|
+ /** @type {boolean} */
|
|
|
+ selectionSyncing: false,
|
|
|
+
|
|
|
/** 当前库存 */
|
|
|
currentInventory: null,
|
|
|
|
|
@@ -1347,6 +1351,8 @@ export default {
|
|
|
* @returns {void}
|
|
|
*/
|
|
|
handleSelectionChange(selection) {
|
|
|
+ // 程序化同步时不触发合并逻辑,避免回调环
|
|
|
+ if (this.selectionSyncing) return
|
|
|
// 基于当前页数据与新选择集,维护跨页 selection 的“并集 - 当前页未选差集”
|
|
|
const currentPageRows = Array.isArray(this.pagedStockTableData) ? this.pagedStockTableData : []
|
|
|
const currentPageKeys = new Set(
|
|
@@ -1484,6 +1490,8 @@ export default {
|
|
|
this.pageSize = newSize
|
|
|
// 变更每页大小后,将页码重置为 1
|
|
|
this.currentPage = 1
|
|
|
+ // 同步当前页表格的选择回显
|
|
|
+ this.syncTableSelection()
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -1494,6 +1502,8 @@ export default {
|
|
|
handlePageChange(page) {
|
|
|
const newPage = Number(page) > 0 ? Number(page) : 1
|
|
|
this.currentPage = newPage
|
|
|
+ // 同步当前页表格的选择回显
|
|
|
+ this.syncTableSelection()
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -1510,6 +1520,8 @@ export default {
|
|
|
if (this.currentPage < 1) {
|
|
|
this.currentPage = 1
|
|
|
}
|
|
|
+ // 校正页码后,确保当前页的表格勾选状态与 selectedRowKeys 保持一致
|
|
|
+ this.syncTableSelection()
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -1625,6 +1637,40 @@ export default {
|
|
|
// 异常时不阻塞新增,默认允许保存
|
|
|
this.$emit && this.$emit(FORECAST_FORM_EVENTS.SAVE_DISABLED_CHANGE, false)
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 程序化同步当前页表格勾选状态到 selectedRowKeys
|
|
|
+ * @returns {void}
|
|
|
+ */
|
|
|
+ syncTableSelection() {
|
|
|
+ try {
|
|
|
+ /** @type {any} */
|
|
|
+ const table = this.$refs && this.$refs.stockTable
|
|
|
+ if (!table || typeof table.clearSelection !== 'function' || typeof table.toggleRowSelection !== 'function') return
|
|
|
+ this.selectionSyncing = true
|
|
|
+ this.$nextTick(() => {
|
|
|
+ try {
|
|
|
+ table.clearSelection()
|
|
|
+ const selectedSet = new Set(Array.isArray(this.selectedRowKeys) ? this.selectedRowKeys : [])
|
|
|
+ const rows = Array.isArray(this.pagedStockTableData) ? this.pagedStockTableData : []
|
|
|
+ rows.forEach(row => {
|
|
|
+ const key = this.getRowUniqueKey(row)
|
|
|
+ if (selectedSet.has(key)) {
|
|
|
+ table.toggleRowSelection(row, true)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (e) {
|
|
|
+ console.warn('同步表格选择异常:', e)
|
|
|
+ } finally {
|
|
|
+ this.selectionSyncing = false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (e) {
|
|
|
+ console.warn('syncTableSelection 初始化失败:', e)
|
|
|
+ this.selectionSyncing = false
|
|
|
+ }
|
|
|
+ },
|
|
|
}
|
|
|
}
|
|
|
+
|