Commit 3246d92f by liimin

修改生产名片逻辑

1 parent 139abfd7
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
}, },
"usingComponents": { "usingComponents": {
"authorize": "components/Authorize/Authorize", "authorize": "components/Authorize/Authorize",
"phone-number": "components/PhoneNumber/PhoneNumber" "phone-number": "components/PhoneNumber/PhoneNumber",
"poster": "components/Poster/poster/index"
}, },
"sitemapLocation": "sitemap.json", "sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents" "lazyCodeLoading": "requiredComponents"
......
{
"component": true
}
\ No newline at end of file \ 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 \ 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 \ No newline at end of file
{
"component": true,
"usingComponents": {
"we-canvas": "../index/index"
}
}
\ No newline at end of file \ 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 \ 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"; ...@@ -11,6 +11,7 @@ import Draw from "../../../utils/Draw";
import { ssoApi, entmicroApi } from "../../../api/api"; import { ssoApi, entmicroApi } from "../../../api/api";
import util from "../../../utils/util"; import util from "../../../utils/util";
import { trackData } from "../../../utils/data"; import { trackData } from "../../../utils/data";
import Poster from '../../../components/Poster/poster/poster';
Page({ Page({
behaviors: [menuMixin], behaviors: [menuMixin],
/** /**
...@@ -62,7 +63,8 @@ Page({ ...@@ -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'], 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, clueCurrent: 0,
awardBanner: [{src: 'company-img7.png', name: '组织荣誉'}, {src: 'company-img71.png', name: '行业奖项'}], awardBanner: [{src: 'company-img7.png', name: '组织荣誉'}, {src: 'company-img71.png', name: '行业奖项'}],
awardCurrent: 0 awardCurrent: 0,
posterConfig:{}
}, },
introduce(e) { introduce(e) {
const curTabIndex = e.currentTarget.dataset.index; const curTabIndex = e.currentTarget.dataset.index;
...@@ -216,14 +218,14 @@ Page({ ...@@ -216,14 +218,14 @@ Page({
const canvasWidth = 208, const canvasWidth = 208,
canvasHeight = 166, canvasHeight = 166,
textBaseline = "top"; textBaseline = "top";
const draw_function = new Draw(this, { // const draw_function = new Draw(this, {
width: canvasWidth, // width: canvasWidth,
height: canvasHeight, // height: canvasHeight,
// pixelRatio: 2, // // pixelRatio: 2,
// backgroundColor: '#096' // // backgroundColor: '#096'
}); // });
const drawCard = (callBack) => { const drawCard = (callBack) => {
let index = 0; // let index = 0;
const iconWidth = 9, const iconWidth = 9,
iconHeight = 9, iconHeight = 9,
iconX = 18, iconX = 18,
...@@ -285,7 +287,7 @@ Page({ ...@@ -285,7 +287,7 @@ Page({
}, },
{ {
text: data.operation, text: data.operation,
x: 22 + draw_function.getTextWidth(data.staffName, 14), x: 22, //+ draw_function.getTextWidth(data.staffName, 14),
y: 40, y: 40,
color: "#6E6E7A", color: "#6E6E7A",
fontWeight: 400, fontWeight: 400,
...@@ -309,34 +311,59 @@ Page({ ...@@ -309,34 +311,59 @@ Page({
lineHeight: 9, lineHeight: 9,
}, },
]; ];
const drawImages = (callBack) => { this.setData({ posterConfig: { width: 208,
draw_function.drawImages(imgList[index], () => { height: 166,texts:textList,images:imgList} }, () => {
index += 1; Poster.create();
if (index != imgList.length) drawImages(callBack);
else callBack();
}); });
// 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']
// })
// });
// }
// });
}; };
drawImages(() => { drawCard();
try { },
textList.map((e, ind) => { /**
e.textBaseline = textBaseline; * 异步生成海报
draw_function.drawText(e); */
if (ind == textList.length - 1) throw true; onPosterSuccess(src) {
}); const { detail } = src;
} catch (error) { // wx.previewImage({
draw_function.toDataURL(({ path }) => { // current: detail,
// urls: [detail]
// })
this.setData({ this.setData({
shareImg: path, shareImg: detail,
}); });
wx.hideLoading() wx.hideLoading()
wx.showShareMenu({ wx.showShareMenu({
menus: ['shareAppMessage', 'shareTimeline'] menus: ['shareAppMessage', 'shareTimeline']
}) })
}); // setData配置数据
} // this.setData({ posterConfig: {...} }, () => {
}); // Poster.create();
}; // });
drawCard();
}, },
// 获取用户昵称 // 获取用户昵称
getUserProfile(e) { getUserProfile(e) {
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
<import src="../../template/menu/menu.wxml" /> <import src="../../template/menu/menu.wxml" />
<import src="index.skeleton.wxml"/> <import src="index.skeleton.wxml"/>
<template is="skeleton" wx:if="true" /> <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}}" > <view class="main-box" wx:if="{{cardInfo}}" >
<user-info data-skeleton-hide="cardInfo" cardInfo="{{cardInfo}}"></user-info> <user-info data-skeleton-hide="cardInfo" cardInfo="{{cardInfo}}"></user-info>
<view class="main-bottom"> <view class="main-bottom">
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
"minifyWXML": true, "minifyWXML": true,
"showES6CompileOption": false, "showES6CompileOption": false,
"useCompilerPlugins": false, "useCompilerPlugins": false,
"ignoreUploadUnusedFiles": true "ignoreUploadUnusedFiles": false
}, },
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "2.25.4", "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!