Browse Source

‘完善我的二维码分享,保存相册’

master
Lj 4 weeks ago
parent
commit
09b5cc7e4a
1 changed files with 79 additions and 2 deletions
  1. +79
    -2
      pages/subcomponent/promo-qrcode.vue

+ 79
- 2
pages/subcomponent/promo-qrcode.vue View File

@ -26,14 +26,15 @@
</view> </view>
<!-- 底部按钮 --> <!-- 底部按钮 -->
<view class="bottom-btns-modal"> <view class="bottom-btns-modal">
<button class="btn gray">分享给好友</button>
<button class="btn green">保存到本地</button>
<button class="btn gray" open-type="share">分享给好友</button>
<button class="btn green" @tap="saveToAlbum">保存到本地</button>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import pullRefreshMixin from '@/pages/mixins/pullRefreshMixin.js' import pullRefreshMixin from '@/pages/mixins/pullRefreshMixin.js'
import config from '@/api/config.js'
export default { export default {
mixins: [pullRefreshMixin], mixins: [pullRefreshMixin],
@ -58,6 +59,23 @@
// //
this.getQrcode() this.getQrcode()
}, },
//
// #ifdef MP-WEIXIN
onShareAppMessage() {
return {
title: `${this.userInfo.name}邀请您一起参与旧衣回收`,
path: `/pages/component/home?shareId=${this.inviteCode}`,
imageUrl: this.qrcodeUrl || '/static/share-default.png'
}
},
onShareTimeline() {
return {
title: `${this.userInfo.name}邀请您一起参与旧衣回收,环保从我做起!`,
query: `shareId=${this.inviteCode}`,
imageUrl: this.qrcodeUrl || '/static/share-default.png'
}
},
// #endif
methods: { methods: {
async onRefresh() { async onRefresh() {
// //
@ -87,6 +105,65 @@
}) })
} }
}, },
//
saveToAlbum() {
if (!this.qrcodeUrl) {
uni.showToast({
title: '二维码还未加载完成',
icon: 'none'
})
return
}
//
uni.getSetting({
success: (res) => {
if (!res.authSetting['scope.writePhotosAlbum']) {
//
uni.authorize({
scope: 'scope.writePhotosAlbum',
success: () => {
this.doSaveImage()
},
fail: () => {
//
uni.showModal({
title: '提示',
content: '需要您授权保存相册权限',
showCancel: false,
success: () => {
uni.openSetting()
}
})
}
})
} else {
//
this.doSaveImage()
}
}
})
},
//
doSaveImage() {
uni.saveImageToPhotosAlbum({
filePath: this.qrcodeUrl,
success: () => {
uni.showToast({
title: '保存成功',
icon: 'success'
})
},
fail: (err) => {
console.log('保存失败', err)
uni.showToast({
title: '保存失败',
icon: 'none'
})
}
})
}
} }
} }
</script> </script>


Loading…
Cancel
Save