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

news2024/10/23 4:49:13

需求:

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.coloradmin.cn/o/1843820.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

人工智能驱动材料科学前沿:微软与PNNL联合推进电池材料创新

新型电池技术的研发对实现绿色能源目标具有决定性意义 微软公司与美国太平洋西北国家实验室&#xff08;PNNL&#xff09;近期开展了一项开创性的合作&#xff0c;利用尖端人工智能技术&#xff0c;在极短时间内完成对海量潜在电池材料的系统筛选。 微软和PNNL的研究团队采用了…

使用RT-Thread Studio创建STM32项目

引言 RT-Thread&#xff08;简称RTT&#xff09;是一个开源的实时操作系统&#xff0c;主要面向嵌入式系统应用。它具有高度可裁剪性、跨平台、高可靠性和实时性等特性&#xff0c;广泛应用于物联网&#xff08;IoT&#xff09;、工业控制、智能家居和消费电子等领域。本文将介…

web中间件漏洞-Resin漏洞-密码爆破、上传war

web中间件漏洞-Resin漏洞-密码爆破、上传webshell 使用爆破结果resin/resin进入后台&#xff0c;选择deploy。想部署webshell,得使用SSL方式请求&#xff0c;访问https://192.168.1.2:8443/resin-admin/index.php?qdeploy&s0(注&#xff1a;如果使用最新的火狐浏览器或者谷…

Windows Server配置NFS,做ESXI共享存储

1:登录wINDOWS系统&#xff0c;点击添加角色和功能。 2:根据向导提示&#xff0c;一路下一步。在服务器角色中选择文件和存储服务器在文件和iSCSI服务中勾选NFS服务器。 3&#xff1a;按照提示一路下一步&#xff0c;安装NFS。 4&#xff1a;安装完成后关闭安装界面。 5&#x…

C++语法19 循环嵌套结构(for/while循环)

语法阶段已经更新到第18章了&#xff0c;前面的知识你都学会了吗&#xff1f;如果还没有学习前面的知识&#xff0c;请点击&#x1f449;语法专栏进行学习哦&#xff01; 目录 循环嵌套 训练&#xff1a;数字矩形 解析 参考代码 训练&#xff1a;星号三角形 解析 参考代码 …

HCIA-速查-ENSP模拟器2步清空配置

需求&#xff1a;清空模拟器配置 清空当前图中配置 步骤1&#xff1a;reset saved-configuration 后输入y确认 步骤2&#xff1a;reboot后输入n否认再输入y确认 验证已经清空配置

html做一个画柱形图的软件

你可以使用 HTML、CSS 和 JavaScript 创建一个简单的柱形图绘制软件。为了方便起见&#xff0c;我们可以使用一个流行的 JavaScript 图表库&#xff0c;比如 Chart.js&#xff0c;它能够简化创建和操作图表的过程。 以下是一个完整的示例&#xff0c;展示如何使用 HTML 和 Cha…

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功能验证 本人其他相关文章链接 一、背景 亲…

NAT Easyip实验

我们这篇博客将重点讲述easy ip的配置&#xff1a; 以下面的一个简单的实验拓扑图为例&#xff1a; 本实验使用的网络地址&#xff1a; 1. 我们先来完成基础配置&#xff1a; 1.1AR1的基础配置&#xff1a; 1.2AR2上的基础配置 1.3完成AR1和AR2的基础配置后&#xff0c;我们…

6.2 事件的创建,修改和删除

6.2.1 事件的概述 事件(Event)是在指定时刻才被执行的过程式数据库对象。 事件通过MySQL中一个很有特色的功能模块——事件调度器(Event Scheduler)进行监视&#xff0c;并确定其是否需要被调用。 MySQL的事件调度器可以精确到每秒钟执行一个任务&#xff0c;比操作系统的计…

如何在linux中下载R或者更新R

一、问题阐述 package ‘Seurat’ was built under R version 4.3.3Loading required package: SeuratObject Error: This is R 4.0.4, package ‘SeuratObject’ needs > 4.1.0 当你在rstudio中出现这样的报错时&#xff0c;意味着你需要更新你的R 的版本了。 二、解决方…

【ARMv8/ARMv9 硬件加速系列 3.4 -- SVE 复制指令CPY 使用介绍】

文章目录 SVE 复制指令CPYSVE 指令格式SVE 使用语法SVE CPY 使用示例SVE CPY 小结SVE 复制指令CPY CPY <Zd>.<T>, <Pg>/M, #<imm>{, <shift>}cpy 指令在 ARMv9 的

SpringCloud Alibaba Sentinel 热点参数限流和系统保护规则

Wiki地址&#xff1a;WIKI热点参数限流 官网地址&#xff1a;https://sentinelguard.io/zh-cn/docs/parameter-flow-control.html 何为热点&#xff1f;热点即经常访问的数据。很多时候我们希望统计某个热点数据中访问频次最高的 Top K 数据&#xff0c;并对其访问进行限制。…

Mybatis中BaseEntity作用

新建各种对象的时候&#xff0c;一般来说&#xff0c;有几个属性是所有对象共有的&#xff0c;比如说id,is_del&#xff0c;is_enable这些&#xff0c;然后设置一个基础对象&#xff0c;以后新建所有对象的时候都继承它&#xff0c;就省的每次都要写这些共有的属性了

【Day01】0基础微信小程序入门-学习笔记

文章目录 今日学习目标小程序简介1. 小程序和普通网页开发的区别2. 体验小程序 第一个小程序1.第一个小程序-注册2.第一个小程序-安装开发者工具3.第一个小程序-创建小程序项目 小程序代码构成1.小程序代码构成-项目结构2. 小程序代码构成-JSON文件3. 小程序代码构成-WXML模板4…

视听分割相关论文阅读

1. End-to-End Referring Video Object Segmentation with Multimodal Transformers RVOS&#xff08;视频中的参考对象分割&#xff09;比RIS&#xff08;图像中的参考对象分割&#xff09;要困难得多&#xff0c;因为指代动作的文本表达通常无法从单个静态帧中正确推断出来。…

商超仓库管理系统

摘要 随着全球经济和互联网技术的快速发展&#xff0c;依靠互联网技术的各种管理系统逐渐应用到社会的方方面面。各行业的有识之士都逐渐开始意识到过去传统的人工管理模式已经逐渐成为企业发展的绊脚石&#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…

找不到com.fasterxml.jackson.core.exc.StreamWriteException的类文件

1. 前言: 使用springboot搭建的项目, 需要使用 jackson 更改json文件的内容; maven管理jar包, 导入jar包版本信息如下: <!-- 读写json文件所需依赖 --> <dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databin…

HarmonyOS最佳实践文档总结汇总(面试题可能会问)

api12 上面来了最佳实现方案&#xff0c;未来面试题有的问了 编号分类内容子类链接 1性能体验设计体验设计概述 文档中心用户体验设计 文档中心流畅评测指标 文档中心交互流畅体验设计 文档中心视觉流畅体验设计 文档中心2性能优化开发高性能ArkUIUI组件性能优化文档中心合…