金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

186 lines
4.3 KiB

<template>
<view id="shareImg">
<view class="img-box">
<image mode="widthFix" :src="info.url" alt></image>
</view>
<view class="btn-box">
<view class="btn" :style="'background: ' + config.mainColor" @tap="downImg">保存海报</view>
</view>
<!--用户拒绝下载图片授权弹出-->
<alert :is_refused="is_refused" bind:close="closeAlert"></alert>
</view>
</template>
<script>
import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
// import alert from "@components/alert/alert";
export default {
data() {
return {
info: '',
order_no: '',
config: '',
is_refused: false
};
},
onLoad(e) {
// 第三方平台配置颜色
var bgConfig = this.$cookieStorage.get('globalConfig') || '';
this.setData({
config: bgConfig
});
this.setData({
order_no: e.order_no
});
this.getShearImg();
},
// components: {
// alert
// },
props: {},
methods: {
getShearImg() {
wx.showLoading({
title: '加载中',
mask: true
});
var token = this.$cookieStorage.get('user_token');
this.$http.get({
api: 'api/order/share/img',
data: {
order_no: this.order_no,
pages: 'pages/order/orderShare/orderShare'
},
header: {
Authorization: token
}
}).then(res => {
if (res.statusCode == 200) {
res = res.data;
if (res.status) {
this.setData({
info: res.data
});
} else {
wx.showModal({
content: res.message || '请求失败',
showCancel: false
});
}
} else {
wx.showModal({
content: '请求失败',
showCancel: false
});
}
wx.hideLoading();
}).catch(() => {
wx.hideLoading();
wx.showModal({
content: '请求失败',
showCancel: false
});
});
},
closeAlert() {
this.setData({
is_refused: false
});
},
// 下载图片
downImg() {
if (this.info.url) {
wx.showLoading({
title: '正在下载',
mask: true
});
this.$http.dowloadFile({
api: this.info.url
}).then(res => {
if (res.statusCode == 200) {
wx.getSetting({
success: ret => {
// 如果之前没有授权
if (!ret.authSetting['scope.writePhotosAlbum']) {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success: rej => {
this.saveImg(res.tempFilePath);
},
// 用户拒绝授权
fail: ret => {
this.setData({
is_refused: true
});
wx.hideLoading();
}
});
} else {
this.saveImg(res.tempFilePath);
}
}
});
} else {
wx.hideLoading();
wx.showToast({
title: '下载图片失败',
icon: 'none'
});
}
}, err => {});
}
},
// 保存图片
saveImg(path) {
wx.saveImageToPhotosAlbum({
filePath: path,
success: res => {
wx.hideLoading();
},
fail: rej => {
wx.hideLoading();
wx.showToast({
title: '保存图片失败',
icon: 'none'
});
}
});
},
setData: function (obj) {
let that = this;
let keys = [];
let val, data;
Object.keys(obj).forEach(function (key) {
keys = key.split('.');
val = obj[key];
data = that.$data;
keys.forEach(function (key2, index) {
if (index + 1 == keys.length) {
that.$set(data, key2, val);
} else {
if (!data[key2]) {
that.$set(data, key2, {});
}
}
data = data[key2];
});
});
}
},
computed: {},
watch: {}
};
</script>
<style rel="stylesheet/less" lang="less">
@import "shareImg";
</style>