初始化
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
const app = getApp();
|
||||
const {
|
||||
getWxml,
|
||||
getStyle,
|
||||
getWxml1,
|
||||
getStyle1,
|
||||
} = require("../../pages/activitySharing/poster-data.js");
|
||||
const {
|
||||
isCreateImageSuccess
|
||||
} = require('../../utils/util.js')
|
||||
Component({
|
||||
options: {
|
||||
|
||||
},
|
||||
properties: {
|
||||
metaData: {
|
||||
type: Object,
|
||||
value: {}
|
||||
},
|
||||
|
||||
},
|
||||
data: {
|
||||
isShowQrcode: false,
|
||||
poster: null,
|
||||
isShowPoster: false
|
||||
},
|
||||
observers: {
|
||||
|
||||
},
|
||||
relations: {
|
||||
|
||||
},
|
||||
lifetimes: {
|
||||
|
||||
},
|
||||
methods: {
|
||||
shareQr() {
|
||||
wx.showShareImageMenu({
|
||||
path: this.data.qrCode,
|
||||
});
|
||||
},
|
||||
websiteClick() {
|
||||
wx.navigateTo({
|
||||
url: `/pages/mywebsite/index`,
|
||||
})
|
||||
},
|
||||
showQrcode() {
|
||||
this.getImg1();
|
||||
},
|
||||
shareFriend() {
|
||||
wx.showShareImageMenu({
|
||||
path: this.data.poster,
|
||||
});
|
||||
},
|
||||
showPoster() {
|
||||
|
||||
this.getImg()
|
||||
},
|
||||
async getImg1() {
|
||||
const obj = {
|
||||
img: this.data.metaData.shareQRCode
|
||||
}
|
||||
console.log(obj);
|
||||
const poster = this.selectComponent("#poster");
|
||||
wx.showLoading({
|
||||
title: '加载中',
|
||||
})
|
||||
setTimeout(() => {
|
||||
const wxml = getWxml1(obj);
|
||||
const style = getStyle1();
|
||||
const p1 = poster.renderToCanvas({
|
||||
wxml,
|
||||
style
|
||||
});
|
||||
let container = null;
|
||||
p1.then((res) => {
|
||||
container = res;
|
||||
return poster.canvasToTempFilePath();
|
||||
}).then((res) => {
|
||||
console.log(res, 'res');
|
||||
this.setData({
|
||||
qrCode: res.tempFilePath,
|
||||
width: container.layoutBox.width,
|
||||
height: container.layoutBox.height,
|
||||
isShowQrcode: true
|
||||
});
|
||||
wx.hideLoading()
|
||||
});
|
||||
}, 500);
|
||||
},
|
||||
onVisibleChange2(e) {
|
||||
this.setData({
|
||||
isShowPoster: e.detail.visible,
|
||||
});
|
||||
},
|
||||
onVisibleChange(e) {
|
||||
|
||||
this.setData({
|
||||
isShowQrcode: e.detail.visible,
|
||||
});
|
||||
},
|
||||
async getImg() {
|
||||
var isPortraitSuccess = false;
|
||||
if (app.globalData.avatarUrl && app.globalData.avatarUrl != '') {
|
||||
try {
|
||||
isPortraitSuccess = await isCreateImageSuccess(app.globalData.avatarUrl, "canvas", this);
|
||||
} catch (ex) {
|
||||
console.log(ex)
|
||||
}
|
||||
}
|
||||
var obj = {
|
||||
title: this.data.metaData.title,
|
||||
img: this.data.metaData.imageCoverUrl,
|
||||
portrait: isPortraitSuccess ? app.globalData.avatarUrl : "https://pxboss.xiaohebang.cn/system/material/mini/fx/avatar.png",
|
||||
name: app.globalData.nickName,
|
||||
qrcode: this.data.metaData.shareQRCode,
|
||||
};
|
||||
const poster = this.selectComponent("#poster");
|
||||
|
||||
wx.showLoading({
|
||||
title: '加载中',
|
||||
})
|
||||
setTimeout(() => {
|
||||
const wxml = getWxml(obj);
|
||||
const style = getStyle();
|
||||
const p1 = poster.renderToCanvas({
|
||||
wxml,
|
||||
style
|
||||
});
|
||||
console.log(p1);
|
||||
let container = null;
|
||||
p1.then((res) => {
|
||||
container = res;
|
||||
console.log(container);
|
||||
return poster.canvasToTempFilePath();
|
||||
}).then((res) => {
|
||||
this.setData({
|
||||
poster: res.tempFilePath,
|
||||
width: container.layoutBox.width,
|
||||
height: container.layoutBox.height,
|
||||
isShowPoster: true
|
||||
});
|
||||
wx.hideLoading()
|
||||
});
|
||||
}, 500);
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-progress": "tdesign-miniprogram/progress/progress",
|
||||
"t-popup": "tdesign-miniprogram/popup/popup",
|
||||
"wxml-to-canvas": "wxml-to-canvas"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<t-popup visible="{{isShowQrcode}}" bind:visible-change="onVisibleChange" close-on-overlay-click="true" placement="center">
|
||||
<view>
|
||||
<image style="border-radius: 18px;" show-menu-by-longpress="{{true}}" src="{{metaData.shareQRCode}}" mode="widthFix"></image>
|
||||
</view>
|
||||
<button class="ac-action" bindtap="shareQr">
|
||||
<image src="https://xiaohebang.oss-cn-beijing.aliyuncs.com/system/material/mini/fx/xz.png" />
|
||||
<text>分享二维码</text>
|
||||
</button>
|
||||
|
||||
|
||||
</t-popup>
|
||||
|
||||
<t-popup visible="{{isShowPoster}}" bind:visible-change="onVisibleChange2" close-on-overlay-click="true" placement="center">
|
||||
<view>
|
||||
<image class="ac-poster-preview" src="{{poster}}" style="width: 300px;" mode="widthFix" show-menu-by-longpress />
|
||||
</view>
|
||||
<button class="ac-action" bindtap="shareFriend">
|
||||
<image src="https://xiaohebang.oss-cn-beijing.aliyuncs.com/system/material/mini/fx/xz.png" />
|
||||
<text>分享海报</text>
|
||||
</button>
|
||||
</t-popup>
|
||||
|
||||
<view class="btns">
|
||||
<view bindtap="showQrcode" wx:if="{{metaData.shareQRCode}}" class="ac_ks_inter my_qrcode">
|
||||
<image src="https://pxboss.xiaohebang.cn/system/material/mini/com/i-saoma.png" mode="aspectFit" />
|
||||
</view>
|
||||
<view class="ac_poster ac_ks_inter" bindtap="showPoster" wx:if="{{metaData}}">
|
||||
<image src="https://pxboss.xiaohebang.cn/system/material/mini/com/poster1.png" mode="aspectFit" />
|
||||
</view>
|
||||
<view wx:if="{{metaData}}" bindtap="websiteClick" class="ac_wi_website ac_ks_inter" >
|
||||
<image src="https://pxboss.xiaohebang.cn/system/material/mini/com/micsite1.png" mode="aspectFit" />
|
||||
</view>
|
||||
<!-- <view bindtap="phoneClick" data-phoneNumber="{{.globalPhone}}" wx:if="{{activityBag.bascInfo.globalPhone}}" class="ac_ks_inter ac_link_phone">
|
||||
<image src="https://pxboss.xiaohebang.cn/system/material/mini/com/i-phone.png" mode="aspectFit" />
|
||||
</view> -->
|
||||
</view>
|
||||
<canvas canvas-id="canvas" id="canvas" type="2d" style="position: fixed; left: -100%" />
|
||||
<wxml-to-canvas id="poster" class="ac-poster-canvas" width="300" height="600"></wxml-to-canvas>
|
||||
@@ -0,0 +1,51 @@
|
||||
/* components/comPart/compart.wxss */
|
||||
.btns {
|
||||
position: fixed;
|
||||
z-index: 999;
|
||||
right: 10px;
|
||||
bottom: 100px;
|
||||
}
|
||||
.ac_ks_inter {
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
height: 50px;
|
||||
width: 50px;
|
||||
line-height: 50px;
|
||||
text-align: center;
|
||||
border-radius: 50px;
|
||||
color: white;
|
||||
z-index: 999;
|
||||
font-size: 12px;
|
||||
overflow: hidden
|
||||
}
|
||||
.ac_ks_inter image {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
}
|
||||
.ac-poster-canvas {
|
||||
position: absolute;
|
||||
left: -100%;
|
||||
}
|
||||
.ac_ks_inter + .ac_ks_inter {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.ac-action {
|
||||
margin: initial;
|
||||
width: initial !important;
|
||||
background: initial;
|
||||
padding: initial;
|
||||
font-weight: initial;
|
||||
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
.ac-action image {
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.ac-action text {
|
||||
color: #fff;
|
||||
}
|
||||
Reference in New Issue
Block a user