125 lines
3.3 KiB
JavaScript
125 lines
3.3 KiB
JavaScript
import { API } from './../../../utils/network/api'
|
|
import { FileUtil } from './../../../utils/fileutil'
|
|
const api = new API()
|
|
const app = getApp()
|
|
Page({
|
|
data: {
|
|
navbarData: {
|
|
showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
|
|
title: '多点执业认证', //导航栏 中间的标题
|
|
},
|
|
height: app.globalData.height,
|
|
ctx: null,
|
|
canvas: null,
|
|
txt_show: true
|
|
},
|
|
|
|
onReady() {
|
|
const query = wx.createSelectorQuery()
|
|
query.select('#sign_panels')
|
|
.fields({ node: true, size: true })
|
|
.exec((res) => {
|
|
const canvas = res[0].node
|
|
const ctx = canvas.getContext('2d')
|
|
ctx.lineWidth = 5;
|
|
// const dpr = wx.getSystemInfoSync().pixelRatio
|
|
|
|
canvas.width = res[0].width
|
|
canvas.height = res[0].height
|
|
ctx.scale(1, 1)
|
|
console.log(ctx);
|
|
this.setData({
|
|
ctx: ctx,
|
|
canvas: canvas
|
|
});
|
|
|
|
})
|
|
},
|
|
|
|
ontouchmove(e){
|
|
this.data.ctx.lineWidth = 5;
|
|
this.data.ctx.lineCap="round";
|
|
this.data.ctx.lineJoin ="round";
|
|
this.data.ctx.lineTo(e.changedTouches[0].pageX,e.changedTouches[0].pageY);
|
|
this.data.ctx.stroke();
|
|
},
|
|
ontouchstart(e){
|
|
this.setData({
|
|
txt_show: false
|
|
});
|
|
console.log(this.data.ctx);
|
|
this.data.ctx.beginPath();
|
|
this.data.ctx.moveTo(e.changedTouches[0].pageX,e.changedTouches[0].pageY);
|
|
},
|
|
|
|
toClear() {
|
|
this.setData({
|
|
txt_show: true
|
|
});
|
|
this.data.ctx.clearRect(0,0,this.data.canvas.width,this.data.canvas.height)
|
|
},
|
|
|
|
toSave(event) {
|
|
let _this = this;
|
|
let base64Img = _this.data.canvas.toDataURL()
|
|
console.log("sign: ", base64Img);
|
|
wx.canvasToTempFilePath({
|
|
canvasId: "sign_panels",
|
|
canvas: _this.data.canvas,
|
|
x:0,
|
|
y:0,
|
|
success(res) {
|
|
console.log(res.tempFilePath)
|
|
let filePath = res.tempFilePath;
|
|
_this.doUploadFile(event, 2, filePath);
|
|
}
|
|
})
|
|
},
|
|
|
|
doUploadFile(event, scene, filePath) {
|
|
console.log("index douploadFIle: ", event);
|
|
console.log("scene: ", scene);
|
|
let _this = this;
|
|
api.getOssSign({user_type:2,scene:scene}).then(response => {
|
|
console.log(response);
|
|
console.log("filePath: ", filePath);
|
|
const filename = FileUtil.UUID()+".png";
|
|
const host = response.data.host;
|
|
const signature = response.data.signature;
|
|
const ossAccessKeyId = response.data.accessid;
|
|
const policy = response.data.policy;
|
|
const key = response.data.dir+filename;
|
|
wx.uploadFile({
|
|
url: host, // 开发者服务器的URL。
|
|
filePath: filePath,
|
|
name: 'file', // 必须填file。
|
|
formData: {
|
|
key,
|
|
policy,
|
|
OSSAccessKeyId: ossAccessKeyId,
|
|
signature,
|
|
},
|
|
success: (res) => {
|
|
console.log("upload: ", res);
|
|
if (res.statusCode === 204) {
|
|
wx.showToast({title: '上传成功'})
|
|
let url = host+"/"+key;
|
|
console.log(url);
|
|
wx.setStorageSync("sign_image", url);
|
|
}
|
|
wx.navigateBack()
|
|
},
|
|
fail: err => {
|
|
console.log(err);
|
|
wx.showToast({
|
|
title: '上传失败',
|
|
icon: "error"
|
|
})
|
|
}
|
|
});
|
|
}).catch(errors => {
|
|
console.error(errors);
|
|
})
|
|
}
|
|
|
|
}) |