🐛 修复组织类型字典非数字key导致下拉无数据,并调整用户弹窗布局

兼容 organization_type 的中文 dictKey 展示;用户弹窗所属组织与备注宽度按四列布局对齐。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-29 03:31:56 +08:00
parent 1ed524f80f
commit 2210e33643
2 changed files with 75 additions and 19 deletions
+62 -16
View File
@@ -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;
+13 -3
View File
@@ -221,7 +221,7 @@
<el-col :span="6"><el-form-item label="邮箱"><el-input v-model="form.email" /></el-form-item></el-col>
<el-col :span="6"><el-form-item label="性别"><el-select v-model="form.sex"><el-option label="男" :value="1" /><el-option label="女" :value="2" /><el-option label="未知" :value="3" /></el-select></el-form-item></el-col>
<el-col :span="6"><el-form-item label="岗位" prop="postId"><el-tree-select v-model="form.postId" :data="postList" :props="{ label: 'postName', value: 'id' }" check-strictly /></el-form-item></el-col>
<el-col :span="12">
<el-col :span="6">
<el-form-item label="所属组织" prop="deptId">
<el-cascader
v-model="deptCascaderValue"
@@ -232,7 +232,6 @@
collapse-tags
collapse-tags-tooltip
placeholder="请选择所属组织(可多选)"
style="width: 100%"
/>
</el-form-item>
</el-col>
@@ -240,7 +239,18 @@
<el-col :span="6"><el-form-item label="人员类别"><el-select v-model="form.personCategory"><el-option label="内部员工" :value="1" /><el-option label="承运商" :value="2" /></el-select></el-form-item></el-col>
<el-col :span="18"><el-form-item label="数据权限范围"><el-radio-group v-model="form.dataScopeRange"><el-radio :value="1">仅所属组织</el-radio><el-radio :value="2">全部组织</el-radio><el-radio :value="3">自定义</el-radio></el-radio-group></el-form-item></el-col>
<el-col :span="18"><el-form-item label="数据层级范围"><el-radio-group v-model="form.dataLevelRange"><el-radio :value="1">包含下级</el-radio><el-radio :value="2">仅本级</el-radio></el-radio-group></el-form-item></el-col>
<el-col :span="24"><el-form-item label="备注"><el-input v-model="form.remark" type="textarea" :rows="2" maxlength="200" show-word-limit /></el-form-item></el-col>
<el-col :span="24">
<el-form-item label="备注">
<el-input
v-model="form.remark"
type="textarea"
:rows="2"
maxlength="200"
show-word-limit
style="width: 100%"
/>
</el-form-item>
</el-col>
</el-row>
</el-form>
</section-card>