首页 > 其他分享 >el-table合并行,控制全选框的可选状态

el-table合并行,控制全选框的可选状态

时间:2024-07-23 19:21:43浏览次数:11  
标签:el return res leftItem error table false 选框 row

给相同的类合并行

 <el-table
            border
            class="customer-no-border-table"
            element-loading-text="数据正在加载中..."
            :row-class-name="tableRowClassName"
            :header-cell-style="{ background: '#E7F2FD', color: '#252525' }"
            style="width: 100%; border-top: 1px solid #409eff"
            :cell-style="{ borderColor: '#1890ff' }"
            v-loading="leftLoading"
            ref="leftTable"
            :data="leftTable"
            @row-click="getItem"
            highlight-current-row
            height="400"
            :span-method="objectSpanMethod"
          >
            <el-table-column
              prop="detailTypeGroupStr"
              align="center"
              width="100"
            >
            </el-table-column>
            <el-table-column
              label="升级对象"
              prop="detailTypeStr"
              align="center"
            >
              <template slot-scope="{ row, $index }">
                <div
                  style="
                    display: flex;
                    justify-content: space-around;
                    align-items: center;
                  "
                >
                  <div>{{ row.detailTypeStr }}</div>
                  <div>
                    <el-button
                      type="primary"
                      size="small"
                      style="margin-left: 20px"
                      v-if="
                        (row.flagIndex !== 0 && row.detailTypeGroup === 11) ||
                        (row.flagIndex !== 0 && row.detailTypeGroup === 12)
                      "
                      @click="oneClickSet(row)"
                      >一键同步</el-button
                    >
                  </div>
                </div>
              </template>
            </el-table-column>
</el-table>
  this.leftTable = res.data;
          this.getSpanArr(res.data);
          // 给要显示一键设置按钮的行,添加flagIndex标识
          const newArray = this.leftTable.map((i, index) => {
            const j = this.spanArr[index];
            return {
              ...i,
              flagIndex: j,
            };
          });
          this.leftTable = newArray;

 // 合并行
    objectSpanMethod({ rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        const _row = this.spanArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          // [0,0] 表示这一行不显示, [2,1]表示行的合并数
          rowspan: _row,
          colspan: _col,
        };
      }
    },
    getSpanArr(data) {
      // data就是我们从后台拿到的数据
      for (let i = 0; i < data.length; i++) {
        //如果是第一条记录(索引为0),向数组中加入1,并设置索引位置
        if (i === 0) {
          this.spanArr.push(1);
          this.pos = 0; //spanArr的索引
        } else {
          //如果不是第一条记录,则判断它与前一条记录是否相等
          //根据相同 扣分类别名称 进行合并,根据需要可进行修改
          if (data[i].detailTypeGroup === data[i - 1].detailTypeGroup) {
            //如果相等,则向spanArr中添入元素0,并将前一位元素+1,表示合并行数+1
            this.spanArr[this.pos] += 1;
            this.spanArr.push(0);
          } else {
            this.spanArr.push(1);
            this.pos = i;
          }
        }
      }
    },

禁止选中

  <el-table
            border
            class="customer-no-border-table"
            element-loading-text="数据正在加载中..."
            :row-class-name="tableRowClassName"
            :header-cell-style="{ background: '#E7F2FD', color: '#252525' }"
            style="width: 100%; border-top: 1px solid #409eff"
            v-loading="centerLoading"
            ref="centerTable"
            :data="centerTable"
            highlight-current-row
            height="400"
            :row-key="rowKey"
            @row-click="getItemCenter"
            :header-cell-class-name="cellClass"
          >
            <el-table-column
              align="center"
              :resizable="false"
              :render-header="renderHeader"
              width="55"
            >
              <template #default="scope">
                <el-checkbox
                  v-model="scope.row.checked"
                  @change="select(scope.row)"
                  :disabled="disabled()"
                />
              </template>
            </el-table-column>
            <el-table-column
              label="硬件类型"
              prop="deviceDictCodeStr"
              align="center"
            ></el-table-column>
            <div slot="empty">
              <img
                alt="暂无数据"
                src="@/assets/noReport.png"
                style="margin-top: 80px"
              />
            </div>
          </el-table>
computed: {
    cellClass() {
      if (
        (this.leftItem.detailTypeGroup == 11 && this.leftItem.flagIndex == 0) ||
        (this.leftItem.detailTypeGroup == 12 && this.leftItem.flagIndex == 0)
      ) {
        return "DisableSelection";
      }
    },
  },
methods:{
 // 控制选择硬件的多选框能否被点击
    disabled() {
      // 有一键设置的时候, 不能编辑下面的厂商;
      if (
        (this.leftItem.detailTypeGroup == 11 && this.leftItem.flagIndex == 0) ||
        (this.leftItem.detailTypeGroup == 12 && this.leftItem.flagIndex == 0)
      ) {
        return true;
      } else {
        return false;
      }
    }
}

完整代码:

<template>
  <div>
    <div class="bigBox">
      <div class="leftBox">
        <div class="title">
          <div class="img">
            <img src="@/assets/upgradeObject.png" alt="升级对象" />
          </div>
          <div class="text">升级对象</div>
        </div>
        <el-form :inline="true" class="searchBox">
          <el-form-item>
            <el-input
              v-model.trim="upgradeObject"
              placeholder="请输入升级对象"
              clearable
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" class="searchBut" @click="searchLeftTable"
              >搜 索</el-button
            >
          </el-form-item>
        </el-form>
        <div class="leftTable">
          <el-table
            border
            class="customer-no-border-table"
            element-loading-text="数据正在加载中..."
            :row-class-name="tableRowClassName"
            :header-cell-style="{ background: '#E7F2FD', color: '#252525' }"
            style="width: 100%; border-top: 1px solid #409eff"
            :cell-style="{ borderColor: '#1890ff' }"
            v-loading="leftLoading"
            ref="leftTable"
            :data="leftTable"
            @row-click="getItem"
            highlight-current-row
            height="400"
            :span-method="objectSpanMethod"
          >
            <el-table-column
              prop="detailTypeGroupStr"
              align="center"
              width="100"
            >
            </el-table-column>
            <el-table-column
              label="升级对象"
              prop="detailTypeStr"
              align="center"
            >
              <template slot-scope="{ row, $index }">
                <div
                  style="
                    display: flex;
                    justify-content: space-around;
                    align-items: center;
                  "
                >
                  <div>{{ row.detailTypeStr }}</div>
                  <div>
                    <el-button
                      type="primary"
                      size="small"
                      style="margin-left: 20px"
                      v-if="
                        (row.flagIndex !== 0 && row.detailTypeGroup === 11) ||
                        (row.flagIndex !== 0 && row.detailTypeGroup === 12)
                      "
                      @click="oneClickSet(row)"
                      >一键同步</el-button
                    >
                  </div>
                </div>
              </template>
            </el-table-column>
            <div slot="empty">
              <img
                alt="暂无数据"
                src="@/assets/noReport.png"
                style="margin-top: 80px"
              />
            </div>
          </el-table>
        </div>
      </div>
      <div v-if="isShow" class="rightBox">
        <div class="centerTable">
          <div class="title">
            <div class="img">
              <img src="@/assets/hardwareType.png" alt="硬件类型" />
            </div>
            <div class="text">硬件类型</div>
          </div>
          <el-form :inline="true" class="searchBox">
            <el-form-item>
              <el-input
                v-model.trim="hardwareType"
                placeholder="请输入硬件类型"
                clearable
              ></el-input>
            </el-form-item>

            <el-form-item>
              <el-button
                type="primary"
                class="searchBut"
                @click="searchCenterTable"
                >搜 索</el-button
              >
            </el-form-item>
          </el-form>
          <el-table
            border
            class="customer-no-border-table"
            element-loading-text="数据正在加载中..."
            :row-class-name="tableRowClassName"
            :header-cell-style="{ background: '#E7F2FD', color: '#252525' }"
            style="width: 100%; border-top: 1px solid #409eff"
            v-loading="centerLoading"
            ref="centerTable"
            :data="centerTable"
            highlight-current-row
            height="400"
            :row-key="rowKey"
            @row-click="getItemCenter"
            :header-cell-class-name="cellClass"
          >
            <el-table-column
              align="center"
              :resizable="false"
              :render-header="renderHeader"
              width="55"
            >
              <template #default="scope">
                <el-checkbox
                  v-model="scope.row.checked"
                  @change="select(scope.row)"
                  :disabled="disabled()"
                />
              </template>
            </el-table-column>
            <el-table-column
              label="硬件类型"
              prop="deviceDictCodeStr"
              align="center"
            ></el-table-column>
            <div slot="empty">
              <img
                alt="暂无数据"
                src="@/assets/noReport.png"
                style="margin-top: 80px"
              />
            </div>
          </el-table>
        </div>
        <div class="rightTable" v-if="isShowRight">
          <div class="title">
            <div class="img">
              <img src="@/assets/factoryName.png" alt="厂商名称" />
            </div>
            <div class="text">厂商名称</div>
          </div>
          <el-table
            border
            class="customer-no-border-table"
            element-loading-text="数据正在加载中..."
            :row-class-name="tableRowClassName"
            :header-cell-style="{ background: '#E7F2FD', color: '#252525' }"
            style="width: 100%; border-top: 1px solid #409eff"
            v-loading="rightLoading"
            ref="rightTable"
            :data="rightTable"
            height="400"
          >
            <el-table-column
              label="厂商名称"
              prop="factoryDictCodeStr"
              align="center"
            ></el-table-column>
            <div slot="empty">
              <img
                alt="暂无数据"
                src="@/assets/noReport.png"
                style="margin-top: 80px"
              />
            </div>
          </el-table>
        </div>
        <div v-else style="margin: auto">
          <img
            src="@/assets/selectUpgrdeObject.png"
            alt="请选择硬件类型进行配置"
          />
          <div style="text-align: center">请选择硬件类型进行配置</div>
        </div>
      </div>
      <div v-else style="margin: auto">
        <img
          src="@/assets/selectUpgrdeObject.png"
          alt="请选择升级对象进行配置"
        />
        <div style="text-align: center">请选择升级对象进行配置</div>
      </div>
    </div>

    <div style="position: fixed; right: 40px">
      <el-button
        type="primary"
        @click="save"
        style="height: 30px; width: 78px; padding: 0; line-height: 30px"
        >保存</el-button
      >
    </div>
  </div>
</template>

<script>
import {
  getBasicDataDictList,
  getDetailTypeList,
  getModuleList,
  getFactoryList,
  saveDetailTypeModuleLink,
} from "_config/url.js";
export default {
  props: ["power"],
  data() {
    return {
      upgradeObject: "", //升级对象
      hardwareType: "", //硬件类型

      leftTable: [],
      centerTable: [],
      rightTable: [],

      leftLoading: false,
      centerLoading: false,
      rightLoading: false,

      isShow: false,
      isShowRight: false,
      leftItem: "", //左边表格的选中行
      centerItem: "", //中间表格的选中行
      powerType: "", //功率code
      spanArr: [], //每行合并数
      pos: 0, //角标索引
      isCheckAll: false,
      isIndeterminate: false,
      centerTableNoCondition: [],
    };
  },
  computed: {
    cellClass() {
      if (
        (this.leftItem.detailTypeGroup == 11 && this.leftItem.flagIndex == 0) ||
        (this.leftItem.detailTypeGroup == 12 && this.leftItem.flagIndex == 0)
      ) {
        return "DisableSelection";
      }
    },
  },
  mounted() {
    this.getOptions();
  },
  methods: {
    // 控制选择硬件的多选框能否被点击
    disabled() {
      // 有一键设置的时候, 不能编辑下面的厂商;
      if (
        (this.leftItem.detailTypeGroup == 11 && this.leftItem.flagIndex == 0) ||
        (this.leftItem.detailTypeGroup == 12 && this.leftItem.flagIndex == 0)
      ) {
        return true;
      } else {
        return false;
      }
    },
    // 一键同步
    oneClickSet(row) {
      let group = row.detailTypeGroup;
      this.leftTable = this.leftTable.map((item, i) => {
        if (item.detailTypeGroup === group) {
          return {
            ...item,
            deviceCodeList: row.deviceCodeList,
          };
        } else {
          return item;
        }
      });
    },
    // 合并行
    objectSpanMethod({ rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        const _row = this.spanArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          // [0,0] 表示这一行不显示, [2,1]表示行的合并数
          rowspan: _row,
          colspan: _col,
        };
      }
    },
    getSpanArr(data) {
      // data就是我们从后台拿到的数据
      for (let i = 0; i < data.length; i++) {
        //如果是第一条记录(索引为0),向数组中加入1,并设置索引位置
        if (i === 0) {
          this.spanArr.push(1);
          this.pos = 0; //spanArr的索引
        } else {
          //如果不是第一条记录,则判断它与前一条记录是否相等
          //根据相同 扣分类别名称 进行合并,根据需要可进行修改
          if (data[i].detailTypeGroup === data[i - 1].detailTypeGroup) {
            //如果相等,则向spanArr中添入元素0,并将前一位元素+1,表示合并行数+1
            this.spanArr[this.pos] += 1;
            this.spanArr.push(0);
          } else {
            this.spanArr.push(1);
            this.pos = i;
          }
        }
      }
    },
    //获取字典项
    getOptions() {
      this.$fetch(getBasicDataDictList)
        .then((res) => {
          if (res.code == 200) {
            this.optionsPowerType = res.data.powerTypeDict; //功率类型

            const foundItem = this.optionsPowerType.find(
              (i) => i.name == this.power
            );
            this.powerType = foundItem ? foundItem.code : "";
            this.searchLeftTable();
          } else {
            this.$message.error(res.message);
          }
        })
        .catch((err) => {
          this.errorMessage(err);
        });
    },
    // 左边表格选中
    getItem(val) {
      // console.log("

标签:el,return,res,leftItem,error,table,false,选框,row
From: https://www.cnblogs.com/hxy--Tina/p/18318562

相关文章

  • [米联客-安路飞龙DR1-FPSOC] FPGA基础篇连载-03安路TD结合modelsim仿真
    软件版本:Anlogic-TD5.9.1-DR1_ES1.1操作系统:WIN1064bit硬件平台:适用安路(Anlogic)FPGA实验平台:米联客-MLK-L1-CZ06-DR1M90G开发板板卡获取平台:https://milianke.tmall.com/登录"米联客"FPGA社区http://www.uisrc.com视频课程、答疑解惑!1概述FPGA开发中对设计的代码功能......
  • Python贝叶斯、transformer自注意力机制self-attention个性化推荐模型预测课程平台学
    全文链接:https://tecdat.cn/?p=37090原文出处:拓端数据部落公众号 分析师:KungFu近年来,在线课程凭借便捷的网络变得越来越流行。为了有更好的用户体验,在线课程平台想要给用户推荐他们所感兴趣的课程,以便增大点击率和用户黏性。解决方案任务/目标根据学生所选的历史课程,预测出......
  • DNS概述及DNS服务器的搭建(twelve day)
    回顾关闭防火墙systemctlstopfirewalld永久停止防火墙systemctldisable firewalld关闭selinuxsetenforce0永久关闭selinux安全架构vim/etc/selinux/config修改静态IP地址vim/etc/sysconfig/network-scripts/ifcfg-ens160  #修改uuid的目的是为了保证网络......
  • 使用Velero备份、恢复的备份、恢复、迁移K8S集群上的资源
    开源地址:GitHub-vmware-tanzu/velero:BackupandmigrateKubernetesapplicationsandtheirpersistentvolumeshttps://github.com/vmware-tanzu/velero官网:https://velero.io/Velero的基本原理就是将Kubernetes集群资源对象数据备份到对象存储中,并能从对象存储中拉取......
  • Mac ml-agents release 19(v0
    Macml-agentsrelease19(v0.28.0)踩雷主要参考这篇博客:ML-Agents在MacM1上的安装跟着这篇安装完,在激活虚拟环境的终端输入mlagents-learn检验,如果正常应输出如下:后面超时报错不用管,因为还没在unity中启动训练环境。但是在跟完这篇博客后我这里并未成功执行此命令,报了几......
  • 在1Panel服务器面板中使用ClamAV防病毒引擎 轻松实现病毒扫描
    ClamAV是一款开源(GPLv2)防病毒工具包(anti-virustoolkit),能够有效检测和清除多种类型的恶意软件、病毒和钓鱼邮件,同时提供了免费且持续的病毒特征库升级。全新发布的1Panelv1.10.12-lts版本中新增了ClamAV病毒扫描功能,支持够通过图形化界面安装和使用ClamAV,并可在应......
  • Telnet协议
     由图可知使用了两个路由器来替代pc和web客户端要求1.首先配置ar1的两个接口ip地址2.配置替代pc和备份web服务器的接口IP地址这里的补充两个设备的路由表是为了pc访问web服务器做准备的 3.配置telnet注意登录用户user时,输入密码的时候密码不会显示出来远程......
  • 使用poi操作excel报这个错 java.lang.NoSuchMethodError: org.apache.logging.log4j.L
    使用poi操作excel报这个错java.lang.NoSuchMethodError:org.apache.logging.log4j.Logger.atTrace()Lorg/apache/logging/log4j/经查发现poi、poi-ooxml引用了log4j-api,版本较低,没有atTrace()方法 解决办法:移除poi、poi-ooxml引用的log4j-api,重新引用高版本的依赖 ......
  • 使用shell获取路径参数的最后一个目录层级
    1、填写路径参数时可能会出现最后有多余的"/"场景,所以要先移除可能尾随的斜杠        举例:url=/Walmart-Onn-GTV/wave1/toAmlPatch/        last_dir=${A%/}    echo"$last_dir"结果        /Walmart-Onn-GTV/wave1/toAmlPatch2、使用ba......
  • VXE-Table+antvX6+element+DataV+vue2边框开发流程识别配置
    本demo为了实现自定义流程保存回显新增效果,复制即用,模拟数据太长没在代码中体现,需要可以找我拿vxe-table官方连接:VxeTablev4antVX6连接:https://x6.antv.antgroup.com/element连接:Element-Theworld'smostpopularVueUIframeworkDataV连接:DataV效果图H......