From 71e03a05ce5bc17e7a49402ad91e94a7deec149c Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Thu, 9 Oct 2025 22:02:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=BD=BF=E7=94=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=9A=E8=A1=A8=E5=A4=B4=E4=B8=8A=E6=9C=89=E5=A4=9A?= =?UTF-8?q?=E6=9D=A1=E6=95=B0=E6=8D=AE=EF=BC=8C=E6=88=91=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=9D=A1=E6=95=B0=E6=8D=AE=EF=BC=8C=E8=BF=99?= =?UTF-8?q?=E4=B8=80=E8=A1=8C=E5=86=85=E5=AE=B9=E4=BC=9A=E9=AB=98=E4=BA=AE?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=EF=BC=8C=E7=84=B6=E5=90=8E=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E3=80=81=E8=AE=A1=E7=AE=97=E3=80=81=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=AD=89=E6=93=8D=E4=BD=9C=E5=90=8E=EF=BC=8C=E5=B0=B1?= =?UTF-8?q?=E5=8F=98=E6=88=90=E7=AC=AC=E4=B8=80=E8=A1=8C=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E9=AB=98=E4=BA=AE=E6=98=BE=E7=A4=BA=EF=BC=8C=E8=BF=99=E6=97=B6?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E9=9C=80=E8=A6=81=E6=89=BE=E5=88=B0=E5=88=9A?= =?UTF-8?q?=E5=88=9A=E9=82=A3=E6=9D=A1=E6=95=B0=E6=8D=AE=E9=80=89=E4=B8=AD?= =?UTF-8?q?=E5=90=8E=E6=89=8D=E8=83=BD=E8=BF=9B=E8=A1=8C=E5=89=A9=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/modules/ecss/codelnotify.vue | 153 +++++++++++++++++- src/views/modules/ecss/codelnotifyConfirm.vue | 137 +++++++++++++++- 2 files changed, 281 insertions(+), 9 deletions(-) diff --git a/src/views/modules/ecss/codelnotify.vue b/src/views/modules/ecss/codelnotify.vue index c7cfd5d..0adf64f 100644 --- a/src/views/modules/ecss/codelnotify.vue +++ b/src/views/modules/ecss/codelnotify.vue @@ -722,6 +722,8 @@ pageSize: 100, totalPage: 0, height: 200, + // 选中行持久化相关 + selectedRowKey: null, // 当前选中行的唯一标识 componentPartModelFlag: false, componentPartData: { site: '', @@ -1786,11 +1788,36 @@ this.pageSize = data.page.pageSize this.totalPage = data.page.totalCount if(this.dataList.length>0){ - this.$refs.mainTable.setCurrentRow(this.dataList[0]); - this.changeData(this.dataList[0]) this.dataList.forEach(o => { o.modifyLabel = !!o.modifyFlag?'是':''; }); + + // 使用 $nextTick 确保 DOM 渲染完成后再设置选中行 + this.$nextTick(() => { + try { + // 检查表格引用是否存在 + if (!this.$refs.mainTable) { + console.warn('[行选择持久化] 表格引用不存在,跳过设置选中行'); + return; + } + + // 尝试恢复之前选中的行 + const restoredRow = this.restoreSelectedRow(); + if (restoredRow) { + this.$refs.mainTable.setCurrentRow(restoredRow); + this.changeData(restoredRow); + } else { + // 如果没有之前选中的行,默认选中第一行 + this.$refs.mainTable.setCurrentRow(this.dataList[0]); + this.changeData(this.dataList[0]); + } + } catch (error) { + console.error('[行选择持久化] 设置选中行失败:', error); + // 降级处理:只调用 changeData,不设置表格选中状态 + const restoredRow = this.restoreSelectedRow(); + this.changeData(restoredRow || this.dataList[0]); + } + }); }else { this.changeData(null) } @@ -1861,6 +1888,13 @@ changeData(row){ this.currentRow = JSON.parse(JSON.stringify(row)); this.headerData=row; + + // 保存选中行的唯一标识到本地存储 + if (row && row.delNo) { + this.selectedRowKey = row.delNo; + this.saveSelectedRowToStorage(); + } + this.refreshCurrentTabTable (); }, importModel(){ @@ -1912,6 +1946,12 @@ } updateEcssDelHeader(this.updateHeaderModel).then(({data}) => { if (data && data.code === 0) { + // 保存当前选中行的标识,以便刷新后恢复 + const currentSelectedKey = this.currentRow ? this.currentRow.delNo : null; + if (currentSelectedKey) { + this.selectedRowKey = currentSelectedKey; + this.saveSelectedRowToStorage(); + } this.searchTable() this.updateHeaderModelFlag = false this.$message({ @@ -1931,6 +1971,10 @@ this.$confirm('确认删除吗?', '提示').then(() => { deleteEcssDelHeader(row).then(({data}) => { if (data && data.code === 0) { + // 如果删除的是当前选中行,清除选中状态 + if (this.currentRow && this.currentRow.delNo === row.delNo) { + this.clearSelectedRowStorage(); + } this.searchTable() this.$message({ message: '操作成功', @@ -1967,6 +2011,12 @@ this.$confirm('确认废弃吗?', '提示').then(() => { cancelEcssDelHeader(row).then(({data}) => { if (data && data.code === 0) { + // 保存当前选中行的标识,以便刷新后恢复 + const currentSelectedKey = row ? row.delNo : null; + if (currentSelectedKey) { + this.selectedRowKey = currentSelectedKey; + this.saveSelectedRowToStorage(); + } this.searchTable() this.$message({ message: '操作成功', @@ -1986,6 +2036,12 @@ this.$confirm('确认取消废弃吗?', '提示').then(() => { recoverEcssDelHeader(row).then(({data}) => { if (data && data.code === 0) { + // 保存当前选中行的标识,以便刷新后恢复 + const currentSelectedKey = row ? row.delNo : null; + if (currentSelectedKey) { + this.selectedRowKey = currentSelectedKey; + this.saveSelectedRowToStorage(); + } this.searchTable() this.$message({ message: '操作成功', @@ -2042,6 +2098,12 @@ changeEcssDelStatus(inData).then(({data}) => { if (data && data.code === 0) { + // 保存当前选中行的标识,以便刷新后恢复 + const currentSelectedKey = this.currentRow ? this.currentRow.delNo : null; + if (currentSelectedKey) { + this.selectedRowKey = currentSelectedKey; + this.saveSelectedRowToStorage(); + } this.searchTable() this.$message({ message: '操作成功', @@ -2078,6 +2140,12 @@ this.$confirm('确认取消下达吗?', '提示').then(() => { changeEcssDelStatus(inData).then(({data}) => { if (data && data.code === 0) { + // 保存当前选中行的标识,以便刷新后恢复 + const currentSelectedKey = row ? row.delNo : null; + if (currentSelectedKey) { + this.selectedRowKey = currentSelectedKey; + this.saveSelectedRowToStorage(); + } this.searchTable() this.$message({ message: '操作成功', @@ -2103,6 +2171,12 @@ this.$confirm('确认一键结单吗?', '提示').then(() => { changeEcssDelStatus(inData).then(({data}) => { if (data && data.code === 0) { + // 保存当前选中行的标识,以便刷新后恢复 + const currentSelectedKey = row ? row.delNo : null; + if (currentSelectedKey) { + this.selectedRowKey = currentSelectedKey; + this.saveSelectedRowToStorage(); + } this.searchTable() this.$message({ message: '操作成功', @@ -2552,6 +2626,70 @@ } this.templateFlag = false }, + + /** + * 保存选中行到本地存储 + * 使用页面路径和用户名作为存储键的一部分,确保不同页面和用户的选择互不影响 + */ + saveSelectedRowToStorage() { + try { + const storageKey = `codelnotify_selected_row_${this.$store.state.user.name}`; + localStorage.setItem(storageKey, this.selectedRowKey); + console.log(`[行选择持久化] 已保存选中行: ${this.selectedRowKey}`); + } catch (error) { + console.warn('保存选中行状态失败:', error); + } + }, + + /** + * 从本地存储恢复选中行 + * @returns {Object|null} 返回匹配的行数据,如果没有找到则返回null + */ + restoreSelectedRow() { + try { + const storageKey = `codelnotify_selected_row_${this.$store.state.user.name}`; + const savedRowKey = localStorage.getItem(storageKey); + + // 检查必要的条件 + if (!savedRowKey) { + console.log('[行选择持久化] 没有保存的选中行'); + return null; + } + + if (!this.dataList || this.dataList.length === 0) { + console.log('[行选择持久化] 数据列表为空,无法恢复选中行'); + return null; + } + + // 在当前数据列表中查找匹配的行 + const matchedRow = this.dataList.find(row => row && row.delNo === savedRowKey); + if (matchedRow) { + this.selectedRowKey = savedRowKey; + console.log(`[行选择持久化] 已恢复选中行: ${savedRowKey}`); + return matchedRow; + } else { + console.log(`[行选择持久化] 未找到匹配的行: ${savedRowKey},当前数据列表长度: ${this.dataList.length}`); + } + + return null; + } catch (error) { + console.warn('恢复选中行状态失败:', error); + return null; + } + }, + + /** + * 清除本地存储的选中行状态 + */ + clearSelectedRowStorage() { + try { + const storageKey = `codelnotify_selected_row_${this.$store.state.user.name}`; + localStorage.removeItem(storageKey); + this.selectedRowKey = null; + } catch (error) { + console.warn('清除选中行状态失败:', error); + } + }, }, activated() { this.searchTable() @@ -2560,6 +2698,17 @@ this.getBu () // 动态列 this.getTableUserColumn(this.$route.meta.menuId+'table1',1) + + // 初始化时从本地存储加载选中行状态 + try { + const storageKey = `codelnotify_selected_row_${this.$store.state.user.name}`; + const savedRowKey = localStorage.getItem(storageKey); + if (savedRowKey) { + this.selectedRowKey = savedRowKey; + } + } catch (error) { + console.warn('初始化选中行状态失败:', error); + } } } diff --git a/src/views/modules/ecss/codelnotifyConfirm.vue b/src/views/modules/ecss/codelnotifyConfirm.vue index acfdca1..2c2fb29 100644 --- a/src/views/modules/ecss/codelnotifyConfirm.vue +++ b/src/views/modules/ecss/codelnotifyConfirm.vue @@ -655,6 +655,8 @@ pageIndex: 1, pageSize: 100, totalPage: 0, + // 选中行持久化相关 + selectedRowKey: null, // 当前选中行的唯一标识 height: 200, buList:[], dataList:[], @@ -1935,15 +1937,38 @@ this.pageSize = data.page.pageSize this.totalPage = data.page.totalCount if(this.dataList.length>0){ - this.$refs.mainTable.setCurrentRow(this.dataList[0]); - this.changeData(this.dataList[0]) this.dataList.forEach(o => { if (o.notifyStatus==='仓库已确认'&&!o.notifyDate) { o.notifyDate='发货日期不确定' } - this.dataList.forEach(o => { - o.modifyLabel = !!o.modifyFlag?'是':''; - }); + o.modifyLabel = !!o.modifyFlag?'是':''; + }); + + // 使用 $nextTick 确保 DOM 渲染完成后再设置选中行 + this.$nextTick(() => { + try { + // 检查表格引用是否存在 + if (!this.$refs.mainTable) { + console.warn('[确认页面行选择持久化] 表格引用不存在,跳过设置选中行'); + return; + } + + // 尝试恢复之前选中的行 + const restoredRow = this.restoreSelectedRow(); + if (restoredRow) { + this.$refs.mainTable.setCurrentRow(restoredRow); + this.changeData(restoredRow); + } else { + // 如果没有之前选中的行,默认选中第一行 + this.$refs.mainTable.setCurrentRow(this.dataList[0]); + this.changeData(this.dataList[0]); + } + } catch (error) { + console.error('[确认页面行选择持久化] 设置选中行失败:', error); + // 降级处理:只调用 changeData,不设置表格选中状态 + const restoredRow = this.restoreSelectedRow(); + this.changeData(restoredRow || this.dataList[0]); + } }); }else { this.changeData(null) @@ -1991,6 +2016,13 @@ this.currentRow.notifyDate='' } this.headerData=row; + + // 保存选中行的唯一标识到本地存储 + if (row && row.delNo) { + this.selectedRowKey = row.delNo; + this.saveSelectedRowToStorage(); + } + this.refreshCurrentTabTable (); }, refreshCurrentTabTable(){ @@ -2033,6 +2065,12 @@ confirmDo(){ confirmEcssDel(this.confirmModel).then(({data}) => { if (data && data.code === 0) { + // 保存当前选中行的标识,以便刷新后恢复 + const currentSelectedKey = this.confirmModel ? this.confirmModel.delNo : null; + if (currentSelectedKey) { + this.selectedRowKey = currentSelectedKey; + this.saveSelectedRowToStorage(); + } this.searchTable() this.confirmModelFlag=false this.$message({ @@ -2056,6 +2094,12 @@ this.$confirm('取消确认这条发货通知单?', '提示').then(() => { cancerConfirmEcssDel(indata).then(({data}) => { if (data && data.code === 0) { + // 保存当前选中行的标识,以便刷新后恢复 + const currentSelectedKey = row ? row.delNo : null; + if (currentSelectedKey) { + this.selectedRowKey = currentSelectedKey; + this.saveSelectedRowToStorage(); + } this.searchTable() this.$message({ message: '操作成功', @@ -2106,6 +2150,12 @@ this.confirmModel.updateBy = this.$store.state.user.name updateEcssDel(this.confirmModel).then(({data}) => { if (data && data.code === 0) { + // 保存当前选中行的标识,以便刷新后恢复 + const currentSelectedKey = this.confirmModel ? this.confirmModel.delNo : null; + if (currentSelectedKey) { + this.selectedRowKey = currentSelectedKey; + this.saveSelectedRowToStorage(); + } this.searchTable() this.updateModelFlag=false this.$message({ @@ -2595,8 +2645,70 @@ this.$nextTick(() => this.$refs.detailTable.doLayout());// 强制刷新布局, 否则会被表格覆盖 return sums; }, - - + + /** + * 保存选中行到本地存储 + * 使用页面路径和用户名作为存储键的一部分,确保不同页面和用户的选择互不影响 + */ + saveSelectedRowToStorage() { + try { + const storageKey = `codelnotifyConfirm_selected_row_${this.$store.state.user.name}`; + localStorage.setItem(storageKey, this.selectedRowKey); + console.log(`[确认页面行选择持久化] 已保存选中行: ${this.selectedRowKey}`); + } catch (error) { + console.warn('保存选中行状态失败:', error); + } + }, + + /** + * 从本地存储恢复选中行 + * @returns {Object|null} 返回匹配的行数据,如果没有找到则返回null + */ + restoreSelectedRow() { + try { + const storageKey = `codelnotifyConfirm_selected_row_${this.$store.state.user.name}`; + const savedRowKey = localStorage.getItem(storageKey); + + // 检查必要的条件 + if (!savedRowKey) { + console.log('[确认页面行选择持久化] 没有保存的选中行'); + return null; + } + + if (!this.dataList || this.dataList.length === 0) { + console.log('[确认页面行选择持久化] 数据列表为空,无法恢复选中行'); + return null; + } + + // 在当前数据列表中查找匹配的行 + const matchedRow = this.dataList.find(row => row && row.delNo === savedRowKey); + if (matchedRow) { + this.selectedRowKey = savedRowKey; + console.log(`[确认页面行选择持久化] 已恢复选中行: ${savedRowKey}`); + return matchedRow; + } else { + console.log(`[确认页面行选择持久化] 未找到匹配的行: ${savedRowKey},当前数据列表长度: ${this.dataList.length}`); + } + + return null; + } catch (error) { + console.warn('恢复选中行状态失败:', error); + return null; + } + }, + + /** + * 清除本地存储的选中行状态 + */ + clearSelectedRowStorage() { + try { + const storageKey = `codelnotifyConfirm_selected_row_${this.$store.state.user.name}`; + localStorage.removeItem(storageKey); + this.selectedRowKey = null; + } catch (error) { + console.warn('清除选中行状态失败:', error); + } + }, }, activated() { @@ -2606,6 +2718,17 @@ this.getBu () // 动态列 this.getTableUserColumn(this.$route.meta.menuId+'table1',1) + + // 初始化时从本地存储加载选中行状态 + try { + const storageKey = `codelnotifyConfirm_selected_row_${this.$store.state.user.name}`; + const savedRowKey = localStorage.getItem(storageKey); + if (savedRowKey) { + this.selectedRowKey = savedRowKey; + } + } catch (error) { + console.warn('初始化选中行状态失败:', error); + } } }