当前位置: 首页 > 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; 本是是一种循环…...

基于距离变化能量开销动态调整的WSN低功耗拓扑控制开销算法matlab仿真

目录 1.程序功能描述 2.测试软件版本以及运行结果展示 3.核心程序 4.算法仿真参数 5.算法理论概述 6.参考文献 7.完整程序 1.程序功能描述 通过动态调整节点通信的能量开销&#xff0c;平衡网络负载&#xff0c;延长WSN生命周期。具体通过建立基于距离的能量消耗模型&am…...

Auto-Coder使用GPT-4o完成:在用TabPFN这个模型构建一个预测未来3天涨跌的分类任务

通过akshare库&#xff0c;获取股票数据&#xff0c;并生成TabPFN这个模型 可以识别、处理的格式&#xff0c;写一个完整的预处理示例&#xff0c;并构建一个预测未来 3 天股价涨跌的分类任务 用TabPFN这个模型构建一个预测未来 3 天股价涨跌的分类任务&#xff0c;进行预测并输…...

cf2117E

原题链接&#xff1a;https://codeforces.com/contest/2117/problem/E 题目背景&#xff1a; 给定两个数组a,b&#xff0c;可以执行多次以下操作&#xff1a;选择 i (1 < i < n - 1)&#xff0c;并设置 或&#xff0c;也可以在执行上述操作前执行一次删除任意 和 。求…...

Qt Http Server模块功能及架构

Qt Http Server 是 Qt 6.0 中引入的一个新模块&#xff0c;它提供了一个轻量级的 HTTP 服务器实现&#xff0c;主要用于构建基于 HTTP 的应用程序和服务。 功能介绍&#xff1a; 主要功能 HTTP服务器功能&#xff1a; 支持 HTTP/1.1 协议 简单的请求/响应处理模型 支持 GET…...

3403. 从盒子中找出字典序最大的字符串 I

3403. 从盒子中找出字典序最大的字符串 I 题目链接&#xff1a;3403. 从盒子中找出字典序最大的字符串 I 代码如下&#xff1a; class Solution { public:string answerString(string word, int numFriends) {if (numFriends 1) {return word;}string res;for (int i 0;i &…...

Android Bitmap治理全解析:从加载优化到泄漏防控的全生命周期管理

引言 Bitmap&#xff08;位图&#xff09;是Android应用内存占用的“头号杀手”。一张1080P&#xff08;1920x1080&#xff09;的图片以ARGB_8888格式加载时&#xff0c;内存占用高达8MB&#xff08;192010804字节&#xff09;。据统计&#xff0c;超过60%的应用OOM崩溃与Bitm…...

mysql已经安装,但是通过rpm -q 没有找mysql相关的已安装包

文章目录 现象&#xff1a;mysql已经安装&#xff0c;但是通过rpm -q 没有找mysql相关的已安装包遇到 rpm 命令找不到已经安装的 MySQL 包时&#xff0c;可能是因为以下几个原因&#xff1a;1.MySQL 不是通过 RPM 包安装的2.RPM 数据库损坏3.使用了不同的包名或路径4.使用其他包…...

华硕a豆14 Air香氛版,美学与科技的馨香融合

在快节奏的现代生活中&#xff0c;我们渴望一个能激发创想、愉悦感官的工作与生活伙伴&#xff0c;它不仅是冰冷的科技工具&#xff0c;更能触动我们内心深处的细腻情感。正是在这样的期许下&#xff0c;华硕a豆14 Air香氛版翩然而至&#xff0c;它以一种前所未有的方式&#x…...

ubuntu系统文件误删(/lib/x86_64-linux-gnu/libc.so.6)修复方案 [成功解决]

报错信息&#xff1a;libc.so.6: cannot open shared object file: No such file or directory&#xff1a; #ls, ln, sudo...命令都不能用 error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory重启后报错信息&…...

倒装芯片凸点成型工艺

UBM&#xff08;Under Bump Metallization&#xff09;与Bump&#xff08;焊球&#xff09;形成工艺流程。我们可以将整张流程图分为三大阶段来理解&#xff1a; &#x1f527; 一、UBM&#xff08;Under Bump Metallization&#xff09;工艺流程&#xff08;黄色区域&#xff…...