From 50ad03c02b17bb77ac0f05da4d63103aadd42853 Mon Sep 17 00:00:00 2001 From: liwenxuan <1298531568@qq.com> Date: Thu, 8 Jan 2026 15:44:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=A9=E9=98=B5=E5=A1=AB=E5=85=85=E5=8F=AF?= =?UTF-8?q?=E4=BB=85=E9=80=89=E6=A0=87=E9=A2=98=E8=A1=8C=E6=88=96=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DesignForm/formControlPropertiNew.vue | 191 ++++++++--- .../DesignForm/public/form/form.vue | 306 +++++++++++++++++- 2 files changed, 438 insertions(+), 59 deletions(-) diff --git a/src/components/DesignForm/formControlPropertiNew.vue b/src/components/DesignForm/formControlPropertiNew.vue index acf4afb..b8d63a8 100644 --- a/src/components/DesignForm/formControlPropertiNew.vue +++ b/src/components/DesignForm/formControlPropertiNew.vue @@ -2910,7 +2910,10 @@ function mergeArrays(a, b) { //选项批量编辑 liwenxuan 20251212 end -//自动填充设置 liwenxuan 20251230 start + + + +// 自动填充设置 liwenxuan 20251230 start let datapropsformList = JSON.parse(JSON.stringify(props.formList)) @@ -2919,28 +2922,23 @@ const zdtcszTree = computed(()=>{ datapropsformList = JSON.parse(JSON.stringify(props.formList)) } - //console.log(datapropsformList) if(associatedFormsCurrentFormFieldTreeForGlxxszExceptSelf && associatedFormsCurrentFormFieldTreeForGlxxszExceptSelf.value[0].children && associatedFormsCurrentFormFieldTreeForGlxxszExceptSelf.value[0].children.length>0){ - - let datab = JSON.parse(JSON.stringify(associatedFormsCurrentFormFieldTreeForGlxxszExceptSelf.value[0].children)) let currentCompId = controlData.value.name const treeC = mergeAndFilterFormTrees(datapropsformList, datab,currentCompId); - //console.log(treeC) return treeC }else{ return [] } }) + // 使用 ref 替代 computed,使其可写 const zdtcszTableData = ref([]) // 获取当前正在设置自动填充的组件("结果"组件)的选项 const currentComponentOptions = computed(() => { - return controlData.value.options - }) // 获取当前选择的索引列节点(用于获取label) @@ -2957,7 +2955,7 @@ const currentTitleColumnNode = computed(() => { // 索引列的标签 const indexColumnLabel = computed(() => { - if (!currentIndexColumnNode.value) return "索引列" + if (!currentIndexColumnNode.value) return "默认行" return currentIndexColumnNode.value.label }) @@ -2991,8 +2989,8 @@ const zdtcszTableColumns = computed(() => { // 监听标题行和索引列的变化,重新生成表格数据 watch([titleOptions, indexOptions], ([newTitleOptions, newIndexOptions]) => { - // 如果没有标题行或索引列,清空表格数据 - if (!newTitleOptions.length || !newIndexOptions.length) { + // 如果都没有选择,清空表格数据 + if (!newTitleOptions.length && !newIndexOptions.length) { zdtcszTableData.value = [] return } @@ -3000,35 +2998,95 @@ watch([titleOptions, indexOptions], ([newTitleOptions, newIndexOptions]) => { // 从 controlData 中获取之前保存的数据 const savedData = controlData.value?.control?.zdtcsz?.tableData || {} - // 生成新的表格数据 - const newTableData = newIndexOptions.map(rowItem => { - const rowKey = rowItem.value + // 情况1:只有标题行,没有索引列 + if (newTitleOptions.length && !newIndexOptions.length) { + // 创建一行默认数据 + const defaultRowKey = 'default' const rowObj = { - rowKey: rowKey, - rowLabel: rowItem.label // 使用选项的label作为第一列显示 + rowKey: defaultRowKey, + rowLabel: '默认' // 第一列显示"默认" } // 为每个标题列生成值,如果有保存的数据则使用保存的数据 newTitleOptions.forEach(colItem => { const colKey = colItem.value - const savedValue = savedData[rowKey]?.[colKey] || '' + const savedValue = savedData[defaultRowKey]?.[colKey] || '' rowObj[`col_${colKey}`] = savedValue }) - return rowObj - }) - - zdtcszTableData.value = newTableData + zdtcszTableData.value = [rowObj] + } + // 情况2:只有索引列,没有标题行 + else if (!newTitleOptions.length && newIndexOptions.length) { + // 创建一个默认列 + const newTableData = newIndexOptions.map(rowItem => { + const rowKey = rowItem.value + const rowObj = { + rowKey: rowKey, + rowLabel: rowItem.label + } + + // 创建一个默认列 + const defaultColKey = 'default' + const savedValue = savedData[rowKey]?.[defaultColKey] || '' + rowObj[`col_${defaultColKey}`] = savedValue + + return rowObj + }) + + zdtcszTableData.value = newTableData + } + // 情况3:标题行和索引列都有 + else if (newTitleOptions.length && newIndexOptions.length) { + // 生成新的表格数据 + const newTableData = newIndexOptions.map(rowItem => { + const rowKey = rowItem.value + const rowObj = { + rowKey: rowKey, + rowLabel: rowItem.label + } + + // 为每个标题列生成值,如果有保存的数据则使用保存的数据 + newTitleOptions.forEach(colItem => { + const colKey = colItem.value + const savedValue = savedData[rowKey]?.[colKey] || '' + rowObj[`col_${colKey}`] = savedValue + }) + + return rowObj + }) + + zdtcszTableData.value = newTableData + } }, { immediate: true }) // 监听表格数据变化,保存到临时存储 const handleTableDataChange = () => { // 将表格数据转换为更容易存储的格式 const tableData = {} + zdtcszTableData.value.forEach(row => { const rowKey = row.rowKey tableData[rowKey] = {} - titleOptions.value.forEach(col => { + + // 获取当前有效的列 + let currentColumns = [] + if (titleOptions.value.length > 0) { + // 有标题行,使用标题行的选项 + currentColumns = titleOptions.value + } else if (zdtcszTableData.value[0]) { + // 没有标题行,从第一行数据中提取所有col_开头的字段 + const firstRow = zdtcszTableData.value[0] + Object.keys(firstRow).forEach(key => { + if (key.startsWith('col_')) { + const colKey = key.replace('col_', '') + currentColumns.push({ value: colKey }) + } + }) + } + + // 保存每一列的值 + currentColumns.forEach(col => { const colKey = col.value tableData[rowKey][colKey] = row[`col_${colKey}`] || '' }) @@ -3055,6 +3113,10 @@ const handleDetermineZdtcszDialogFlag = () => { console.log('左上角标签:', leftTopLabel.value) */ } + + + + /** * 合并两个组件树,仅保留type为radio和select的节点,并过滤掉指定compId的节点,同时保留options属性 * @param {Array} treeA - 组件树a,包含表单结构信息 @@ -8534,9 +8596,8 @@ const formatTooltip = (val: number) => { - - - + { align="center" /> - - - + + + @@ -8632,7 +8722,6 @@ const formatTooltip = (val: number) => { -