Commit 75c5d4e0 authored by Xuguangxing's avatar Xuguangxing

fix: 海报空图以及intersection-poilly的问题

parent 89429060
...@@ -167,48 +167,69 @@ export default { ...@@ -167,48 +167,69 @@ export default {
} }
return n; return n;
}, },
async prepare(rawData) { // async prepare(rawData) {
this.sharePicData = rawData; // this.sharePicData = rawData;
this.handleAvator(rawData); // this.handleAvator(rawData);
// // 将每个字符套入行内标签,用于解决canvas fillText的不换行问题
// let skuName = '';
// const originSkuName = rawData.skuName || '';
// for (let i = 0; i < originSkuName.length; i++) {
// skuName += `<span>${originSkuName[i]}</span>`;
// }
// this.skuName = skuName;
// const [endTimeYMD, endTimeHMS = ''] = (rawData.endTime && rawData.endTime.split(' ')) || [];
// if (endTimeYMD) {
// const day = new Date(endTimeYMD);
// this.endTime = `${day.getMonth() + 1}月${day.getDate()}日 ${endTimeHMS}`;
// }
// const [qrcodeUrl] = await groupBuyApi.getQrcodeUrl(rawData);
// this.qrcodeUrl = qrcodeUrl;
// },
async createAndUploadPic(sharePicData) {
this.$store.dispatch('change_loading_pic', true);
this.sharePicData = sharePicData;
this.handleAvator(sharePicData);
// 将每个字符套入行内标签,用于解决canvas fillText的不换行问题 // 将每个字符套入行内标签,用于解决canvas fillText的不换行问题
let skuName = ''; let skuName = '';
const originSkuName = rawData.skuName || ''; const originSkuName = sharePicData.skuName || '';
for (let i = 0; i < originSkuName.length; i++) { for (let i = 0; i < originSkuName.length; i++) {
skuName += `<span>${originSkuName[i]}</span>`; skuName += `<span>${originSkuName[i]}</span>`;
} }
this.skuName = skuName; this.skuName = skuName;
const [endTimeYMD, endTimeHMS = ''] = (rawData.endTime && rawData.endTime.split(' ')) || []; const [endTimeYMD, endTimeHMS = ''] =
(sharePicData.endTime && sharePicData.endTime.split(' ')) || [];
if (endTimeYMD) { if (endTimeYMD) {
const day = new Date(endTimeYMD); const day = new Date(endTimeYMD);
this.endTime = `${day.getMonth() + 1}${day.getDate()}${endTimeHMS}`; this.endTime = `${day.getMonth() + 1}${day.getDate()}${endTimeHMS}`;
} }
const [qrcodeUrl] = await groupBuyApi.getQrcodeUrl(rawData); const [qrcodeUrl] = await groupBuyApi.getQrcodeUrl(sharePicData);
this.qrcodeUrl = qrcodeUrl; this.qrcodeUrl = qrcodeUrl;
},
async createAndUploadPic(sharePicData) {
this.$store.dispatch('change_loading_pic', true);
await this.prepare(sharePicData);
this.$nextTick(() => { this.$nextTick(() => {
html2canvas(this.$refs.sharePic, { setTimeout(() => {
width: 1080, html2canvas(this.$refs.sharePic, {
height: 1920, width: 1080,
useCORS: true, height: 1920,
scale: 1, useCORS: true,
allowTaint: false scale: 1,
}) allowTaint: false
.then(canvas => {
canvas.name = `${this.randomString()}.jpeg`;
canvas.toBlob(blob => this.uploadPic(blob), 'image/jpeg', 0.85);
}) })
.catch(error => { .then(canvas => {
this.errorHandler(error); canvas.name = `${this.randomString()}.jpeg`;
}); canvas.toBlob(blob => this.uploadPic(blob), 'image/jpeg', 0.85);
})
.catch(error => {
this.errorHandler(error);
});
}, 300);
}); });
}, },
// 上传海报到七牛,成功后触发outputPicUr事件,参数是七牛文件地址 // 上传海报到七牛,成功后触发outputPicUr事件,参数是七牛文件地址
......
...@@ -12,6 +12,7 @@ import Raven from 'raven-js'; ...@@ -12,6 +12,7 @@ import Raven from 'raven-js';
import RavenVue from 'raven-js/plugins/vue'; import RavenVue from 'raven-js/plugins/vue';
import { release } from '../.sentryclirc'; import { release } from '../.sentryclirc';
import lazyload from '@qg/cherry-ui/src/lazyload/index'; import lazyload from '@qg/cherry-ui/src/lazyload/index';
import 'intersection-observer';
if (process.env.SENTRY_ENV !== 'test' && process.env.NODE_ENV === 'production') { if (process.env.SENTRY_ENV !== 'test' && process.env.NODE_ENV === 'production') {
Raven.config('//8d1b2a5f74bb42ad806e52a11b1173f2@sentry.q-gp.com/80', { Raven.config('//8d1b2a5f74bb42ad806e52a11b1173f2@sentry.q-gp.com/80', {
release, release,
......
...@@ -104,22 +104,27 @@ export default { ...@@ -104,22 +104,27 @@ export default {
mounted() { mounted() {
this.$nextTick(() => { this.$nextTick(() => {
if (this.$refs.buttonArea) { if (this.$refs.buttonArea) {
this.observer = new IntersectionObserver(entries => { if (IntersectionObserver) {
entries.forEach(item => { this.observer &&
if (item.intersectionRatio == 0) { this.observer.unobserve &&
this.$emit('changeButtonVisible', true); this.observer.unobserve(this.$refs.buttonArea);
} else { this.observer = new IntersectionObserver(entries => {
this.$emit('changeButtonVisible', false); entries.forEach(item => {
} if (item.intersectionRatio == 0) {
this.$emit('changeButtonVisible', true);
} else {
this.$emit('changeButtonVisible', false);
}
});
}); });
}); }
this.observer.USE_MUTATION_OBSERVER = false; this.observer.USE_MUTATION_OBSERVER = false;
this.observer.observe(this.$refs.buttonArea); this.observer.observe(this.$refs.buttonArea);
} }
}); });
}, },
beforeDestroy() { beforeDestroy() {
if (this.$refs.buttonArea) { if (this.$refs.buttonArea && this.observer) {
this.observer.unobserve(this.$refs.buttonArea); this.observer.unobserve(this.$refs.buttonArea);
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment