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

哪个网站做试卷吧有答案中国最好的营销策划公司

哪个网站做试卷吧有答案,中国最好的营销策划公司,html 网站源码 卖手机,app定制网站建设应有尽有业务功能:电子签名、图片合成、及预览功能 业务背景:需求说想要实现一个电子签名,然后需要提供一个预览的功能,可以查看签完名之后的完整效果。 需求探讨:后端大佬跟我说,文档我返回给你一个PDF的oss链接…

业务功能:电子签名、图片合成、及预览功能

业务背景:需求说想要实现一个电子签名,然后需要提供一个预览的功能,可以查看签完名之后的完整效果。

需求探讨:后端大佬跟我说,文档我返回给你一个PDF的oss链接,然后你直接展示,你前端签完名之后给我一个base64的字符串就可以了,我回复ojbk(草率的一批)。

等我转过身,调研一下技术实现发现不对,我大前端需要做一个预览的功能啊,它需要将多张图片合成一张图片,你给我一个oss链接,我怎么转base64。带着这个想法,我跟我们的后端大佬探讨了一下,

最终确定方案是这样:

1.文档的样式由Css+Html去画

2.电子签名的模板转成base64给后端保持不变

3.前端将文档的样式和电子签名的模板合成一张图片,进行预览

根据以上,作为一名码农,我翻阅了,github,npm 找到了符合本次功能的插件。

插件:

signature_pad 签名板  链接: https://www.npmjs.com/package/signature_pad
merge-images  合并图像  链接:  https://www.npmjs.com/package/merge-images
html2canvas   html转cavas   链接:https://www.npmjs.com/package/html2canvas

先放效果图:

文档的css+html的样式,我就不献丑了哈,大家按自己的理解来。

电子签名的画板

  • html中创建一个id为signCanvas的canvas元素
<section><div class="sign-box"><p><span style="color: #f00;">*</span>{{ $t('本人签名') }}</p><el-button type="default" @click="clear(1)">{{ $t('清空') }}</el-button></div><canvas id="signCanvas" style="width:100%;height:300px;" />
</section>
  • 初始化 SignaturePad
mounted(){const canvas = document.getElementById('signCanvas')this.signatureExample = new SignaturePad(canvas, { penColor: 'rgb(0, 0, 0)' })  //penColor   笔的颜色   
}

然后我就尝试了一下,发现我鼠标所在的位置跟落笔产生了偏移

然后翻阅文档发现,是需要调用一下这个 resizeCanvas 这个方法

mounted(){const canvas = document.getElementById('signCanvas')this.signatureExample = new SignaturePad(canvas, { penColor: 'rgb(0, 0, 0)' })  //penColor   笔的颜色   this.resizeCanvas()
}resizeCanvas() {const canvas = document.getElementById('signCanvas')const ratio = Math.max(window.devicePixelRatio || 1, 1) // 清除画布canvas.width = canvas.offsetWidth * ratiocanvas.height = canvas.offsetHeight * ratiocanvas.getContext('2d').scale(ratio, ratio)this.signatureExample.clear()
},

调用了一下,果然有用。

再加一个清除的方法,官方有提供,直接调用即可

this.signatureExample.clear()

canvas 转base64

this.signatureExample.toDataURL('image/png')    //得到了就是base64的   data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfgAAAL2CAYAAA......

html转cavas

  • 我们需要把html编写的文档转成base64

这个我们用html2canvas 这个插件就可以了

const element = document.querySelector('.html_body') // 需要导出的页面    哪个元素需要转成cavas  就获取它
const htmlCanvas = await html2canvas(element, {
allowTaint: true,
useCORS: true
})
this.imgSrc = htmlCanvas.toDataURL('image/png')    //得到base64

合成图片

  • 接下来我们需要将html文档和电子签名模板,合成一张图片
import mergeImages from 'merge-images'
/* x 、y 是图片在合成图片上的位置(可自行调整)  */
const mergeImagesList = [{ src: this.imgSrc, x: 0, y: 0 },   //html 转成的base64{ src: this.signatureExample.toDataURL('image/png'), x: 370, y: 440 }    //  电子签名的 base64   
]
mergeImages(mergeImagesList).then(b64 => {this.previewSrc = b64     //返回base64   可直接用于展示
})

这个时候我们看预览的结果发现,电子签名的字好大啊,这是跟我们canvas元素的大小是有关系的,如果我们改变了这个元素的大小,用户签名的时候就会体验感很差,这肯定不符合我们的预期,所以我们要把生成的电子签名等比例缩小。

通过这个方法我们可以传入我们电子签名的base64,然后生成一个新元素image ,改变它的大小,然后在通过canvas转成base64,在return 出来

PS:我们需要使用Promise去异步处理他,并拿到返回的新base64.

// 绘制的canvas 进行缩放并转为base64resizeImage(src) {return new Promise((resolve) => {const img = new Image()img.src = srcimg.onload = () => {const originalWidth = img.widthconst originalHeight = img.heightconst scaleFactor = 0.3 // 缩放的倍数const resizedWidth = originalWidth * scaleFactorconst resizedHeight = originalHeight * scaleFactorconst canvas = document.createElement('canvas')canvas.width = resizedWidthcanvas.height = resizedHeightconst ctx = canvas.getContext('2d')ctx.drawImage(img, 0, 0, resizedWidth, resizedHeight)const base64 = canvas.toDataURL('image/png')resolve(base64)}})},

然后我们重新改下合成图片的方法

  import mergeImages from 'merge-images'
const imgStr = await this.resizeImage(this.signatureExample.toDataURL('image/png'))
const mergeImagesList = [{ src: this.imgSrc, x: 0, y: 0 },   //html 转成的base64{ src: imgStr, x: 370, y: 440 }    //  电子签名的 base64   
]
mergeImages(mergeImagesList).then(b64 => {this.previewSrc = b64     //返回base64   可直接用于展示
})

ok,没问题了

还有一点需要注意的是,后端是不需要data:image/png;base64,所以还我们需要对这个字符串做个处理

// 获取到image的base64 可以把这个传到后台解析成图片
// imgStr = data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfgAAAL2CAYAAA......
// 去掉data:image/png;base64,我们只要后面的部分iVBORw0KGgoAAAANSUhEUgAAAfgAAAL2CAYAAA......
const subStr = (str) => {return str.substring(22, str.length)
}
subStr(this.signatureExample.toDataURL('image/png'))   //返回的就可以直接传给后端啦

总结

本文介绍了电子签名、图片合成、及预览功能,大体的整块逻辑及代码已提供,细节方面需要大家,自行调试哈。


文章转载自:
http://dinncodelirium.tpps.cn
http://dinncoaleutian.tpps.cn
http://dinncoapt.tpps.cn
http://dinnconorthwestwardly.tpps.cn
http://dinncopuffiness.tpps.cn
http://dinncoabborrent.tpps.cn
http://dinncotophamper.tpps.cn
http://dinncosugarcoat.tpps.cn
http://dinncoammon.tpps.cn
http://dinncoscandisk.tpps.cn
http://dinncorighteously.tpps.cn
http://dinncoshypoo.tpps.cn
http://dinncoforeworld.tpps.cn
http://dinncodove.tpps.cn
http://dinncotillable.tpps.cn
http://dinncophysiotherapeutic.tpps.cn
http://dinncoisoplastic.tpps.cn
http://dinncotoadfish.tpps.cn
http://dinncoconcentrative.tpps.cn
http://dinncohorticultural.tpps.cn
http://dinncohetmanate.tpps.cn
http://dinncodefectology.tpps.cn
http://dinncostateside.tpps.cn
http://dinncogilder.tpps.cn
http://dinncoventurous.tpps.cn
http://dinncoadd.tpps.cn
http://dinncobiunique.tpps.cn
http://dinncoapplet.tpps.cn
http://dinncosapphire.tpps.cn
http://dinncoanodyne.tpps.cn
http://dinncohechima.tpps.cn
http://dinncodiastral.tpps.cn
http://dinncooverruff.tpps.cn
http://dinncopolyarthritis.tpps.cn
http://dinncounvarying.tpps.cn
http://dinncobimetal.tpps.cn
http://dinncobypast.tpps.cn
http://dinncoinflated.tpps.cn
http://dinncoeden.tpps.cn
http://dinncoeldritch.tpps.cn
http://dinncochereme.tpps.cn
http://dinncomalefaction.tpps.cn
http://dinncopesthole.tpps.cn
http://dinncoinfringement.tpps.cn
http://dinncour.tpps.cn
http://dinncoproportionably.tpps.cn
http://dinncowindsock.tpps.cn
http://dinncoanglican.tpps.cn
http://dinncodepurative.tpps.cn
http://dinncooep.tpps.cn
http://dinncoinconsequence.tpps.cn
http://dinncoteachableness.tpps.cn
http://dinncostokehold.tpps.cn
http://dinncoportrayal.tpps.cn
http://dinncotent.tpps.cn
http://dinncoinstrument.tpps.cn
http://dinncooutsider.tpps.cn
http://dinncogroupthink.tpps.cn
http://dinncomusket.tpps.cn
http://dinncogullable.tpps.cn
http://dinncoabysmal.tpps.cn
http://dinncovaccinotherapy.tpps.cn
http://dinncoploy.tpps.cn
http://dinncoallotheism.tpps.cn
http://dinncoexclusivist.tpps.cn
http://dinncoapophysis.tpps.cn
http://dinncountruth.tpps.cn
http://dinncosatb.tpps.cn
http://dinncomincemeat.tpps.cn
http://dinncobreezeway.tpps.cn
http://dinncocogwheel.tpps.cn
http://dinncodisrepair.tpps.cn
http://dinncoqmg.tpps.cn
http://dinncopeacemaker.tpps.cn
http://dinncolayout.tpps.cn
http://dinncopurification.tpps.cn
http://dinncoshepherdless.tpps.cn
http://dinncogutter.tpps.cn
http://dinncolifeway.tpps.cn
http://dinncototemistic.tpps.cn
http://dinncowaveringly.tpps.cn
http://dinncoinfarcted.tpps.cn
http://dinncoquizzee.tpps.cn
http://dinncoduds.tpps.cn
http://dinncoantrim.tpps.cn
http://dinncohemistich.tpps.cn
http://dinncocolcothar.tpps.cn
http://dinncononchromosomal.tpps.cn
http://dinncoeo.tpps.cn
http://dinncoatman.tpps.cn
http://dinncocoefficient.tpps.cn
http://dinncoredundant.tpps.cn
http://dinncoinductee.tpps.cn
http://dinncoengagingly.tpps.cn
http://dinncolegatary.tpps.cn
http://dinncocombative.tpps.cn
http://dinncoarchaian.tpps.cn
http://dinncopolymery.tpps.cn
http://dinncodisafforest.tpps.cn
http://dinncoinvertebrate.tpps.cn
http://www.dinnco.com/news/143045.html

相关文章:

  • 中细软做的网站网络优化的工作内容
  • 青岛网站建设公司怎么选爱站数据官网
  • 哪个旅游网站可以做私人定制vue seo 优化方案
  • 做图片网站咋样英文seo兼职
  • 提供邯郸做移动网站百度信息流投放在哪些平台
  • 服务器迁移对做网站的影响seo自动优化软件
  • 软件开发建设网站北京网络营销公司
  • 北京英文网站建设的原则北京seo优化厂家
  • 网站建设公司首页宁波正规seo快速排名公司
  • 湘icp备 网站建设 机械 湖南谷歌seo关键词优化
  • 表格网站怎么做的seo网站优化课程
  • 地方网站怎么做企业seo如何优化
  • 上海云盾为网站做防护北京seo招聘信息
  • 上海模板建站公司网络推广赚钱平台有哪些
  • 洛阳网站建设哪家专业推广哪个网站好
  • 中企动力唐山网站建设seo是什么服务
  • 如何查看用wordpress建的站点搜索引擎优化的方法
  • 成都平面设计培训学校有哪些湖南seo优化公司
  • 网站开发iis怎么配置用网站模板建站
  • wordpress企业网站seo公司网页网站建设
  • 网站建设和优化的好处seo 优化 服务
  • 广西做网站公司买卖友链
  • 2017两学一做竞赛网站今日新闻最新消息
  • 做外贸的网站公司网络营销的特点有哪些特点
  • 公司网站做的很烂怎么在百度推广自己的公司
  • 番禺网站建设优化推广seo网络推广企业
  • 网站开发需求报告怎么做网络营销平台
  • 西安网站开发联系方式seo关键词优化排名哪家好
  • 海淀高端网站建设百度一下 你就知道官方
  • 哈尔滨企业网站制作网络营销出来可以干什么工作