版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
第微信小程序canvas實現(xiàn)手寫簽名本文實例為大家分享了微信小程序canvas實現(xiàn)手寫簽名的具體代碼,供大家參考,具體內(nèi)容如下
很多時候,程序中需要用到簽名的功能,附上源碼(微信小程序)
.wxml
view
view請簽名:/view
view
view簽名區(qū)域/view
canvasdisable-scroll="true"
canvas-id="myCanvas"bindtouchstart="touchStart"bindtouchmove="touchMove"bindtouchend="touchEnd"
touchcancel="canvasEnd"binderror="canvasIdErrorCallback"/canvas
/view
/view
view
view
van-buttonroundcustom-type="info"plaincolor="#5359a7"
catchtap="clearDraw"清除/van-button
/view
view
van-buttonroundcustom-type="info"color="#1417b7"catchtap="submitDraw"
提交/van-button
/view
/view
.js
data:{
iphonex_height:app.globalData.iphonex_safe_area_height,//inphonex安全區(qū)高度
currentColor:'#000',
canvasw:0,
canvash:0,
userId:'',
signFile:'',
base64:'',
*生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad:function(options){
varthat=this;
that.setData({
userId:options.userId,
signFile:options.signFile,
name:,
drawId_:options.drawId,
list_:JSON.parse(options.list_),
userID:options.userID,
})
console.log(that.data.list_);
this.begin=false;
this.startX=0;
this.startY=0;
this.context=wx.createCanvasContext('myCanvas')
this.context.setLineWidth(4);
this.context.setLineCap('round');
this.context.setLineJoin('round');
wx.getSystemInfo({
success:function(res){
that.setData({
canvasw:res.windowWidth,//設(shè)備寬度
canvash:400
});
}
});
touchStart:function(e){
this.lineBegin(e.touches[0].x,e.touches[0].y)
//繪制中手指在屏幕上移動
touchMove:function(e){
if(this.begin){
this.lineAddPoint(e.touches[0].x,e.touches[0].y);
this.context.draw(true);
}
//繪制結(jié)束手指抬起
touchEnd:function(){
this.lineEnd();
//繪制線條結(jié)束
lineEnd:function(){
this.context.closePath();
this.begin=false;
//開始繪制線條
lineBegin:function(x,y){
this.begin=true;
this.context.beginPath()
this.startX=x;
this.startY=y;
this.context.moveTo(this.startX,this.startY)
this.lineAddPoint(x,y);
//繪制線條中間添加點
lineAddPoint:function(x,y){
this.context.moveTo(this.startX,this.startY)
this.context.lineTo(x,y)
this.context.stroke();
this.startX=x;
this.startY=y;
},
提交:請求接口
//提交
submitDraw(){
console.log("提交");
varthat=this;
console.log();
//跳轉(zhuǎn)攜帶的參數(shù)
if(=="sponsor_drawing"){
console.log("申請人簽字");
wx.canvasToTempFilePath({
canvasId:'myCanvas',
success:function(res){
if(that.startY==0){
wx.showToast({
icon:'none',
title:'您還沒有簽名',
})
}else{
//整理簽名格式
that.setData({
//轉(zhuǎn)base64
base64:wx.getFileSystemManager().readFileSync(res.tempFilePath,"base64").replace(/\s/g,""),
})
console.log("base64");
console.log(that.data.base64);
//請求接口提交信息
//申請人簽字
leturl='/release/releasedrawId='+that.data.drawId_+'signature='+`${encodeURIComponent(that.data.base64)}`;
letdata={}
wx.showLoading({
title:'發(fā)布中',
})
app.wxRequest('POST',1,url,data,(res)={
if(res.code==200){
wx.hideLoading();
Toast('提存信息發(fā)布成功');
if(that.data.list_!=null){
varissuer_=that.data.list_.issuer;//發(fā)布人信息
varaccept_=that.data.list_.accept;//受領(lǐng)人信息
if(app.globalData.note_bool){
for(vari=0;iaccept_.length;i++){
if(list_!=null){
that.call_function(1,issuer_[0].name,accept_[i].name,accept_[i].phone);//短信通知
}
}
}
}
setTimeout(function(){
wx.switchTab({
url:'/pages/user/mydrawing/index',
});
},500)
}else{
wx.hideLoading();
Toast('提存信息發(fā)布失敗');
}
},(err)={
wx.hideLoading();
Toast('加載失敗');
console.log(err);
})
}
},
})
}elseif(=="kuanApplyof"){
console.log("受領(lǐng)人簽字");
wx.canvasToTempFilePath({
canvasId:'myCanvas',
success:function(res){
if(that.startY==0){
wx.showToast({
icon:'none',
title:'您還沒有簽名',
})
}else{
//整理簽名格式
that.setData({
//轉(zhuǎn)base64
base64:wx.getFileSystemManager().readFileSync(res.tempFilePath,"base64"),
})
console.log("base64");
console.log(that.data.base64);
//請求接口提交信息
//list_=JSON.parse(list_);
console.log(that.data.list_);
leturl='/accept/applydrawId='+that.data.drawId_+'userId='+that.data.userID+'signature='+`${encodeURIComponent(that.data.base64)}`;
letdata={
account:that.data.list_.account,//開戶名
mobile:that.data.list_.mobile,//手機(jī)號
cardNo:that.data.list_.cardNo,//身份證號
bankName:that.data.list_.bankName,//開戶行
bankNo:that.data.list_.bankNo,//卡號
remarks:that.data.list_.remarks,//備注信息
applyMaterialList:that.data.list_.applyMaterialList,//申請材料信息
}
console.log(data);
wx.showLoading({
title:'確認(rèn)中',
})
app.wxRequest('POST',2,url,data,(res)={
console.log(res);
if(res.code==200){
wx.hideLoading();
Toast('確認(rèn)提存信息成功');
varname_accept=null;
for(vari=0;ithat.data.list_.accept_list.length;i++){
if(app.globalData.user_phone==that.data.list_.accept_list[i].mobile){
name_accept=that.data.list_.accept_list[i].name;
}
}
letsendMobile=app.globalData.sendMobile;//公證
if(that.data.list_!=nullname_accept!=null){
if(app.globalData.note_bool){
if(sendMobile!=''){
that.call_function(7,that.data.list_.issuer_list.realName,name_accept,sendMobile);
}
}
}
setTimeout(()={
wx.switchTab({
url:'/pages/user/perceptio/index',
})
},500)
}else{
wx.hideLoading();
Toast('確認(rèn)提存信息失敗');
}
},(err)={
wx.hideLoading();
Toast('加載失敗');
console.log(err);
})
}
},
})
}else{
Toast('提存信息發(fā)布失敗');
}
clearDraw(){
console.log("清除");
this.startY=0
this.context.draw()
this.context.setLineWidth(4);
this.context.setLineCap('round');
this.context.setLineJoin('round');
}
樣式(css)
/*miniprogram/pages/common/drawing/index.wxss*/
.contentBox{
width:100%;
background:#4f58a8;
.title{
font-size:30rpx;
color:#fff;
font-weight:600;
text-indent:20rpx;
padding:30rpx0;
.main{
padding-top:40rpx;
width:100%;
margin:0auto;
background:#ffffff;
border-radius:30rpx30rpx00;
.warningTitle{
width:90%;
margin:30rpxauto0;
font-weight:600;
line-height:60rpx;
font-size:40rpx;
.txtWarning{
line-height:20px;
widt
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030挪威可再生能源產(chǎn)業(yè)政策支持及投資布局評估
- 2025-2030披荊斬棘行業(yè)市場發(fā)展分析及趨勢前景與投資戰(zhàn)略研究報告
- 2026年數(shù)字化管理專家認(rèn)證題庫200道含答案【培優(yōu)a卷】
- 2026年社區(qū)參與在橋梁設(shè)計中的重要性
- 2026年控制系統(tǒng)設(shè)計中的信號處理
- 幼兒園創(chuàng)意手工布藝教案案例
- 永州生物中考試卷解析
- 企業(yè)遵紀(jì)守法員工手冊及常見案例解析
- 跨境電子商務(wù)基礎(chǔ)教學(xué)課件6-5-其他物流方式
- 幼兒園慶典活動策劃與祝詞范本
- 廣東省大灣區(qū)2023-2024學(xué)年高一上學(xué)期期末生物試題【含答案解析】
- 第四單元地理信息技術(shù)的應(yīng)用課件 【高效課堂+精研精講】高中地理魯教版(2019)必修第一冊
- 魯科版高中化學(xué)必修一教案全冊
- 提高隧道初支平整度合格率
- 2023年版測量結(jié)果的計量溯源性要求
- 建筑能耗與碳排放研究報告
- GB 29415-2013耐火電纜槽盒
- 中國古代經(jīng)濟(jì)試題
- 軟件定義汽車:產(chǎn)業(yè)生態(tài)創(chuàng)新白皮書
- 磷石膏抹灰專項施工方案
- 水電水利工程施工質(zhì)量管理培訓(xùn)講義
評論
0/150
提交評論