微信小程序?qū)崿F(xiàn)橫屏手寫(xiě)簽名
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)橫屏手寫(xiě)簽名的具體代碼,供大家參考,具體內(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)聽(tīng)頁(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) { },
? //開(kāi)始
? 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 () {
? ? //清除畫(huà)布
? ? 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í)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崿F(xiàn)手寫(xiě)簽名(簽字版)
- 微信小程序?qū)崿F(xiàn)手寫(xiě)簽名
- 微信小程序canvas實(shí)現(xiàn)手寫(xiě)簽名
- 微信小程序?qū)崿F(xiàn)橫屏和豎屏簽名功能
- 微信小程序?qū)崿F(xiàn)電子簽名功能
- java遇到微信小程序 "支付驗(yàn)證簽名失敗" 問(wèn)題解決
- 微信小程序?qū)崿F(xiàn)簡(jiǎn)單手寫(xiě)簽名組件的方法實(shí)例
- 微信小程序?qū)崿F(xiàn)電子簽名并導(dǎo)出圖片
- 微信小程序?qū)崿F(xiàn)電子簽名
- 微信小程序用canvas實(shí)現(xiàn)電子簽名
相關(guān)文章
利用HTML與JavaScript實(shí)現(xiàn)注冊(cè)頁(yè)面源碼
這篇文章主要給大家介紹了關(guān)于利用HTML與JavaScript實(shí)現(xiàn)注冊(cè)頁(yè)面的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),對(duì)大家實(shí)現(xiàn)注冊(cè)頁(yè)面具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-12-12
通過(guò)JS動(dòng)態(tài)創(chuàng)建一個(gè)html DOM元素并顯示
需要通過(guò)點(diǎn)擊某個(gè)元素后, 動(dòng)態(tài)創(chuàng)建一個(gè)DOM元素并顯示,因此寫(xiě)了一些相關(guān)的js函數(shù),在此記錄下2014-10-10
JS中靜態(tài)頁(yè)面實(shí)現(xiàn)微信分享功能
小編使用ajax實(shí)現(xiàn)靜態(tài)頁(yè)面也能實(shí)現(xiàn)微信分享功能,今天小編給大家分享實(shí)現(xiàn)代碼,對(duì)js靜態(tài)頁(yè)面微信分享功能感興趣的朋友參考下本文2017-02-02
用ES6的class模仿Vue寫(xiě)一個(gè)雙向綁定的示例代碼
本篇文章主要介紹了用ES6的class模仿Vue寫(xiě)一個(gè)雙向綁定的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-04-04
layui內(nèi)置模塊layim發(fā)送圖片添加加載動(dòng)畫(huà)的方法
今天小編就為大家分享一篇layui內(nèi)置模塊layim發(fā)送圖片添加加載動(dòng)畫(huà)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09
js通過(guò)指定下標(biāo)或指定元素進(jìn)行刪除數(shù)組的實(shí)例
下面小編就為大家?guī)?lái)一篇js通過(guò)指定下標(biāo)或指定元素進(jìn)行刪除數(shù)組的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01

