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

uniapp小程序实现横屏手写签名

在这里插入图片描述

<template>
  <view class="signBox column-me">
    <!-- 这个是自定义的title-可根据自己封装的title的作为调整 -->
    <status-bar title="电子签名" :bgColor="null"></status-bar>
    <view class="topHint">请绘制清晰可辨的签名并保存</view>
    <canvas class="canvas flex1" :canvas-id="cid" :id="cid" @touchstart="touchstart" @touchmove="touchmove"
      @touchend="touchend" :disable-scroll="true"></canvas>
    <view class="btn margin-top10 margin-bottom10">
      <view class="cancelBtn" @click="reWrite">重写</view>
      <view class="saveBtn margin-left30" @click="save">保存</view>
    </view>
  </view>
</template>

<script>
  export default {
    components: {},
    data() {
      return {
        line: [],
        radius: 0,
        taskId: '',
        //以下与签名有关参数
        dom: null,
        cid: 'canvas', //画布id
        Strokes: [],
        showCanvasDialog: false,
        canvasImg: '', //签名图片
      }
    },
    onLoad(e) {
      this.taskId = e.taskId
    },
    computed: {},
    mounted: function() {
      let that = this
      this.initCanvas()
    },
    methods: {
      initCanvas() {
        let that = this
        this.$nextTick(function() {
          this.dom = uni.createCanvasContext(this.cid, this);
          var query = wx.createSelectorQuery();
          query.select('#canvas').boundingClientRect();
          query.exec(function(res) {
            let widths = res[0].width
            let heights = res[0].height
            that.dom.rect(0, 0, widths, heights)
            that.dom.setFillStyle('#FFFFFF')
            that.dom.fill()
            that.dom.draw()
          })
        });
      },
      touchstart(e) {
        this.Strokes.push({
          imageData: null,
          style: {
            color: '#000000',
            lineWidth: '3',
          },
          points: [{
            x: e.touches[0].x,
            y: e.touches[0].y,
            type: e.type,
          }]
        })
        this.drawLine(this.Strokes[this.Strokes.length - 1], e.type);
      },
      touchmove(e) {
        this.Strokes[this.Strokes.length - 1].points.push({
          x: e.touches[0].x,
          y: e.touches[0].y,
          type: e.type,
        })
        this.drawLine(this.Strokes[this.Strokes.length - 1], e.type);
      },
      touchend(e) {
        if (this.Strokes[this.Strokes.length - 1].points.length < 2) { //当此路径只有一个点的时候
          this.Strokes.pop();
        }
      },
      drawLine(StrokesItem, type) {
        if (StrokesItem.points.length > 1) {
          this.dom.setLineCap('round')
          this.dom.setStrokeStyle(StrokesItem.style.color);
          this.dom.setLineWidth(StrokesItem.style.lineWidth);
          this.dom.moveTo(StrokesItem.points[StrokesItem.points.length - 2].x, StrokesItem.points[StrokesItem
            .points.length -
            2].y);
          this.dom.lineTo(StrokesItem.points[StrokesItem.points.length - 1].x, StrokesItem.points[StrokesItem
            .points.length -
            1].y);
          this.dom.stroke();
          this.dom.draw(true);
        }
      },
      //重写签名
      reWrite() {
        this.Strokes = [];
        this.dom.draw();
        this.initCanvas()
      },
      // 保存图片
      save() {
        let that = this
        uni.canvasToTempFilePath({
          canvasId: 'canvas',
          fileType: 'png',
          quality: 1, //图片质量
          success: function(res) {
            let imgs = [res.tempFilePath]
            that.$.upload_img(imgs, 0, res => {
              let imgUrl = res.data //签名图片
              let mediaUrl = that.$.get_data('mediaUrl') //采集图片
              if (that.$.isEmpty(mediaUrl)) {
                mediaUrl = ''
              }
              that.$.ajax("POST", "/customer/user/checkTask", {
                taskId: that.taskId,
                status: 1, //状态:1同意2拒绝  
                signImage: imgUrl,
                userVideo: mediaUrl,
              }, (res) => {
                if (res.code === 1000) {
                  that.$.ti_shi(res.message)
                  setTimeout(() => {
                    uni.$emit('signOk')
                    that.$.back()
                  }, 1000)
                } else {
                  that.$.ti_shi(res.message)
                }
              });
            })
          },
          fail(e) {
            console.log(e)
          }
        })
      }
    }
  }
</script>

<style scoped lang="less">
  .signBox {
    position: relative;
    overflow: hidden;
    background-color: #F6F6F6;
    height: 100vh;
    width: 100vw;

    .canvas {
      width: 100%;
      background: #FFFFFF;
    }

    .topHint {
      width: 100%;
      height: 60rpx;
      line-height: 60rpx;
      font-size: 28rpx;
      color: #6D7984;
      text-align: center;
      background: ;
    }

    .btn {
      width: 100%;
      height: 132rpx;
      display: flex;
      align-items: center;
      justify-content: center;

      .saveBtn {
        width: 300rpx;
        height: 88rpx;
        line-height: 88rpx;
        background: #215AA0;
        border-radius: 20rpx;
        text-align: center;
        font-size: 32rpx;
        color: #FFFFFF;
      }

      .cancelBtn {
        width: 298rpx;
        height: 86rpx;
        line-height: 86rpx;
        background: #FFFFFF;
        border-radius: 20rpx;
        text-align: center;
        font-size: 32rpx;
        color: #202233;
        border: 1px solid #BBC4CC;
      }
    }
  }
</style>

http://www.kler.cn/news/290479.html

相关文章:

  • 宠物智能家居监测器的融合
  • LeetCode 606.根据二叉树创建字符串
  • 开源vscode AI插件
  • 什么是基于云的 SIEM
  • MuseTalk模型构建指南
  • css改变鼠标样式
  • 论文速读|BiGym:一款基于演示的移动双手操作机器人基准
  • IO进程练习:请在linux 利用c语言编程实现两个线程按照顺序依次输出”ABABABAB......“
  • pdf转cad软件,5款快速上手转换软件分享
  • vue el-tree主键id重复 添加自增id 以及原相同节点同步勾选 同步操作
  • 在Ubuntu上使用apt工具安装RabbitMQ
  • 单链表的问题(2)
  • NCBI-get-GCFIDs_fast.py
  • 基于贝叶斯优化CNN-LSTM网络的数据分类识别算法matlab仿真
  • 戴尔科技领涨市场,AI服务器需求成关键驱动力
  • Error when attempting to add data source to Azure OpenAI api
  • uniapp css样式盒子上面的箭头样式
  • ElasticSearch学习笔记(四)分页、高亮、RestClient查询文档
  • 20240904日报
  • C#如何查看/写入日志到Windows事件查看器
  • c++学习笔记(5)
  • .gitignore 修改问题
  • 力扣151.反转字符串中的单词
  • 输电线路分布式故障诊断系统:分布式智慧网络的构建
  • c#笔记5 详解事件的内置类型EventHandler、windows事件在winform中的运用
  • 【IEEE出版 | 往届会后3个月EI检索】第三届IEEE云计算、大数据应用与软件工程国际学术会议 (IEEE-CBASE 2024,10月18-20)
  • 6 - Shell编程之sed与awk编辑器
  • 高级java每日一道面试题-2024年8月28日-框架篇[Spring篇]-你对Spring的事务管理了解多少?
  • Windows bat脚本学习七(从hex文件中获取bin大小)
  • centos 局域网 内部 时间同步 chrony