diff --git a/src/components/DesignForm/app/groupPage.vue b/src/components/DesignForm/app/groupPage.vue index 2dcd504..230af6d 100644 --- a/src/components/DesignForm/app/groupPage.vue +++ b/src/components/DesignForm/app/groupPage.vue @@ -34,7 +34,7 @@ const props = defineProps({ //---------pagination configs------ const totalNum = ref(0) const pageSize = ref(props.searchSend.pagesize) - +const selectedMergeKeys = ref([]) //------------------ by han2015: 支持表单排序功能---------------------- const columnSortData = new Map(); @@ -59,10 +59,66 @@ const onUpdateSort = (data: { prop: string; order: "ascending" | "descending" | } else { columnSortData.delete(data.prop); } - getPageData() + + selectedMergeKeys.value=Array.from(columnSortData.keys()) + getPageData(); } +// 计算合并位置(预处理,避免每次渲染重复计算) +const spanMap = computed(() => { + const map = {} + const pos = {} + // 按优先级排序的合并列,获取排序列 + selectedMergeKeys.value.forEach((key, index) => { + map[key] = [] + pos[key] = 0 + + for (let i = 0; i < tableDataList.value.length; i++) { + if (i === 0) { + map[key][i] = 1 // 第一行总是 1 + pos[key] = 0 + } else { + // 检查:当前列及其所有前置列是否都相同 + let shouldMerge = true + for (let j = 0; j <= index; j++) { + const checkKey = selectedMergeKeys.value[j] + if (tableDataList.value[i][checkKey] !== tableDataList.value[i-1][checkKey]) { + shouldMerge = false + break + } + } + + if (shouldMerge) { + // 合并:累加到合并起始位置,当前位置标记 0 + map[key][pos[key]] += 1 + map[key][i] = 0 + } else { + // 不合并:新开一个合并组 + map[key][i] = 1 + pos[key] = i // 更新合并起始位置 + } + } + } + }) + + return map +}) + + +const objectSpanMethod = ({ row, column, rowIndex, columnIndex }) => { + const key = column.property + + if (spanMap.value[key]) { + const rowspan = spanMap.value[key][rowIndex] + return { + rowspan: rowspan, + colspan: rowspan > 0 ? 1 : 0 + } + } + + return { rowspan: 1, colspan: 1 } +} const tableDataList = ref([]) // 表格行数据 const groupColumnSearch = (val:any,clas?:number) =>{ @@ -79,7 +135,7 @@ const handleCurrentChange = (page: number) => { getPageData(); }; -const getPageData=()=>{ +const getPageData=async ()=>{ // by han2015: 处理排序字段信息 let arr:string[]=[]; columnSortData.forEach((value, key) => { @@ -89,21 +145,13 @@ const getPageData=()=>{ let sendData = props.searchSend sendData.sortData= arr.join(", ") sendData.pagesize = 50 - gainFormPageListCont(sendData) + await gainFormPageListCont(sendData) .then(({data})=>{ totalNum.value = data.total tableDataList.value = data.list }) } -const spanMethod = (data: { row: any; rowIndex: number; column: TableColumnCtx; columnIndex: number; }) => { - if(data.rowIndex==1){ - console.log(data.column) - } - -} - - onMounted(()=>{ nextTick(()=>{ getPageData() @@ -114,13 +162,14 @@ defineExpose({ groupColumnSearch }) +