10c6d284 by simon

默认提交

1 parent 302e3d6b
......@@ -28,6 +28,7 @@ module.exports = {
*/
areaQuery: 'https://api.k.wxpai.cn/bizproxy/kdapi/area', // post 区域查询
uploadFile: '/kdapi/file/upload' //上传图片通用接口
wxacodeGet: "/mzcfsapi/qrcode/createV2", // 通用上传 ?path=/pages/index/index?pa=1
uploadFile: '/kdapi/file/upload', //上传图片通用接口
}
......
{
"component": true
}
\ No newline at end of file
<!--index.wxml-->
<view class="container">
<canvas canvas-id='canvasid' class="canvas {{debug ? 'debug' : 'pro'}}" style='width: {{pxWidth}}px; height: {{pxHeight}}px;'></canvas>
</view>
.canvas {
width: 750rpx;
height: 750rpx;
}
.canvas.pro {
position: absolute;
bottom: 0;
left: 0;
transform: translate3d(-9999rpx, 0, 0);
}
.canvas.debug {
position: absolute;
bottom: 0;
left: 0;
border: 1rpx solid #ccc;
}
\ No newline at end of file
Component({
properties: {
config: {
type: Object,
value: {},
},
preload: { // 是否预下载图片资源
type: Boolean,
value: false,
},
hideLoading: { // 是否隐藏loading
type: Boolean,
value: false,
}
},
ready() {
if (this.data.preload) {
const poster = this.selectComponent('#poster');
this.downloadStatus = 'doing';
poster.downloadResource(this.data.config.images).then(() => {
this.downloadStatus = 'success';
this.trigger('downloadSuccess');
}).catch((e) => {
this.downloadStatus = 'fail';
this.trigger('downloadFail', e);
});
}
},
methods: {
trigger(event, data) {
if (this.listener && typeof this.listener[event] === 'function') {
this.listener[event](data);
}
},
once(event, fun) {
if (typeof this.listener === 'undefined') {
this.listener = {};
}
this.listener[event] = fun;
},
downloadResource(reset) {
return new Promise((resolve, reject) => {
if (reset) {
this.downloadStatus = null;
}
const poster = this.selectComponent('#poster');
if (this.downloadStatus && this.downloadStatus !== 'fail') {
if (this.downloadStatus === 'success') {
resolve();
} else {
this.once('downloadSuccess', () => resolve());
this.once('downloadFail', (e) => reject(e));
}
} else {
poster.downloadResource(this.data.config.images)
.then(() => {
this.downloadStatus = 'success';
resolve();
})
.catch((e) => reject(e));
}
})
},
onCreate(reset = false) {
!this.data.hideLoading && wx.showLoading({ mask: true, title: '生成中' });
return this.downloadResource(typeof reset === 'boolean' && reset).then(() => {
!this.data.hideLoading && wx.hideLoading();
const poster = this.selectComponent('#poster');
poster.create(this.data.config);
})
.catch((err) => {
!this.data.hideLoading && wx.hideLoading();
wx.showToast({ icon: 'none', title: err.errMsg || '生成失败' });
console.error(err);
this.triggerEvent('fail', err);
})
},
onCreateSuccess(e) {
const { detail } = e;
this.triggerEvent('success', detail);
},
onCreateFail(err) {
console.error(err);
this.triggerEvent('fail', err);
}
}
})
\ No newline at end of file
{
"component": true,
"usingComponents": {
"we-canvas": "../index/index"
}
}
\ No newline at end of file
<view bindtap='onCreate'>
<slot/>
</view>
<we-canvas id="poster" bind:success="onCreateSuccess" bind:fail="onCreateFail"/>
\ No newline at end of file
const defaultOptions = {
selector: '#poster'
};
function Poster(options = {}) {
options = {
...defaultOptions,
...options,
};
const pages = getCurrentPages();
const ctx = pages[pages.length - 1];
const poster = ctx.selectComponent(options.selector);
delete options.selector;
return poster;
};
Poster.create = (reset = false) => {
const poster = Poster();
if (!poster) {
console.error('请设置组件的id="poster"!!!');
} else {
return Poster().onCreate(reset);
}
}
export default Poster;
\ No newline at end of file
......@@ -4,6 +4,7 @@ import {
} from '../../utils/util';
import Dialog from '../../ui/vant-weapp/dialog/dialog';
import Poster from '../../miniprogram_dist/poster/poster';
const back = wx.getBackgroundAudioManager();
......@@ -41,7 +42,9 @@ Page({
isPlayingBgm: false,
isMore: false,
// shortcutPics:["red-package2","more-bless"]
imageUrl: "", // 海报图
posterVisible: false,
wxCodeUrl: "", // 微信小程序码
},
onShareAppMessage(res) {
let shareType = ""
......@@ -128,7 +131,6 @@ Page({
*/
initData() {},
playBgm() {
return;
let _this = this;
let {
detailData
......@@ -192,11 +194,273 @@ Page({
}
},
/**
onHidePosterHandler() {
this.setData({
posterVisible: false
})
},
/**
* 图片查看
*/
onPreviewImageHandler(evt) {
let current = this.data.imageUrl;
let urls = [current];
wx.previewImage({
current: current,
urls: urls
})
},
/**
* 保存图片到本地
*/
saveImageToPhotosAlbum() {
let _this = this;
wx.saveImageToPhotosAlbum({
filePath: _this.data.imageUrl,
success(res) {
wx.showToast({
title: '保存成功',
icon: 'success'
});
},
fail(err) {
wx.getSetting({
success: (res) => {
if (!res.authSetting['scope.writePhotosAlbum']) {
// 未授权
wx.showModal({
title: '提示',
content: '小程序请求访问相册权限',
confirmText: '前往授权',
success(res) {
if (res.confirm) {
wx.openSetting({
success(res) {}
})
} else if (res.cancel) {}
}
})
}
}
})
}
})
},
// 配置小程序码
getWxCode() {
let {
detailData
} = this.data;
let memberCode = app.store.getItem("memberCode");
let wxCodePath = `pages/blessing/blessing?c=${detailData.blessCode}&m=${memberCode}`;
return new Promise((resolve, reject) => {
// 先获取小程序码
app.get({
mode: "common",
url: app.api.wxacodeGet,
data: {
path: encodeURIComponent(wxCodePath)
}
}).then((result) => {
this.setData({
wxCodeUrl: result
})
resolve(result);
})
});
},
/**
* 分享图片祝福
* 生成海报
*/
onPosterHandler(){
onPosterHandler() {
console.log("onPosterHandler");
// 先获取小程序码
this.getWxCode().then((result) => {
let posterData = this.getPosterConfig();
this.onCreatePoster(posterData);
});
},
onPosterSuccess(e) {
wx.hideLoading();
const {
detail
} = e;
console.log("detail:", detail)
this.setData({
imageUrl: detail,
posterVisible: true,
})
},
onPosterFail(err) {
wx.hideLoading();
console.error(err);
},
/**
* 异步生成海报
*/
onCreatePoster(posterConfig) {
console.log("posterConfig:", posterConfig);
this.setData({
posterConfig: posterConfig
}, () => {
Poster.create(true); // 入参:true为抹掉重新生成
});
},
// 获取海报数据
getPosterConfig() {
let {
detailData,
ownerMember,
memberList,
wxCodeUrl
} = this.data;
let avatarWid = 120;
let nickname = ownerMember.memberName;
let avatar = ownerMember.memberHead;
let desc = "";
if (detailData.type == 1) {
// 组队
if (detailData.count > 0) {
desc = `携${detailData.familyName}${detailData.count}人`
} else {
desc = `携${detailData.familyName}`
}
} else {
// 单人
desc = `向各位亲朋好友`
}
let blocks = []
let images = [
// 背景图
{
x: 0,
y: 0,
width: 750,
height: 1334,
url: "../../image/poster/poster_c1.png",
},
// 头像
{
x: 184,
y: 186,
width: avatarWid,
height: avatarWid,
borderRadius: avatarWid,
zIndex: 22,
url: avatar,
},
// 小程序码
{
width: 100,
height: 100,
x: 586,
y: 1198,
url: wxCodeUrl,
zIndex: 31
}
];
let lines = [];
let texts = [
// 房主昵称
{
x: 53,
y: 460,
fontSize: 60,
color: "#fee085",
textAlign: "left",
zIndex: 11,
text: nickname,
},
// 文案
{
x: 53,
y: 540,
fontSize: 60,
color: "#fee085",
textAlign: "left",
zIndex: 11,
text: desc,
}
];
// 组队补充
if (detailData.type == 1) {
// 头像昵称取出3人
let member1 = memberList[0] || null;
let member2 = memberList[1] || null;
let member3 = memberList[2] || null;
let memberDrawList = [];
if (member1) memberDrawList.push(member1);
if (member2) memberDrawList.push(member2);
if (member3) memberDrawList.push(member3);
let endX = 630;
let wid = 160;
let startY = 800;
memberDrawList.forEach((element, idx) => {
// blocks.push({
// x: endX - (idx * wid) - ((wid - 92)),
// y: startY,
// width: 92,
// height: 92,
// borderRadius: 92,
// zIndex: 90,
// borderColor: "#fee085",
// })
images.push({
x: endX - (idx * wid) - ((wid - 92) / 2) - 4,
y: startY + 2,
width: 92,
height: 92,
borderRadius: 92,
zIndex: 101,
url: avatar,
})
texts.push({
x: endX - (idx * wid),
y: startY + 136,
width: wid,
fontSize: 24,
color: "#fee085",
textAlign: "center",
zIndex: 101,
text: element.memberName,
})
});
texts.push({
x: 686,
y: startY + 200,
fontSize: 48,
color: "#fee085",
textAlign: "right",
zIndex: 11,
text: `长按查看全部${detailData.count}人 >>`,
})
}
let posterData = {
width: 750,
height: 1334,
debug: false,
blocks: blocks,
images: images,
lines: lines,
texts: texts,
}
return posterData;
},
// 显示更新用户信息
......
{}
{
"usingComponents": {
"poster": "/miniprogram_dist/poster/index"
}
}
......
......@@ -5,6 +5,10 @@
font-size: 36rpx;
}
.van-popup {
background-color: transparent !important;
}
// 用户头像
.portrait {
position: relative;
......@@ -65,6 +69,24 @@
text-align: center;
}
.poster {
width: 540px;
}
.save-btn {
margin: 24px auto;
@include btc(290px, 76px);
color: #fee085;
font-size: 36px;
border-radius: 8px;
box-shadow: 5.9px 5.5px 18px 0 rgba(26, 36, 91, 0.73);
background-image: linear-gradient(to top, #b41d36, #bb2634);
color: #940023;
box-shadow: 5.9px 5.5px 18px 0 rgba(26, 36, 91, 0.73);
background-image: linear-gradient(to top, #f4b44d, #e8b976, #ffebb5);
}
.page {
padding-bottom: 200px;
......@@ -321,7 +343,7 @@
position: fixed;
bottom: 0;
width: 100%;
z-index: 101;
z-index: 21;
.bottom-bg {
width: 750px;
......@@ -362,7 +384,7 @@
position: fixed;
right: 24px;
top: 24px;
z-index: 201;
z-index: 31;
}
......@@ -403,3 +425,7 @@
-webkit-transform: rotate(360deg);
}
}
#poster {
position: absolute;
}
......
<poster id="poster" hide-loading="{{true}}" preload="{{false}}" config="{{posterConfig}}" bind:success="onPosterSuccess" bind:fail="onPosterFail"></poster>
<view class="page">
<view class="app__bgc bgc" style="background-color: {{detailData.background}};"></view>
<!-- <view class="app__bg bg " style="background: url('{{detailData.backgroundImage}}')"></view> -->
......@@ -67,7 +68,7 @@
<!-- 尾部头像 -->
<view class="portrait">
<image class="portrait-inner" mode="scaleToFill" src="{{ownerMember.memberHead}}" />
<image class="portrait-border" mode="scaleToFill" src="{{detailData.headFrame}}" />
<image class="portrait-border ani-rotation" mode="scaleToFill" src="{{detailData.headFrame}}" />
</view>
<view class="name">
<view class="tt t1">{{ownerMember.memberName}}</view>
......@@ -185,4 +186,11 @@
<view class="t1">邀请你一起加入组队送祝福!</view>
</view>
</van-dialog>
<shortcut2 types="{{[]}}" pics="{{['red-package2','more-bless']}}"></shortcut2>
<van-popup show="{{ authorizeVisible }}">
<authorize-comp bind:evtcomp="evtcomp"></authorize-comp>
</van-popup>
<van-popup bind:click-overlay="onHidePosterHandler" show="{{ posterVisible }}">
<image bindtap="onPreviewImageHandler" class="poster" mode="widthFix" src="{{imageUrl}}" />
<view bindtap="saveImageToPhotosAlbum" class="save-btn">一键保存</view>
</van-popup>
<shortcut2 types="{{[]}}" pics="{{['red-package2','more-bless']}}"></shortcut2>
......