跨行合并表格

  • 示例图

9c6959d0c66f4821819f82113d534095

  • 第一列会出现跨行合并

  • 父组件代码

    pgxAxis = []
    pgyAxis = []
    verticalSpans = []
    // 处理纵向合并(行合并)
    processVerticalMerge() {
    if (this.pgyAxis.length === 0) {
    return;
    }

    const spans = new Array(this.pgyAxis.length).fill(0);
    let currentValue = this.pgyAxis[0];
    let count = 1;
    spans[0] = 1;

    // 从第二个元素开始遍历
    for (let i = 1; i < this.pgyAxis.length; i++) {
    if (this.pgyAxis[i] === currentValue) {
    count++;
    spans[i] = 0; // 被合并的单元格
    } else {
    // 设置上一组的合并数量
    spans[i - count] = count;
    // 开始新的一组
    currentValue = this.pgyAxis[i];
    count = 1;
    spans[i] = 1;
    }
    }

    // 设置最后一组的合并数量
    spans[this.pgyAxis.length - count] = count;
    this.verticalSpans = spans;
    }

  • 子组件代码

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