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

vue3-print打印eletable某一行的数据

主页面的表格

<template><el-table :data="list"><el-table-column label="操作" align="center"><template #default="scope"><el-buttonlinktype="primary"@click="handleType(scope.row)":loading="qrCodeLoading">打印</el-button></template></el-table-column></el-table>// 打印子页面<type ref="qrRef" @success="loadData"/>
</template>
<script>const qrRef = ref()
const qrCodeLoading = ref(false)/** 打印 */
const multiple = ref([])
const handleType = async (row) => {try {multiple.value.push(row)console.log('ss', multiple)qrRef.value.open(multiple)// todo 接口multiple.value = []} catch {} finally {qrCodeLoading.value = false}
}const loadData = async (arg) => {// todo 打印完毕
}</script>

 子页面---

<template><Dialogv-model="dialogVisible":title="dialogTitle"width="1000px"height="1200px"@close="handleCloseModal"><e-row><el-button type="success" plain v-print="printObj"><Icon icon="ep:download"/>打印</el-button></e-row><el-row class="row-con" id="printMe"><divv-for="item in tableData":ref="setItemRef":key="item.partCode"style="width: 100%"><div style="border: 2px black; margin-top:105px; margin-left: 54px; margin-right: 55px; margin-bottom: 8px;"><div style="width: 100%; display: flex; flex-direction: row">{{ 需要打印的内容+tableData }}</div></div></div></el-row></Dialog>
</template><script setup lang="ts">
import qrcode from 'qrcode'const dialogVisible = ref(false)
const dialogTitle = ref('条码打印')const handleCloseModal = () => {dialogVisible.value = false
}
const tableData = ref([])onMounted(() => {// console.log(t.userInfo.account)
})const itemRefs = ref([])
const setItemRef = (el) => {if (el) {itemRefs.value.push(el)}
}
const printObj = ref({id: 'printMe',popTitle: '',maxWidth: 302, // 最大宽度extraCss:'https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.compat.css, https://cdn.bootcdn.net/ajax/libs/hover.css/2.3.1/css/hover-min.css',extraHead: '<meta http-equiv="Content-Language"content="zh-cn"/>',// extraHead: '<meta http-equiv="Content-Language" content="zh-cn"/>,<style> #printMe { height: 302px !important; } <style>',//  可以传进去  style tag 标签;注意要逗号分隔   解决特定区域不显示问题beforeOpenCallback(vue) {vue.printLoading = trueconsole.log('打开之前')},openCallback(vue) {vue.printLoading = falseconsole.log('执行了打印', vue)},closeCallback(vue) {console.log('关闭了打印工具', vue)}})
const open = (data) => {dialogVisible.value = trueconsole.log('data', data)tableData.value = data.valueconsole.log('tableData', tableData.value)tableData.value.forEach((item) => {//var code = 'your-data' // 替换为你需要生成二维码的数据qrcode.toDataURL(item.partCode, (err, url) => {if (err) {console.error(err)} else {console.log('toDataURL', url)}})})
}
defineExpose({open}) // 提供 open 方法,用于打开弹窗
</script>
<style scoped lang="scss">
.row-con {display: flex;flex-flow: row wrap;
}.printContainer {-webkit-print-color-adjust: exact;/* 打印时表格上边框会消失 貌似是因为 使用伪元素的缘故 */::v-deep(.el-table__inner-wrapper::after) {height: 0px !important;}/* 使用自己的表格上边框 */::v-deep(.el-table__inner-wrapper) {border-top: 1px solid #e5e7eb;}/* 打印时边框太小会被挤没,那让边框变大点就好了*/::v-deep(.el-table__cell) {border-right: 2px solid #e5e7eb;}
}</style>

http://www.lryc.cn/news/436165.html

相关文章:

  • 【Vue】pnpm创建Vue3+Vite项目
  • springboot配置多数据源
  • 无人叉车3d激光slam多房间建图定位异常处理方案-墙体画线地图切分方案
  • ChatGPT+Simple Mind Map生成思维导图:快速提升学习效率
  • Day9 | Java框架 | SpringBoot
  • Wordpress右下角表单弹出插件
  • 影刀RPA实战:自动化批量生成条形码完整指南
  • Python Flask简介
  • 视频监控平台是如何运作的?EasyCVR视频汇聚平台的高效策略与实践
  • 欧拉下搭建第三方软件仓库—docker
  • pcs升压变流一体机
  • 上海泗博EtherNet/IP转PROFIBUS DP网关EPS-320IP成都地铁项目应用案例
  • 猫鼠游戏: KaijiK病毒入侵溯源分析
  • 【Hot100算法刷题集】双指针-02-盛水最多的容器(含暴力枚举、双指针法及其合理性证明)
  • Spring和Spring FrameWork有什么关系?两者是同一个东西吗?
  • windows10 python 解决鼠标右键菜单中没有Edit with IDLE(不使用注册表编辑器)
  • 一些深度学习相关指令
  • Python 实现自动配置华为交换机
  • 上海亚商投顾:沪指探底回升 华为产业链午后爆发
  • 回归预测 | MATLAB实现PSO-LSTM(粒子群优化长短期记忆神经网络)多输入单输出
  • Linux seq命令
  • 黑龙江等保测评:保障数据安全的最佳选择,助力企业无忧发展!
  • 基于OpenCV和ROS节点的智能家居服务机器人设计流程
  • vue中reduce属性的使用@3@
  • 【MySQL】索引的使用与调优技巧
  • C++库之一:Loki
  • 前后端时间转换的那些常见问题及处理方法
  • 怎么利用XML发送物流快递通知短信
  • 什么是CPU、GPU、NPU?(包懂+会)
  • TypeScript接口