欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序?qū)崿F(xiàn)橫屏手寫簽名

 更新時(shí)間:2022年07月08日 09:42:34   作者:huangzhin  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)橫屏手寫簽名,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)橫屏手寫簽名的具體代碼,供大家參考,具體內(nèi)容如下

1.關(guān)鍵配置:

"pageOrientation": "landscape"  ---- 配置該頁(yè)面橫屏展示

2.效果圖:

3.代碼:

wxml

<view class="container">
? <canvas class="canvas" id="canvas" canvas-id="canvas" disable-scroll="true" bindtouchstart="canvasStart"
? ? bindtouchmove="canvasMove" bindtouchend="canvasEnd" touchcancel="canvasEnd"
? ? binderror="canvasIdErrorCallback"></canvas>
? <view class="tips">
? ? 請(qǐng)?jiān)诳騼?nèi)簽字
? </view>
? <view class='addBtn'>
? ? <button type="default" class='txt' bindtap="cleardraw">重新簽名</button>
? ? <button type="default" class='txt' bindtap="getimg">提交簽字</button>
? </view>
</view>

js

const fileManager = wx.getFileSystemManager();
?
// canvas 全局配置
var context = null; // 使用 wx.createContext 獲取繪圖上下文 context
var isButtonDown = false;
var arrx = [];
var arry = [];
var arrz = [];
var canvasw = 0;
var canvash = 0;
//獲取系統(tǒng)信息
wx.getSystemInfo({
? success: function (res) {
? ? canvasw = res.windowHeight * 1.2; //設(shè)備寬度
? ? // canvash = res.windowWidth * 7 / 15;
? ? canvash = res.windowWidth * 1.2;
? }
});
//注冊(cè)頁(yè)面
Page({
?
? /**
? ?* 頁(yè)面的初始數(shù)據(jù)
? ?*/
? data: {
? ? signFlag: false,
? },
?
? /**
? ?* 生命周期函數(shù)--監(jiān)聽頁(yè)面加載
? ?*/
? onLoad: function (options) {
? ? context = wx.createCanvasContext('canvas');
? ? context.setFillStyle('#fff')
? ? context.fillRect(0, 0, canvasw, canvash)
? ? context.draw(true)
? ? context.beginPath()
? ? context.setStrokeStyle('#000000');
? ? context.setLineWidth(4);
? ? context.setLineCap('round');
? ? context.setLineJoin('round');
? },
? onShow() {
? ? arrx = [];
? ? arry = [];
? ? arrz = [];
? },
?
? isJSON(str) {
? ? if (typeof str == 'string') {
? ? ? try {
? ? ? ? var obj = JSON.parse(str);
? ? ? ? if (typeof obj == 'object' && obj) {
? ? ? ? ? return true;
? ? ? ? } else {
? ? ? ? ? return false;
? ? ? ? }
? ? ? } catch (e) {
? ? ? ? return false;
? ? ? }
? ? }
? },
?
? canvasIdErrorCallback: function (e) { },
? //開始
? canvasStart: function (event) {
? ? isButtonDown = true;
? ? arrz.push(0);
? ? arrx.push(event.changedTouches[0].x);
? ? arry.push(event.changedTouches[0].y);
? ? //context.moveTo(event.changedTouches[0].x, event.changedTouches[0].y);
?
? },
? //過(guò)程
? canvasMove: function (event) {
? ? if (isButtonDown) {
? ? ? arrz.push(1);
? ? ? arrx.push(event.changedTouches[0].x);
? ? ? arry.push(event.changedTouches[0].y);
? ? ? // context.lineTo(event.changedTouches[0].x, event.changedTouches[0].y);
? ? ? // context.stroke();
? ? ? // context.draw()
? ? };
?
? ? this.setData({
? ? ? signFlag: true,
? ? })
?
? ? for (var i = 0; i < arrx.length; i++) {
? ? ? if (arrz[i] == 0) {
? ? ? ? context.moveTo(arrx[i], arry[i])
? ? ? } else {
? ? ? ? context.lineTo(arrx[i], arry[i])
? ? ? };
?
? ? };
?
? ? context.setStrokeStyle('#000000');
? ? context.setLineWidth(4);
? ? context.setLineCap('round');
? ? context.setLineJoin('round');
? ? context.stroke();
? ? context.draw(true);
? },
? canvasEnd: function (event) {
? ? isButtonDown = false;
? },
? cleardraw: function () {
? ? //清除畫布
? ? arrx = [];
? ? arry = [];
? ? arrz = [];
? ? context.clearRect(0, 0, canvasw, canvash);
? ? context.draw(true);
? },
? //導(dǎo)出圖片
? getimg: function () {
? ? let that = this
? ? if (arrx.length == 0) {
? ? ? wx.showModal({
? ? ? ? title: '提示',
? ? ? ? content: '簽名內(nèi)容不能為空!',
? ? ? ? showCancel: false
? ? ? });
? ? ? return false;
? ? };
? ? console.log(this.data.signFlag);
? ? if (!this.data.signFlag) {
? ? ? wx.showModal({
? ? ? ? title: '提示',
? ? ? ? content: '簽名內(nèi)容不能為空!',
? ? ? ? showCancel: false
? ? ? });
? ? ? return false;
? ? }
? ? //生成圖片
? ? wx.canvasToTempFilePath({
? ? ? canvasId: 'canvas',
? ? ? success: function (res) {
? ? ? ? //將圖片轉(zhuǎn)換為base64 的格式
? ? ? ? let base64 = 'data:image/jpg;base64,' + fileManager.readFileSync(res.tempFilePath, 'base64');
? ? ? ? //其他
? ? ? ??
? ? ? }
? ? })
?
? },
?
})

wxss

page{
? background: #fff;
}
.container {
? width: 95%;
? position: absolute;
? height: 95%;
? top: 50%;
? left: 50%;
? transform: translate(-50%, -50%);
? box-sizing: border-box;
? background: #fff;
? border-radius: 5px;
}
.canvas {
? width: 100%;
? height: 70%;
? border: 1px solid #aaa;
? box-sizing: border-box;
}
.tips{
? height: 10%;
? display: flex;
? align-items: center;
? justify-content: center;
? text-align: center;
? color: #aaa;
}
?
.addBtn {
? display: flex;
? align-items: center;
? justify-content: center;
? height: 18%;
? position: fixed;
? bottom: 0;
? width: 100%;
? background: #fff;
? z-index: 100;
}
?
.addBtn .txt {
? text-align: center;
? width: 90%;
? font-size: 13px;
? border-radius: 100px;
? background: #0097fe;
? color: #fff;
? box-sizing: border-box;
? margin: 0 10px;
? padding: 10px;
? z-index: 100;
}

json

{
? "navigationBarTitleText": "電子簽名",
? "pageOrientation": "landscape"
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論