1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
async shareFc(index) { //分享邀请二维码,参数index是列表点击的索引
if (uni.getStorageSync('tmpIndex') === index) { //判断临时索引是否是点击的索引
this.qrShow = true;
} else {
try{
uni.setStorageSync('tmpIndex', index); //将点击的索引绑定给本地sync,作为临时索引
let d = await getSharePoster({ //传入两个await参数,一个是类型,一个是canvasID
// type: [this.classList[index].userid,this.classList[index].classid],
type: 'testShareType',
posterCanvasId: this.canvasId,
qrCodeArray: (bgObj, type) => {
return [{
text: '二维码内容暂时不写', //后期可以传入相关的二维码参数,以便于扫码时获取
// image: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1559644434957&di=0db394a4ae41b6cff704fa3d4cbd997b&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201806%2F30%2F20180630233629_GueV4.thumb.700_0.jpeg',
size: 580, //二维码大小
dx: (bgObj.width-580)/2, //x坐标
dy: bgObj.height-1200 //y坐标
}]
},
imagesArray: (bgObj, type) => { //接收的第一个参数为背景图片的信息, 第二个参数是自定义标识(感觉这里用不到), 图片为示例图片
return [{
url: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1314428097,3858988978&fm=26&gp=0.jpg',
dx: 100,
dy: bgObj.height - 300,
circleSet: { // 圆形图片
circle: true
},
infoCallBack(imageInfo) {
let scale = 200/imageInfo.height;
return {
dWidth: imageInfo.width*scale,
dHeight: 200
}
}
}]
},
setCanvasWH: (bgObj, type) => { // 为动态设置画布宽高的方法,
this.poster = bgObj;
},
setDraw: (obj) => {
let {
Context,
bgObj,
type
} = obj;
Context.setFillStyle('black');
Context.setGlobalAlpha(0.3);
Context.fillRect(0, bgObj.height - 400, bgObj.width, 400);
Context.setGlobalAlpha(1);
Context.setFillStyle('white');
Context.setFontSize(100);
//输出姓名
let text = uni.getStorageSync('realName');
Context.fillText(text, bgObj.width - text.length * 50 - 160, bgObj.height - 175);
//输出班级
Context.setFillStyle('orange');
Context.setFontSize(110);
let textTitle = this.classList[index].classname;
Context.fillText(textTitle, (bgObj.width - textTitle.length * 110)/2, bgObj.height - 430);
}
});
console.log('海报生成成功, 临时路径: ' + d.poster.tempFilePath)
this.poster.finalPath = d.poster.tempFilePath;
console.log(this.poster.finalPath);
this.qrShow = true;
}catch(e){
_app.hideLoading();
_app.showToast(JSON.stringify(e));
console.log(JSON.stringify(e));
}
}
},
saveImage() {
uni.saveImageToPhotosAlbum({
filePath: this.poster.finalPath,
success(res) {
_app.showToast('保存成功');
}
})
},
share() {
// #ifdef APP-PLUS
_app.getShare(false, false, 2, '', '', '', this.poster.finalPath, false, false);
// #endif
// #ifndef APP-PLUS
_app.showToast('分享了');
// #endif
},
hideQr() {
this.qrShow = false;
}
|