请求获取小程序支付码

This commit is contained in:
wangxiaowei 2024-06-30 00:14:38 +08:00
parent 8ec9a7ebc5
commit dd59458c0c
2 changed files with 91 additions and 9 deletions

@ -1,18 +1,24 @@
<template>
<view class="content">
<view class="basic-info">
<image :src="pay_image" class="qrcode"></image>
</view>
<view v-if="pay_image" class="submit-btn">
<button class="btn-style" @click="saveQrcode()">保存二维码</button>
</view>
</view>
</template>
<script>
import {localStorePayImage} from '@/api/shop.js'
import {
localStorePayImage
} from '@/api/shop.js'
export default {
data() {
return {
orderList: []
orderList: [],
pay_image: ''
};
},
onLoad() {
@ -21,10 +27,60 @@
methods: {
// 获取商家支付二维码
async getPayImage() {
await localStorePayImage((res) => {
console.log(res)
const {
data,
code,
msg
} = await localStorePayImage()
if (code == 1) {
this.pay_image = data.pay_image
}
},
// 保存二维码图片
saveQrcode() {
// #ifndef H5
uni.showLoading({title: '正在下载……'});
uni.downloadFile({
url: this.pay_image,
success: (res) => {
if (res.statusCode === 200) {
//隐藏加载框
uni.hideLoading();
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function(res) {
uni.showToast({
icon: 'none',
mask: true,
title: '文件已保存',
duration: 3000
});
},
fail: function() {
console.log('保存失败');
}
});
}
},
fail: function() {
uni.showToast({
icon: 'none',
mask: true,
title: '失败请重新下载'
});
}
})
}
// #endif
// #ifdef H5
this.$toast({
title: '请长按图片保存'
})
// #endif
},
}
}
</script>
@ -32,7 +88,7 @@
<style lang="scss" scoped>
.content {
padding: 20rpx;
.basic-info {
width: 100%;
padding: 30rpx;
@ -40,6 +96,32 @@
background: #fff;
border-radius: 10rpx;
margin: 20rpx 0;
text-align: center;
.qrcode {
padding: 40rpx 36rpx 40rpx 0;
border-radius: 20rpx;
background-color: #ffffff;
text-align: center;
width: 400rpx;
height: 400rpx;
}
}
.submit-btn {
margin-top: 40rpx;
width: 100%;
.btn-style {
width: 100%;
border: none;
border-radius: 999rpx;
background: #fb2d2d;
color: #fdf8f4;
display: flex;
justify-content: center;
align-items: center;
}
}
}
</style>

@ -255,7 +255,7 @@
scanQRCode() {
uni.scanCode({
success: function (res) {
console.log(res)
}
});
}