|
@@ -5,7 +5,15 @@ Page({
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
- ls_url: ""
|
|
|
+ ls_url: "",
|
|
|
+ selectIndex: 0,
|
|
|
+ users: [{
|
|
|
+ name: "李勇利"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "张云翔"
|
|
|
+ },
|
|
|
+ ]
|
|
|
},
|
|
|
systemInfo: wx.getSystemInfoSync(),
|
|
|
/**
|
|
@@ -25,6 +33,7 @@ Page({
|
|
|
height,
|
|
|
path
|
|
|
} = res;
|
|
|
+ const users = JSON.parse(JSON.stringify(this.data.users));
|
|
|
const canvas = wx.createOffscreenCanvas({
|
|
|
type: '2d',
|
|
|
width,
|
|
@@ -33,42 +42,50 @@ Page({
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
const img = canvas.createImage();
|
|
|
img.onload = () => {
|
|
|
- ctx.drawImage(img, 0, 0, width, height);
|
|
|
- ctx.fillStyle = "#91725D";
|
|
|
- ctx.font = (width / 20) + 'px 微软雅黑';
|
|
|
- ctx.fillText("李勇利", width * 0.33, height * 0.4);
|
|
|
- wx.canvasToTempFilePath({
|
|
|
- x: 0,
|
|
|
- y: 0,
|
|
|
- width,
|
|
|
- height,
|
|
|
- destWidth: width,
|
|
|
- destHeight: height,
|
|
|
- canvas,
|
|
|
- fileType: 'jpg',
|
|
|
- success: res => {
|
|
|
- this.setData({
|
|
|
- ls_url: res.tempFilePath,
|
|
|
- width,
|
|
|
- height
|
|
|
- });
|
|
|
- },
|
|
|
- complete: () => {
|
|
|
- wx.hideLoading();
|
|
|
- }
|
|
|
- })
|
|
|
+ for (let i = 0; i < users.length; i++) {
|
|
|
+ const v = users[i];
|
|
|
+ ctx.drawImage(img, 0, 0, width, height);
|
|
|
+ ctx.fillStyle = "#91725D";
|
|
|
+ ctx.font = (width / 20) + 'px 微软雅黑';
|
|
|
+ ctx.fillText(v.name, width * 0.33, height * 0.4);
|
|
|
+ wx.canvasToTempFilePath({
|
|
|
+ x: 0,
|
|
|
+ y: 0,
|
|
|
+ width,
|
|
|
+ height,
|
|
|
+ destWidth: width,
|
|
|
+ destHeight: height,
|
|
|
+ canvas,
|
|
|
+ fileType: 'jpg',
|
|
|
+ success: res => {
|
|
|
+ v.url = res.tempFilePath
|
|
|
+ if (i === users.length - 1) {
|
|
|
+ this.setData({
|
|
|
+ ls_url: users,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ complete: () => {
|
|
|
+ wx.hideLoading();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
img.onerror = () => wx.hideLoading();
|
|
|
img.src = path // 要加载的图片 url
|
|
|
- }).catch(err=>{
|
|
|
+ }).catch(err => {
|
|
|
wx.hideLoading();
|
|
|
});
|
|
|
},
|
|
|
-
|
|
|
+ change(e) {
|
|
|
+ this.setData({
|
|
|
+ selectIndex: e.detail.current
|
|
|
+ })
|
|
|
+ },
|
|
|
download() {
|
|
|
- if (!this.data.ls_url) return
|
|
|
+ if (!this.data.ls_url[this.data.selectIndex] || !this.data.ls_url[this.data.selectIndex].url) return
|
|
|
wx.saveImageToPhotosAlbum({
|
|
|
- filePath: this.data.ls_url, // 使用下载得到的临时文件路径
|
|
|
+ filePath: this.data.ls_url[this.data.selectIndex].url, // 使用下载得到的临时文件路径
|
|
|
success: function (saveRes) {
|
|
|
wx.showToast({
|
|
|
title: '已保存至相册',
|