From 6e12337e17704d873d8954d80e4567a94e23d92d Mon Sep 17 00:00:00 2001 From: xuxueyang <xuxy@fengyuntec.com> Date: 星期五, 09 八月 2024 19:02:14 +0800 Subject: [PATCH] 1 --- sub_pages/partner/partner-info/partner-code.vue | 106 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 95 insertions(+), 11 deletions(-) diff --git a/sub_pages/partner/partner-info/partner-code.vue b/sub_pages/partner/partner-info/partner-code.vue index 0d43c5f..4202524 100644 --- a/sub_pages/partner/partner-info/partner-code.vue +++ b/sub_pages/partner/partner-info/partner-code.vue @@ -2,9 +2,17 @@ <!-- 联系我们 --> <!-- --> <view class="contact-container"> - <view class="container" @click="saveCode"> - <!-- <image src="../../../static/uni.png" mode="aspectFit" class="code"></image> --> + <view class="container" @click="saveCode" v-if="!codeUrl"> <canvas type="2d" id="myQrcode" class="code"></canvas> + <view class="info"> + <view class="desc"> + <p>{{name||'-'}}的推广二维码</p> + <p style="font-size: 600;color: #000;">点击保存二维码</p> + </view> + </view> + </view> + <view v-if="codeUrl" @click="saveImg"> + <image :src="codeUrl" class="code-img"></image> <view class="info"> <view class="desc"> <p>{{name||'-'}}的推广二维码</p> @@ -23,23 +31,90 @@ return { name: '', userId: '', + codeUrl: '', canvas: undefined, } }, + // onShareAppMessage() { + // let params = `id=${this.info.Id}` + // if (this.isGroup) { + // params += `&groupId=${this.groupId}` + // } + // if (this.memberId) { + // params += `&inviteId=${this.memberId}` + // } + // let path = `/pages/home/product/detail?${params}` + // return { + // title: this.info.Name, + // path: path + // } + // } onLoad(options) { if (!this.currentInfo.partnerDTO) { this.$message.showToast('请先完善合伙人信息') return } + //有定制二维码,显示定制二维码 + this.codeUrl = this.currentInfo.partnerDTO.codeUrl || '' this.name = this.currentInfo.partnerDTO.name || '佚名' // this.userId = this.currentInfo.userId - this.initcode() + if (!this.codeUrl) + this.initcode() }, methods: { + async saveImg() { + await this.$message.confirm('确定保存此文件吗') + let _this = this + _this.$message.showLoading() + + uni.downloadFile({ + url: _this.codeUrl, //下载地址接口返回 + success: (data) => { + _this.$message.hideLoading() + console.log('success', data) + if (data.statusCode === 200) { + //文件保存到本地 + uni.saveImageToPhotosAlbum({ + filePath: data.tempFilePath, + success: function() { + console.log('save success'); + uni.showToast({ + title: '保存成功' + }) + }, + fail(res) { + console.error(res) + uni.showToast({ + title: '保存失败。', + icon: 'error' + }) + } + }) + + }else{ + uni.showToast({ + title: '保存失败。.', + icon: 'error' + }) + } + }, + fail: (err) => { + _this.$message.hideLoading() + + console.log(err); + uni.showToast({ + icon: 'none', + mask: true, + title: '失败请重新下载', + }); + }, + }); + }, initcode() { let that = this const query = uni.createSelectorQuery() - + var qrUrl = + `https://scan.hmyxianhua.com/wx/?partnerUserId=${this.currentInfo.id||'-'}&partnerUserName=${this.name||'-'}` query.select('#myQrcode') .fields({ node: true, @@ -50,8 +125,8 @@ that.canvas = canvas // 调用方法drawQrcode生成二维码 drawQrcode({ - callback:function(e){ - console.log('drawQrcode callback',e) + callback: function(e) { + console.log('drawQrcode callback', e) }, canvas: canvas, canvasId: 'myQrcode', @@ -60,11 +135,12 @@ padding: 30, background: '#ffffff', foreground: '#000000', - text: JSON.stringify({ - 'name': that.name, - 'userId': that.currentInfo.id, - 'version': '1.0.0' - }), + // text: JSON.stringify({ + // 'name': that.name, + // 'userId': that.currentInfo.id, + // 'version': '1.1.0' + // }), + text: qrUrl // text: `https://www.hmyxianhua.com/wx-c-jump/sub_pages/customer/customer-info/customer-info?name=${that.name}&userId=${that.currentInfo.id}` // JSON.stringify({ // 'name': that.name, @@ -123,6 +199,14 @@ .contact-container { position: relative; + .code-img { + width: 600rpx; + min-height: 600rpx; + display: inline-block; + margin: 0 auto; + margin-top: 100rpx; + } + .container { position: absolute; top: 148rpx; -- Gitblit v1.9.3