Browse Source

'修复显示bug

master
Lj 6 days ago
parent
commit
a52373d796
1 changed files with 111 additions and 62 deletions
  1. +111
    -62
      pages/subcomponent/promo-qrcode.vue

+ 111
- 62
pages/subcomponent/promo-qrcode.vue View File

@ -21,7 +21,14 @@
</view> --> </view> -->
<!-- 二维码区 --> <!-- 二维码区 -->
<view class="qrcode-modal-section"> <view class="qrcode-modal-section">
<!-- 加载骨架屏 -->
<view v-if="isLoading" class="qrcode-skeleton">
<view class="skeleton-img"></view>
<view class="skeleton-text"></view>
</view>
<!-- 二维码图片 -->
<image <image
v-else
class="qrcode-img" class="qrcode-img"
:src="qrcodeUrl" :src="qrcodeUrl"
mode="widthFix" mode="widthFix"
@ -52,9 +59,9 @@ export default {
data() { data() {
return { return {
userInfo: {}, userInfo: {},
qrcodeUrl: '/static/qrcode.png', // URL
qrcodeLocalPath: '', //
qrcodeUrl: '/static/qrcode.png', // URL
inviteCode: '888888', inviteCode: '888888',
isLoading: true, //
} }
}, },
onLoad() { onLoad() {
@ -104,65 +111,57 @@ export default {
}, },
getQrcode() { getQrcode() {
//
if (getApp().globalData.qr_path && getApp().globalData.qr_path.startsWith('wxfile://')) {
console.log('获取到二维码路径', getApp().globalData.qr_path)
this.qrcodeLocalPath = getApp().globalData.qr_path
this.qrcodeUrl = getApp().globalData.qr_path
} else {
console.log('全局二维码路径不存在,调用后端API生成')
uni.showLoading({
title: '生成二维码中...'
})
this.generateQrcode()
}
console.log('调用后端API生成二维码')
uni.showLoading({
title: '生成二维码中...'
})
this.generateQrcode()
}, },
// API
//
generateQrcode() { generateQrcode() {
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
uni.hideLoading()
this.onImageLoad();
//
//
console.log('设置二维码URL:', this.qrcodeUrl)
console.log('当前加载状态:', this.isLoading)
},
//
saveToAlbum() {
if (!this.qrcodeUrl || this.qrcodeUrl === '/static/qrcode.png') {
uni.showToast({
title: '二维码还未加载完成',
icon: 'none'
})
return
}
//
uni.downloadFile({ uni.downloadFile({
url: qrcodeUrl,
url: this.qrcodeUrl,
success: res => { success: res => {
console.log('下载成功:', res)
if (res.statusCode === 200) { if (res.statusCode === 200) {
// 使
const tempFilePath = res.tempFilePath
getApp().globalData.qr_path = tempFilePath
this.qrcodeLocalPath = tempFilePath
console.log('本地二维码路径:', tempFilePath)
this.saveLocalImage(res.tempFilePath)
} else { } else {
console.log('下载失败,状态码:', res.statusCode)
uni.showToast({ title: '二维码下载失败', icon: 'none' })
uni.showToast({ title: '下载失败', icon: 'none' })
} }
}, },
fail: err => { fail: err => {
console.log('下载失败:', err) console.log('下载失败:', err)
uni.showToast({ title: '二维码下载失败', icon: 'none' })
},
complete() {
uni.hideLoading()
uni.showToast({ title: '下载失败', icon: 'none' })
} }
}) })
}, },
//
saveToAlbum() {
if (!this.qrcodeLocalPath) {
uni.showToast({
title: '二维码还未下载完成,请稍后再试',
icon: 'none'
})
return
}
//
saveLocalImage(tempFilePath) {
// 使 // 使
uni.getSetting({ uni.getSetting({
success: (res) => { success: (res) => {
@ -178,30 +177,41 @@ export default {
}) })
} else { } else {
// //
this.doSaveImage()
uni.saveImageToPhotosAlbum({
filePath: tempFilePath,
success: () => {
uni.showToast({
title: '保存成功',
icon: 'success'
})
},
fail: (err) => {
console.log('保存失败', err)
uni.showToast({
title: '保存失败',
icon: 'none'
})
}
})
} }
}, },
fail: () => { fail: () => {
// //
this.doSaveImage()
}
})
},
//
doSaveImage() {
uni.saveImageToPhotosAlbum({
filePath: this.qrcodeLocalPath,
success: () => {
uni.showToast({
title: '保存成功',
icon: 'success'
})
},
fail: (err) => {
console.log('保存失败', err)
uni.showToast({
title: '保存失败',
icon: 'none'
uni.saveImageToPhotosAlbum({
filePath: tempFilePath,
success: () => {
uni.showToast({
title: '保存成功',
icon: 'success'
})
},
fail: (err) => {
console.log('保存失败', err)
uni.showToast({
title: '保存失败',
icon: 'none'
})
}
}) })
} }
}) })
@ -210,13 +220,16 @@ export default {
// //
onImageLoad() { onImageLoad() {
console.log('二维码图片加载成功') console.log('二维码图片加载成功')
this.isLoading = false
console.log('加载状态已更新为:', this.isLoading)
}, },
// //
onImageError() { onImageError() {
console.log('二维码图片加载失败,使用默认图片') console.log('二维码图片加载失败,使用默认图片')
this.qrcodeUrl = '/static/qrcode.png' this.qrcodeUrl = '/static/qrcode.png'
this.qrcodeLocalPath = ''
this.isLoading = false
console.log('错误处理完成,加载状态:', this.isLoading)
} }
} }
} }
@ -315,6 +328,42 @@ export default {
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08); box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
} }
/* 骨架屏样式 */
.qrcode-skeleton {
width: 100%;
display: flex;
flex-direction: column;
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;
}
100% {
background-position: -200% 0;
}
}
.invite-code { .invite-code {


Loading…
Cancel
Save