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

vite+vue3+typescript+elementPlus前端实现电子证书查询系统

实现背景:之前电子证书的实现是后端实现的,主要采用GD库技术,在底图上添加文字水印和图片水印实现的。这里采用前端技术实现电子证书的呈现以及点击证书下载,优点是:后端给前端传递的是一组数据,不需要传证书的图片,交互所需数据流大大减少了。后端不需要生成证书,就不需要额外开辟存储证书的空间,当用户量很大时,节省开支。

前端技术栈:vite+vue3+typescript+elementPlus

证书查询首页实现,代码如下:

<template><el-row class="header"><el-col :span="24"><el-text>电子证书查询系统</el-text></el-col></el-row><el-row class="main"><el-col :span="24"><el-card style="max-width: 680px" shadow="always"><template #header><div class="card-header"><span>证书查询系统</span></div></template><el-formref="ruleFormRef":model="ruleForm":rules="rules"label-width="auto"class="demo-ruleForm":size="formSize":label-position="labelPosition"status-icon><el-form-item label="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" prop="name"><el-input v-model="ruleForm.name" placeholder="请输入姓名" /></el-form-item><el-form-item label="身份证号" prop="idNo"><el-input v-model="ruleForm.idNo" placeholder="请输入身份证号" /></el-form-item><el-form-item label="证书编号" prop="certificateNo"><el-input v-model="ruleForm.certificateNo" placeholder="请输入证书编号" /></el-form-item><el-form-item><el-button type="primary" @click="submitForm(ruleFormRef)"> 查询 </el-button></el-form-item></el-form></el-card></el-col></el-row>
</template><script lang="ts" setup name="CertificateIndex">
import { reactive, ref } from 'vue'
import type { ComponentSize, FormInstance, FormRules, FormProps } from 'element-plus'
import { ElMessage } from 'element-plus'
import { createItem } from '../services/crudService'
import { useRouter } from 'vue-router'const router = useRouter()interface RuleForm {name: stringidNo: stringcertificateNo: string
}const formSize = ref<ComponentSize>('large')
const labelPosition = ref<FormProps['labelPosition']>('left')
const ruleFormRef = ref<FormInstance>()
const ruleForm = reactive<RuleForm>({name: '',idNo: '',certificateNo: ''
})const rules = reactive<FormRules<RuleForm>>({name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],idNo: [{ required: true, message: '请输入身份证号', trigger: 'blur' }],certificateNo: [{ required: true, message: '请输入证书编号', trigger: 'blur' }]
})const submitForm = async (formEl: FormInstance | undefined) => {if (!formEl) return// Validate the formawait formEl.validate()// If validation passes, call createItem with the form dataconst { data } = await createItem(ruleForm)if (!data.id) {ElMessage({message: '暂无此人相关证书!',type: 'warning'})return}router.push({ name: 'CertificateDetail', query: { data: JSON.stringify(data) } })
}
</script><style scoped style="scss">
.header {background-color: #1174c2;width: 100%;height: 50px;.el-col {text-align: center;vertical-align: center;padding: 0.5rem 0;.el-text {font-size: 1.5rem;color: #fff;}}
}.main {margin-top: 100px;.el-col {.el-card {margin: 0 auto;.card-header {text-align: center;vertical-align: center;font-size: 1.5rem;background-color: #1174c2;color: #fff;width: 100%;padding: 0.8rem 0;}.el-form {.el-form-item {margin: 2rem auto;}.el-button {font-size: 1.5rem;padding: 1.5rem 0;width: 100%;background-color: #1174c2;}}}}
}
</style>

证书查询首页实现,效果呈现如下:

在这里插入图片描述

电子证书查询结果实现,代码如下:

<template><div class="main"><divclass="card-header p-2 w-full bg-[#1174c2] text-[#fff] text-center text-xl fixed top-0 left-0 w-full z-50"><span>电子证书查询结果</span></div><el-card shadow="always" class="mt-20"><div class="content" ref="contentToCapture"><div class="logo w-28 h-10 mt-4"></div><div class="text-center mt-20 mb-6 text-lg dirBlod font-bold">内部审核员证书</div><div class="mb-4 main"><img:src="crossOriginImageSrc"alt="Cross-origin image"style="width: 88px; height: 118px"fit="cover"/><div class="text-base mt-6">{{ form.name }}</div></div><div class="id text-base mb-4 dirBlod text-center">ID: {{ form.idNo }}</div><div class="text text-base"><div class="mb-4 dirBlod text-center">兹证明其参加了 {{ form.course }}</div><div class="ml-4 dirBlod">内部审核员培训课程并经考核合格,特发此证。</div></div><div class="footer mt-20"><div class="text-xs"><div class="dirBlod leading-6">发证日期 {{ form.authorizationDate }}</div><div class="dirBlod leading-6">编号 {{ form.certificateNo }}</div><div class="dirBlod leading-6">查询 {{ form.url }}</div></div><div class="text-base dirBlod gz-bg"><div class="gz-bg-img"></div>xx教育培训有限公司</div></div></div><div @click="captureAndDownload" class="text-center mt-5 text-blue-600 cursor-pointer">证书下载</div></el-card></div>
</template><script lang="ts" setup name="CertificateDetail">
import { ref, reactive, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import html2canvas from 'html2canvas'
import { saveAs } from 'file-saver'
// 后端基本路径
const url = '/dev-api'
const route = useRoute()
const form = reactive(JSON.parse(route.query.data as string))
const crossOriginImageSrc = ref(url + form.path) // 示例跨域图片
const contentToCapture = ref<HTMLDivElement>()async function captureAndDownload() {if (!contentToCapture.value) returntry {const canvas = await html2canvas(contentToCapture.value, {useCORS: true // 允许跨域请求})const imgDataUrl = canvas.toDataURL('image/png')const uniqueBlobUrl = URL.createObjectURL(new Blob([await fetch(imgDataUrl).then((res) => res.blob())], { type: 'image/png' }))saveAs(uniqueBlobUrl, 'screenshot.png')} catch (error) {console.error('Error capturing screenshot:', error)}
}
</script>
<style scoped lang="scss">
.main {display: flex;flex-direction: column;justify-content: center;align-items: center;
}
.card-header {height: 50px;
}
.el-card {margin-top: 60px;margin-bottom: 60px;width: 620px;
}.content {position: relative;background: url(@/assets/images/bg.png) no-repeat;background-size: 100% 100%;height: 880px;padding: 106px;font-family: 'dirBlod', sans-serif;.logo {background: url(@/assets/images/logo.png) no-repeat;background-size: 100% 100%;}
}.footer {display: flex;justify-content: space-between;align-items: center;
}
.dirBlod {font-family: 'dirBlod', sans-serif;
}
.gz-bg {position: relative;.gz-bg-img {position: absolute;top: -280%;left: 20%;width: 120px;height: 120px;background: url(@/assets/images/seal.png) no-repeat;background-size: 100% 100%;}
}
</style>

电子证书查询结果实现,效果呈现如下:

在这里插入图片描述
小结:
1、节省了存储电子证书图片的空间;
2、后端负责数据,前端负责呈现,实现更加灵活

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • RabbitMQ 基础架构流程 数据隔离 创建用户
  • Java高级Day38-网络编程作业
  • 如何打造高校实验室教学管理系统?Java SpringBoot助力,MySQL存储优化,2025届必备设计指南
  • 【Linux】Linux 管道:进程间通信的利器
  • 【微信小程序】搭建项目步骤 + 引入Tdesign UI
  • 计算机网络(三) —— 简单Udp网络程序
  • 通信工程学习:什么是AB地址总线、DB数据总线、CD控制总线
  • linux下oracle启动及关于pfile和spfile启动参数文件的配置
  • lvs DR模式调试
  • 利用 B+树索引提高查询效率的方法
  • Python世界:求解满足某完全平方关系的整数实践
  • Java内存模型详解
  • httprunner学习笔记(自用版)
  • LabVIEW步进电机控制方式
  • 云计算实训41——部署project_exam_system项目(续)
  • 【编码】-360实习笔试编程题(二)-2016.03.29
  • 2017-08-04 前端日报
  • C++类中的特殊成员函数
  • canvas 绘制双线技巧
  • CSS 专业技巧
  • Django 博客开发教程 16 - 统计文章阅读量
  • download使用浅析
  • extjs4学习之配置
  • Git 使用集
  • js 实现textarea输入字数提示
  • MySQL Access denied for user 'root'@'localhost' 解决方法
  • Mysql数据库的条件查询语句
  • Sass 快速入门教程
  • unity如何实现一个固定宽度的orthagraphic相机
  • vue数据传递--我有特殊的实现技巧
  • 大快搜索数据爬虫技术实例安装教学篇
  • 构造函数(constructor)与原型链(prototype)关系
  • 简析gRPC client 连接管理
  • 开源SQL-on-Hadoop系统一览
  • 巧用 TypeScript (一)
  • 如何在GitHub上创建个人博客
  • 使用权重正则化较少模型过拟合
  • 一些css基础学习笔记
  • ​​​​​​​ubuntu16.04 fastreid训练过程
  • ​浅谈 Linux 中的 core dump 分析方法
  • ​软考-高级-信息系统项目管理师教程 第四版【第19章-配置与变更管理-思维导图】​
  • #AngularJS#$sce.trustAsResourceUrl
  • #java学习笔记(面向对象)----(未完结)
  • ()、[]、{}、(())、[[]]命令替换
  • (2)nginx 安装、启停
  • (33)STM32——485实验笔记
  • (CVPRW,2024)可学习的提示:遥感领域小样本语义分割
  • (MIT博士)林达华老师-概率模型与计算机视觉”
  • (MonoGame从入门到放弃-1) MonoGame环境搭建
  • (PADS学习)第二章:原理图绘制 第一部分
  • (翻译)Entity Framework技巧系列之七 - Tip 26 – 28
  • (分享)一个图片添加水印的小demo的页面,可自定义样式
  • (十六)Flask之蓝图
  • (十五)devops持续集成开发——jenkins流水线构建策略配置及触发器的使用
  • (四) Graphivz 颜色选择