|
@@ -18,7 +18,11 @@ Page({
|
|
showPoster:false,
|
|
showPoster:false,
|
|
posterImg:'',//生成的海报
|
|
posterImg:'',//生成的海报
|
|
},
|
|
},
|
|
- async onLoad(){
|
|
|
|
|
|
+ onLoad(){
|
|
|
|
+ // this.getminiProgramConfig();
|
|
|
|
+ },
|
|
|
|
+ // 获取配置信息
|
|
|
|
+ async getminiProgramConfig(){
|
|
const res = await miniProgramConfig();
|
|
const res = await miniProgramConfig();
|
|
wx.setStorageSync('programConfig', res.data);
|
|
wx.setStorageSync('programConfig', res.data);
|
|
app.globalData.programConfig = res.data;
|
|
app.globalData.programConfig = res.data;
|
|
@@ -32,6 +36,9 @@ Page({
|
|
})
|
|
})
|
|
},
|
|
},
|
|
onShow() {
|
|
onShow() {
|
|
|
|
+ if(!wx.getStorageSync('programConfig')){
|
|
|
|
+ this.getminiProgramConfig();
|
|
|
|
+ }
|
|
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
|
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
|
this.getTabBar().setData({
|
|
this.getTabBar().setData({
|
|
selected: 0
|
|
selected: 0
|
|
@@ -101,9 +108,8 @@ Page({
|
|
},
|
|
},
|
|
// 点击海报生成图片
|
|
// 点击海报生成图片
|
|
async openPoster() {
|
|
async openPoster() {
|
|
- const userInfo = app.globalData.userInfo;
|
|
|
|
- const programConfig = app.globalData.programConfig;
|
|
|
|
- console.log(userInfo)
|
|
|
|
|
|
+ const userInfo = app.globalData.userInfo || wx.getStorageSync('userInfo');
|
|
|
|
+ const programConfig = app.globalData.programConfig || wx.getStorageSync('programConfig');
|
|
const posterKey = `posterImg_${userInfo.avatar}_${userInfo.nickname}_${programConfig.share_img}_${programConfig.share_qrcode}`;
|
|
const posterKey = `posterImg_${userInfo.avatar}_${userInfo.nickname}_${programConfig.share_img}_${programConfig.share_qrcode}`;
|
|
const cachedData = wx.getStorageSync('posterCache') || {};
|
|
const cachedData = wx.getStorageSync('posterCache') || {};
|
|
if (cachedData.key === posterKey && cachedData.path) {
|
|
if (cachedData.key === posterKey && cachedData.path) {
|
|
@@ -117,6 +123,8 @@ Page({
|
|
},
|
|
},
|
|
|
|
|
|
async drawPoster() {
|
|
async drawPoster() {
|
|
|
|
+ const userInfo = app.globalData.userInfo || wx.getStorageSync('userInfo');
|
|
|
|
+ const programConfig = app.globalData.programConfig || wx.getStorageSync('programConfig');
|
|
const ctx = wx.createCanvasContext('posterCanvas', this);
|
|
const ctx = wx.createCanvasContext('posterCanvas', this);
|
|
const canvasWidth = 300;
|
|
const canvasWidth = 300;
|
|
const canvasHeight = 600;
|
|
const canvasHeight = 600;
|
|
@@ -128,7 +136,7 @@ Page({
|
|
this.drawRoundRect(ctx, 0, 0, canvasWidth, canvasHeight, radius);
|
|
this.drawRoundRect(ctx, 0, 0, canvasWidth, canvasHeight, radius);
|
|
|
|
|
|
// 背景图
|
|
// 背景图
|
|
- const bgUrl = app.globalData.programConfig.share_img;
|
|
|
|
|
|
+ const bgUrl = programConfig.share_img;
|
|
if (bgUrl) {
|
|
if (bgUrl) {
|
|
const bgPath = bgUrl.startsWith('http') ? await this.downloadImage(bgUrl) : bgUrl;
|
|
const bgPath = bgUrl.startsWith('http') ? await this.downloadImage(bgUrl) : bgUrl;
|
|
ctx.drawImage(bgPath, 0, 0, canvasWidth, canvasHeight - bottomHeight);
|
|
ctx.drawImage(bgPath, 0, 0, canvasWidth, canvasHeight - bottomHeight);
|
|
@@ -139,7 +147,7 @@ Page({
|
|
ctx.fillRect(0, canvasHeight - bottomHeight, canvasWidth, bottomHeight);
|
|
ctx.fillRect(0, canvasHeight - bottomHeight, canvasWidth, bottomHeight);
|
|
|
|
|
|
// 用户头像(圆形)
|
|
// 用户头像(圆形)
|
|
- const avatarUrl = app.globalData.userInfo.avatar;
|
|
|
|
|
|
+ const avatarUrl = userInfo.avatar;
|
|
if (avatarUrl) {
|
|
if (avatarUrl) {
|
|
const avatarPath = avatarUrl.startsWith('http') ? await this.downloadImage(avatarUrl) : avatarUrl;
|
|
const avatarPath = avatarUrl.startsWith('http') ? await this.downloadImage(avatarUrl) : avatarUrl;
|
|
const avatarSize = 40;
|
|
const avatarSize = 40;
|
|
@@ -154,7 +162,7 @@ Page({
|
|
}
|
|
}
|
|
|
|
|
|
// 昵称
|
|
// 昵称
|
|
- const nickName = app.globalData.userInfo.nickname || '游客';
|
|
|
|
|
|
+ const nickName = userInfo.nickname || '游客';
|
|
ctx.setFontSize(16);
|
|
ctx.setFontSize(16);
|
|
ctx.setFillStyle('#000');
|
|
ctx.setFillStyle('#000');
|
|
const textX = 20 + 40 + 12;
|
|
const textX = 20 + 40 + 12;
|
|
@@ -162,7 +170,7 @@ Page({
|
|
ctx.fillText(nickName, textX, textY);
|
|
ctx.fillText(nickName, textX, textY);
|
|
|
|
|
|
// 二维码
|
|
// 二维码
|
|
- const qrUrl = app.globalData.programConfig.share_qrcode;
|
|
|
|
|
|
+ const qrUrl = programConfig.share_qrcode;
|
|
if (qrUrl) {
|
|
if (qrUrl) {
|
|
const qrPath = qrUrl.startsWith('http') ? await this.downloadImage(qrUrl) : qrUrl;
|
|
const qrPath = qrUrl.startsWith('http') ? await this.downloadImage(qrUrl) : qrUrl;
|
|
const qrSize = 50;
|
|
const qrSize = 50;
|
|
@@ -215,10 +223,6 @@ Page({
|
|
},
|
|
},
|
|
// 保存相册
|
|
// 保存相册
|
|
savePoster() {
|
|
savePoster() {
|
|
- if (!this.data.posterImg) {
|
|
|
|
- wx.showToast({ title: '没有海报图片', icon: 'none' });
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
wx.saveImageToPhotosAlbum({
|
|
wx.saveImageToPhotosAlbum({
|
|
filePath: this.data.posterImg,
|
|
filePath: this.data.posterImg,
|
|
success() { wx.showToast({ title: '保存成功' }); },
|
|
success() { wx.showToast({ title: '保存成功' }); },
|