|
|
@@ -93,11 +93,14 @@
|
|
|
<div>长按识别二维码</div>
|
|
|
<div>查看详情&点评</div>
|
|
|
</div>
|
|
|
- <div class="QRcodes" ref="QRcodes">
|
|
|
- <div class="logo">
|
|
|
- <img :src="require('@/assets/logo1.png')" width="100%" height="100%" />
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ <vue-qr
|
|
|
+ class="QRcodes"
|
|
|
+ :callback="QRCallback"
|
|
|
+ :text="vueQrText"
|
|
|
+ :dotScale="0.8"
|
|
|
+ :margin="8"
|
|
|
+ :logoSrc="require('@/assets/logo1.png')"
|
|
|
+ :logoMargin="2"></vue-qr>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div
|
|
|
@@ -121,10 +124,11 @@
|
|
|
</template>
|
|
|
<script>
|
|
|
import html2canvas from 'html2canvas';
|
|
|
-import QRCode from 'qrcodejs2';
|
|
|
import { imgToBase64 } from '@/api/index';
|
|
|
+import VueQr from 'vue-qr';
|
|
|
export default {
|
|
|
name: 'share',
|
|
|
+ components: { VueQr },
|
|
|
props: {
|
|
|
// 日报数据
|
|
|
reportTarget: {
|
|
|
@@ -156,37 +160,40 @@ export default {
|
|
|
retryCount: 0,
|
|
|
photosData: [],
|
|
|
zIndex: -1,
|
|
|
+ qrcode: null,
|
|
|
+ vueQrText: '',
|
|
|
};
|
|
|
},
|
|
|
created() {
|
|
|
this.zIndex = -1;
|
|
|
this.canvasImageUrl = '';
|
|
|
- },
|
|
|
- mounted() {
|
|
|
+ this.vueQrText = 'http://1.npz.cn/2/' + this.reportId;
|
|
|
this.toastLoading(0, '生成中...', true);
|
|
|
- // 二维码
|
|
|
- this.creatQrCode();
|
|
|
- if (this.urlList.length) {
|
|
|
- imgToBase64({ urlList: this.urlList }).then((res) => {
|
|
|
- if (res.data && res.code == 200) {
|
|
|
- this.photosData = res.data;
|
|
|
- this.$nextTick(async () => {
|
|
|
- await this.htmlToCanvas();
|
|
|
- });
|
|
|
- } else {
|
|
|
- this.$toast(res.msg);
|
|
|
- this.$nextTick(async () => {
|
|
|
- await this.htmlToCanvas();
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- this.$nextTick(async () => {
|
|
|
- await this.htmlToCanvas();
|
|
|
- });
|
|
|
- }
|
|
|
},
|
|
|
methods: {
|
|
|
+ // 二维码生成成功回调
|
|
|
+ QRCallback() {
|
|
|
+ // 二维码
|
|
|
+ if (this.urlList.length) {
|
|
|
+ imgToBase64({ urlList: this.urlList }).then((res) => {
|
|
|
+ if (res.data && res.code == 200) {
|
|
|
+ this.photosData = res.data;
|
|
|
+ this.$nextTick(async () => {
|
|
|
+ await this.htmlToCanvas();
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.$toast(res.msg);
|
|
|
+ this.$nextTick(async () => {
|
|
|
+ await this.htmlToCanvas();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.$nextTick(async () => {
|
|
|
+ await this.htmlToCanvas();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
//异步执行
|
|
|
imageUrlToBase64(imageUrl) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
@@ -289,46 +296,18 @@ export default {
|
|
|
this.$toast('生成分享图失败,请稍后重试');
|
|
|
});
|
|
|
},
|
|
|
- creatQrCode() {
|
|
|
- // let proText = 'https://suishenbang.nipponpaint.com.cn';
|
|
|
- let path = 'http://1.npz.cn/2/' + this.reportId || '';
|
|
|
- var qrcode = new QRCode(this.$refs.QRcodes, {
|
|
|
- text: path,
|
|
|
- colorDark: '#000000',
|
|
|
- colorLight: 'rgba(255,255,255,0)', // 完全透明背景
|
|
|
- correctLevel: QRCode.CorrectLevel.H,
|
|
|
- width: 90, // 固定尺寸保证安卓一致性
|
|
|
- height: 90,
|
|
|
- margin: 2,
|
|
|
- render: 'canvas',
|
|
|
- onRenderingEnd: () => {
|
|
|
- const canvas = this.$refs.QRcodes.querySelector('canvas');
|
|
|
- // 显式设置物理像素尺寸
|
|
|
- const dpr = window.devicePixelRatio || 1;
|
|
|
- canvas.width = 200 * dpr;
|
|
|
- canvas.height = 200 * dpr;
|
|
|
-
|
|
|
- // 设置CSS显示尺寸保持200x200
|
|
|
- canvas.style.width = '200px';
|
|
|
- canvas.style.height = '200px';
|
|
|
-
|
|
|
- // 优化安卓设备显示
|
|
|
- canvas.style.imageRendering = 'pixelated';
|
|
|
- canvas.style.transform = 'translateZ(0)'; // 触发硬件加速
|
|
|
- canvas.style.backgroundColor = '#fff';
|
|
|
-
|
|
|
- // 调整画布缩放比例
|
|
|
- const ctx = canvas.getContext('2d');
|
|
|
- ctx.scale(dpr, dpr);
|
|
|
- },
|
|
|
- });
|
|
|
- },
|
|
|
closeShare() {
|
|
|
this.canvasImageUrl = '';
|
|
|
this.$emit('setShareImg', false);
|
|
|
this.$emit('setDailyDetailsBox', true);
|
|
|
},
|
|
|
},
|
|
|
+ beforeDestroy() {
|
|
|
+ // 组件销毁时清除实例
|
|
|
+ if (this.qrcode) {
|
|
|
+ this.$refs.qrcode.innerHTML = '';
|
|
|
+ }
|
|
|
+ },
|
|
|
};
|
|
|
</script>
|
|
|
<style lang="scss" scoped>
|