vue签字板

安装相关插件

cnpm i vue-esign --save

全局引入

import vueEsign from 'vue-esign'
Vue.use(vueEsign)

在弹窗里面添加

<el-dialog
  width="60%"
  title="签字"
  :visible.sync="innerVisible"
  append-to-body
  :before-close="handleClose1"
  :close-on-click-modal="false"
>
  <vue-esign
    style="border: solid 1px #000"
    ref="esign"
    :width="1200"
    :height="600"
    :isCrop="isCrop"
    :lineColor="lineColor"
  />
  <span slot="footer" class="dialog-footer">
    <button @click="handleClose1" type="button">
      <span>关 闭</span>
    </button>

    <button @click="handleGenerate()" type="button">
      <span>确 定</span>
    </button>
    <button @click="handleReset()" type="button">
      <span>清 空</span>
    </button>
  </span>
</el-dialog>


<img :src="imgimg" alt="" />    // 签完字直接显示

<img v-if="resultImg != null" :src="src + resultImg" alt=""/>  // 后台返回显示 先上传再调用

相关变量

  innerVisible: false,
  lineColor: "#000",
  isCrop: false,
  resultImg: null,
  imgimg: null,

相关方法

// 关闭签字板
handleClose1() {
  this.innerVisible = false;
  this.handleReset();
},
// 签字确定按钮
handleGenerate() {
  this.$refs["esign"]
    .generate()
    .then((res) => {
      // this.imgimg = res; // 用来直接显示
      this.imgimg = this.base64ImgtoFile(res);
      this.resultImg = res; // 得到了签字生成的base64图片
      this.innerVisible = false;
      const formData = new FormData();
      formData.append("file", this.imgimg);   // 将图片以64传过去
      uploadImages(formData)  // 上传方法
        .then((res) => {
          this.resultImg = res.fileName.uploadPath;
          this.fileName = res.fileName;
        })
        .catch((err) => {});
      this.handleReset();
    })
    .catch((err) => {
      //  没有签名,点击生成图片时调用
      this.$message({
        message: err + " 未签名!",
        type: "warning",
      });
    });
},
// 清空签字版
handleReset() {
  this.$refs["esign"].reset(); //清空画布
},



// 图片转化
base64ImgtoFile(dataurl, filename = "file") {
  let arr = dataurl.split(",");
  let mime = arr[0].match(/:(.*?);/)[1];
  let suffix = mime.split("/")[1];
  let bstr = atob(arr[1]);
  let n = bstr.length;
  let u8arr = new Uint8Array(n);
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n);
  }
  return new File([u8arr], `${filename}.${suffix}`, {
    type: mime,
  });
},

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猫和老许

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值