微信小程序手写签名

场景: 客户是做二手房的,二手房上架是需要平台和房主签订一个房源合同,需要在线签约,所以就有了这个需求。
其他的不多说,大家可以去小程序 : web小白成长之旅 去看一下效果。

	<view class="content">
		<canvas class='firstCanvas'
				:height="getHeight"
		        canvas-id="firstCanvas"
		        @touchmove='move'
		        @touchend='end'
		        @error="error"
		        disable-scroll='true'
				
				>
				<!-- <cover-view class="qmmsg" v-if="isShowmsg" click="focused">请在空白处签名</cover-view> -->
		</canvas>
		<view class="operate-btn">
		  <view class="button" @click='clearClick()'>清除</view>
		  <view class="button" @click='saveClick()' >保存</view>
		</view>
	</view>
let content = null
	let touchs = []
	let canvasw = 0
	let canvash = 0
	export default{
		onLoad() {
			
		},
		compputed:{
			getHeight() {
				return `${uni.getSystemInfoSync().windowHeight-500}px`
			}
		},
		onShow() {
			// 建立画布
			content = uni.createCanvasContext('firstCanvas', this)
			this.drawBackground(content, '#fff', canvasw+1000, canvash+3000, -10, -10)
			console.log(canvasw,canvash)
			content.setStrokeStyle('#000000')
			content.setLineWidth(5)
			content.setLineCap('round')
			content.setLineJoin('round')
		},
		data(){
			return{
				isShowmsg:true
			}
		},
		methods:{
			error (e) {
				console.log(e)
			},
			move (e) {
			  let point = {x: e.touches[0].x, y: e.touches[0].y}
			  touchs.push(point)
			  if (touchs.length >= 2) {
			    this.draw(touchs)
			  }
			},
			end (e) {
			  for (let i = 0; i < touchs.length; i++) {
			    touchs.pop()
			  }
			},
			draw (touchs) {
					let point1 = touchs[0]
					let point2 = touchs[1]
					touchs.shift()
					content.moveTo(point1.x, point1.y)
					content.lineTo(point2.x, point2.y)
					content.stroke()
					content.draw(true)	
			},
			drawBackground (ctx, color = 'white', width = 1000, height = 3000, x = 0, y = 0) {
			  ctx.rect(x, y, width, height)
			  ctx.setFillStyle(color)
			  ctx.fill()
			},
			clearClick () {
				console.log(canvasw,canvash)
			  content.clearRect(0, 0, 1000, 3000)
			  content.draw(true)
			  content.beginPath();
			},
			saveClick () {
			  let that = this
			  wx.canvasToTempFilePath({
			    canvasId: 'firstCanvas',
			    success: function (res) {
			      console.log(res)
			      // 预览图片
				  let imgArr=[]
				  imgArr.push(res.tempFilePath);
			      		wx.previewImage({
			      			urls: imgArr,
			      			longPressActions: {
			      				itemList: ['发送给朋友', '保存图片', '收藏'],
			      				success: function(data) {
			      					console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
			      				},
			      				fail: function(err) {
			      					console.log(err.errMsg);
			      				}
			      			}
			      		});
				  
			    }
			  }, this)
			},
		}
	}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值