当前位置: 首页 > news >正文

#子传父父传子props和emits #封装的table #vue3

#子传父&父传子props和emits #封装的table #vue3

父组件:emits defineEmits props
子组件:
在这里插入图片描述

子组件

<template><el-table v-bind="$attrs" ref="innerTableRef" v-loading="loading" border :data="tableData"@sort-change="handleSortChange">
<el-table-column v-for="{label,prop,type,align,width,tooltip,meta,fixed,reserveSelection,sortable,} in visibleColumns" :key="prop" :align="align ?? 'center'" :width="width" :label="label" :prop="prop":show-overflow-tooltip="tooltip ?? true" :type="type" :fixed="fixed" :reserve-selection="reserveSelection":sortable="sortable"><template #default="{ row, column: { rawColumnKey } }"><template v-if="type === 'operate'"><div class="flex justify-evenly"><slot :row="row" name="operate" /></div></template><template v-else-if="prop"><template v-if="type === 'radio'"><el-radio v-model="radioVal" class="none-label" :label="row[prop]" @input="onRadioInput(row)" /></template><template v-else-if="type === 'link'"><template v-if="!meta"><el-link class="cell-link" type="primary"@click="$emit(`click${getFirstCharUpperCaseProperty(rawColumnKey)}`, row)">{{ row[prop] }}</el-link></template></template><template v-else-if="type === 'tag' && meta"><el-tag v-if="row[prop] != null" effect="dark" :type="getMetaType(row[prop], meta, 'tag')">{{ getMetaLabel(row[prop], meta, 'tag') }}</el-tag></template><template v-else-if="type === 'custom'"><slot :name="rawColumnKey" :row="row" /></template><span v-else>{{ row[prop] }}</span></template></template></el-table-column></el-table>
</template><script setup lang="ts">const emits = defineEmits<{sortChange: [data: { column: any, prop: string, order: any }]
}>()
// 表格排序改变事件
function handleSortChange(data: { column: any, prop: string, order: any }) {emits('sortChange', data)
}

父组件

<template>
<div class="bg-white rounded-md p-2.5 shadow"><table-component v-model:page-index="queryParams.pageIndex" v-model:page-size="queryParams.pageSize":table-config="tableData.tableConfig" :table-data="tableData.data" :loading="tableData.loading":total="tableData.totalRows" @fetch="fetchData" @click-sys-uni-code="onClickCode" @sortChange="handleSortChange"><template #btn><el-button v-permission="['production_processing:add']" :icon="Plus" type="primary" @click="onHeadEvent('add')">添加</el-button></template><template #operate="{ row }"><el-link v-permission="['production_processing:input']" :icon="View" type="primary"@click="onRow('input', row)">{{ row.set == true ? '编辑' : '录入' }}</el-link><el-link v-permission="['production_processing:delete']" :icon="Delete" type="danger"@click="onRow('delete', row)">删除</el-link></template><template #status="{ row }"><template v-if="row.status == ASSEMBLY_ATATUS.PROGRRESS"><el-progress :text-inside="true" :stroke-width="15" :percentage="row.progressNumber" /></template><template v-if="row.status == ASSEMBLY_ATATUS.NO"><el-tag effect="dark" type="danger">未开始</el-tag></template><template v-if="row.status == ASSEMBLY_ATATUS.COMPLETED"><el-tag effect="dark" type="success">已完成</el-tag></template><template v-if="row.status == ASSEMBLY_ATATUS.CLOSED"><el-tag effect="dark" type="info">已关闭</el-tag></template></template><template #doneTimePreset="{ row }">{{ row.doneTimePreset }}<triangle border-color="red" title="超"v-if="dateVal(nowDate) <= dateVal(row.doneTimePreset) || dateVal(row.doneTimePreset) <= dateVal(row.doneTimeFact)" /></template><template #doneTimeFact="{ row }">{{ row.doneTimeFact == '' ? '' : row.doneTimeFact.substring(0, 10) }}<triangle border-color="red" title="超" v-if="dateVal(nowDate) <= dateVal(row.doneTimeFact)" /></template></table-component></div>
<script setup lang="ts">
const queryParams = ref({fBillNo: '', //订单编号sysUniCode: '', //系统序列码fMaterialNumber: '', //物料编号fMaterialName: '', //物料名称fMaterialSpecification: '', //规格型号status: [] as number[], //状态 0未开始 1进行中 2已完成srcProjectType: null, //源项目类型 1合同 2研发 3维修srcSysUniCode: '', //源项目系统序列码pageIndex: 1,pageSize: 10,outsource: false, //是否筛选加工外协OrderBy: null,Desc: true
})
const tableData = ref({tableConfig: [{label: '序号',type: 'index',width: 60},{label: '系统序列号',prop: 'sysUniCode',type: 'link'},{label: '订单编号',prop: 'fBillNo'},{label: '物料编码',prop: 'fMaterialNumber'},{label: '物料名称',prop: 'fMaterialName'},{label: '规格型号',prop: 'fMaterialSpecification'},{label: '单位',prop: 'fUnit',width: '90'},{label: '数量',prop: 'fAmount',width: '90'},{label: '合格品入库数量',prop: 'okInStock',width: '130'},{label: '进度',prop: 'status',type: 'custom',width: '200'},{label: '当前工序',prop: 'currProcedure'},{label: '预计完成时间',prop: 'doneTimePreset',type: 'custom',sortable: 'custom',},{label: '实际完成时间',prop: 'doneTimeFact',type: 'custom',sortable: 'custom',},{label: '来源项目',prop: 'srcProjectType',type: 'tag',meta: {tagConfig: [{label: '合同项目',value: SOURCE_PROJECT.CONTRACT,type: 'primary'},{label: '研发项目',value: SOURCE_PROJECT.RESEARCH,type: 'warning'},{label: '维修项目',value: SOURCE_PROJECT.SERVICE,type: 'danger'}]}},{label: '来源序列号',prop: 'srcSysUniCode'},{label: '操作',type: 'operate',width: 150}],data: [],loading: false,totalRows: 0
})
// 排序
function handleSortChange(data: { prop: string, order: string }) {console.log(data, 222)// 有排序if (data.order) {console.log(data.prop, (data.prop === 'doneTimePreset' ? 1 : 2));queryParams.value.OrderBy = (data.prop === 'doneTimePreset' ? 1 : 2)queryParams.value.Desc = (data.order === 'descending')} else {// 没排序-使用默认排序queryParams.value.OrderBy = null}// 还原成第一页并重新发起请求queryParams.value.pageIndex = 1fetchData()
}

怎么说呢还是得多看多写

相关文章:

#子传父父传子props和emits #封装的table #vue3

#子传父&父传子props和emits #封装的table #vue3 父组件&#xff1a;emits defineEmits props 子组件&#xff1a; 子组件 <template><el-table v-bind"$attrs" ref"innerTableRef" v-loading"loading" border :data"tabl…...

尚硅谷谷粒商城项目笔记——四、使用docker安装redis【电脑CPU:AMD】

四、使用docker安装redis 注意&#xff1a; 因为电脑是AMD芯片&#xff0c;自己知识储备不够&#xff0c;无法保证和课程中用到的环境一样&#xff0c;所以环境都是自己根据适应硬件软件环境重新配置的&#xff0c;这里的虚拟机使用的是VMware。 在解决了 Docker 安装的问题之…...

Java在无人驾驶方向的就业方向

在无人驾驶领域&#xff0c;Java作为一种主流编程语言&#xff0c;尽管不是最常见的选择&#xff08;例如&#xff0c;C和Python通常更受欢迎&#xff09;&#xff0c;但它仍然有很多应用场景和就业机会。以下是一些Java在无人驾驶方向的就业方向&#xff1a; 1. 后台服务开发 …...

机器学习中的关键距离度量及其应用

引言 在当今的数据驱动世界中&#xff0c;机器学习算法扮演着至关重要的角色&#xff0c;它们在图像分类、面部识别、在线内容审核、零售目录优化和推荐系统等多个领域发挥着重要作用。这些算法的核心在于它们能够识别和利用数据之间的相似性。而实现这一点的关键&#xff0c;…...

Redis中缓存雪崩、缓存穿透、缓存预热、缓存更新、缓存降级等问题

目录 1.什么是缓存雪崩1.1 导致雪崩的原因1.2 如何解决 2.什么是缓存穿透2.1 导致穿透的原因2.2 如何解决 3.什么是缓存预热3.1 如何解决 4.什么是缓存降级4.1 缓存降级的目的4.2 解决方案4.3 服务降级的目的 5.缓存更新 1.什么是缓存雪崩 就是存储在缓存里面的大量数据&#…...

【C++】vector 的模拟实现

&#x1f4e2;博客主页&#xff1a;https://blog.csdn.net/2301_779549673 &#x1f4e2;欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; 如有错误敬请指正&#xff01; &#x1f4e2;本文由 JohnKi 原创&#xff0c;首发于 CSDN&#x1f649; &#x1f4e2;未来很长&#…...

【C++】模版详解

1、概念 C模版分两类&#xff1a;函数模版和类模版 1&#xff09;函数模板的格式 template <class 形参名&#xff0c;class 形参名&#xff0c;......> 返回类型 函数名(参数列表) {函数体 }例如&#xff1a; template <class T> void swap(T& a, T& b…...

应用商店故障(UOS系统)

应用商店故障&#xff08;UOS系统&#xff09; 1. 安装应用商店内的应用无法下载&#xff0c;更新系统时提示依赖关系被破坏&#xff0c;怎么办&#xff1f; 问题描述 安装应用商店内的应用无法下载&#xff0c;更新系统时均提示依赖关系被破坏 解决方案 1、可先建议用户尝试修…...

8月8号前端日报:web在线进行eps32固件升级

最近几天在开发固件更新的功能&#xff0c;学习了不少相关的知识。 在arduino中对esp32进行固件更新&#xff0c;本质是使用esp官方的esptool&#xff0c;使用一个python exe程序&#xff0c;执行一段脚本&#xff0c;该脚本会将固件文件按照对应的位置来写入到esp芯片中。一共…...

win7安装python3.10

到这下载 PythonWin7/3.10.1 at master adang1345/PythonWin7 GitHub...

【Liunx】线程与进程的经典面试题总结

在这个浮躁的时代 只有自律的人才能脱颖而出 -- 《觉醒年代》 线程与进程的面试题总结 1 简述什么是LWP2 简述LWP与pthread_create创建的线程之间的关系3 简述轻量级进程ID与进程ID之间的区别4 请简述什么是线程互斥&#xff0c;为什么需要互斥5 简述你了解的进程间通信方式…...

Python中的 `break` 语句:掌握循环控制的艺术

Python中的 break 语句&#xff1a;掌握循环控制的艺术 下滑即可查看博客内容 &#x1f308; 欢迎莅临我的个人主页 &#x1f448;这里是我静心耕耘深度学习领域、真诚分享知识与智慧的小天地&#xff01;&#x1f387; &#x1f393; 博主简介&#xff1a;985高校的普通本硕…...

ES2023(ES14)新特性有什么?

1. Array.prototype.with with 方法返回一个新数组&#xff0c;替换指定索引处的元素 const arr [a, b, c, d]; const res arr.with(2, f); console.log(res);//[a, b, f, d] console.log(arr);//[a, b, c, d] Array.prototype.toSorted 2. Array.prototype.toSorted toS…...

Linux 中的特殊文件权限:SUID、GUID 和 Sticky

注&#xff1a; 机翻&#xff0c;未校。 Special File Permissions in Linux: SUID, GUID and Sticky Bit You see an s instead of x in the file permissions? Linux has some special file permissions called SUID, GUID and Sticky Bit. Know more about them. 在文件权…...

2024 某公司python 面试真题

Q: Can the type of options or labels of switch-case be floating? 在C语言中&#xff0c;switch-case语句的标签必须是整数类型&#xff0c;不能是浮点型。而在Python中&#xff0c;没有switch-case语句&#xff0c;但是可以使用字典来实现类似的功能&#xff0c;而字典的键…...

jwt伪造身份组组组合拳艰难通关

前言 现在的攻防演练不再像以往那样一个漏洞直捣黄龙&#xff0c;而是需要各种组合拳才能信手沾来&#xff0c;但是有时候使尽浑身解数也不能诚心如意。 前期信息收集 首先是拿到靶标的清单 访问系统的界面&#xff0c;没有什么能利用的功能点 首先进行目录扫描&#xff0c;…...

leetcode日记(64)最小覆盖子串

很复杂的题目&#xff0c;无论是思路还是实践都很难… 思路还是看了答案&#xff08;&#xff1f;&#xff09;设定两个指针“框”出一串字符串&#xff0c;初始两个指针都指在s的零位&#xff0c;先移动下指针&#xff0c;直到使框出的字符串中包含t中所有字符串&#xff0c;…...

C语言——编译与链接

目录 引言 翻译环境与运行环境 翻译环境 1.翻译环境的简述 2.编译过程 2.1 预处理&#xff08;预编译&#xff09; 2.2 编译 2.2.1 词法分析 2.2.2 语法分析 2.2.3 语义分析 2.3 汇编 3.链接 运行环境 结束语 引言 C语言编译与链接过程是理解程序如何从代码转化…...

你一定想看的LVS详细介绍及常见模式(NAT,DR,防火墙标记)实验详解

目录 一、什么是LVS 二、LVS的核心思想 三、 LVS的优势 四、LVS的调度算法 4.1. LVS的调度算法类型 4.2. LVS静态调度算法 4.3. LVS动态调度算法 4.4.在4.15版本内核以后新增调度算法 五、LVS软件相关信息 六、ipvsadm命令 七、 LVS的NAT模式实验详解 7.1实验环境 7.…...

嵌入式初学-C语言-十七

#接嵌入式初学-C语言-十六# 函数的递归调用 含义&#xff1a; 在一个函数中直接或者间接调用了函数本身&#xff0c;称之为函数的递归调用 // 直接调用a()->a(); // 间接调用a()->b()->a();a()->b()->..->a();递归调用的本质&#xff1a; 本是是一种循环…...

2025届最火的六大降重复率助手实测分析

Ai论文网站排名&#xff08;开题报告、文献综述、降aigc率、降重综合对比&#xff09; TOP1. 千笔AI TOP2. aipasspaper TOP3. 清北论文 TOP4. 豆包 TOP5. kimi TOP6. deepseek 专门用于降低文本里人工智能生成内容可检测概率的工具是降AIGC工具&#xff0c;此类工具借助…...

Singularity GPU支持深度指南:在容器中无缝使用CUDA和ROCm

Singularity GPU支持深度指南&#xff1a;在容器中无缝使用CUDA和ROCm 【免费下载链接】singularity Singularity has been renamed to Apptainer as part of us moving the project to the Linux Foundation. This repo has been persisted as a snapshot right before the ch…...

八大网盘直链解析终极指南:如何彻底告别下载限速困扰

八大网盘直链解析终极指南&#xff1a;如何彻底告别下载限速困扰 【免费下载链接】Online-disk-direct-link-download-assistant 一个基于 JavaScript 的网盘文件下载地址获取工具。基于【网盘直链下载助手】修改 &#xff0c;支持 百度网盘 / 阿里云盘 / 中国移动云盘 / 天翼云…...

工业显示屏选购要点,接口兼容与长期稳定测试

采购设备用串口屏这些年&#xff0c;我经常要和各种品牌打交道。今天不谈那些华丽的宣传语&#xff0c;就用实际工作中的观察&#xff0c;聊聊恒域威这个品牌的显示屏在适配方面的一些特点&#xff0c;希望能给同行一些参考。从硬件接口到工作环境选串口屏&#xff0c;首先要看…...

告别设计规范传递难题:Sketch MeaXure如何实现设计与开发无缝协作

告别设计规范传递难题&#xff1a;Sketch MeaXure如何实现设计与开发无缝协作 【免费下载链接】sketch-meaxure 项目地址: https://gitcode.com/gh_mirrors/sk/sketch-meaxure 副标题&#xff1a;5大核心功能让设计标注效率提升80%&#xff0c;沟通成本降低60% 设计规…...

终极游戏清理指南:用SteamCleaner快速释放硬盘空间的完整教程

终极游戏清理指南&#xff1a;用SteamCleaner快速释放硬盘空间的完整教程 【免费下载链接】SteamCleaner :us: A PC utility for restoring disk space from various game clients like Origin, Steam, Uplay, Battle.net, GoG and Nexon :us: 项目地址: https://gitcode.com…...

AI工厂令牌生产加速:统一服务与实时AI架构

使用统一服务和实时AI加速AI工厂中的令牌生产 在当今的AI工厂环境中&#xff0c;性能并非理论概念&#xff0c;而是经济、竞争和生存的关键。可用GPU时间下降1%&#xff0c;可能意味着每小时损失数百万令牌。几分钟的拥塞可能演变成数小时的恢复时间。机架级功率过载会导致功率…...

SEO优化排名报价一般多少钱_如何针对不同搜索引擎进行SEO优化排名

SEO优化排名报价一般多少钱_如何针对不同搜索引擎进行SEO优化排名 在当今的数字时代&#xff0c;SEO优化排名已经成为企业网站提升流量、吸引客户的重要手段。SEO优化排名报价一般多少钱&#xff0c;以及如何针对不同搜索引擎进行有效的SEO优化&#xff0c;是许多企业在决定是…...

如何为Retoolkit贡献新工具:开发者完整指南与最佳实践

如何为Retoolkit贡献新工具&#xff1a;开发者完整指南与最佳实践 【免费下载链接】retoolkit Reverse Engineers Toolkit 项目地址: https://gitcode.com/gh_mirrors/re/retoolkit Retoolkit是一个功能强大的逆向工程工具包&#xff0c;为安全研究人员和逆向工程师提供…...

Golang反射实战:如何用结构体标签实现JSON自动解析(附避坑指南)

Golang反射实战&#xff1a;如何用结构体标签实现JSON自动解析&#xff08;附避坑指南&#xff09; 在Golang开发中&#xff0c;处理JSON数据是日常工作中最常见的任务之一。无论是构建RESTful API、处理配置文件&#xff0c;还是与前端进行数据交互&#xff0c;JSON都扮演着关…...