Vue-esign手写签字、鼠标写名字目前兼容pc、桌面端(electron)、移动端;可返回base64或者文件流

Vue-esign

手写签字、鼠标写名字

目前兼容pc、桌面端(electron)、移动端;

可返回base64或者文件流

  1. 安装:npm install vue-esign save

2、main.js文件中全局引入:

// (vue2)签字

import vueEsign from 'vue-esign'

Vue.use(vueEsign)

vue3可直接导入后使用

import vueEsign from 'vue-esign'

3、页面内容

<div style="background-color: #ffff;padding-bottom:4px;">

          <vue-esign ref="esign" :width="900" :height="300" :isCrop="isCrop" :lineWidth="lineWidth" :lineColor="lineColor" :bgColor="bgColor" />

          <div style="margin: 10px">

            <button @click="handleReset" class="mr-[10px] bg-[#1890ff]">清空画板</button>

            <button @click="handleGenerate" class="mr-[10px] bg-[#1890ff]"> 生成图片</button>

          </div>

 </div>

4、Vue3:

/**

 * --------- 签名 ------------

 */
const constlineWidth = 6;

const lineColor = '#000000';

const bgColor = ref('#ffff');

const resultImg = ref('');

const isCrop = false;

const esign = ref();

const qz = () => {};


const handleReset = () => {

  esign.value.reset(); //清空画布

  bgColor.value = '#ffff';

};



/**

 * 将base64转化成图片方法

 */

const base64ImgtoFile = (dataurl, filename = 'file') => {

  const arr = dataurl.split(',');

  const mime = arr[0].match(/:(.*?);/)[1];

  const suffix = mime.split('/')[1];

  const bstr = atob(arr[1]);

  let n = bstr.length;

  const u8arr = new Uint8Array(n);

  while (n--) {

    u8arr[n] = bstr.charCodeAt(n);

  }

  return new File([u8arr], `${filename}.${suffix}`, {

    type: mime,

  });

};



/**

 * 签字生成的base64图片

 */

const handleGenerate = () => {

  esign.value

    .generate()

    .then((res) => {

      resultImg.value = res; // 得到了签字生成的base64图片

      let imgFile = base64ImgtoFile(res, 'file'); //得到文件格式

    })

    .catch((err) => {

      // 没有签名,点击生成图片时调用

      alert(err); // 画布没有签字时会执行这里 'Not Signned'

    });

};
  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值