|
|
- <template>
- <view class="se-p-60">
- <view class="se-p-40 se-flex se-bgc-white se-br-20 se-bs se-flex-v-sa">
- <text class="se-pb-50 se-pt-100">邀请好友</text>
- <image class="se-a-300 se-br-20" :src="qrcode" mode=""></image>
- <!-- <text class="se-pt-50 se-pb-80">邀请码:{{shareId}} </text> -->
- <!-- 邀请码:TKAFGED -->
- </view>
- <view class="se-px-100 se-pt-80 se-fs-20 se-flex">
- <view @click="onSubmit"
- class="se-mx-10 se-flex-1 se-br-40 se-flex-h-c se-h-80 se-lh-80 se-ta-c se-fs-28 se-c-white se-bgc-green">
- <text>保存到本地</text>
- </view>
- </view>
- </view>
- </template>
-
- <script>
- import { getInviteCode } from "@/common/api.js"
- export default {
- data() {
- return {
- qrcode:"",
- shareId:""
- }
- },
- watch: {
-
- },
- onLoad(options) {
- this.onInviteCode()
- },
- methods: {
- onInviteCode(){
- let that = this
- let params={}
- getInviteCode(params).then(response=>{
- console.info("getInviteCode",response)
- that.qrcode = response.result.url
- that.shareId = response.result.shareId
- }).catch(error=>{
-
- })
- },
- onSubmit(){
- const url = this.qrcode;
- // 先下载网络图片到本地
- uni.downloadFile({
- url, // 网络图片地址
- success: (res) => {
- if (res.statusCode === 200) {
- // 下载成功,调用保存图片接口
- uni.saveImageToPhotosAlbum({
- filePath: res.tempFilePath, // 本地图片路径
- success: () => {
- uni.showToast({
- title: '图片保存成功',
- icon: 'success',
- });
- },
- fail: (err) => {
- if (err.errMsg.includes('auth')) {
- // 如果用户没有授权,提示并引导用户授权
- uni.showModal({
- title: '授权提示',
- content: '需要授权保存图片到相册,是否前往设置授权?',
- success: (res) => {
- if (res.confirm) {
- uni.openSetting();
- }
- },
- });
- } else {
- uni.showToast({
- title: '保存失败',
- icon: 'none',
- });
- }
- },
- });
- } else {
- uni.showToast({
- title: '图片下载失败',
- icon: 'none',
- });
- }
- },
- fail: () => {
- uni.showToast({
- title: '图片下载失败',
- icon: 'none',
- });
- },
- });
- },
-
- },
- onReady() {
-
- },
- }
- </script>
-
- <style>
- page {
- background-color: #f5f5f5;
- }
- </style>
|