123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <template>
- <view class="box">
- <view class="maBoximg">
-
- <image :src="qrImg" mode="" class="QR"></image>
- </view>
- <image src="../../static/img/saveBtn.png" mode="" class="saveBtn" @click="saveEwm"></image>
- </view>
- </template>
- <script>
-
- export default {
-
- data() {
- return {
-
- qrImg: '',
- openSettingBtnHidden: true,//是否授权
- }
- },
- onLoad() {
-
- this.getQR();
-
- },
- methods: {
- getQR() {
- uni.showLoading({
- title: '加载中'
- })
- let uidStr = uni.getStorageSync("logodata").uid.replace(/\-/g, "");
- let url = 'worldKeepCar/worldDistribution/createMiniAppQrCode',
- params = {
- path: 'pages/homePage/homePage',
- scene: uidStr,
- }
- this.$httpBinary(url, params, 'GET').then(res => {
- uni.hideLoading();
- this.qrImg = 'data:image/png;base64,' + uni.arrayBufferToBase64(res)
-
- })
- },
-
-
- toSave() {
- uni.showModal({
- title: '图片保存',
- content: '确定要保存图片吗',
- success: e => {
- if (e['confirm']) {
- this.saveImgFile();
- }
- }
- });
- },
-
- //微信小程序保存到相册
-
-
- saveEwm:function(e){
- let that = this;
- //获取相册授权
- uni.getSetting({
- success(res) {
- if (!res.authSetting['scope.writePhotosAlbum']) {
- uni.authorize({
- scope: 'scope.writePhotosAlbum',
- success() {
- //这里是用户同意授权后的回调
- that.saveBase64Img(that.qrImg);
- },
- fail() {//这里是用户拒绝授权后的回调
- that.openSettingBtnHidden=false
- }
- })
- } else {//用户已经授权过了
- that.saveBase64Img(that.qrImg);
- }
- }
- })
- },
-
-
- saveBase64Img(base64) {
- //#ifdef APP-PLUS
- const bitmap = new plus.nativeObj.Bitmap('test');
-
- bitmap.loadBase64Data(
- base64,
- function() {
- const url = '_doc/' + new Date() + '.png'; // url建议用时间戳命名方式
- console.log('url:', url);
- bitmap.save(
- url,
- {
- overwrite: true ,// 是否覆盖
- quality: 'quality' , // 图片清晰度
- },
- i => {
- uni.saveImageToPhotosAlbum({
- filePath: url,
- success: function() {
- console.log('保存成功');
- bitmap.clear();
- }
- });
- },
- e => {
- console.log('保存失败', e);
- bitmap.clear();
- }
- );
- },
- e => {
- console.log('保存失败', e);
- bitmap.clear();
- }
- );
- //#endif
- }
-
-
-
-
- }
- }
- </script>
- <style>
- .box {
- min-height: 100vh;
- width: 100%;
- background-image: url('http://123.56.219.146:10086/keepCar/yqyl.png');
- background-size: 100% 100%;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- }
- .maBoximg {
- width: 377rpx;
- height: 377rpx;
- border-radius: 19rpx;
- background-color: #FFFFFF;
- padding: 20rpx;
- }
- .QR{
- width: 100%;
- height: 100%;
- }
- .saveBtn {
- width: 411rpx;
- height: 115rpx;
- margin-top: 60rpx;
- }
- </style>
|