import { getMiniprogramQrcodeByPage,getTouTiaoMiniprogramQrcodeByPage } from "@/api/auth"; export default { data() { return { qrcodeText: "", isPosterCanvasVisable: false, isQrcodeCanvasVisable: false, filename: "", is_preview: true, }; }, methods: { handleQrcodeCreateSuccess(path) { this.x_cb(path); }, pathToQrcodePath(type = 'poster', data) { if (this.pre_qrcode) return Promise.resolve(this.pre_qrcode); // #ifdef MP switch (type) { case 'poster': var { full_path, scene } = this.$util.getFullPath(this.shareQrcodeData); break; case 'gift': var full_path = data.url; var scene = `id=${data.id}&guid=${data.uid}&goid=${data.oid}`; break; case 'pink': var full_path = data.url; var scene = `id=${data.id}&uid=${data.uid}&pid=${data.pid}&oid=${data.oid}`; break; case 'download': var full_path = data.url; var scene = `id=${data.id}&spread_uid=${data.spread_uid}`; break; case 'spread': var full_path = data.url; var scene = `spread_uid=${data.spread_uid}`; break; case 'special': var full_path = data.url; var scene = `id=${data.id}&spread_uid=${data.spread_uid}`; break; default: break; } /* #ifndef MP-TOUTIAO */ return getMiniprogramQrcodeByPage(full_path, scene).then((res) => { return this.$util.getImagePath( res.data.url + "?t=" + new Date().getTime() ); }); /* #endif */ return getTouTiaoMiniprogramQrcodeByPage(full_path, scene).then((res) => { return this.$util.getImagePath( res.data.url + "?t=" + new Date().getTime() ); }).catch(err=>{ this.$util.showMsg(err) setTimeout(() => { uni.navigateBack({ delta: 1 }); }, 1500); }); // #endif // #ifndef MP switch (type) { case 'poster': var path = this.site_url; this.qrcodeText = path; break; case 'gift': var path = this.site_url; this.qrcodeText = path; break; case 'pink': var path = this.site_url; this.qrcodeText = path; break; case 'download': var path = this.url; this.qrcodeText = path; break; case 'spread': var path = this.url; this.qrcodeText = path; break; default: break; } return new Promise((resolve) => { this.x_cb = (v) => { this.isQrcodeCanvasVisable = false; resolve(v); }; this.isQrcodeCanvasVisable = true; }); // #endif }, // 生成分享海报 async createSharePoster(type = "poster", data = {}) { /* #ifdef MP-KUAISHOU */ return this.$util.showMsg("点击右上角分享"); /* #endif */ let filename = this.filename; if (!filename) { uni.showLoading({ mask: true, }); const task1 = this.$util.getImagePath(this.poster_image); console.log(this.is_certificate,data.pre_qrcode); let task2; if (this.is_certificate) { task2 = this.$util.getImagePath(this.pre_qrcode); } else { task2 = this.pathToQrcodePath(type, data); } try { const [bgPath, codePath] = await Promise.all([task1, task2]); this.isPosterCanvasVisable = true; await this.$util.asyncNextTick(this); const fn = this.renderProductPoster || this.$poster.renderProductPoster; console.log(fn) const result = await fn(this, "poster", bgPath, codePath); console.log(result) this.isPosterCanvasVisable = false; filename = this.filename = result; uni.hideLoading(); } catch (err) { uni.hideLoading(); this.isPosterCanvasVisable = false; this.$util.showMsg(err); return; } } this.is_preview && uni.previewImage({ current: 0, urls: [filename], }); }, } };