vue2移动端电子手签封装

使用到了vant-ui和canvas

html部分

<template>
  <div>
    <div style="border: 1px solid #eee" ref="canvasBox">
      <canvas class="canvasId" />
    </div>
    <div class="btnBox">
      <van-button round plain color="#396cd1" @click="clear">{{lang=='cn'?'重签\nre-sign':'re-sign'}}</van-button>
      <van-button round color="#396cd1" @click="save">{{lang=='cn'?'确定\nconfirm':'confirm'}}</van-button>
    </div>
  </div>
</template>

js部分


<script>
import SignaturePad from 'signature_pad'
import { Button, Notify } from 'vant'
import { mapGetters } from 'vuex'
export default {
  name: 'signature',
  components: {
    [Button.name]: Button,
    [Notify.Component.name]: Notify.Component
  },
  data () {
    return {
      SignaturePad: null,
      config: {
        penColor: '#000000', // 笔刷颜色
        minWidth: 3 // 最小宽度
      }
    }
  },
  computed: {
    ...mapGetters(['lang'])
  },
  mounted () {
    this.getCanvas()
  },
  methods: {
    getCanvas () {
      var canvas = document.querySelector('.canvasId')
      this.signaturePad = new SignaturePad(canvas, this.config)
      canvas.height = 200
      canvas.width = this.$refs.canvasBox.clientWidth
    },
    base64ToFile (base64, fileName) {
      const arr = base64.split(',')
      const mime = arr[0].match(/:(.*?);/)[1]
      const bytes = atob(arr[1])
      let n = bytes.length
      const ia = new Uint8Array(n)
      while (n--) {
        ia[n] = bytes.charCodeAt(n)
      }
      return new File([ia], fileName, { type: mime })
    },
    // 保存
    save () {
      // 默认保存为png格式
      if (this.signaturePad.isEmpty()) {
        Notify({ type: 'danger', message: '电子签名不能为空' })
      } else {
        this.$emit('setSign', this.signaturePad.toDataURL())
      }
    },
    // 清除
    clear () {
      // 清除画布内容
      this.signaturePad.clear()
    }
  }
}
</script>

css部分


<style scoped lang="scss">
.btnBox {
  padding: 10px;
  text-align: center;
  display: flex;
  justify-content: center;
  .van-button {
    width: 34%;
    height: 4.2rem;
    margin-left: 1rem;
    margin-right: 1rem;
  }
  /deep/ .van-button--info {
    height: 2.4rem;
    padding: 0 2.4rem;
    &:first-child {
      margin-right: 2.4rem;
    }
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue开发移动端App时,可以使用一些工具和组件来进行适配和开发。首先,在main.js中引入`vue-awesome-mui`并使用`Vue.use(Mui)`来引入MUI组件库。注意,MUI只能在手机上使用,所以在浏览器运行时可能无法看到效果。\[1\] 为了适配移动端设备的屏幕大小和比例差异,可以使用`flexible.js`进行适配。在main.js中引入`flexible.js`文件,并将其作为静态文件放在最外层的static文件夹中引入。这样可以实现移动端项目的适配。\[2\] 在开发移动端App时,可以使用一些常见的组件和标签,如`router-link`用于导航跳转,`keep-alive`用于缓存不活动的组件实例,以提高性能。此外,还可以使用一些UI组件库,如`mint-ui`和`vant-ui`来快速构建界面。\[2\] 除此之外,还可以使用Axios进行网络请求的封装,使用iconfont图标库,连接真机进行调试,打包APK并发布应用。在开发过程中,可以不断学习并更新项目,逐步完善项目结构和功能。\[3\] 总结来说,开发Vue移动端App需要引入相应的组件库和工具,进行适配和开发,并不断学习和更新项目。 #### 引用[.reference_title] - *1* *2* *3* [vue开发移动端app-学习记录](https://blog.csdn.net/weixin_44736005/article/details/113406120)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值