<template>
|
<view>
|
<view class="button p-t-12 bg-white">
|
<button :disabled="canvasImages == '' ? true : false" type="primary" @click="downloadImg">下载二维码</button>
|
<button :disabled="canvasImages != '' ? false : true" @click="previewHandle">预览二维码</button>
|
<!-- #ifdef MP-WEIXIN -->
|
<!-- <button type="warn" :disabled="canvasImages != '' ? false : true" open-type="share">分享给朋友</button> -->
|
<!-- #endif -->
|
</view>
|
<shareImages ref="canvas" :canvasWidth="canvasWidth" :canvasHeight="canvasHeight" :shareTitle="shareTitle"
|
:goodsTitle="goodsTitle" :shareImage="shareImage" :goodsTitle2="goodsTitle2" :qrSize="qrSize" :qrUrl="qrUrl"
|
@success="shareSuccess" :canvasID="canvasID">
|
</shareImages>
|
</view>
|
</template>
|
|
<script>
|
import shareImages from '@/components/hj-placard/shareImages.vue'
|
export default {
|
components: {
|
shareImages
|
},
|
data() {
|
return {
|
name: '',
|
canvasID: "myQrcode",
|
canvasImages: '',
|
canvasWidth: 375, // 宽度
|
canvasHeight: 650, // 高度
|
shareTitle: '我是这张图片的标题', // 分享标题
|
goodsTitle: '\n', // 商品宣传标题
|
goodsTitle2: '',
|
shareImage: 'https://hmy-flower.oss-cn-shanghai.aliyuncs.com/d4/d43cdefc7b8f4c3e91fb451a236a4435WechatIMG2882.jpg', // 背景图片
|
qrSize: 100, // 二维码大小
|
qrUrl: '', // 生成二维码的链接
|
}
|
},
|
onLoad() {
|
if (!this.currentInfo.partnerDTO) {
|
this.$message.showToast('请先完善合伙人信息')
|
return
|
}
|
this.name = this.currentInfo.partnerDTO.name || '佚名'
|
this.qrUrl =
|
`https://scan.hmyxianhua.com/wx/?partnerUserId=${this.currentInfo.id||'-'}&partnerUserName=${this.name||'-'}`
|
this.goodsTitle = `${this.name||'-'}的推广二维码`
|
this.goodsTitle2 = `扫码注册绑定合伙人`
|
this.$message.showLoading()
|
setTimeout(() => {
|
this.createsShareImage()
|
}, 500)
|
setTimeout(() => {
|
this.$message.hideLoading()
|
}, 2000)
|
|
},
|
methods: {
|
// 生成分享图片
|
createsShareImage() {
|
// console.log(this.$refs.canvas)
|
this.$refs.canvas.canvasCreate();
|
},
|
// 预览图片
|
previewHandle() {
|
uni.previewImage({
|
urls: [this.canvasImages],
|
});
|
},
|
// 回调图片地址
|
shareSuccess(e) {
|
// console.log('地址',e)
|
this.canvasImages = e
|
},
|
downloadImg() {
|
// this.$refs.canvas.downloadImg();
|
uni.saveImageToPhotosAlbum({
|
filePath: this.canvasImages,
|
success: function() {
|
console.log('save success');
|
uni.showToast({
|
title: '保存成功'
|
})
|
},
|
fail(res) {
|
console.error(res)
|
uni.showToast({
|
title: '保存失败。',
|
icon: 'error'
|
})
|
}
|
})
|
|
|
},
|
// 分享
|
onShareAppMessage(res) {
|
// if (res.from === 'button') {
|
// console.log(res.target)
|
// }
|
return {
|
title: `${this.name||'-'}的推广二维码`,
|
path: this.canvasImages
|
}
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
.button {
|
display: flex;
|
}
|
</style>
|