Browse Source

'修复保存的bug'

master
Lj 5 days ago
parent
commit
2efa62cc11
1 changed files with 180 additions and 71 deletions
  1. +180
    -71
      pages/subcomponent/promo-qrcode.vue

+ 180
- 71
pages/subcomponent/promo-qrcode.vue View File

@ -28,7 +28,7 @@
</view> </view>
<!-- 二维码图片 --> <!-- 二维码图片 -->
<image <image
v-else
v-else-if="qrcodeUrl"
class="qrcode-img" class="qrcode-img"
:src="qrcodeUrl" :src="qrcodeUrl"
mode="widthFix" mode="widthFix"
@ -59,9 +59,11 @@ export default {
data() { data() {
return { return {
userInfo: {}, userInfo: {},
qrcodeUrl: '/static/qrcode.png', // URL
qrcodeUrl: '', // URL
inviteCode: '888888', inviteCode: '888888',
isLoading: true, //
isLoading: true, //
retryCount: 0, //
maxRetries: 2, //
} }
}, },
onLoad() { onLoad() {
@ -69,27 +71,33 @@ export default {
this.fetchUserInfo() this.fetchUserInfo()
this.getQrcode() this.getQrcode()
}, },
onUnload() {
//
},
// //
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
onShareAppMessage() { onShareAppMessage() {
return { return {
title: `${this.userInfo.nickName || '用户'}邀请您一起参与旧衣回收`, title: `${this.userInfo.nickName || '用户'}邀请您一起参与旧衣回收`,
path: `/pages/component/home?shareId=${this.inviteCode}`, path: `/pages/component/home?shareId=${this.inviteCode}`,
imageUrl: this.qrcodeUrl || '/static/share-default.png'
imageUrl: this.qrcodeUrl
} }
}, },
onShareTimeline() { onShareTimeline() {
return { return {
title: `${this.userInfo.nickName || '用户'}邀请您一起参与旧衣回收,环保从我做起!`, title: `${this.userInfo.nickName || '用户'}邀请您一起参与旧衣回收,环保从我做起!`,
query: `shareId=${this.inviteCode}`, query: `shareId=${this.inviteCode}`,
imageUrl: this.qrcodeUrl || '/static/share-default.png'
imageUrl: this.qrcodeUrl
} }
}, },
// #endif // #endif
methods: { methods: {
async onRefresh() { async onRefresh() {
//
await new Promise(resolve => setTimeout(resolve, 1000))
//
this.retryCount = 0 //
this.isLoading = true //
this.fetchUserInfo()
this.getQrcode()
uni.stopPullRefresh() uni.stopPullRefresh()
}, },
navigateBack() { navigateBack() {
@ -120,23 +128,29 @@ export default {
// //
generateQrcode() { generateQrcode() {
//
if (this.retryCount === 0) {
this.retryCount = 0
}
//
this.isLoading = true
const token = uni.getStorageSync('token') const token = uni.getStorageSync('token')
const qrcodeUrl = `${config.baseUrl}/recycle-admin/applet/promotion/getInviteCode?token=${token}` const qrcodeUrl = `${config.baseUrl}/recycle-admin/applet/promotion/getInviteCode?token=${token}`
console.log('二维码URL:', qrcodeUrl)
// console.log('URL:', qrcodeUrl)
// 使 // 使
this.qrcodeUrl = qrcodeUrl this.qrcodeUrl = qrcodeUrl
if(this.qrcodeUrl){
this.isLoading = false
}
uni.hideLoading() uni.hideLoading()
this.onImageLoad();
//
console.log('设置二维码URL:', this.qrcodeUrl)
console.log('当前加载状态:', this.isLoading)
}, },
// //
saveToAlbum() { saveToAlbum() {
if (!this.qrcodeUrl || this.qrcodeUrl === '/static/qrcode.png') {
if (!this.qrcodeUrl) {
uni.showToast({ uni.showToast({
title: '二维码还未加载完成', title: '二维码还未加载完成',
icon: 'none' icon: 'none'
@ -144,35 +158,88 @@ export default {
return return
} }
// iOS
const systemInfo = uni.getSystemInfoSync()
const isIOS = systemInfo.platform === 'ios'
//
uni.showLoading({
title: '保存中...'
})
// //
uni.downloadFile({ uni.downloadFile({
url: this.qrcodeUrl, url: this.qrcodeUrl,
success: res => { success: res => {
uni.hideLoading()
if (res.statusCode === 200) { if (res.statusCode === 200) {
this.saveLocalImage(res.tempFilePath)
this.saveLocalImage(res.tempFilePath, isIOS)
} else { } else {
uni.showToast({ title: '下载失败', icon: 'none' }) uni.showToast({ title: '下载失败', icon: 'none' })
} }
}, },
fail: err => { fail: err => {
uni.hideLoading()
console.log('下载失败:', err) console.log('下载失败:', err)
uni.showToast({ title: '下载失败', icon: 'none' }) uni.showToast({ title: '下载失败', icon: 'none' })
} }
}) })
}, },
// //
saveLocalImage(tempFilePath) {
// 使
saveLocalImage(tempFilePath, isIOS) {
// #ifdef APP-PLUS
// APP
uni.saveImageToPhotosAlbum({
filePath: tempFilePath,
success: () => {
uni.showToast({
title: '保存成功',
icon: 'success'
})
},
fail: (err) => {
console.log('保存失败', err)
// iOS
if (isIOS || (err.errMsg && err.errMsg.includes('auth deny'))) {
uni.showModal({
title: '权限提示',
content: '需要您授权保存相册权限,请在设置中开启',
confirmText: '去设置',
success: (res) => {
if (res.confirm) {
// #ifdef APP-PLUS
plus.runtime.openURL('app-settings://')
// #endif
// #ifdef MP-WEIXIN
uni.openSetting()
// #endif
}
}
})
} else {
uni.showToast({
title: '保存失败',
icon: 'none'
})
}
}
})
// #endif
// #ifdef MP-WEIXIN
//
uni.getSetting({ uni.getSetting({
success: (res) => { success: (res) => {
if (res.authSetting['scope.writePhotosAlbum'] === false) { if (res.authSetting['scope.writePhotosAlbum'] === false) {
// //
uni.showModal({ uni.showModal({
title: '提示',
title: '权限提示',
content: '需要您授权保存相册权限,请在设置中开启', content: '需要您授权保存相册权限,请在设置中开启',
showCancel: false,
success: () => {
uni.openSetting()
confirmText: '去设置',
success: (modalRes) => {
if (modalRes.confirm) {
uni.openSetting()
}
} }
}) })
} else { } else {
@ -187,10 +254,24 @@ export default {
}, },
fail: (err) => { fail: (err) => {
console.log('保存失败', err) console.log('保存失败', err)
uni.showToast({
title: '保存失败',
icon: 'none'
})
// iOS
if (isIOS) {
uni.showModal({
title: 'iOS权限提示',
content: 'iOS设备需要手动授权相册权限,请在设置中开启',
confirmText: '去设置',
success: (modalRes) => {
if (modalRes.confirm) {
uni.openSetting()
}
}
})
} else {
uni.showToast({
title: '保存失败',
icon: 'none'
})
}
} }
}) })
} }
@ -207,29 +288,60 @@ export default {
}, },
fail: (err) => { fail: (err) => {
console.log('保存失败', err) console.log('保存失败', err)
uni.showToast({
title: '保存失败',
icon: 'none'
})
// iOS
if (isIOS) {
uni.showModal({
title: 'iOS权限提示',
content: 'iOS设备需要手动授权相册权限,请在设置中开启',
confirmText: '去设置',
success: (modalRes) => {
if (modalRes.confirm) {
uni.openSetting()
}
}
})
} else {
uni.showToast({
title: '保存失败',
icon: 'none'
})
}
} }
}) })
} }
}) })
// #endif
}, },
// //
onImageLoad() { onImageLoad() {
console.log('二维码图片加载成功') console.log('二维码图片加载成功')
this.isLoading = false
console.log('加载状态已更新为:', this.isLoading)
this.isLoading = false //
}, },
// //
onImageError() { onImageError() {
console.log('二维码图片加载失败,使用默认图片')
this.qrcodeUrl = '/static/qrcode.png'
this.isLoading = false
console.log('错误处理完成,加载状态:', this.isLoading)
console.log('二维码图片加载失败,尝试重试')
//
if (this.retryCount < this.maxRetries) {
this.retryCount++
console.log(`${this.retryCount}次重试加载二维码`)
// 1
setTimeout(() => {
this.generateQrcode()
}, 1000)
return
}
//
console.log('重试次数用完,二维码加载失败')
this.isLoading = false //
uni.showToast({
title: '二维码加载失败',
icon: 'none'
})
} }
} }
} }
@ -320,51 +432,48 @@ export default {
align-items: center; align-items: center;
margin-bottom: 48rpx; margin-bottom: 48rpx;
.qrcode-img {
width: 100%;
height: 100%;
background: #fff;
border-radius: 24rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
}
/* 骨架屏样式 */
.qrcode-skeleton { .qrcode-skeleton {
width: 100%; width: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
}
.skeleton-img {
width: 300rpx;
height: 300rpx;
border-radius: 20rpx;
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
background-size: 200% 100%;
animation: skeleton-loading 1.5s infinite;
margin-bottom: 20rpx;
}
.skeleton-text {
width: 200rpx;
height: 32rpx;
border-radius: 16rpx;
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
background-size: 200% 100%;
animation: skeleton-loading 1.5s infinite;
}
@keyframes skeleton-loading {
0% {
background-position: 200% 0;
.skeleton-img {
width: 300rpx;
height: 300rpx;
border-radius: 20rpx;
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
background-size: 200% 100%;
animation: skeleton-loading 1.5s infinite;
margin-bottom: 20rpx;
} }
100% {
background-position: -200% 0;
.skeleton-text {
width: 200rpx;
height: 32rpx;
border-radius: 16rpx;
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
background-size: 200% 100%;
animation: skeleton-loading 1.5s infinite;
}
@keyframes skeleton-loading {
0% {
background-position: 200% 0;
}
100% {
background-position: -200% 0;
}
} }
} }
.qrcode-img {
width: 100%;
height: 100%;
background: #fff;
border-radius: 24rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
}
.invite-code { .invite-code {
margin-top: 32rpx; margin-top: 32rpx;


Loading…
Cancel
Save