最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue?Canvas實現(xiàn)電子簽名

 更新時間:2022年07月21日 10:15:01   作者:歲末Zzz  
這篇文章主要為大家詳細介紹了Vue?Canvas實現(xiàn)電子簽名,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

最近再做移動端電子簽名,Vue+Canvas實現(xiàn),移動端、PC端均可,也可以從github下載 。

我在做這個功能的時候參考了 這個代碼,但是在移動端光標與實際劃線有偏移,我在我的代碼中修正了這個問題。

代碼

<template>
? ? ? <section class="signature">
? ? ? ? ? <div class="signatureBox">
? ? ? ? ? ? ? <div class="canvasBox" ref="canvasHW">
? ? ? ? ? ? ? ? ? <canvas ref="canvasF" @touchstart='touchStart' @touchmove='touchMove' @touchend='touchEnd' @mousedown="mouseDown" @mousemove="mouseMove" @mouseup="mouseUp"></canvas>
? ? ? ? ? ? ? ? ? <div class="btnBox">
? ? ? ? ? ? ? ? ? ? ? <div @click="overwrite">重寫</div>
? ? ? ? ? ? ? ? ? ? ? <div @click="commit">提交簽名</div>
? ? ? ? ? ? ? ? ? </div> ??
? ? ? ? ? ? ? </div>
? ? ? ? ? </div>
? ? ? ? ? <img class="imgCanvas" :src="imgUrl">
? ? ? </section> ? ?
</template>

JS

<script>
? export default {
? ? data() {
? ? ? return {
? ? ? ? stageInfo:'',
? ? ? ? imgUrl:'',
? ? ? ? client: {},
? ? ? ? points: [],
? ? ? ? canvasTxt: null,
? ? ? ? startX: 0,
? ? ? ? startY: 0,
? ? ? ? moveY: 0,
? ? ? ? moveX: 0,
? ? ? ? endY: 0,
? ? ? ? endX: 0,
? ? ? ? w: null,
? ? ? ? h: null,
? ? ? ? isDown: false,
? ? ? ? isViewAutograph: this.$route.query.isViews > 0,
? ? ? ? contractSuccess: this.$route.query.contractSuccess
? ? ? }
? ? },
? ? mounted() {
? ? ? let canvas = this.$refs.canvasF
? ? ? canvas.height = this.$refs.canvasHW.offsetHeight - 500
? ? ? canvas.width = this.$refs.canvasHW.offsetWidth - 50
? ? ? this.canvasTxt = canvas.getContext('2d')
? ? ? this.stageInfo = canvas.getBoundingClientRect()
? ? },
? ? methods: {
? ? ? //mobile
? ? ? touchStart(ev) {
? ? ? ? ev = ev || event
? ? ? ? ev.preventDefault()
? ? ? ? if (ev.touches.length == 1) {
? ? ? ? ? let obj = {
? ? ? ? ? ? x: ev.targetTouches[0].clienX,
? ? ? ? ? ? y: ev.targetTouches[0].clientY,
? ? ? ? ? }
? ? ? ? ? this.startX = obj.x
? ? ? ? ? this.startY = obj.y
? ? ? ? ? this.canvasTxt.beginPath()
? ? ? ? ? this.canvasTxt.moveTo(this.startX, this.startY)
? ? ? ? ? this.canvasTxt.lineTo(obj.x, obj.y)
? ? ? ? ? this.canvasTxt.stroke()
? ? ? ? ? this.canvasTxt.closePath()
? ? ? ? ? this.points.push(obj)
? ? ? ? }
? ? ? },
? ? ? touchMove(ev) {
? ? ? ? ev = ev || event
? ? ? ? ev.preventDefault()
? ? ? ? if (ev.touches.length == 1) {
? ? ? ? ? let obj = {
? ? ? ? ? ? x: ev.targetTouches[0].clientX - this.stageInfo.left,
? ? ? ? ? ? y: ev.targetTouches[0].clientY - this.stageInfo.top
? ? ? ? ? }
? ? ? ? ? this.moveY = obj.y
? ? ? ? ? this.moveX = obj.x
? ? ? ? ? this.canvasTxt.beginPath()
? ? ? ? ? this.canvasTxt.moveTo(this.startX, this.startY)
? ? ? ? ? this.canvasTxt.lineTo(obj.x, obj.y)
? ? ? ? ? this.canvasTxt.stroke()
? ? ? ? ? this.canvasTxt.closePath()
? ? ? ? ? this.startY = obj.y
? ? ? ? ? this.startX = obj.x
? ? ? ? ? this.points.push(obj)
? ? ? ? }
? ? ? },
? ? ? touchEnd(ev) {
? ? ? ? ev = ev || event
? ? ? ? ev.preventDefault()
? ? ? ? if (ev.touches.length == 1) {
? ? ? ? ? let obj = {
? ? ? ? ? ? x: ev.targetTouches[0].clientX - this.stageInfo.left,
? ? ? ? ? ? y: ev.targetTouches[0].clientY - this.stageInfo.top
? ? ? ? ? }
? ? ? ? ? this.canvasTxt.beginPath()
? ? ? ? ? this.canvasTxt.moveTo(this.startX, this.startY)
? ? ? ? ? this.canvasTxt.lineTo(obj.x, obj.y)
? ? ? ? ? this.canvasTxt.stroke()
? ? ? ? ? this.canvasTxt.closePath()
? ? ? ? ? this.points.push(obj)
? ? ? ? }
? ? ? },
? ? ? //pc
? ? ? mouseDown(ev) {
? ? ? ? ev = ev || event
? ? ? ? ev.preventDefault()
? ? ? ? if (1) {
? ? ? ? ? let obj = {
? ? ? ? ? ? x: ev.offsetX,
? ? ? ? ? ? y: ev.offsetY
? ? ? ? ? }
? ? ? ? ? this.startX = obj.x
? ? ? ? ? this.startY = obj.y
? ? ? ? ? this.canvasTxt.beginPath()
? ? ? ? ? this.canvasTxt.moveTo(this.startX, this.startY)
? ? ? ? ? this.canvasTxt.lineTo(obj.x, obj.y)
? ? ? ? ? this.canvasTxt.stroke()
? ? ? ? ? this.canvasTxt.closePath()
? ? ? ? ? this.points.push(obj)
? ? ? ? ? this.isDown = true
? ? ? ? }
? ? ? },
? ? ? mouseMove(ev) {
? ? ? ? ev = ev || event
? ? ? ? ev.preventDefault()
? ? ? ? if (this.isDown) {
? ? ? ? ? let obj = {
? ? ? ? ? ? x: ev.offsetX,
? ? ? ? ? ? y: ev.offsetY
? ? ? ? ? }
? ? ? ? ? this.moveY = obj.y
? ? ? ? ? this.moveX = obj.x
? ? ? ? ? this.canvasTxt.beginPath()
? ? ? ? ? this.canvasTxt.moveTo(this.startX, this.startY)
? ? ? ? ? this.canvasTxt.lineTo(obj.x, obj.y)
? ? ? ? ? this.canvasTxt.stroke()
? ? ? ? ? this.canvasTxt.closePath()
? ? ? ? ? this.startY = obj.y
? ? ? ? ? this.startX = obj.x
? ? ? ? ? this.points.push(obj)
? ? ? ? }
? ? ? },
? ? ? mouseUp(ev) {
? ? ? ? ev = ev || event
? ? ? ? ev.preventDefault()
? ? ? ? if (1) {
? ? ? ? ? let obj = {
? ? ? ? ? ? x: ev.offsetX,
? ? ? ? ? ? y: ev.offsetY
? ? ? ? ? }
? ? ? ? ? this.canvasTxt.beginPath()
? ? ? ? ? this.canvasTxt.moveTo(this.startX, this.startY)
? ? ? ? ? this.canvasTxt.lineTo(obj.x, obj.y)
? ? ? ? ? this.canvasTxt.stroke()
? ? ? ? ? this.canvasTxt.closePath()
? ? ? ? ? this.points.push(obj)
? ? ? ? ? this.points.push({x: -1, y: -1})
? ? ? ? ? this.isDown = false
? ? ? ? }
? ? ? },
? ? ? //重寫
? ? ? overwrite() {
? ? ? ? this.canvasTxt.clearRect(0, 0, this.$refs.canvasF.width, this.$refs.canvasF.height)
? ? ? ? this.points = []
? ? ? },
? ? ? //提交簽名
? ? ? commit() {
? ? ? ? this.imgUrl=this.$refs.canvasF.toDataURL();
? ? ? ? console.log(this.$refs.canvasF.toDataURL()) //簽名img回傳后臺
? ? ? }
? ? }
? }
</script>

CSS

<style scoped>
? .signatureBox {
? ? width: 100%;
? ? height: calc(100% - 50px);
? ? box-sizing: border-box;
? ? overflow: hidden;
? ? background: #fff;
? ? z-index: 100;
? ? display: flex;
? ? flex-direction: column;
? }
? .canvasBox {
? ? box-sizing: border-box;
? ? flex: 1;
? }
? canvas {
? ? border: 1px solid #7d7d7d;
? }
? .btnBox {
? ? padding: 10px;
? ? text-align: center;
? }
? .btnBox button:first-of-type {
? ? background: transparent;
? ? border-radius: 4px;
? ? height: 40px;
? ? width: 80px;
? ? font-size: 14px;
? }
? .btnBox button:last-of-type {
? ? background: #71b900;
? ? color: #fff;
? ? border-radius: 4px;
? ? height: 40px;
? ? width: 80px;
? ? font-size: 14px;
? }
</style>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 利用nginx部署vue項目的全過程

    利用nginx部署vue項目的全過程

    今天要用到服務(wù)器nginx,還需要把自己的vue的項目部署到服務(wù)器上去所以就寫一下記錄下來,下面這篇文章主要給大家介紹了關(guān)于利用nginx部署vue項目的相關(guān)資料,需要的朋友可以參考下
    2022-03-03
  • vue靜態(tài)界面之左二級菜單右表單表格的實例代碼

    vue靜態(tài)界面之左二級菜單右表單表格的實例代碼

    這篇文章主要介紹了vue靜態(tài)界面之左二級菜單右表單表格,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08
  • vue實現(xiàn)滾動條始終懸浮在頁面最下方

    vue實現(xiàn)滾動條始終懸浮在頁面最下方

    這篇文章主要為大家詳細介紹了vue實現(xiàn)滾動條始終懸浮在頁面最下方,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • vue-router路由模式詳解(小結(jié))

    vue-router路由模式詳解(小結(jié))

    這篇文章主要介紹了vue-router路由模式詳解(小結(jié)),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-08-08
  • 手把手教你如何創(chuàng)建一個VUE項目(超簡單)

    手把手教你如何創(chuàng)建一個VUE項目(超簡單)

    這篇文章主要給大家介紹了關(guān)于如何創(chuàng)建一個VUE項目的相關(guān)資料,創(chuàng)建vue項目有很多種方式,這里給大家介紹一種非常簡單的方法,需要的朋友可以參考下
    2023-08-08
  • 封裝 axios+promise通用請求函數(shù)操作

    封裝 axios+promise通用請求函數(shù)操作

    這篇文章主要介紹了封裝 axios+promise通用請求函數(shù)操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • vue歌曲進度條示例代碼

    vue歌曲進度條示例代碼

    這篇文章主要介紹了vue歌曲進度條demo,本文通過示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-10-10
  • Element-UI日期選擇器(選擇日期范圍)禁用未來日期實現(xiàn)代碼

    Element-UI日期選擇器(選擇日期范圍)禁用未來日期實現(xiàn)代碼

    我們在網(wǎng)頁開發(fā)時通常需要用到一些日期組件來方便用戶選擇時間,其中element日期組件是一個非常好用的工具,這篇文章主要給大家介紹了關(guān)于Element-UI日期選擇器(選擇日期范圍)禁用未來日期的相關(guān)資料,需要的朋友可以參考下
    2024-02-02
  • vue的基本用法與常見指令

    vue的基本用法與常見指令

    Vue.js是JavaScript MVVM(Model-View-ViewModel)庫,十分簡潔,Vue核心只關(guān)注視圖層,相對AngularJS提供更加簡潔、易于理解的API。接下來通過本文給大家介紹vue的基本用法與常見指令,感興趣的朋友一起看看吧
    2017-08-08
  • ElementUI修改實現(xiàn)更好用圖片上傳預(yù)覽組件

    ElementUI修改實現(xiàn)更好用圖片上傳預(yù)覽組件

    這篇文章主要為大家介紹了ElementUI修改實現(xiàn)更好用圖片上傳預(yù)覽組件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-09-09

最新評論

武穴市| 铜川市| 扎兰屯市| 松桃| 文成县| 色达县| 临夏县| 井研县| 菏泽市| 额济纳旗| 定日县| 武陟县| 宣化县| 沁阳市| 岗巴县| 怀来县| 龙海市| 德兴市| 康平县| 龙山县| 元朗区| 澎湖县| 乐山市| 平遥县| 博乐市| 田东县| 义乌市| 探索| 伊川县| 凤台县| 梨树县| 离岛区| 天全县| 华安县| 桂平市| 海原县| 东乌珠穆沁旗| 花垣县| 阿克陶县| 沅陵县| 色达县|