el-table表格变更前后根据数据值改变背景颜色

需求:

1.左侧变更前表格数据不可以编辑,并且背景色加灰

2.右侧变更后表格数据可被编辑,编辑后变更前与变更后行数据不一致,添加背景色区分

3.点击删除的时候,给变更后表格当前行,添加背景色和删除的中横线

    <el-table
          ref="table"
          :data="tableDataList"
          style="width: 100%; margin: 0 auto; font-size: 14px;"
          height="100%"
          align="center"
          row-key="node_code"
          :row-class-name="tableRowClassName"
          :cell-class-name="tableCellClassName"
          @cell-click="handleCellClick"
        >
          <el-table-column align="center" label="操作" min-width="90" fixed="right">
            <template slot-scope="scope">
              <div>
                <a class="mc" title="删除" @click="handleDel(scope.row)"><em slot="reference" class="el-icon-delete mc" style="cursor: pointer" /></a>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="变更前">
            <el-table-column v-for="(item, index) in viewColumns" :key="index" :fixed="item.fixed" :prop="item.prop" :align="item.align" :label="item.label" :min-width="item.width" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <!-- <el-input v-if="scope.row.index == rowIndex && scope.column.index == columnIndex" v-model="scope.row[item.prop]" class="item__input" placeholder="请输入" @blur="handleBlur" /> -->
                <div class="item__txt">{{ scope.row[item.prop] }}</div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="变更后" class="after_class">
            <!-- 变更前的数据是不可修改的,变更后的数据是可以被修改的 -->
            <el-table-column v-for="(item, index) in viewColumnsTwo" :key="index" :fixed="item.fixed" :prop="item.prop" :align="item.align" :label="item.label" :min-width="item.width" :show-overflow-tooltip="true" class="after_class">
              <template slot-scope="scope" class="after_class">
                <el-input v-if="scope.row.index == rowIndex && scope.column.index == columnIndex" v-model="scope.row[item.prop]" class="item__input" placeholder="请输入" @blur="handleBlur" />
                <div v-else class="item__txt after_class">{{ scope.row[item.prop] }}</div>
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>

数据值:

<script>
data() {
    return {
tableDataList:[],
//isEdit单元格控制是否可编辑
       viewColumns: [
        { prop: 'topSymptomBefore', width: '120', align: 'center', label: '事项', fixed: false, isEdit: false },
        { prop: 'controlItemBefore', width: '120', align: 'center', label: '管理项', fixed: false, isEdit: false },
        { prop: 'controlStandardBefore', width: '120', align: 'center', label: '管理基准', fixed: false, isEdit: false },
        { prop: 'remarkBefore', width: '120', align: 'center', label: '备注', fixed: false, isEdit: false}
      ],
      // idAfter是当前数据的id,新增的时候 这个数据是
      viewColumnsTwo: [
        { prop: 'topSymptomAfter', width: '120', align: 'center', label: '事项', fixed: false, isEdit: true },
        { prop: 'controlItemAfter', width: '120', align: 'center', label: '管理项', fixed: false, isEdit: true },
        { prop: 'controlStandardAfter', width: '120', align: 'center', label: '管理基准', fixed: false, isEdit: true },
        { prop: 'remarkAfter', width: '120', align: 'center', label: '备注', fixed: false, isEdit: true }
      ], 
    }
}


</script>

添加背景色处理:

 tableCellClassName({ row, column, columnIndex }) {
      // 把每一列的索引放到column里
      column.index = columnIndex
      if (row.colorFlag) {
        if ((column.property == 'topSymptomAfter' || column.property == 'controlItemAfter' || column.property == 'controlStandardAfter' || column.property == 'remarkAfter')) {
          return 'warning-row' // 返回被点击行的样式
        }
      }
      if (column.property == 'topSymptomBefore' || column.property == 'controlItemBefore' || column.property == 'controlStandardBefore' || column.property == 'remarkBefore') {
        return 'success-row' // 返回被点击行的样式
      }
      // 对比后的数据 不等于 对比前的数据,那么添加背景色
      if (column.property == 'topSymptomAfter' && (row.topSymptomAfter.toString() !== row.topSymptomBefore.toString())) {
        return 'fill-row'
      }
      if (column.property == 'controlItemAfter' && (row.controlItemAfter.toString() !== row.controlItemBefore.toString())) {
        return 'fill-row'
      }
      if (column.property == 'controlStandardAfter' && (row.controlStandardAfter.toString() !== row.controlStandardBefore.toString())) {
        return 'fill-row'
      }
      if (column.property == 'remarkAfter' && (row.remarkAfter.toString() !== row.remarkBefore.toString())) {
        return 'fill-row'
      }
      return '' // 返回其他行的默认样式
    },

//删除行
 handleDel(row) {
      this.handleIdentification(row)
      // this.tableDataList = this.tableDataList.filter(item => item.index !== row.index)
      if (!(row.topSymptomBefore && row.controlItemBefore && row.controlStandardBefore && row.remarkBefore)) {
        row.colorFlag = false
        // 如果左侧没有数据值,只有右侧有数据值,点击删除 是删除整条数据
        this.tableDataList = this.tableDataList.filter(item => item.index !== row.index)
      }
      if ((row.topSymptomAfter || row.controlItemAfter || row.controlStandardAfter || row.remarkAfter)) {
        row.colorFlag = true
        updateMqs(this.addForm).then(res => {
          this.$message.success(res.msg)
        }).catch(res => {
          this.$message.error(res.msg)
        })
      }
    },
<style lang="scss" scoped>
::v-deep .el-table .warning-row{
   text-decoration: line-through;
   background-color: #f0f9eb;
   color: red
}
::v-deep .el-table  .success-row {
   background-color: #F0F0F0;
 }
::v-deep .el-table .fill-row{
  background-color: #F5F108;
}

</style>

成果:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/727531.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

jax.nn.initializers.glorot_normal()

import jax import jax.numpy as jnp from jax import random import jax.nn.initializers as init# 设置随机数种子 key random.PRNGKey(42)# 定义权重的形状 shape (in_dim, out_dim)# 获取 Glorot 正态初始化函数 glorot_normal_init init.glorot_normal()# 初始化权重 w…

C++初学者指南第一步---10.内存(基础)

C初学者指南第一步—10.内存&#xff08;基础&#xff09; 文章目录 C初学者指南第一步---10.内存&#xff08;基础&#xff09;1.内存模型1.1 纸上谈兵&#xff1a;C的抽象内存模型1.2 实践&#xff1a;内存的实际处理 2. 自动存储3.动态存储&#xff1a;std::vector3.1 动态内…

互联网技术基础-计算机人必看

目录 1.Internet的工作原理 1、Internet是一个分组交换系统 2、路由器是Internet实现互连的“标准件” 3、TCP/IP是Internet的核心协议 4、客户机/服务器的工作模式 2. IP地址 2.1 IP地址分类 2.2特殊IP地址 2.3路由器和IP编制原则 2.4子网的划分 2.5 IPV6 3.域名系…

Spatio-temporal Relation Modeling for Few-shot Action Recognition

标题&#xff1a;少样本动作识别的时空关系建模 源文链接&#xff1a;Thatipelli_Spatio-Temporal_Relation_Modeling_for_Few-Shot_Action_Recognition_CVPR_2022_paper.pdf (thecvf.com)https://openaccess.thecvf.com/content/CVPR2022/papers/Thatipelli_Spatio-Temporal_…

Sping源码(九)—— Bean的初始化(非懒加载)— Bean的创建方式(factoryMethod)

序言 前面文章介绍了在Spring中多种创建Bean实例的方式&#xff0c;包括采用FactoryBean的方式创建对象、使用反射创建对象、自定义BeanFactoryPostProcessor。 这篇文章继续介绍Spring中创建Bean的形式之一——factoryMethod。方法用的不多&#xff0c;感兴趣可以当扩展了解。…

Centos7.9安装kerberos

文章目录 一、背景二、Kerberos安装部署2.1kerberos服务端必要软件安装2.2配置krb5.conf2.3配置kdc.conf2.4配置kadm5.acl2.5创建Kerberos数据库2.6启动Kerberos服务2.7创建Kerberos管理员principal2.8客户端安装kerberos2.9Kerberos功能验证 本人其他相关文章链接 一、背景 亲…

Qemu虚拟机在线迁移到VMware

libvirt版本&#xff1a;libvirt-10.0.0qemu版本&#xff1a;qemu-8.2.0 在生产环境中&#xff0c;大多数的场景是 vmware 虚拟机迁移到 qemu 环境&#xff0c;一般是通过关机然后导出、导入磁盘镜像来实现。 如果要将 qemu 环境虚拟机迁移到 vmware 怎么办呢&#xff1f;要求…

112、路径总和

给你二叉树的根节点 root 和一个表示目标和的整数 targetSum 。判断该树中是否存在 根节点到叶子节点 的路径&#xff0c;这条路径上所有节点值相加等于目标和 targetSum 。如果存在&#xff0c;返回 true &#xff1b;否则&#xff0c;返回 false 。 叶子节点 是指没有子节点…

【VMware】VMware虚拟机安装_配置_使用教程

一、准备工作 1、下载VMware软件&#xff1a;访问VMware官方网站&#xff0c;下载适合你操作系统的VMware Workstation Pro安装包。 下载地址&#xff1a;VMware Desktop Hypervisors for Windows, Linux, and Mac 2、准备操作系统镜像文件&#xff1a;根据你想要在虚拟机中安…

[Vulnhub] Sleepy JDWP+Tomcat+Reverse+Reverse-enginnering

信息收集 Server IP AddressPorts Opening192.168.8.100TCP:21,8009,9001 $ nmap -sV -sC 192.168.8.100 -p- --min-rate 1000 -Pn Starting Nmap 7.92 ( https://nmap.org ) at 2024-06-20 05:06 EDT Nmap scan report for 192.168.8.100 (192.168.8.100) Host is up (0.00…

前端入门篇(五十二)练习6:transition过渡小动画

所以应该先找到第n个li&#xff0c;找到li再找img&#xff0c;li没有找错&#xff0c;底下又各自只有一个img&#xff0c;解决 ul li:nth-child(1) img { } 描述文字从下往上&#xff1a; 一开始描述也在框框下面&#xff0c;当hover时&#xff0c;translateY(0)&#xff0…

【etcd】etcd单机安装及简单操作

https://blog.csdn.net/Mr_XiMu/article/details/125026635 https://blog.csdn.net/m0_73192864/article/details/136509244 etcd在生产环境中一般为集群方式部署 etcd使用的2个默认端口号&#xff1a;2379和2380 2379&#xff1a;用于客户端通信(类似于sqlserver的1433&#x…

动态住宅代理IP:多账号矩阵管理的使用

如果您要处理多个在线帐户&#xff0c;选择正确的代理类型对于实现流畅的性能至关重要。但最适合这项工作的代理类型是什么&#xff1f; 为了更好地管理不同平台上的多个账户并优化成本&#xff0c;动态住宅代理IP通常作用在此。 一、什么是轮换代理&#xff1f; 轮换代理充当…

【Android面试八股文】你刚刚提到了V2签名使用美团的Walle实现多渠道打包,那么你能讲一讲Android 签名的 v1、v2、v3、v4版本的区别吗?

文章目录 前言一、简介二、APK 签名方案 v1 (JAR签名)2.1. 签名过程2.2 验证过程2.3 详细例子2.4 优缺点2.5 美团基于V1版本的多渠道打包方案三、APK 签名方案 v23.1 为什么要设计APK 签名方案 v2 ?3.2 APK 签名方案 v2 : 签名前和签名后的 APK3.2.1 签名前和签名后的 APK3.2…

04 - matlab m_map地学绘图工具基础函数 - 设置网格

04 - matlab m_map地学绘图工具基础函数 - 设置网格 0. 引言1. 关于m_grid2. 关于m_utmgrid3. 结语 0. 引言 本篇介绍下m_map中网格设置有关的函数m_grid和m_utmgrid&#xff0c;其中m_grid较为常用&#xff0c;m_utmgrid为设置UTM网格&#xff0c;仅支持在UTM投影下使用。 首先…

学校图书借阅管理系统(数据库课设)PS:有前端界面

1.课设要求描述 ●实现图书信息、类别、出版社等信息的管理; ●实现读者信息、借阅证信息的管理; ●实现图书的借阅、续借、归还管理; ●实现超期罚款管理、收款管理; ●创建触发器&#xff0c;分别实现借书和还书时自动更新图书信息的在册数量; ●创建视图查询各种图书…

工业AIoT竞赛

模块一&#xff1a;工业物联环境构建 # 查看节点状态 kubectl get nodes # 查看所有 pods 状态 kubectl get pods --all-namespaces cd /data/script/ ls | grep install_openyurt_manager # ./install_openyurt_manager_v5.sh是搜索到的脚本文件 ./install_openyurt_manager_v…

C/C++ struct stat介绍

目录 前言 struct stat struct stat 使用 参考 共勉 前言 本文详细介绍了stat结构体的成员变量&#xff0c;以及使用案例&#xff0c;希望能够帮到您。 struct stat struct stat 结构体用于表示文件或者文件系统对象信息的一种结构体的声明&#xff0c;通常在POSIX&#x…

电子书(chm)-加载JS--CS上线

免责声明: 本文仅做技术交流与学习... 目录 cs--web投递 html(js)代码 html生成chm工具--EasyCHM 1-选择powershell 模式 生成 2-选择bitsadmin模式生成 chm反编译成html cs--web投递 cs配置监听器--->攻击---->web投递---> 端口选择没占用的, URL路径到时候会在…

前端下载文件流,axios设置responseType: arraybuffer/blob无效

项目中调用后端下载文件接口&#xff0c;设置responseType: arraybuffer,实际拿到的数据data是字符串 axios({method: post,url: /api/v1/records/recording-file/play,// 如果有需要发送的数据&#xff0c;可以放在这里data: { uuid: 06e7075d-4ce0-476f-88cb-87fb0a1b4844 }…