Commit 3246d92f by liimin

修改生产名片逻辑

1 parent 139abfd7
......@@ -27,7 +27,8 @@
},
"usingComponents": {
"authorize": "components/Authorize/Authorize",
"phone-number": "components/PhoneNumber/PhoneNumber"
"phone-number": "components/PhoneNumber/PhoneNumber",
"poster": "components/Poster/poster/index"
},
"sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents"
......
{
"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).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)
.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 = {}, that) {
options = {
...defaultOptions,
...options,
};
const pages = getCurrentPages();
let ctx = pages[pages.length - 1];
if (that) ctx = that
const poster = ctx.selectComponent(options.selector);
delete options.selector;
return poster;
};
Poster.create = (reset = false, that) => {
const poster = Poster({}, that);
if (!poster) {
console.error('请设置组件的id="poster"!!!');
} else {
return Poster({}, that).onCreate(reset);
}
}
export default Poster;
......@@ -11,6 +11,7 @@ import Draw from "../../../utils/Draw";
import { ssoApi, entmicroApi } from "../../../api/api";
import util from "../../../utils/util";
import { trackData } from "../../../utils/data";
import Poster from '../../../components/Poster/poster/poster';
Page({
behaviors: [menuMixin],
/**
......@@ -62,7 +63,8 @@ Page({
clueList: ['clue-img2.webp', 'clue-img3.webp', 'clue-img4.webp', 'clue-img5.webp', 'clue-img6.webp', 'clue-img7.webp', 'clue-img8.webp', 'clue-img9.webp', 'clue-img10.webp', 'clue-img11.webp', 'clue-img12.webp', 'clue-img13.webp'],
clueCurrent: 0,
awardBanner: [{src: 'company-img7.png', name: '组织荣誉'}, {src: 'company-img71.png', name: '行业奖项'}],
awardCurrent: 0
awardCurrent: 0,
posterConfig:{}
},
introduce(e) {
const curTabIndex = e.currentTarget.dataset.index;
......@@ -216,14 +218,14 @@ Page({
const canvasWidth = 208,
canvasHeight = 166,
textBaseline = "top";
const draw_function = new Draw(this, {
width: canvasWidth,
height: canvasHeight,
// pixelRatio: 2,
// backgroundColor: '#096'
});
// const draw_function = new Draw(this, {
// width: canvasWidth,
// height: canvasHeight,
// // pixelRatio: 2,
// // backgroundColor: '#096'
// });
const drawCard = (callBack) => {
let index = 0;
// let index = 0;
const iconWidth = 9,
iconHeight = 9,
iconX = 18,
......@@ -285,7 +287,7 @@ Page({
},
{
text: data.operation,
x: 22 + draw_function.getTextWidth(data.staffName, 14),
x: 22, //+ draw_function.getTextWidth(data.staffName, 14),
y: 40,
color: "#6E6E7A",
fontWeight: 400,
......@@ -309,35 +311,60 @@ Page({
lineHeight: 9,
},
];
const drawImages = (callBack) => {
draw_function.drawImages(imgList[index], () => {
index += 1;
if (index != imgList.length) drawImages(callBack);
else callBack();
});
};
drawImages(() => {
try {
textList.map((e, ind) => {
e.textBaseline = textBaseline;
draw_function.drawText(e);
if (ind == textList.length - 1) throw true;
});
} catch (error) {
draw_function.toDataURL(({ path }) => {
this.setData({
shareImg: path,
});
wx.hideLoading()
wx.showShareMenu({
menus: ['shareAppMessage', 'shareTimeline']
})
});
}
});
this.setData({ posterConfig: { width: 208,
height: 166,texts:textList,images:imgList} }, () => {
Poster.create();
});
// const drawImages = (callBack) => {
// draw_function.drawImages(imgList[index], () => {
// index += 1;
// if (index != imgList.length) drawImages(callBack);
// else callBack();
// });
// };
// drawImages(() => {
// try {
// textList.map((e, ind) => {
// e.textBaseline = textBaseline;
// draw_function.drawText(e);
// if (ind == textList.length - 1) throw true;
// });
// } catch (error) {
// draw_function.toDataURL(({ path }) => {
// this.setData({
// shareImg: path,
// });
// wx.hideLoading()
// wx.showShareMenu({
// menus: ['shareAppMessage', 'shareTimeline']
// })
// });
// }
// });
};
drawCard();
},
/**
* 异步生成海报
*/
onPosterSuccess(src) {
const { detail } = src;
// wx.previewImage({
// current: detail,
// urls: [detail]
// })
this.setData({
shareImg: detail,
});
wx.hideLoading()
wx.showShareMenu({
menus: ['shareAppMessage', 'shareTimeline']
})
// setData配置数据
// this.setData({ posterConfig: {...} }, () => {
// Poster.create();
// });
},
// 获取用户昵称
getUserProfile(e) {
this.setData({
......
......@@ -4,6 +4,9 @@
<import src="../../template/menu/menu.wxml" />
<import src="index.skeleton.wxml"/>
<template is="skeleton" wx:if="true" />
<poster id="poster" config="{{posterConfig}}" bind:success="onPosterSuccess" bind:fail="onPosterFail">
<button>点击生成海报</button>
</poster>
<view class="main-box" wx:if="{{cardInfo}}" >
<user-info data-skeleton-hide="cardInfo" cardInfo="{{cardInfo}}"></user-info>
<view class="main-bottom">
......@@ -39,7 +42,7 @@
</block> -->
</block>
</view>
<view wx:if="{{!hasUserInfo}}" class="user-profile" bindtap="getUserProfile"></view>
<!-- 服务咨询 -->
<view bindtap="goConsult">
......
......@@ -40,7 +40,7 @@
"minifyWXML": true,
"showES6CompileOption": false,
"useCompilerPlugins": false,
"ignoreUploadUnusedFiles": true
"ignoreUploadUnusedFiles": false
},
"compileType": "miniprogram",
"libVersion": "2.25.4",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!