element 表格第一列合并,第二列展开后出现错位情况

展开后发现蓝色一行挤下来,而且还错位了

解决思路:展开行,在dom上其实是新增了一行的高度,合并上新增一个高度就可以

复制代码
<el-table
  v-loading="tabLoading"
  fit
  ref="oneRef"
  height="100%"
  :span-method="objectSpanMethod"
  @expand-change="expandHeight"
  highlight-current-row
>

async expandHeight(row: any, expanded: any) {
    this.$nextTick(() => {
      this.spanObj = dataMethod(this.data, ['factoryDivText']);
      const A10 = expanded.filter((k: any) => {
        return 'A10' == k.factoryDiv;
      });
      if (A10.length > 0) {
        this.spanObj.factoryDivText[0] = this.spanObj.factoryDivText[0] + A10.length;
      }

      const A20 = expanded.filter((k: any) => {
        return 'A20' == k.factoryDiv;
      });
      if (A20.length > 0) {
        let A20Index = 0;
        this.spanObj.factoryDivText.map((v: any, index: any) => {
          if (A10.length == 0) {
            this.spanObj.factoryDivText[0] = this.spanObj.factoryDivText[0] + A20.length;
          } else {
            if (index != 0 && v != 0) A20Index = index;
          }
        });
        this.spanObj.factoryDivText[A20Index] = this.spanObj.factoryDivText[0] + A20.length;
      }
      (this.$refs.oneRef as any).doLayout();
    });
  }



export const dataMethod = (data: any[], isH: string[]) => {
  const spanObj: any = {};
  const pos: any = {};
  let lastItem: any = null; // 上一个数据项
  data.map((it, i) => {
    Object.keys(it).map(key => {
      if (i === 0) {
        spanObj[key] = [1];
        pos[key] = i;
      } else {
        if (isH.includes(key) && lastItem && isEqual(lastItem, it, isH)) {
          spanObj[key][pos[key]] += 1;
          spanObj[key].push(0);
        } else {
          spanObj[key].push(1);
          pos[key] = i;
        }
      }
    });
    lastItem = it;
  });

  return spanObj;
};


objectSpanMethod({ column, rowIndex }: any) {
    const _row = this.spanObj[column.property] ? this.spanObj[column.property][rowIndex] : 1;
    const _col = _row > 0 ? 1 : 0;
    return {
      rowspan: _row,
      colspan: _col,
    };
  }

获取点击后合并的长度+合并的数字

最终结果展开后正常展示了

相关推荐
贾公子9 小时前
AI 内容检测 API 接入实战——异步任务、幂等键与轮询的正确写法
vue.js
星光不问赶路人10 小时前
Vue 项目类型检查:深入理解 vue-tsc --build
前端·vue.js
WeiXin_DZbishe10 小时前
基于springboot装修风格选择系统的设计与开发-计算机毕设【课程设计】77964
java·vue.js·spring boot·后端·python·php·课程设计
雪碧聊技术10 小时前
Vue 一个页面中使用多个同类组件出现“串数据“现象?一个 key 就能解决
vue.js·v-show·一个页面使用多个相同组件·解决数据错乱·v-if、key
Java小卷13 小时前
Vue3 动态表单支持弹框组件
前端·vue.js·低代码
溪语流沙13 小时前
【Web全栈进阶】前端对接新契约:信封解包 + 统一错误处理
前端·vue.js·python·状态模式·fastapi
Q264336502313 小时前
【有源码】基于SpringBoot+Vue的居民健康体检与慢病干预管理系统-面向智慧医疗的体检预约与健康知识服务平台
java·vue.js·spring boot·mysql·毕业设计·javaweb·课程设计
雪芽蓝域zzs14 小时前
Vue导入方法三种方式对比
前端·javascript·vue.js
雪芽蓝域zzs15 小时前
从零搭建【pnpm+Vue3+TS+Setup+VueRouter4+Pinia+Axios+ElementPlus (unplugin 按需)】仿若依后台
前端·vue.js
weixin_BYSJ198718 小时前
【计算机毕设】基于Spring_Boot_Vue的马拉松报名与选手成绩追踪系统05445
java·vue.js·spring boot·学习·spring·django·课程设计