|
@@ -162,8 +162,25 @@ Page({
|
|
|
const systemInfo = wx.getSystemInfoSync();
|
|
|
return rpx * (systemInfo.windowWidth / 750);
|
|
|
},
|
|
|
+ getImageInfo(url) {
|
|
|
+ console.log(url);
|
|
|
+ return new Promise((result) => {
|
|
|
+ wx.getImageInfo({
|
|
|
+ src: url,
|
|
|
+ success: function (res) {
|
|
|
+
|
|
|
+ let Path = res.path;
|
|
|
+ result(Path)
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ console.log(err);
|
|
|
+ result()
|
|
|
+ }
|
|
|
+ });
|
|
|
+ })
|
|
|
+ },
|
|
|
|
|
|
- saveImage() {
|
|
|
+ async saveImage() {
|
|
|
|
|
|
const canvas = wx.createCanvasContext('myCanvas');
|
|
|
const width = this.rpxToPx(670);
|
|
@@ -176,119 +193,107 @@ Page({
|
|
|
canvas.setFillStyle('#CAE1FD');
|
|
|
canvas.fillRect(0, 0, width, height);
|
|
|
canvas.setFillStyle('#0178EE');
|
|
|
+ let mainimage = await this.getImageInfo(this.data.randomImage)
|
|
|
+ let avatar = Parse.User.current()?.get('avatar')
|
|
|
+ console.log('avatar', avatar);
|
|
|
+ let userAvatar = await this.getImageInfo(avatar)
|
|
|
+ console.log('userAvatar', userAvatar);
|
|
|
+
|
|
|
+ canvas.drawImage(mainimage, 0, 0, width, this.rpxToPx(500));
|
|
|
+
|
|
|
+ if (userAvatar) {
|
|
|
+
|
|
|
+ const avatarX = this.rpxToPx(40);
|
|
|
+ const avatarY = this.rpxToPx(540);
|
|
|
+ const avatarSize = this.rpxToPx(83);
|
|
|
+ const radius = avatarSize / 2;
|
|
|
+
|
|
|
+
|
|
|
+ canvas.save();
|
|
|
+ canvas.beginPath();
|
|
|
+ canvas.moveTo(avatarX + radius, avatarY);
|
|
|
+ canvas.lineTo(avatarX + avatarSize - radius, avatarY);
|
|
|
+ canvas.arc(avatarX + avatarSize - radius, avatarY + radius, radius, 1.5 * Math.PI, 0, false);
|
|
|
+ canvas.lineTo(avatarX + avatarSize, avatarY + avatarSize - radius);
|
|
|
+ canvas.arc(avatarX + avatarSize - radius, avatarY + avatarSize - radius, radius, 0, 0.5 * Math.PI, false);
|
|
|
+ canvas.lineTo(avatarX + radius, avatarY + avatarSize);
|
|
|
+ canvas.arc(avatarX + radius, avatarY + avatarSize - radius, radius, 0.5 * Math.PI, Math.PI, false);
|
|
|
+ canvas.lineTo(avatarX, avatarY + radius);
|
|
|
+ canvas.arc(avatarX + radius, avatarY + radius, radius, Math.PI, 1.5 * Math.PI, false);
|
|
|
+ canvas.closePath();
|
|
|
+ canvas.clip();
|
|
|
+
|
|
|
+
|
|
|
+ canvas.drawImage(userAvatar, avatarX, avatarY, avatarSize, avatarSize);
|
|
|
+ canvas.restore();
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- wx.getImageInfo({
|
|
|
- src: this.data.randomImage,
|
|
|
- success: (res) => {
|
|
|
- canvas.drawImage(res.path, 0, 0, width, this.rpxToPx(500));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- wx.getImageInfo({
|
|
|
- src: this.data.sharList[0].user.avatar,
|
|
|
- success: (avatarRes) => {
|
|
|
-
|
|
|
- const avatarX = this.rpxToPx(40);
|
|
|
- const avatarY = this.rpxToPx(540);
|
|
|
- const avatarSize = this.rpxToPx(83);
|
|
|
- const radius = avatarSize / 2;
|
|
|
-
|
|
|
-
|
|
|
- canvas.save();
|
|
|
- canvas.beginPath();
|
|
|
- canvas.moveTo(avatarX + radius, avatarY);
|
|
|
- canvas.lineTo(avatarX + avatarSize - radius, avatarY);
|
|
|
- canvas.arc(avatarX + avatarSize - radius, avatarY + radius, radius, 1.5 * Math.PI, 0, false);
|
|
|
- canvas.lineTo(avatarX + avatarSize, avatarY + avatarSize - radius);
|
|
|
- canvas.arc(avatarX + avatarSize - radius, avatarY + avatarSize - radius, radius, 0, 0.5 * Math.PI, false);
|
|
|
- canvas.lineTo(avatarX + radius, avatarY + avatarSize);
|
|
|
- canvas.arc(avatarX + radius, avatarY + avatarSize - radius, radius, 0.5 * Math.PI, Math.PI, false);
|
|
|
- canvas.lineTo(avatarX, avatarY + radius);
|
|
|
- canvas.arc(avatarX + radius, avatarY + radius, radius, Math.PI, 1.5 * Math.PI, false);
|
|
|
- canvas.closePath();
|
|
|
- canvas.clip();
|
|
|
-
|
|
|
-
|
|
|
- canvas.drawImage(avatarRes.path, avatarX, avatarY, avatarSize, avatarSize);
|
|
|
- canvas.restore();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- const nickname = this.data.sharList[0].user.nickname;
|
|
|
- const currentTime = this.data.sharList[0].currentTime;
|
|
|
- const rank = this.data.sharList[0].rank;
|
|
|
- const steps = this.data.sharList[0].steps || 0;
|
|
|
- const distance = this.data.sharList[0].distance || 0;
|
|
|
-
|
|
|
- canvas.setFontSize(this.rpxToPx(30));
|
|
|
- canvas.fillText(nickname, this.rpxToPx(140), this.rpxToPx(580));
|
|
|
-
|
|
|
- canvas.setFontSize(this.rpxToPx(28));
|
|
|
- canvas.fillText(currentTime, this.rpxToPx(140), this.rpxToPx(610));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- canvas.setFontSize(this.rpxToPx(55));
|
|
|
- canvas.fillText('梦想家', this.rpxToPx(40), this.rpxToPx(720));
|
|
|
-
|
|
|
- canvas.setFontSize(this.rpxToPx(30));
|
|
|
- canvas.fillText('用汗水实现想象,用脚步丈量梦想', this.rpxToPx(40), this.rpxToPx(780));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- canvas.setFontSize(this.rpxToPx(28));
|
|
|
-
|
|
|
- canvas.fillText('今日排名', this.rpxToPx(40), this.rpxToPx(840));
|
|
|
-
|
|
|
-
|
|
|
- canvas.fillText('今日步数', this.rpxToPx(240), this.rpxToPx(840));
|
|
|
-
|
|
|
-
|
|
|
- canvas.fillText('公里数', this.rpxToPx(440), this.rpxToPx(840));
|
|
|
-
|
|
|
- canvas.setFontSize(this.rpxToPx(40));
|
|
|
- canvas.fillText(rank, this.rpxToPx(80), this.rpxToPx(900));
|
|
|
- canvas.fillText(steps, this.rpxToPx(240), this.rpxToPx(900));
|
|
|
- canvas.fillText(distance + 'km', this.rpxToPx(444), this.rpxToPx(900));
|
|
|
-
|
|
|
-
|
|
|
- canvas.setFillStyle('red');
|
|
|
- canvas.fillRect(width - this.rpxToPx(140), height - this.rpxToPx(160), this.rpxToPx(120), this.rpxToPx(120));
|
|
|
-
|
|
|
-
|
|
|
- canvas.setFillStyle('#0178EE');
|
|
|
- canvas.setFontSize(this.rpxToPx(28));
|
|
|
- canvas.fillText('长按二维码加入跑团', width - this.rpxToPx(420), height - this.rpxToPx(120));
|
|
|
- canvas.fillText('和我一起运动', width - this.rpxToPx(380), height - this.rpxToPx(80));
|
|
|
-
|
|
|
- canvas.draw(false, () => {
|
|
|
- console.log('123');
|
|
|
- wx.canvasToTempFilePath({
|
|
|
- canvasId: 'myCanvas',
|
|
|
- success: (res) => {
|
|
|
- console.log('绘制完成', res);
|
|
|
- this.setData({
|
|
|
- saveimage: res.tempFilePath
|
|
|
- });
|
|
|
- console.log(this.data.saveimage);
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
- console.error('canvasToTempFilePath 失败', err);
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
- console.error('用户头像加载失败', this.data.sharList[0].user.avatar, err);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- fail: () => {
|
|
|
- console.error('主图片加载失败');
|
|
|
- }
|
|
|
+
|
|
|
+ const nickname = this.data.sharList[0].user.nickname;
|
|
|
+ const currentTime = this.data.sharList[0].currentTime;
|
|
|
+ const rank = this.data.sharList[0].rank;
|
|
|
+ const steps = this.data.sharList[0].steps || 0;
|
|
|
+ const distance = this.data.sharList[0].distance || 0;
|
|
|
+
|
|
|
+ canvas.setFontSize(this.rpxToPx(30));
|
|
|
+ canvas.fillText(nickname, this.rpxToPx(140), this.rpxToPx(580));
|
|
|
+
|
|
|
+ canvas.setFontSize(this.rpxToPx(28));
|
|
|
+ canvas.fillText(currentTime, this.rpxToPx(140), this.rpxToPx(610));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ canvas.setFontSize(this.rpxToPx(55));
|
|
|
+ canvas.fillText('梦想家', this.rpxToPx(40), this.rpxToPx(720));
|
|
|
+
|
|
|
+ canvas.setFontSize(this.rpxToPx(30));
|
|
|
+ canvas.fillText('用汗水实现想象,用脚步丈量梦想', this.rpxToPx(40), this.rpxToPx(780));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ canvas.setFontSize(this.rpxToPx(28));
|
|
|
+
|
|
|
+ canvas.fillText('今日排名', this.rpxToPx(40), this.rpxToPx(840));
|
|
|
+
|
|
|
+
|
|
|
+ canvas.fillText('今日步数', this.rpxToPx(240), this.rpxToPx(840));
|
|
|
+
|
|
|
+
|
|
|
+ canvas.fillText('公里数', this.rpxToPx(440), this.rpxToPx(840));
|
|
|
+
|
|
|
+ canvas.setFontSize(this.rpxToPx(40));
|
|
|
+ canvas.fillText(rank, this.rpxToPx(80), this.rpxToPx(900));
|
|
|
+ canvas.fillText(steps, this.rpxToPx(240), this.rpxToPx(900));
|
|
|
+ canvas.fillText(distance + 'km', this.rpxToPx(444), this.rpxToPx(900));
|
|
|
+
|
|
|
+
|
|
|
+ canvas.setFillStyle('red');
|
|
|
+ canvas.fillRect(width - this.rpxToPx(140), height - this.rpxToPx(160), this.rpxToPx(120), this.rpxToPx(120));
|
|
|
+
|
|
|
+
|
|
|
+ canvas.setFillStyle('#0178EE');
|
|
|
+ canvas.setFontSize(this.rpxToPx(28));
|
|
|
+ canvas.fillText('长按二维码加入跑团', width - this.rpxToPx(420), height - this.rpxToPx(120));
|
|
|
+ canvas.fillText('和我一起运动', width - this.rpxToPx(380), height - this.rpxToPx(80));
|
|
|
+
|
|
|
+ canvas.draw(false, () => {
|
|
|
+ console.log('123');
|
|
|
+ wx.canvasToTempFilePath({
|
|
|
+ canvasId: 'myCanvas',
|
|
|
+ success: (res) => {
|
|
|
+ console.log('绘制完成', res);
|
|
|
+ this.setData({
|
|
|
+ saveimage: res.tempFilePath
|
|
|
+ });
|
|
|
+ console.log(this.data.saveimage);
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('canvasToTempFilePath 失败', err);
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
+
|
|
|
},
|
|
|
|
|
|
|
|
@@ -428,7 +433,7 @@ Page({
|
|
|
filePath: imagePath,
|
|
|
success: () => {
|
|
|
wx.showToast({
|
|
|
- title: '保存成功',
|
|
|
+ title: '图片已保存到相册',
|
|
|
icon: 'success'
|
|
|
});
|
|
|
},
|
|
@@ -447,55 +452,69 @@ Page({
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
- savepic2() {
|
|
|
- const that = this
|
|
|
- let fileName = new Date().valueOf();
|
|
|
- let filePath = wx.env.USER_DATA_PATH + '/' + fileName + '.jpg'
|
|
|
- wx.downloadFile({
|
|
|
- url: that.data.saveimage,
|
|
|
- filePath: filePath,
|
|
|
- success: function (res) {
|
|
|
-
|
|
|
- wx.saveImageToPhotosAlbum({
|
|
|
- filePath: filePath,
|
|
|
- success(data) {
|
|
|
- let fileMgr = wx.getFileSystemManager()
|
|
|
- fileMgr.unlink({
|
|
|
- filePath: filePath,
|
|
|
- success() {
|
|
|
- wx.showToast({
|
|
|
- title: '已保存至您的相册',
|
|
|
- icon: 'none',
|
|
|
- duration: 1500
|
|
|
- });
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- fail(err) {
|
|
|
- if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {
|
|
|
- wx.showModal({
|
|
|
- title: '提示',
|
|
|
- content: '需要您授权保存相册',
|
|
|
- showCancel: false,
|
|
|
- success: modalSuccess => {
|
|
|
- wx.openSetting({
|
|
|
- success(settingdata) {
|
|
|
- if (settingdata.authSetting['scope.writePhotosAlbum']) {
|
|
|
- console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
|
|
|
- } else {
|
|
|
- console.log('获取权限失败,给出不给权限就无法正常使用的提示')
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
+
|
|
|
+ savepic2: function () {
|
|
|
+ let that = this;
|
|
|
+ wx.canvasToTempFilePath({
|
|
|
+ x: 0,
|
|
|
+ y: 0,
|
|
|
+ width: 670,
|
|
|
+ height: 1100,
|
|
|
+ destWidth: 670,
|
|
|
+ destHeight: 1100,
|
|
|
+ canvasId: 'myCanvas',
|
|
|
+ success: function (result) {
|
|
|
+ wx.getSetting({
|
|
|
+ success(res) {
|
|
|
+ if (!res.authSetting['scope.writePhotosAlbum']) {
|
|
|
+ wx.authorize({
|
|
|
+ scope: 'scope.writePhotosAlbum',
|
|
|
+ success() {
|
|
|
+
|
|
|
+
|
|
|
+ wx.saveImageToPhotosAlbum({
|
|
|
+ filePath: result.tempFilePath,
|
|
|
+ success(res) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '图片已保存到相册',
|
|
|
+ icon: 'success'
|
|
|
+ });
|
|
|
}
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail() {
|
|
|
+ wx.showToast({
|
|
|
+ title: '打开相册授权,才能保存图片哦~',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ that.setData({
|
|
|
+ openSettingBtnHidden: false
|
|
|
+ })
|
|
|
}
|
|
|
- })
|
|
|
- },
|
|
|
- fail: function (res) {}
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+
|
|
|
+ console.log(result.tempFilePath);
|
|
|
+ wx.saveImageToPhotosAlbum({
|
|
|
+ filePath: result.tempFilePath,
|
|
|
+ success(res) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '图片已保存到相册',
|
|
|
+ icon: 'success'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ console.log(res)
|
|
|
+ }
|
|
|
})
|
|
|
- },
|
|
|
+ },
|
|
|
shar() {
|
|
|
wx.downloadFile({
|
|
|
url: this.data.saveimage,
|
|
@@ -514,9 +533,9 @@ Page({
|
|
|
},
|
|
|
});
|
|
|
},
|
|
|
- sharecircle(){
|
|
|
+ sharecircle() {
|
|
|
wx.navigateTo({
|
|
|
- url: '../../circle/send-circle/index?image='+this.data.saveimage
|
|
|
+ url: '../../circle/send-circle/index?image=' + this.data.saveimage
|
|
|
});
|
|
|
}
|
|
|
})
|