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

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

主页面的表格

<template>
    <el-table :data="list">
        <el-table-column label="操作" align="center">
           <template #default="scope">
             <el-button
                link
                type="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>
  <Dialog
      v-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">
      <div
          v-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 = true
    console.log('打开之前')
  },
  openCallback(vue) {
    vue.printLoading = false
    console.log('执行了打印', vue)
  },
  closeCallback(vue) {
    console.log('关闭了打印工具', vue)
  }

})
const open = (data) => {
  dialogVisible.value = true
  console.log('data', data)
  tableData.value = data.value
  console.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.kler.cn/news/309507.html

相关文章:

  • TI AM62X Secure Boot 流程简述
  • (黑马点评)六、好友关注系列功能实现
  • C语言 | Leetcode C语言接雨水II
  • vscode中前端项目文件格式化备份
  • Apple M3编译OpenSSL安卓平台SO库
  • django orm查询优化
  • Unity常用随机数算法
  • linux-Shell 编程-常用 Shell 脚本技巧
  • Python--数据格式转换
  • 在react中 使用redux
  • ubuntu安装wordpress(基于LNMP环境)
  • GBase8c主备版500升级步骤
  • 演示:基于WPF自绘的中国省份、城市、区县矢量地图
  • android 识别设备是否为模拟器
  • MySQL 按照条件(分组)只取一个形成列表 group max
  • PostgresML:通过 PostgreSQL 集成简化 AI 模型部署
  • git reset 几点疑问
  • 50ETF期权可以当天买卖吗?
  • 2024年10月蓝桥杯青少组的Stema考试开始报名
  • React两种路由模式的实现原理
  • 高防IP是如何防御攻击
  • 苹果电脑也可以清除垃圾吗?苹果电脑清理垃圾用什么软件哪个好?
  • 运用Java实现倒计时功能
  • 工业智能网关未来工业智能化的核心枢纽-天拓四方
  • 战神诸神黄昏9月19日登录PC端! 手机怎么玩战神诸神黄昏
  • 记录开发一个英语听力训练网站
  • 中断和异常处理
  • 【信息论基础第二讲】离散信源的数学模型及其信息测度包括信源的分类、信源的数学模型、离散信源的信息测度、二元信源的条件熵联合熵
  • 相亲交友小程序:轻松找到你的另一半
  • postgresql|数据库|pg_repack和idle_in_transaction_session_timeout参数的关系