From 2210e336435f562f2d546c74cfb95ed2137c8330 Mon Sep 17 00:00:00 2001 From: b2894lxlx <517289602@qq.com> Date: Tue, 29 Sep 2026 03:31:56 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AD=97=E5=85=B8=E9=9D=9E=E6=95=B0=E5=AD=97?= =?UTF-8?q?key=E5=AF=BC=E8=87=B4=E4=B8=8B=E6=8B=89=E6=97=A0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=EF=BC=8C=E5=B9=B6=E8=B0=83=E6=95=B4=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 兼容 organization_type 的中文 dictKey 展示;用户弹窗所属组织与备注宽度按四列布局对齐。 Co-authored-by: Cursor --- src/views/system/dept.vue | 78 +++++++++++++++++++++++++++++++-------- src/views/system/user.vue | 16 ++++++-- 2 files changed, 75 insertions(+), 19 deletions(-) diff --git a/src/views/system/dept.vue b/src/views/system/dept.vue index f6a4f72..5ceb334 100644 --- a/src/views/system/dept.vue +++ b/src/views/system/dept.vue @@ -365,7 +365,6 @@ export default { label: '组织类型', type: 'select', dicData: [], - dataType: 'number', minWidth: 120, order: 90, prop: 'deptCategory', @@ -751,11 +750,8 @@ export default { return getDictionary({ code: ORGANIZATION_TYPE_DICT_CODE }).then(res => { const list = res.data.data || []; this.organizationTypeOptions = list - .map(item => ({ - label: item.dictValue, - value: Number(item.dictKey), - })) - .filter(item => item.label && !Number.isNaN(item.value)); + .map(item => this.normalizeOrganizationTypeOption(item)) + .filter(Boolean); this.resetDeptCategoryOptions(); // 字典异步返回后触发表格组织类型标签重绘 if (Array.isArray(this.data) && this.data.length) { @@ -763,6 +759,26 @@ export default { } }); }, + /** + * 业务字典项转下拉选项:dictKey 为纯数字时转 number(兼容历史 deptCategory 1~6),否则保留原值。 + */ + normalizeOrganizationTypeOption(item) { + const label = item?.dictValue ?? item?.label; + const rawKey = item?.dictKey ?? item?.value; + if (label === undefined || label === null || String(label).trim() === '') { + return null; + } + if (rawKey === undefined || rawKey === null || String(rawKey).trim() === '') { + return null; + } + const keyText = String(rawKey).trim(); + const asNumber = Number(keyText); + const isPureNumber = keyText !== '' && !Number.isNaN(asNumber) && String(asNumber) === keyText; + return { + label: String(label), + value: isPureNumber ? asNumber : keyText, + }; + }, resetDeptCategoryOptions() { const categoryColumn = this.findColumn(this.option.column, 'deptCategory'); if (!categoryColumn) { @@ -770,9 +786,37 @@ export default { } categoryColumn.dicData = [...this.organizationTypeOptions]; }, + isSameDeptCategory(left, right) { + if ( + left === null || + left === undefined || + left === '' || + right === null || + right === undefined || + right === '' + ) { + return false; + } + if (String(left) === String(right)) { + return true; + } + const leftNumber = Number(left); + const rightNumber = Number(right); + return !Number.isNaN(leftNumber) && !Number.isNaN(rightNumber) && leftNumber === rightNumber; + }, + isCarrierDeptCategory(value) { + if (Number(value) === 6) { + return true; + } + const matched = this.organizationTypeOptions.find(item => this.isSameDeptCategory(item.value, value)); + const text = matched?.label || value; + return String(text).includes('承运商'); + }, filterOrganizationTypeOptions(values) { - const valueSet = new Set(values.map(Number)); - return this.organizationTypeOptions.filter(item => valueSet.has(Number(item.value))); + const valueSet = new Set(values.map(item => String(item))); + const filtered = this.organizationTypeOptions.filter(item => valueSet.has(String(item.value))); + // 字典 key 非数字时无法按历史层级码过滤,回退展示全部,避免下拉无选项 + return filtered.length ? filtered : [...this.organizationTypeOptions]; }, updateDeptCategoryOptions() { const categoryColumn = this.findColumn(this.option.column, 'deptCategory'); @@ -790,17 +834,19 @@ export default { dicData = this.filterOrganizationTypeOptions([2, 3]); } else if ([2, 3].includes(Number(parent.deptCategory))) { dicData = this.filterOrganizationTypeOptions([4, 5, 6]); + } else { + dicData = [...this.organizationTypeOptions]; } categoryColumn.dicData = dicData; - if (!dicData.some(item => Number(item.value) === Number(this.form.deptCategory))) { + if (!dicData.some(item => this.isSameDeptCategory(item.value, this.form.deptCategory))) { this.form.deptCategory = dicData[0]?.value; } - if (Number(this.form.deptCategory) === 6) { + if (this.isCarrierDeptCategory(this.form.deptCategory)) { this.openCarrierDialog(); } }, handleDeptCategoryChange(value) { - if (Number(value) === 6) { + if (this.isCarrierDeptCategory(value)) { this.openCarrierDialog(); } }, @@ -863,10 +909,10 @@ export default { if (deptCategory === null || deptCategory === undefined || deptCategory === '') { return '-'; } - const matched = this.organizationTypeOptions.find( - item => Number(item.value) === Number(deptCategory) + const matched = this.organizationTypeOptions.find(item => + this.isSameDeptCategory(item.value, deptCategory) ); - return matched?.label || '-'; + return matched?.label || String(deptCategory); }, getLeaderValue(leaderId, field) { // func.split 空值时返回 '',需兼容为数组,避免表格 formatter 渲染崩溃导致列错位 @@ -906,7 +952,7 @@ export default { row.kingdeeDeptCode = String(row.kingdeeDeptCode || '').trim(); row.leaderId = func.join(row.leaderId); this.normalizeTopParent(row); - if (Number(row.deptCategory) === 6 && !row.carrierCustomerId) { + if (this.isCarrierDeptCategory(row.deptCategory) && !row.carrierCustomerId) { this.$message.warning('请选择承运商'); loading(); return; @@ -937,7 +983,7 @@ export default { row.kingdeeDeptCode = String(row.kingdeeDeptCode || '').trim(); row.leaderId = func.join(row.leaderId); this.normalizeTopParent(row); - if (Number(row.deptCategory) === 6 && !row.carrierCustomerId) { + if (this.isCarrierDeptCategory(row.deptCategory) && !row.carrierCustomerId) { this.$message.warning('请选择承运商'); loading(); return; diff --git a/src/views/system/user.vue b/src/views/system/user.vue index 1e9c069..da942cb 100644 --- a/src/views/system/user.vue +++ b/src/views/system/user.vue @@ -221,7 +221,7 @@ - + @@ -240,7 +239,18 @@ 仅所属组织全部组织自定义 包含下级仅本级 - + + + + +