From 919e073f78905e56d4cc1fa3c667fe9c9d04ef98 Mon Sep 17 00:00:00 2001 From: tangw Date: Fri, 12 Dec 2025 18:05:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xtwh/comopt/components/sysGlobal.vue | 7 +- .../xtwh/comopt/components/sysInput.vue | 328 ++++++++++++++++++ src/views/liswork/xtwh/comopt/index.vue | 6 +- .../localconfig/components/DynamicInput.vue | 109 +++--- 4 files changed, 406 insertions(+), 44 deletions(-) create mode 100644 src/views/liswork/xtwh/comopt/components/sysInput.vue diff --git a/src/views/liswork/xtwh/comopt/components/sysGlobal.vue b/src/views/liswork/xtwh/comopt/components/sysGlobal.vue index 64f5d61..940ecbc 100644 --- a/src/views/liswork/xtwh/comopt/components/sysGlobal.vue +++ b/src/views/liswork/xtwh/comopt/components/sysGlobal.vue @@ -92,7 +92,8 @@ interface RegDictItem { remark: string } // 列表相关 -const menuname = ref("仪器全局") +const optiontype= ref("SYSTEM") +const menuname = ref("系统全局") const regdictList = ref([]) const originRegdictList = ref([]) const loading = ref(false) @@ -123,7 +124,7 @@ const tableData3 = computed(() => { const getList = async (): Promise => { loading.value = true try { - const response = await paramList({ yq: yq.value }) + const response = await paramList({ yq: yq.value,optiontype:optiontype.value }) regdictList.value = JSON.parse(JSON.stringify(response.data)) originRegdictList.value = JSON.parse(JSON.stringify(response.data)) total.value = response.data.length @@ -186,7 +187,7 @@ const handleRestoreDefault = async (): Promise => { ).then(async () => { loading.value = true try { - const res = await getdef({ yq: yq.value }) + const res = await getdef({optiontype:optiontype.value }) regdictList.value = JSON.parse(JSON.stringify(res.data)) originRegdictList.value = JSON.parse(JSON.stringify(res.data)) total.value = res.data.length diff --git a/src/views/liswork/xtwh/comopt/components/sysInput.vue b/src/views/liswork/xtwh/comopt/components/sysInput.vue new file mode 100644 index 0000000..9fc997e --- /dev/null +++ b/src/views/liswork/xtwh/comopt/components/sysInput.vue @@ -0,0 +1,328 @@ + + + + + + \ No newline at end of file diff --git a/src/views/liswork/xtwh/comopt/index.vue b/src/views/liswork/xtwh/comopt/index.vue index c4dc43c..5e7973e 100644 --- a/src/views/liswork/xtwh/comopt/index.vue +++ b/src/views/liswork/xtwh/comopt/index.vue @@ -47,6 +47,7 @@ import { paramList, paramTree, getdef, updateParam } from '@/api/liswork/xtwh/Co import { getFirstLetter } from '@/utils/pinyin.js' import SysGlobal from './components/sysGlobal.vue' +import SysInput from './components/sysInput.vue' import SysReport from './components/sysReport.vue' // ========== TypeScript 类型定义 ========== @@ -102,8 +103,9 @@ const queryParams = ref({ const tabList = [ - { key: 'SysGlobal', label: '系统全局参数', component: SysGlobal }, - { key: 'SysReport', label: '报告界面', component: SysReport }, + { key: 'SysGlobal', label: '全局设定', component: SysGlobal }, + { key: 'SysInput', label: '界面设定', component: SysInput }, + { key: 'SysReport', label: '报告单设置', component: SysReport }, ] const activeName = ref('SysGlobal') diff --git a/src/views/liswork/xtwh/localconfig/components/DynamicInput.vue b/src/views/liswork/xtwh/localconfig/components/DynamicInput.vue index f1560d9..68fb9a3 100644 --- a/src/views/liswork/xtwh/localconfig/components/DynamicInput.vue +++ b/src/views/liswork/xtwh/localconfig/components/DynamicInput.vue @@ -45,7 +45,7 @@ /> - + { return 0; }); -// ========== 核心:值初始化 + 格式适配 ========== +// ========== 核心修复:值初始化 + 格式适配 → 重点优化多选逻辑 ========== watch(() => props.modelValue, (newVal) => { const val = newVal; // 移除兜底空值,保留原始值 switch (props.type) { @@ -187,12 +188,25 @@ watch(() => props.modelValue, (newVal) => { innerValue.value = val === null || val === undefined ? "" : String(val); break; - // 字典多选:后端逗号字符串→前端数组 + // 字典多选:核心修复 → 严格过滤空值/无效值,杜绝默认0 case "3": - multipleValue.value = typeof val === "string" && val - ? val.split(",").map(item => String(item)) - : []; - innerValue.value = val || ""; + // 1. 空值/0/空字符串 → 空数组 + if (val === null || val === undefined || val === "" || val === 0) { + multipleValue.value = []; + } + // 2. 有效字符串 → 分割为数组(过滤空项) + else if (typeof val === "string") { + multipleValue.value = val.split(",").filter(item => item.trim() !== "").map(item => String(item)); + } + // 3. 数组类型(特殊场景)→ 直接赋值 + else if (Array.isArray(val)) { + multipleValue.value = val.filter(item => item !== null && item !== undefined && item !== "").map(item => String(item)); + } + // 4. 其他类型 → 空数组 + else { + multipleValue.value = []; + } + // 移除innerValue同步(避免干扰多选) break; // 数字框:空值处理,支持小数位数 @@ -224,10 +238,13 @@ watch(() => props.modelValue, (newVal) => { innerValue.value = val === null || val === undefined ? "" : val; break; } -}, {immediate: true, deep: true}); +}, { immediate: true, deep: true }); -// ========== 同步子组件值到父组件 ========== +// ========== 修复:移除innerValue对多选的干扰 → 仅监听非多选类型 ========== watch(innerValue, (newVal) => { + // 多选类型跳过innerValue监听 + if (props.type === "3") return; + let finalVal = newVal; // 数字框:空值提交空字符串,非空则保留数字类型 @@ -245,9 +262,9 @@ watch(innerValue, (newVal) => { emit("update:modelValue", finalVal); emit("change", finalVal); -}, {deep: true}); +}, { deep: true }); -// ========== 字典加载逻辑 ========== +// ========== 字典加载逻辑 → 新增:字典加载后重新同步多选值 ========== watch([() => props.type, () => props.dictData], async () => { dictOptions.value = []; // 数字框(type=6)不需要加载字典 @@ -255,8 +272,17 @@ watch([() => props.type, () => props.dictData], async () => { await parseJsonDict(); } else if (["2", "3"].includes(props.type)) { await loadApiDict(); + // 字典加载完成后,重新同步多选值(修复选不到值的问题) + if (props.type === "3") { + const val = props.modelValue; + if (val === null || val === undefined || val === "" || val === 0) { + multipleValue.value = []; + } else if (typeof val === "string") { + multipleValue.value = val.split(",").filter(item => item.trim() !== "").map(item => String(item)); + } + } } -}, {immediate: true, deep: true}); +}, { immediate: true, deep: true }); // 解析下拉框JSON数组(type=1) async function parseJsonDict() { @@ -272,7 +298,7 @@ async function parseJsonDict() { })).filter(item => item.label && item.value); } catch (error) { ElMessage.error(`下拉框数据解析失败:${error.message}`); - console.error("JSON解析失败:", {raw: props.dictData, error}); + console.error("JSON解析失败:", { raw: props.dictData, error }); } } @@ -286,7 +312,7 @@ async function loadApiDict() { } try { dictLoading.value = true; - const res = await getoptionselect({zdlb: dictType}); + const res = await getoptionselect({ zdlb: dictType }); if (res.code === 200 && Array.isArray(res.data)) { dictOptions.value = res.data.map(item => ({ label: item.zdmc || item.label || "", @@ -298,7 +324,7 @@ async function loadApiDict() { } } catch (error) { ElMessage.error("字典请求失败"); - console.error("字典API异常:", {dictType, error}); + console.error("字典API异常:", { dictType, error }); } finally { dictLoading.value = false; } @@ -319,34 +345,34 @@ function handleValueChange(val) { emit("change", finalVal); } -// ========== 多选值变更处理 ========== +// ========== 核心修复:多选值变更处理 → 简化逻辑,杜绝值覆盖 ========== function handleMultipleChange(val) { - const strVal = val?.join(",") || ""; - innerValue.value = strVal; - multipleValue.value = val; + // 1. 过滤空值,避免提交无效数据 + const validVal = val.filter(item => item !== null && item !== undefined && item !== ""); + // 2. 转为逗号分隔字符串(后端格式) + const strVal = validVal.join(","); + // 3. 更新多选值(确保同步) + multipleValue.value = validVal; + // 4. 触发父组件更新 emit("update:modelValue", strVal); emit("change", strVal); } -// ========== 多选值同步监听 ========== -watch(multipleValue, (newVal) => { - if (props.type === "3") { - const strVal = newVal?.join(",") || ""; - innerValue.value = strVal; - emit("update:modelValue", strVal); - } -}, {deep: true}); - -// ========== 初始化兜底 ========== +// ========== 初始化优化 → 移除多选冗余逻辑,杜绝默认0 ========== onMounted(() => { // 开关组件初始值兜底 if (props.type === "0" && innerValue.value === null) { innerValue.value = "0"; // 默认关闭 emit("update:modelValue", 0); // 后端默认值:0 } - // 多选值初始化 - if (props.type === "3" && !multipleValue.value.length && innerValue.value) { - multipleValue.value = innerValue.value.split(",").map(item => String(item)); + // 多选初始化:仅处理有效值,杜绝空值/0转为["0"] + if (props.type === "3") { + const val = props.modelValue; + if (val === null || val === undefined || val === "" || val === 0) { + multipleValue.value = []; + } else if (typeof val === "string") { + multipleValue.value = val.split(",").filter(item => item.trim() !== "").map(item => String(item)); + } } }); @@ -401,10 +427,15 @@ onMounted(() => { } /* 空值时占位符样式 */ - .el-input__placeholder { color: #999; font-size: 12px; } } + +/* 多选下拉样式优化:避免高度溢出 */ +:deep(.el-select--multiple .el-select__tags) { + flex-wrap: wrap; + min-height: 32px; /* 匹配small尺寸高度 */ +} \ No newline at end of file