<!-- 标签---三行信息,测试、校准、限用、停用、封存、合格、禁用 --> <script name="LabelThreeInfo" lang="ts" setup> import type { Ref } from 'vue' import { onMounted, ref } from 'vue' import dayjs from 'dayjs' import { ElLoading, ElMessage } from 'element-plus' import html2canvas from 'html2canvas' import { autoPicture } from './autoPicture' import { getPhotoUrl } from '@/api/file' import { printHtml, printImage } from '@/utils/printUtils' import { listPageApi } from '@/api/system/tool' import { useCreateQr } from '@/commonMethods/useCreateQr' const props = defineProps({ title: { // 标题 type: String, default: '测试', }, backgroundColor: { // 背景颜色 type: String, default: '#12cccc', }, dateTitle: { // 日期标题 type: String, default: '测试日期', }, personTitle: { // 人员标题 type: String, default: '测试人', }, deviceNo: { // 智能模型编号 type: String, default: '', }, year: { type: String, default: '', }, month: { type: String, default: '', }, day: { type: String, default: '', }, personName: { type: String, default: '', }, equipmentId: { type: String, default: '', }, userId: { type: String, default: '', }, }) const qrCodeRef = ref() const qrUrl = ref('') // 二维码图片 watch(() => props.equipmentId, (newValue) => { if (newValue) { console.log('生成二维码的智能模型id:', newValue) qrUrl.value = useCreateQr(newValue)! } }, { immediate: true }) // 签名查询数据 const searchQueryAutograph = ref({ signNo: '', // 编号 signName: '', // 名称 signDirector: '', // 负责人 signUserId: '', // 用户id createStartTime: '', createEndTime: '', limit: 20, offset: 1, signType: '', ids: [], }) const singPicture = ref() as any const url = ref('') // 获取签名数据 const getAutographList = (userId: string) => { searchQueryAutograph.value.signUserId = userId // 创建人的签名 listPageApi(searchQueryAutograph.value).then((res) => { if (res.code === 200) { if (res.data.rows.length) { singPicture.value = res.data.rows[0].minioFileName getPhotoUrl(singPicture.value).then((res) => { url.value = res.data // console.log('签名图片', url.value) }) } else { singPicture.value = '' } } }) } const shareImg = async () => { const el = document.getElementById('printData') console.log('el:', el) // const canvasFalse = document.createElement('canvas') const width = parseInt(window.getComputedStyle(el).width) const height = parseInt(window.getComputedStyle(el).height) console.log('width:', width, 'height:', height) const url = await autoPicture('printData', { width, height }) console.log('生成的图片', url) if (url) { // currentImg.value = canvas // printHtml(canvas) printImage(url, '', '') } } const print = () => { shareImg() } watch(() => props.userId, (newValue) => { if (newValue) { getAutographList(newValue) } }, { immediate: true }) defineExpose({ print }) </script> <template> <div id="printData" class="three-info"> <div class="left"> <div class="deviceNo-class"> {{ props.deviceNo }} </div> <div> <span class="year-class"> {{ props.year }} </span> <span class="month-class"> {{ props.month }} </span> <span class="day-class"> {{ props.day }} </span> </div> <div class="person-class"> <!-- {{ props.personName }} --> <el-image v-if="url" class="personPicture" :src="url" /> </div> </div> <div class="right"> <el-image class="qr" :src="qrUrl" /> </div> </div> </template> <style lang="scss" scoped> .three-info { display: flex; border-radius: 10mm; width: 55mm; height: 20mm; background-color: #f2f3f5; // border-top: 1mm solid transparent; box-sizing: border-box; .left { width: 35mm; padding: 1mm 2mm; padding-left: 5mm; flex: 1; background-color: #f2f3f5; border-radius: 1mm; // font-size: 2.4mm; font-size: 10px; box-sizing: border-box; .deviceNo-class { position: relative; top: 6mm; left: 6mm; } .year-class { position: relative; top: 5.8mm; left: 6mm; } .month-class { position: relative; top: 5.8mm; left: 9.5mm; } .day-class { position: relative; top: 5.8mm; left: 12.5mm; } .person-class { position: relative; top: 7mm; left: 8mm; .personPicture { width: 10mm; height: 3.6mm; } } } .right { // width: 18mm; width: 20mm; height: 20mm; display: flex; justify-content: center; align-items: center; .qr { width: 16mm; height: 16mm; position: relative; right: 1mm; top: 0; } } } </style>