From 46e2b4bb3cfde46967aef2062ebf691be9dc9dde Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Wed, 19 Aug 2026 17:14:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BAlabel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sampleTracking/projectProofTracking.vue | 94 ++++++++++++++++++- 1 file changed, 91 insertions(+), 3 deletions(-) diff --git a/src/views/modules/sampleTracking/projectProofTracking.vue b/src/views/modules/sampleTracking/projectProofTracking.vue index caac7cd..d8a8f4f 100644 --- a/src/views/modules/sampleTracking/projectProofTracking.vue +++ b/src/views/modules/sampleTracking/projectProofTracking.vue @@ -1049,6 +1049,27 @@ function cloneDefaultProcessColumns () { return DEFAULT_PROCESS_COLUMNS.map(item => Object.assign({}, item)) } +function buildProcessCodeLabelMapByRows (rows) { + const nextMap = {} + if (!Array.isArray(rows)) { + return nextMap + } + rows.forEach(item => { + if (!item) { + return + } + const code = item.code == null ? '' : String(item.code).trim() + const label = item.label == null ? '' : String(item.label).trim() + if (!code || !label) { + return + } + // 同时缓存原始编码与小写编码,兼容历史配置大小写不一致的场景。 + nextMap[code] = label + nextMap[code.toLowerCase()] = label + }) + return nextMap +} + const ONE_KEY_ROLE_FIELDS = [ 'projectManager', 'projectOwner', @@ -1279,6 +1300,7 @@ export default { }, trackingColumnList: cloneDefaultTrackingColumns(), processColumns: cloneDefaultProcessColumns(), + processCodeLabelMap: buildProcessCodeLabelMapByRows(cloneDefaultProcessColumns()), buProcessConfigDialogVisible: false, buProcessConfigRows: [], buProcessConfigMap: {}, @@ -1746,6 +1768,7 @@ export default { if (!(data && data.code === 0)) { this.$message.error((data && data.msg) || '加载工序列配置失败,已使用默认配置') this.processColumns = cloneDefaultProcessColumns() + this.mergeProcessCodeLabelMapByRows(this.processColumns) this.ensureBuProcessConfigRows() this.refreshTrackingTableLayout() return this.processColumns @@ -1793,6 +1816,7 @@ export default { }) // 保障切换期可用性:当表里无有效配置时继续使用前端兜底工序定义。 this.processColumns = nextColumns.length > 0 ? nextColumns : cloneDefaultProcessColumns() + this.mergeProcessCodeLabelMapByRows(this.processColumns) this.syncDataListProcessValues() this.ensureBuProcessConfigRows() this.refreshTrackingTableLayout() @@ -1800,6 +1824,7 @@ export default { }).catch(() => { this.$message.error('加载工序列配置异常,已使用默认配置') this.processColumns = cloneDefaultProcessColumns() + this.mergeProcessCodeLabelMapByRows(this.processColumns) this.syncDataListProcessValues() this.ensureBuProcessConfigRows() this.refreshTrackingTableLayout() @@ -1862,16 +1887,67 @@ export default { getAllProcessCodes () { return this.processColumns.map(item => item.code) }, + mergeProcessCodeLabelMapByRows (rows) { + if (!Array.isArray(rows) || rows.length === 0) { + return + } + const nextMap = Object.assign({}, this.processCodeLabelMap || {}) + const rowLabelMap = buildProcessCodeLabelMapByRows(rows) + Object.keys(rowLabelMap).forEach(code => { + nextMap[code] = rowLabelMap[code] + }) + this.processCodeLabelMap = nextMap + }, + mergeProcessCodeLabelMapByObject (labelMap) { + if (!labelMap || typeof labelMap !== 'object') { + return + } + const nextMap = Object.assign({}, this.processCodeLabelMap || {}) + Object.keys(labelMap).forEach(rawCode => { + const code = rawCode == null ? '' : String(rawCode).trim() + const label = labelMap[rawCode] == null ? '' : String(labelMap[rawCode]).trim() + if (!code || !label) { + return + } + // 兼容后端已保存大小写不一致的编码。 + nextMap[code] = label + nextMap[code.toLowerCase()] = label + }) + this.processCodeLabelMap = nextMap + }, getProcessLabelByCode (processCode) { if (!processCode) { return '' } - const matched = this.processColumns.find(item => item && item.code === processCode) + const normalizedCode = String(processCode).trim() + const lowerCode = normalizedCode.toLowerCase() + const matched = this.processColumns.find(item => item && item.code === normalizedCode) if (matched && matched.label) { return matched.label } - const defaultMatched = DEFAULT_PROCESS_COLUMNS.find(item => item && item.code === processCode) - return defaultMatched && defaultMatched.label ? defaultMatched.label : processCode + const caseInsensitiveMatched = this.processColumns.find(item => { + if (!item || !item.code) { + return false + } + return String(item.code).trim().toLowerCase() === lowerCode + }) + if (caseInsensitiveMatched && caseInsensitiveMatched.label) { + return caseInsensitiveMatched.label + } + const codeLabelMap = this.processCodeLabelMap || {} + if (codeLabelMap[normalizedCode]) { + return codeLabelMap[normalizedCode] + } + if (codeLabelMap[lowerCode]) { + return codeLabelMap[lowerCode] + } + const defaultMatched = DEFAULT_PROCESS_COLUMNS.find(item => { + if (!item || !item.code) { + return false + } + return item.code.toLowerCase() === lowerCode + }) + return defaultMatched && defaultMatched.label ? defaultMatched.label : normalizedCode }, getValidProcessOrderCodes (codes) { // 顺序列表不能因为“当前 BU 不可见”而丢项:先保留后端返回顺序,再补齐当前已知工序。 @@ -2001,7 +2077,18 @@ export default { } const rows = data.rows || [] const nextMap = {} + const processLabelMap = {} rows.forEach(item => { + if (item && item.processLabelMap && typeof item.processLabelMap === 'object') { + Object.keys(item.processLabelMap).forEach(rawCode => { + const code = rawCode == null ? '' : String(rawCode).trim() + const label = item.processLabelMap[rawCode] == null ? '' : String(item.processLabelMap[rawCode]).trim() + if (!code || !label) { + return + } + processLabelMap[code] = label + }) + } const buNo = this.normalizeBuNo(item && item.buNo ? item.buNo : '', this.$store.state.user.site) if (!buNo) { return @@ -2021,6 +2108,7 @@ export default { processCodes: showAll ? processOrderCodes.slice() : processOrderCodes.filter(code => selectedCodeMap[code]) } }) + this.mergeProcessCodeLabelMapByObject(processLabelMap) this.buProcessConfigMap = nextMap this.ensureBuProcessConfigRows() this.refreshTrackingTableLayout()