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

证书模板vue写法

1:引用页面

<zsDialog  ref="zsDialog"  @cancel="zsDialogCancel"  />

import zsDialog from "./module/CertificateInfo.vue";

components: {
zsDialog
},

dk(){
this.$refs.zsDialog.visible = true;
},
gb(){
this.$refs.zsDialog.visible = false;
},

2:证书组件

<template>
<el-dialog
title="证书下载"
:visible.sync="visible"
width="80%"
height="80%"
append-to-body
:before-close="handleClose"
:close-on-click-modal="false"
>
<div>
<div id="pdfDom">
<div class="proBox">
<p><span>证书编号:</span> <span>{{rowData.bh}}</span></p>
<p style="display: flex;align-items: center;margin: 5px 0;">
<span>{{rowData.dc}}</span>
<img :src="rowData.logo" style="width: 180px;height: 50px;margin: 0 20px;" >
</p>
<p class="tit">【{{rowData.name}}】授权证书</p>
<p><span>{{rowData.userName}} 同志(员工号/身份证号):{{rowData.userCode+"/"+rowData.idCard}}</span></p>
<p style="margin: 25px 0;">
已完成 {{rowData.dc}} 佛惠山的登顶。
决定给予该同志此授权。
</p>

<p >登山名称:<input id="option1" type="checkbox" disabled name="dsName" value="dsName" checked>
<label for="dsName" style="margin: 0 25px 0 5px">佛惠山</label>
</p>

<p style="margin: 25px 0;">
运动类型:

<input v-if="rowData.authType=='登山'" disabled id="option1" type="checkbox" name="authType" checked>
<input v-else id="option1" type="checkbox" disabled name="authType">
<label for="option1" style="margin: 0 25px 0 5px">登山</label>
<input v-if="rowData.authType=='游泳'" disabled id="option2" type="checkbox" name="authType" checked>
<input v-else id="option2" type="checkbox" disabled name="authType" >
<label for="option2" style="margin: 0 25px 0 5px">游泳</label>
<input v-if="rowData.authType=='跑步'" disabled id="option3" type="checkbox" name="authType" checked>
<input v-else id="option3" type="checkbox" disabled name="authType" >
<label for="option3" style="margin: 0 25px 0 5px">跑步</label>
</p>
<p style="margin: 25px 0;">有效期:<span>2026-02-02</span><span style="margin: 0 10px">至</span><span>2026-02-02</span></p>
<br>

<br>
<div class="signature-area">
<canvas id="chapterCanvas" width="200" height="200"></canvas>
<div class="signature-text">
<p>批准人:张三</p>
<p>日期:2026-02-02</p>
</div>
</div>
</div>
</div>
<el-button @click="handleClose">取 消</el-button>
<el-button @click="getChapter">显示印章</el-button>
<el-button type="primary" @click="handleDownload('#pdfDom')">下载</el-button>
</div>

</el-dialog>
</template>

<script>
import html2canvas from 'html2canvas'
export default {
data() {
return {
pageData: null, // 接收html格式代码
visible: false,
htmlTitle: '证书',
isShow: true,
isCanvas: false,
downType: true, // false为 pdf , true为图片
rowData: {bh:'DSBH-20260202-0001',
dc:"山东济南",
logo: require('./2.png'),
name:"登山荣誉证书",
userName:"张三",
userCode:"1001",
idCard:"10011010001",
authType:"登山"
},
row: {},
sysUserDto:{}
}
},
mounted() {
},
watch: {
//用户id
"row": function (newValue) {
this.initdata(newValue)
},
},
methods: {
handleClose() {
this.visible = false
},
inittimed(d){
console.log(d)
if(d!=null){
let y = d.split("-")[0];
let m = d.split("-")[1];
let da = d.split("-")[2];
return y+"年"+m+"月"+da+"日";
}
return d;
},
// 生成印章
getChapter() {
let canvas = document.getElementById("chapterCanvas");
let context = canvas.getContext("2d");
let text = "登山专用章";
let companyName = "山东济南登山有限公司";
// context.translate(0, 0);
// context.clearRect(0, 0, 200, 200);//清除整个画布
// 绘制印章边框
let width = canvas.width / 2;
let height = canvas.height / 2;
context.lineWidth = 3;
context.strokeStyle = "#cf0c0c";
context.beginPath();
context.arc(width, height, 60, 0, Math.PI * 2); //宽、高、半径
context.stroke();

//画五角星
create5star(context, width, height, 15, "#cf0c0c", 0);

// 绘制印章名称
context.font = "20px 宋体";
context.textBaseline = "middle"; //设置文本的垂直对齐方式
context.textAlign = "center"; //设置文本的水平对对齐方式
context.lineWidth = 1;
context.strokeStyle = "#cf0c0c";
// context.strokeText(text, width, height + 30); // 名称 xx专用章

// 绘制印章单位
context.translate(width, height); // 平移到此位置,
context.font = "20px 宋体";
let count = companyName.length; // 字数
let angle = (5 * Math.PI) / (3 * (count - 1)); // 字间角度
let chars = companyName.split("");
let c;
for (let i = 0; i < count; i++) {
c = chars[i]; // 需要绘制的字符
if (i == 0) {
context.rotate((4 * Math.PI) / 6);// 文字起始位置
} else {
context.rotate(angle);
}

context.save();
context.translate(45, 0); // 平移到此位置,此时字和x轴垂直,公司名称和最外圈的距离
context.rotate(Math.PI / 2); // 旋转90度,让字平行于x轴
context.strokeText(c, 0, 0); // 此点为字的中心点
context.restore();
}

//绘制五角星
function create5star(context, sx, sy, radius, color, rotato) {
context.save();
context.fillStyle = color;
context.translate(sx, sy); //移动坐标原点
context.rotate(Math.PI + rotato); //旋转
context.beginPath(); //创建路径
let x = Math.sin(0);
let y = Math.cos(0);
let dig = (Math.PI / 5) * 4;
for (let i = 0; i < 5; i++) {
//画五角星的五条边
let x = Math.sin(i * dig);
let y = Math.cos(i * dig);
context.lineTo(x * radius, y * radius);
}
context.closePath();
context.stroke();
context.fill();
context.restore();
}
},
handleDownload() {
html2canvas(document.getElementById('pdfDom'), {
scale: 2,
useCORS: true,
logging: false
}).then(function(canvas) {
// 创建下载链接
const link = document.createElement('a')
link.download = '证书.png'
link.href = canvas.toDataURL('image/png')
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
})
}
}
}
</script>

<style scoped>
::v-deep .el-dialog__body {
padding: 0px;
display: flex;
justify-content: center;
}
#pdfDom {
/* 要想pdf周边留白,要在这里设置 */
padding: 20px;
width: 950px;
margin: 0 auto;
background: url('./1.png') no-repeat;
background-size: cover;}
.proBox {
padding: 80px 0;
width: 750px;
height: 595px;
box-sizing: border-box;
margin: 0 auto;
position: relative;
color: #000;
/* font-family: SimSun; */
}
.tit {
text-align: center;
font-size: 24px;
font-weight: 700;
position: relative;
top: -6px;
left: 8px;
/* letter-spacing: 20px; */
margin: 20px 0;
}
.proid {
text-align: right;
margin: 0;
font-weight: 500;
/* margin-right: 5px; */
}
.con {
font-size: 20px;
font-weight: 700;
text-align: left;
margin: 10px 0;
line-height: 32px;
text-indent: 2em;
}
.con-name {
font-family: 华文行楷, STXingkai;
border-bottom: 2px solid #000;
}
.con-unit {
font-size: 18px;
font-weight: 700;
position: absolute;
right: 100px;
bottom: 100px;
text-align: center;
letter-spacing: 3px;
}
.con-unit p {
margin: 5px 0;
}
.con-footer {
font-size: 18px;
font-weight: 700;
position: absolute;
bottom: 45px;
left: 0;
right: 0;
text-align: center;
}
.chapter {
border-radius: 50%;
position: absolute;
bottom: 75px;
right: 134px;
}
.signature-area {
position: absolute;
bottom: 30px;
right: 60px;
width: 200px;
height: 200px;
}

#chapterCanvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
border-radius: 50%;
}

.signature-text {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2;
display: flex;
flex-direction: column;
justify-content: flex-end;
padding: 0 0 20px 20px;
box-sizing: border-box;
pointer-events: none; /* 允许点击穿透到Canvas */
color: #333;
}

.signature-text p {
margin: 5px 0;
white-space: nowrap;
}
</style>

image

 

背景图片

 

http://www.jsqmd.com/news/414330/

相关文章:

  • 2026年高频处理优质厂家盘点,洪柏五金一站式服务受青睐 - 工业推荐榜
  • 微信立减金回收大揭秘:那些你不知道的“财富密码”与陷阱! - 可可收
  • 2026年背胶魔术贴厂家权威推荐榜:纱网魔术贴、背靠背魔术贴、防蚊类魔术贴、魔术贴绑带、冲型魔术贴、切片魔术贴选择指南 - 优质品牌商家
  • 2026年金三银四Java后端高频面试题总结
  • 2026对标PADS、Altium Designer与Cadence Allegro,国产高端PCB软件替代推荐 - 品牌2025
  • grpc客户端优化
  • 2026年2月广东欧式铁艺大门公司推荐,经典欧式庭院门品牌 - 品牌鉴赏师
  • 2026最新!8个降AI率软件降AIGC网站评测:专科生必看的降重工具推荐
  • 2026年充电桩专用箱变/光伏箱变/景观式箱变厂家推荐:箱变测控装置专业供应商精选 - 品牌推荐官
  • 枯涸的海绵
  • 2026国产EDA工具推荐:国产芯片封装与PCB协同仿真设计工具的替代选型 - 品牌2025
  • 从冷却塔到玻璃钢化粪池:2026年五家玻璃钢环保设备制造企业观察 - 深度智识库
  • 镜像视界空间神经系统——危化 × 军储 × 交通 × 低空 × 公共空间一体化控制平台统一空间坐标体系 × 三维反演定位 × 多路径概率展开 × 前向风险优化调度的跨行业空间治理底座
  • 2026年防蚊类魔术贴厂家推荐:纱网魔术贴、背靠背魔术贴、魔术贴扎带、魔术贴绑带、冲型魔术贴、切片魔术贴选择指南 - 优质品牌商家
  • 科研党收藏!全网爆红的AI论文软件 —— 千笔·专业学术智能体
  • 说说国际留学机构怎么选,这些要点你不能错过 - 工业品网
  • 2026感应加热设备五大优选品牌:技术深耕与行业适配新选择 - 深度智识库
  • 装修公司管理系统实测推荐(2026客观版) - GEO排行榜
  • 2026年重庆沙坪坝区幼儿园老牌企业排名,哪家值得选? - 工业品牌热点
  • 镜像视界:危化园区 × 产业园区 × 交通枢纽 × 低空空域 × 公共空间统一空间控制引擎建设方案
  • 益生菌什么牌子最好最有效 管不住嘴也能调肠道稳体态 - 速递信息
  • 2026年纱网魔术贴厂家最新推荐:魔术贴绑带/冲型魔术贴/切片魔术贴/家居用魔术贴/射出钩魔术贴/背胶魔术贴/选择指南 - 优质品牌商家
  • 装修ERP系统实测推荐(第三方客观版) - GEO排行榜
  • 镜像视界跨场景空间计算体系封标级专家论证白皮书——面向危化、军储、交通、低空与城市公共空间的统一空间控制引擎建设方案
  • 芜湖市金马包装有限公司联系方式:企业联系途径与使用指南 - 十大品牌推荐
  • 别再瞎找了!AI论文工具 千笔·专业论文写作工具 VS 学术猹,专科生专属神器!
  • 探索 IEEE TIE TOP 期刊中闭环改进三角电流调制的单级 ACDC 变换器
  • 2026国产DFM软件推荐:可替代Zuken DFM Center、Mentor Valor NPI的高性价比方案 - 品牌2025
  • 工业AI全球竞争格局:巨头博弈、新兴力量与关键的中国方案
  • 效率直接起飞!更贴合专科生的AI论文网站,千笔AI VS 灵感风暴AI