martial-arts/pagesA/my-share/my-share.vue

171 lines
3.8 KiB
Vue
Raw Normal View History

2023-02-21 06:20:06 +00:00
<template>
<view>
2023-02-22 02:39:55 +00:00
<status-container titlet="我的分享" returnc="#FFFFFF">
</status-container>
2023-02-21 06:20:06 +00:00
<!-- 分享图 -->
2023-02-22 02:39:55 +00:00
<image :src="shareImg" mode="widthFix" lazy-load class="qrIamge"></image>
2023-02-21 06:20:06 +00:00
<!-- 底部按钮 -->
<view class="bottom-btn">
<view @tap="downloadImgEv"></view>
</view>
</view>
</template>
<script>
import pitera from '@/components/nothing/pitera.vue';
import yzQr from '@/components/yz-qr/yz-qr.vue';
import {base64ToPath} from '@/jsFile/base64-src.js';
export default {
components:{
pitera,
yzQr
},
data() {
return {
shareImg:'',
}
},
onLoad() {
2023-02-22 02:39:55 +00:00
this.qrCode();
2023-02-21 06:20:06 +00:00
},
2023-02-22 02:39:55 +00:00
2023-02-21 06:20:06 +00:00
methods: {
2023-02-22 02:39:55 +00:00
// 生成二维码
qrCode() {
uni.showLoading({
title:'正在生成推广码',
icon:'loading',
duration:5000
})
// 生成推广码
this.$requst.get('/api/user/personal-poster').then(res=>{
if(res.code==0){
this.shareImg = res.data.poster;
uni.hideLoading();
}
}).catch(err=>{
uni.hideLoading();
uni.showToast({
title:'生成失败',
icon:'none',
position:'bottom'
})
setTimeout(()=>{
uni.navigateBack({delta:1})
},1000)
})
},
//保存相册
2023-02-21 06:20:06 +00:00
downloadImgEv(){
2023-02-22 02:39:55 +00:00
uni.getSetting({//获取用户的当前设置
success:(res)=> {
if(res.authSetting['scope.writePhotosAlbum']){//验证用户是否授权可以访问相册
this.saveImageToPhotosAlbum();
}else{
uni.authorize({//如果没有授权,向用户发起请求
scope: 'scope.writePhotosAlbum',
success:()=> {
this.saveImageToPhotosAlbum();
},
fail:()=>{
uni.showModal({
content:'检测到您没打开保存图片的权限,是否去设置打开?',
confirmText: "确认",
cancelText:'取消',
success: (res) => {
if(res.confirm){
uni.openSetting({
success: (res) => {
console.log(res);
// this.getLocation();
}
})
}else{
console.log('取消');
return false;
}
}
})
setTimeout(()=>{
uni.openSetting({//调起客户端小程序设置界面,让用户开启访问相册
success:(res2)=> {
// console.log(res2.authSetting)
}
});
},3000);
}
})
}
}
})
},
saveImageToPhotosAlbum(){
let base64=this.shareImg.replace(/^data:image\/\w+;base64,/, "");//去掉data:image/png;base64,
let filePath=wx.env.USER_DATA_PATH + '/hym_pay_qrcode.png';
uni.getFileSystemManager().writeFile({
filePath:filePath , //创建一个临时文件名
data: base64, //写入的文本或二进制数据
encoding: 'base64', //写入当前文件的字符编码
success: res => {
2023-02-21 06:20:06 +00:00
uni.saveImageToPhotosAlbum({
2023-02-22 02:39:55 +00:00
filePath: filePath,
success: function(res2) {
uni.showToast({
title:'保存成功',
icon:'success',
duration:2000
})
2023-02-21 06:20:06 +00:00
},
2023-02-22 02:39:55 +00:00
fail: function(err) {
uni.showToast({
title:'保存失败',
icon:'error',
duration:2000
})
2023-02-21 06:20:06 +00:00
}
2023-02-22 02:39:55 +00:00
})
},
fail: err => {
//console.log(err)
2023-02-21 06:20:06 +00:00
}
})
}
2023-02-22 02:39:55 +00:00
2023-02-21 06:20:06 +00:00
}
}
</script>
<style>
image {
width: 100%;
}
.bottom-btn {
position: fixed;
bottom: 0;
left: 0;
right: 0;
2023-02-22 02:39:55 +00:00
padding:20rpx 20rpx;
2023-02-21 06:20:06 +00:00
display: flex;
justify-content: flex-end;
box-shadow: 0rpx -3rpx 20rpx rgba(0,0,0,.05);
}
.bottom-btn view {
background-color: #eb5d10;
color: #FFFFFF;
padding: 20rpx 40rpx;
border-radius: 80rpx;
font-size: 36rpx;
}
2023-02-22 02:39:55 +00:00
.qrIamge {
width: 90%;
display: block;
margin: -120rpx auto 0;
}
2023-02-21 06:20:06 +00:00
</style>