关于el-table的二次封装及使用,支持自定义列内容
关于el-table的二次封装及使用
table组件
<template><el-table ref="tableComRef" :data="tableData" border style="width: 100%"><el-table-column v-if="tableHeaderList[0]?.type === 'selection'" type="selection"></el-table-column><el-table-column label="序号" width="80" type="index" :index="indexMethod"></el-table-column><el-table-columnv-for="(item, index) in (tableHeaderList[0]?.type === 'selection' ? tableHeaderList.slice(1) : tableHeaderList)":key="index":index="indexMethod":width="item.width"align="center":prop="item.prop":property="item.property":type="item.type":label="item.label":show-overflow-tooltip="true"><template #default="scope">// 展示内容判断自定义渲染<div v-if="item.render" class="center" v-html="item.render(scope.row)"></div>// 默认渲染<div v-else class="center" v-html="scope.row[item.property]"></div></template><template v-if="item.custom" #default="scope">// 使用自定义列<div v-if="item.isSlot"><slot name="mySlot" :data="scope.row"></slot></div>// 每一行数据操作列内容都相同时使用下方代码<div v-else><div class="operationAll center cursor-pointer"><div class="center flex-1 cursor-pointer"><divv-for="(customData, index) in item.customList1":key="index":class="customData.class":title="customData.name"class="operation center flex-1"@click="clickHandle(customData.event, scope.row, scope.$index)"><p :style="{ width: customData.width, height: customData.height }"><img :src="customData.imgUrl" alt="" /></p><p :style="{ color: customData.color }">{{ customData.name }}</p></div></div></div></div></template></el-table-column></el-table>
</template><script setup>
import { ref, getCurrentInstance, onMounted, nextTick, computed } from 'vue';
const ins = getCurrentInstance();
const bus = ins.appContext.config.globalProperties.$bus;
const props = defineProps({tableHeaderList: {type: Array,default: [],},tableData: {type: Array,default: [],},showTooltip: {type: Boolean,default: false,},pages: {type: Object,default: {pageSize: 10,currentPage: 1,},},
});const page = computed(() => props.pages);// 初始化tableindex
const indexMethod = (index) => {return page.value.pageSize * (page.value.currentPage - 1) + (index + 1);
};
父组件
<table-list:table-header-list="tableHeader":data="softManageTableData":show-tooltip="true":pages="softManagePage"@selection-change="softManageSelect"><template v-slot:mySlot="{ data }"><div class="end flex-1 cursor-pointer"><divv-for="(item, index) in operationBtns":key="index":class="item.class":title="item.name"class="operation center"@click.stop="emitClick(item,data)">// 公共项<div v-if="item.isCommon" class="center mr-[10px]"><p :style="{ color: item.color }">{{ item.name }}</p></div><div v-else>// 独有项<div v-if="data.relSource === item.isLocalUnit" class="center"><p :style="{ width: item.width, height: item.height }"><img :src="item.imgUrl" alt="" /></p><p :style="{ color: item.color }">{{ item.name }}</p></div></div></div></div></template></table-list>
script部分展示
// table header文字数据
const tableHeader = ref([{type: 'selection',},{type: '',width: '',property: 'name',label: '名称',hasIcon: true,// 自定义渲染render: (val) => {return `<div class="startX"><img src="${val.iconUrl}" alt="" class="w-[32px] h-[32px] softIcon"><p class="ml-[12px]">${ val.name }</p></div>`}},{type: '',width: '100',property: 'type',label: '类型',isSoftType: true,render: (val) => {return val.type === 'B' ? 'B' : 'C';}},{type: '',width: '',property: 'clasName',label: '分类',},{type: '',width: '100',property: 'source',label: '来源',render: (val) => {return val.relSource === '1' ? '外部' : '自有';}},{type: '',width: '100',property: 'version',label: '版本',},{type: '',width: '',property: 'releaseTime',label: '发布时间',},{type: '',width: '100',property: 'person',label: '联系人',},{type: '',width: '',property: 'contact',label: '联系方式',},{type: '',width: '',property: 'status',label: '状态',render: (val) => {let status = '';switch (val.status) {case 'wait':status = '<div class="waitUp center logs"><p></p>1</div>'break;case 'enable':status = '<div class="enableUp center logs"><p></p>启用</div>'break;case 'disable':status = '<div class="disableUp center logs"><p></p>禁用</div>'break;default:break;}return status;}},{type: '',width: '350',property: '',label: '操作',custom: true,// 操作栏需要根据当前数据自定义展示isSlot: true,// 操作栏每一项都一致时可用这个customList1: [{name: '移除',type: 'primary',event: 'removeItem',class: 'removeItem',isShowName: false,width: '23px',height: '24px',imgUrl: new URL('/src/assets/removeIcon.png', import.meta.url).href,},{name: '编辑',type: 'primary',event: 'editItem',class: 'editItem',isShowName: false,width: '23px',height: '24px',imgUrl: new URL('/src/assets/softDetailEditIcon.png', import.meta.url).href,},{name: '详情',type: 'danger',event: 'detailItem',class: 'detailItem',isShowName: false,width: '23px',height: '26px',imgUrl: new URL('/src/assets/detailIcon.png', import.meta.url).href,},],},
]);// 操作栏自定义事件
const emitClick = (item,data) => {if(item.event && typeof item.event === 'function') {// 这里将事件转发了一下,没有直接调用,直接调用会抛出无限递归的错误item.event(data,item);} else {ElMessage.error('点击事件定义有误');}
}// 自定义操作栏
// 本单位操作按钮相关 显示为true 隐藏为false
const operationBtns = ref([{name: '启用',type: 'primary',event: openShareItem,class: 'openShareItem',isCommon: true,width: '23px',height: '24px',imgUrl: new URL('/src/assets/softDetailEditIcon.png', import.meta.url).href,},{name: '禁用',type: 'primary',event: openShareItem,class: 'closeShareItem',isCommon: true,width: '23px',height: '24px',imgUrl: new URL('/src/assets/softDetailEditIcon.png', import.meta.url).href,},{name: '编辑',type: 'primary',event: editItem,class: 'editItem',isLocalUnit: '2',isCommon: false,width: '23px',height: '24px',imgUrl: new URL('/src/assets/softDetailEditIcon.png', import.meta.url).href,},{name: '删除',type: 'primary',event: removeItem,class: 'removeItem',isLocalUnit: '2',isCommon: false,width: '23px',height: '24px',imgUrl: new URL('/src/assets/removeIcon.png', import.meta.url).href,},{name: '移除',type: 'danger',event: moveClearItem,class: 'moveClearItem',isLocalUnit: '1',isCommon: false,width: '23px',height: '26px',imgUrl: new URL('/src/assets/detailIcon.png', import.meta.url).href,},{name: '详情',type: 'danger',event: detailItem,class: 'detailItem',isLocalUnit: '2',isCommon: true,width: '23px',height: '26px',imgUrl: new URL('/src/assets/detailIcon.png', import.meta.url).href,},
])
效果图

相关文章:
关于el-table的二次封装及使用,支持自定义列内容
关于el-table的二次封装及使用 table组件 <template><el-table ref"tableComRef" :data"tableData" border style"width: 100%"><el-table-column v-if"tableHeaderList[0]?.type selection" type"selection&…...
【Vue】Vue3 配置全局 scss 变量
variables.scss $color: #0c8ce9;vite.config.ts // 全局css变量css: {preprocessorOptions: {scss: {additionalData: import "/styles/variables.scss";,},},},.vue 文件使用...
C语言—二维数组
一、二维数组的创建 int arr[3][4];char arr[3][5];double arr[2][4]; 数组创建:“[ ]”中要给一个常量,不能使用变量 二、二维数组的初始化 int arr[3][4]{1,2,3,4};int arr[3][4]{{1,2},{4,5}};int arr[][4]{{2,3},{4,5}}; 前面的为行,…...
GUI加分游戏
需求目标 这个简单的游戏窗口包含一个得分标签和一个按钮。每次点击按钮时,得分增加1,并更新得分标签的显示。 效果 源码 /*** author lwh* date 2023/11/28* description 这个简单的游戏窗口包含一个得分标签和一个按钮。每次点击按钮时,…...
多线程的重要资料-信号量
(1)https://www.cnblogs.com/ike_li/p/8984186.html (2)C#关于AutoResetEvent的使用介绍 | 康瑞部落 (3)AutoResetEvent用法(一)_autoresetevent 的用法-CSDN博客 (4)c++ - Is there an easy way to implement AutoResetEvent in C++0x? - Stack Overflow (5)...
区块链相关技术、概念以及技术实现过程中的一些关键问题 Smart Contracts and Blockchains
作者:禅与计算机程序设计艺术 1.简介 2017年底,区块链已经成为众多投资人和技术人员最关注的话题之一。随着现实世界的不断复杂化、数字货币的流行以及IoT设备的普及,加密数字货币市场正变得越来越活跃。由于区块链具有去中心化、不可篡改、透明性、高并发等特点,使其在金…...
黑马点评Redis笔记
黑马点评Redis笔记 Redis基础篇:https://cyborg2077.github.io/2022/10/21/RedisBasic/ Redis实战篇:https://cyborg2077.github.io/2022/10/22/RedisPractice/ 一、手机号验证码注册登录 RandomUtil 生成定长随机数列 String code RandomUtil.ran…...
MX6ULL学习笔记 (一)交叉工具链的安装
前言: ARM 裸机、Uboot 移植、Linux 移植这些都需要在 Ubuntu 下进行编译,编译就需要编译 器,Ubuntu 自带的 gcc 编译器是针对 X86 架构的!而我们现在要编译的是 ARM 架构的代码,因为我们编译的代码是需要烧写到ARM板子…...
uni-app中的onLoad不执行
问题 想在onLoad()中发请求获取数据,却发现onLoad()根本不会执行 原因 这个页面没有在pages.json中配置,不属于uni-app中的页面 uni-app的文档也做出了说明,组件是无法使用页面级的onLoad等生命周期的 解决方法 uni-app除支持页面生命周…...
EFAK-v3.0.1版部署与使用
一、前言 EFAK((Eagle For Apache Kafka,以前称为Kafka Eagle)用于在使用 Topic 的情况下监控 Kafka 集群。包含Offset 的产生、Lag的变化、Partition的分布、Owner、Topic的创建以及修改的时间等信息。 二、环境&安装包 官方下载连接E…...
股票技术从初级到高级,从实盘进阶到摩尔缠论
一、教程描述 摩尔缠论是什么?一个伟大的缠论分支体系,由顶尖高手创立的缠论分支,这个顶尖高手,江湖上的代号为摩尔,可能是一个人,或者是一群人。摩尔缠论,基于缠论的核心思想与基础理论&#…...
力扣105. 从前序与中序遍历序列构造二叉树
栈 思路: 先序遍历:根、左子树、右子树;中序遍历:左子树、根、右子树;遍历先序遍历数组 prev,使用一个辅助栈缓存“根节点”;通过栈顶“根节点”与中序遍历数组 in 比较,确认是否到…...
Windows环境下的JDK安装与环境配置
一、JDK下载 1、打开Oracle官方网站下载页 Java Downloads | Oracle 中国 2、选择Java archive页,在版本列表中选择需要下载的版本 3、选择系统环境对应的版本,点击对应的下载按钮,弹出技术许可勾选框 4、勾选Oracle技术许可协议 5、输入Or…...
【密码学引论】Hash密码
第六章 Hash密码 md4、md5、sha系列、SM3 定义:将任意长度的消息映射成固定长度消息的函数功能:确保数据的真实性和完整性,主要用于认证和数字签名Hash函数的安全性:单向性、抗若碰撞性、抗强碰撞性生日攻击:对于生日…...
【传智杯】儒略历、评委打分、萝卜数据库题解
🍎 博客主页:🌙披星戴月的贾维斯 🍎 欢迎关注:👍点赞🍃收藏🔥留言 🍇系列专栏:🌙 蓝桥杯 🌙请不要相信胜利就像山坡上的蒲公英一样唾手…...
java基础-IO
1、基础概念 1.1、文件(File) 文件的读写可以说是开发中必不可少的部分,因为系统会存在大量处理设备上的数据,这里的设备指硬盘,内存,键盘录入,网络传输等。当然这里需要考虑的问题不仅仅是实现,还包括同步…...
Java变量理解
成员变量VS局部变量的区别 语法形式:从语法形式上看,成员变量是属于类的,而局部变量是在代码块或方法中定义的变量或是方法的参数;成员变量可以被 public,private,static 等修饰符所修饰,而局部变量不能被访问控制修饰…...
西南科技大学信号与系统A实验二(信号频谱分析)
一、实验目的 1.掌握用 matlab 软件绘制信号频谱的方法; 2.进一步理解抽样定理; 3.理解傅里叶变换的性质(频移特性). 二、实验原理 (一)fft 函数的调用 matlab 提供 fft 函数来计算信号 x(n)的快速离散傅里叶变换 (FFT). z 格式:y=fft(x) 计算信号 x 的快速离散傅里叶…...
C++-youtube cherno C++视频的一些知识点
对函数的调用在汇编中对应一句call func语句,其中func是一个函数的签名(signature)对程序而言,即使只有一个文件,链接器也需要链接,因为它需要链接程序入口点(entry point)一个程序的…...
sed命令
目录 一、sed 1.sed命令选项 2.语法选项 3.sed脚本格式 4.搜索替代 5.分组后向引用 1.提取版本号: 2.提取IP地址 3.提取数字权限 6.变量 二、免交互 1.多行重定向 2.免交互脚本 总结:本章主要介绍了seq和免交互的用法及相关知识 一、sed s…...
Linux应用开发之网络套接字编程(实例篇)
服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...
进程地址空间(比特课总结)
一、进程地址空间 1. 环境变量 1 )⽤户级环境变量与系统级环境变量 全局属性:环境变量具有全局属性,会被⼦进程继承。例如当bash启动⼦进程时,环 境变量会⾃动传递给⼦进程。 本地变量限制:本地变量只在当前进程(ba…...
微软PowerBI考试 PL300-选择 Power BI 模型框架【附练习数据】
微软PowerBI考试 PL300-选择 Power BI 模型框架 20 多年来,Microsoft 持续对企业商业智能 (BI) 进行大量投资。 Azure Analysis Services (AAS) 和 SQL Server Analysis Services (SSAS) 基于无数企业使用的成熟的 BI 数据建模技术。 同样的技术也是 Power BI 数据…...
AI Agent与Agentic AI:原理、应用、挑战与未来展望
文章目录 一、引言二、AI Agent与Agentic AI的兴起2.1 技术契机与生态成熟2.2 Agent的定义与特征2.3 Agent的发展历程 三、AI Agent的核心技术栈解密3.1 感知模块代码示例:使用Python和OpenCV进行图像识别 3.2 认知与决策模块代码示例:使用OpenAI GPT-3进…...
STM32标准库-DMA直接存储器存取
文章目录 一、DMA1.1简介1.2存储器映像1.3DMA框图1.4DMA基本结构1.5DMA请求1.6数据宽度与对齐1.7数据转运DMA1.8ADC扫描模式DMA 二、数据转运DMA2.1接线图2.2代码2.3相关API 一、DMA 1.1简介 DMA(Direct Memory Access)直接存储器存取 DMA可以提供外设…...
OkHttp 中实现断点续传 demo
在 OkHttp 中实现断点续传主要通过以下步骤完成,核心是利用 HTTP 协议的 Range 请求头指定下载范围: 实现原理 Range 请求头:向服务器请求文件的特定字节范围(如 Range: bytes1024-) 本地文件记录:保存已…...
P3 QT项目----记事本(3.8)
3.8 记事本项目总结 项目源码 1.main.cpp #include "widget.h" #include <QApplication> int main(int argc, char *argv[]) {QApplication a(argc, argv);Widget w;w.show();return a.exec(); } 2.widget.cpp #include "widget.h" #include &q…...
Linux云原生安全:零信任架构与机密计算
Linux云原生安全:零信任架构与机密计算 构建坚不可摧的云原生防御体系 引言:云原生安全的范式革命 随着云原生技术的普及,安全边界正在从传统的网络边界向工作负载内部转移。Gartner预测,到2025年,零信任架构将成为超…...
Spring Boot面试题精选汇总
🤟致敬读者 🟩感谢阅读🟦笑口常开🟪生日快乐⬛早点睡觉 📘博主相关 🟧博主信息🟨博客首页🟫专栏推荐🟥活动信息 文章目录 Spring Boot面试题精选汇总⚙️ **一、核心概…...
鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个生活电费的缴纳和查询小程序
一、项目初始化与配置 1. 创建项目 ohpm init harmony/utility-payment-app 2. 配置权限 // module.json5 {"requestPermissions": [{"name": "ohos.permission.INTERNET"},{"name": "ohos.permission.GET_NETWORK_INFO"…...
