This commit is contained in:
2024-09-10 10:49:08 +08:00
parent b5fd06b800
commit dd4f5938da
6391 changed files with 722800 additions and 0 deletions

View File

@@ -0,0 +1,204 @@
<template>
<view class="n-title">第一步</view>
<view class="sub-title">使用微信扫一扫扫描下方二维码并点击确认授权按钮</view>
<view class="image-wrapper">
<view class="image-content" @touchstart="handleStart('authQr')" @touchend="handleEnd">
<image :src="vdata.authQr" mode="scaleToFill" />
</view>
<view class="image-tips">长按可将图片保存至相册</view>
</view>
<view class="n-title">第二步</view>
<view class="sub-title">页面提示授权成功按照手机端的提示关注公众号开启消息推送功能</view>
<view class="image-wrapper footer-image">
<view class="image-content" @touchstart="handleStart('wxmpQr')" @touchend="handleEnd">
<image :src="vdata.wxmpQr" mode="scaleToFill" />
</view>
<view class="image-tips">长按可将图片保存至相册</view>
</view>
<view class="list-footer">
<view class="button-wrapper">
<button class="jeepay-btn" hover-class="hover-button" @tap="goBack">返回列表页</button>
</view>
</view>
<JeepayPopupConfirm ref="confirmSave" />
</template>
<script setup>
import { reactive, ref } from 'vue'
import { $getWxMpInfo } from '@/http/apiManager.js'
import infoBox from '@/commons/utils/infoBox.js'
import qrCode from '@/commons/utils/qrCode.js'
import { saveHeadImgFile } from '@/commons/utils/saveImg.js'
const confirmSave = ref(null)
const vdata = reactive({
timeOut: null,
})
$getWxMpInfo().then(({ bizData }) => {
bizData.authQr = qrCode.drawImg(bizData.authUrl)
Object.assign(vdata, bizData)
})
const handleStart = (key) => {
vdata.timeOut = setTimeout(() => {
saveImage(key)
clearTimeout(vdata.timeOut)
}, 800)
}
const handleEnd = () => clearTimeout(vdata.timeOut)
const saveImage = (key) => {
// #ifdef APP-PLUS
confirmSave.value.open('确认保存图片?').then((res) => {
if (key == 'authQr') return saveQrcodeImg()
uni.downloadFile({
url: vdata[key],
success: (res) => {
console.log(res)
if (res.statusCode == 200) {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: (r) => {
infoBox.showSuccessToast('保存成功')
uni.vibrateShort()
},
fail: (er) => {
console.log(er)
infoBox.showErrorToast('保存失败')
}
})
}
},
fail: (err) => {
console.log(err)
infoBox.showErrorToast('保存失败')
}
})
})
// #endif
//#ifdef MP-WEIXIN
confirmSave.value.open('确认保存图片?').then((res) => {
downloadQR(key)
})
//#endif
}
//#ifdef MP-WEIXIN
function downloadQR(key) {
wx.getSetting({
//获取权限
success(res) {
if (res.authSetting['scope.writePhotosAlbum']) {
if (key == 'authQr') return saveWxQrcodeImg(vdata.authQr)
download(vdata[key])
} else {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success() {
if (key == 'authQr') return saveWxQrcodeImg(vdata.authQr)
download(vdata[key])
},
})
}
},
})
}
function download(data) {
uni.downloadFile({
url: data,
success: (res) => {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function () {
console.log('res', res)
infoBox.showSuccessToast('保存成功')
uni.vibrateShort()
},
fail: function (err) {
infoBox.showErrorToast('保存失败')
},
})
},
})
}
//#endif
const saveQrcodeImg = () => {
saveHeadImgFile(vdata.authQr, 80)
.then((success) => {
infoBox.showSuccessToast('保存成功')
})
.catch((err) => {
console.log(err)
infoBox.showErrorToast('保存失败')
})
}
const saveWxQrcodeImg = (data) => {
const fileManager = wx.getFileSystemManager()
const filePath = wx.env.USER_DATA_PATH + '/res.png'
//这块是定义图片的名称,可自定义其他
fileManager.writeFile({
filePath: filePath,
data: data.slice(22),
encoding: 'base64',
success: (res) => {
wx.saveImageToPhotosAlbum({
filePath: filePath,
success: function (res) {
//保存成功
infoBox.showSuccessToast('保存成功')
},
fail: function (err) {
console.log(err)
//保存失败
infoBox.showErrorToast('保存失败')
},
})
},
fail: (err) => {
infoBox.showErrorToast('保存失败')
},
})
}
const goBack = () => uni.navigateBack()
</script>
<style lang="scss" scoped>
.n-title {
margin: 50rpx 0 20rpx 0;
text-align: center;
font-size: 38rpx;
}
.sub-title {
margin: 0 50rpx;
color: #666666;
font-size: 28rpx;
text-align: center;
}
.image-wrapper {
display: flex;
flex-direction: column;
align-items: center;
border-bottom: 1rpx solid #ededed;
.image-content {
margin: 50rpx 0 30rpx 0;
width: 300rpx;
height: 300rpx;
overflow: hidden;
image {
width: 100%;
height: 100%;
}
}
.image-tips {
margin-bottom: 50rpx;
font-size: 26rpx;
color: #a6a6a6;
}
}
.footer-image {
padding-bottom: 50rpx;
}
</style>