海报:完善小程序码获取和海报生成
This commit is contained in:
@@ -101,12 +101,12 @@
|
||||
// 使用 canvas 生成海报
|
||||
async function getPoster(params) {
|
||||
poster.src = '';
|
||||
|
||||
poster.shareInfo = props.shareInfo;
|
||||
// #ifdef APP-PLUS
|
||||
poster.canvasId = 'canvasId-' + new Date().getTime();
|
||||
// #endif
|
||||
const canvas = await useCanvas(poster, vm);
|
||||
console.log('canvas',canvas);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import sheep from '@/sheep';
|
||||
import { formatImageUrlProtocol } from './index';
|
||||
import third from '@/sheep/api/migration/third';
|
||||
import { formatImageUrlProtocol, getBase64Src } from './index';
|
||||
|
||||
const goods = (poster) => {
|
||||
const goods = async (poster) => {
|
||||
const width = poster.width;
|
||||
const userInfo = sheep.$store('user').userInfo;
|
||||
|
||||
const wxa_qrcode = (await third.wechat.getWxacode(poster.shareInfo.path, poster.shareInfo.query)).data;
|
||||
return {
|
||||
background: formatImageUrlProtocol(sheep.$url.cdn(sheep.$store('app').platform.share.posterInfo.goods_bg)),
|
||||
list: [
|
||||
@@ -107,7 +108,7 @@ const goods = (poster) => {
|
||||
{
|
||||
name: 'wxacode',
|
||||
type: 'image',
|
||||
val: sheep.$api.third.wechat.getWxacode(poster.shareInfo.path),
|
||||
val: wxa_qrcode,
|
||||
x: width * 0.75,
|
||||
y: width * 1.3,
|
||||
width: width * 0.2,
|
||||
|
||||
@@ -30,3 +30,30 @@ export function formatImageUrlProtocol(url) {
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
export function getBase64Src(base64data, appType) {
|
||||
const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || [];
|
||||
switch (appType) {
|
||||
case 'wechat':
|
||||
const filePath = `${wx.env.USER_DATA_PATH}/tmp_base64src.${format}`;
|
||||
return new Promise((resolve, reject) => {
|
||||
const fileManager = uni.getFileSystemManager();
|
||||
fileManager.writeFile({
|
||||
filePath: filePath,
|
||||
data: bodyData, // base64 数据
|
||||
encoding: 'base64', // 字符编码
|
||||
success: () => {
|
||||
resolve(filePath);
|
||||
},
|
||||
file: (err) => {
|
||||
console.log('base64 保存失败', err);
|
||||
},
|
||||
});
|
||||
});
|
||||
default:
|
||||
console.warn('获得 base64 图片地址只做了微信小程序端的转换,其它端请自行实现!!!');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ export default async function useCanvas(options, vm) {
|
||||
vm,
|
||||
);
|
||||
|
||||
let drawer = getPosterData(options);
|
||||
|
||||
let drawer = await getPosterData(options);
|
||||
console.log(drawer);
|
||||
// 绘制背景图
|
||||
const background = await qsc.drawImg({
|
||||
type: 'image',
|
||||
|
||||
Reference in New Issue
Block a user