跨列合并表格

  • 示例图

89526a42850f4aa3b50e65110544cbff

  • 父组件代码

    xsgxAxis = []
    xsgYAxis = []
    tableData = [];
    InitLoad() {
    const tmp1 = this.processHorizontalMerge(data1);
    const tmp2 = data2.map(el => ({
    name: el,
    }));
    this.$nextTick(() => {
    this.sgxAxis = [tmp1, tmp2];
    });
    }
    // 处理横向合并(列合并)
    processHorizontalMerge(originalData) {
    if (originalData.length === 0) {
    return;
    }
    const result = [];
    let currentValue = originalData[0];
    let count = 1;
    // 从第二个元素开始遍历
    for (let i = 1; i < originalData.length; i++) {
    if (originalData[i] === currentValue) {
    count++;
    } else {
    // 保存当前组
    result.push({ name: currentValue, colspan: count });
    // 开始新的一组
    currentValue = originalData[i];
    count = 1;
    }
    }
    // 添加最后一组
    result.push({ name: currentValue, colspan: count });
    return result;
    }

  • 子组件代码

posted @ 2025-12-01 16:59  不完美的完美  阅读(20)  评论(0)    收藏  举报