优化小程序版本更新检测逻辑,增强用户体验。新增扫码功能,支持用户通过扫一扫获取信息并展示解析结果,提升交互性。更新样式以适应新功能,确保界面友好。

This commit is contained in:
乘风
2026-02-13 09:59:08 +08:00
parent 808c959a20
commit 0f9633b8f0
5 changed files with 121 additions and 74 deletions

View File

@@ -240,36 +240,40 @@ App({
}
},
// 检查更新
// 版本更新检测:发现新版本时提示用户立即更新
checkUpdate() {
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate((res) => {
if (res.hasUpdate) {
console.log('发现新版本')
if (!wx.canIUse('getUpdateManager')) return
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate((res) => {
if (res.hasUpdate) {
console.log('[App] 发现新版本,正在后台下载')
wx.showToast({ title: '发现新版本,正在准备…', icon: 'none', duration: 2000 })
}
})
updateManager.onUpdateReady(() => {
wx.showModal({
title: '发现新版本',
content: '小程序已更新,请立即重启以使用最新版本。',
confirmText: '立即更新',
cancelText: '稍后',
showCancel: true,
success: (res) => {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
updateManager.onUpdateReady(() => {
wx.showModal({
title: '更新提示',
content: '新版本已准备好,是否重启应用?',
success: (res) => {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(() => {
wx.showModal({
title: '更新失败',
content: '新版本下载失败,请稍后重新打开小程序或删除后重新搜索打开。',
showCancel: false
})
updateManager.onUpdateFailed(() => {
wx.showToast({
title: '更新失败,请稍后重试',
icon: 'none'
})
})
}
})
},
/**

View File

@@ -40,6 +40,7 @@ Page({
// 菜单列表
menuList: [
{ id: 'scan', title: '扫一扫', icon: '📷', iconBg: 'gray' },
{ id: 'orders', title: '我的订单', icon: '📦', count: 0 },
{ id: 'referral', title: '推广中心', icon: '🎁', iconBg: 'gold', badge: '90%佣金' },
{ id: 'withdrawRecords', title: '提现记录', icon: '📋', iconBg: 'gray' },
@@ -64,7 +65,11 @@ Page({
// 修改昵称弹窗
showNicknameModal: false,
editingNickname: ''
editingNickname: '',
// 扫一扫结果弹窗
showScanResultModal: false,
scanResult: ''
},
onLoad() {
@@ -608,12 +613,17 @@ Page({
// 点击菜单
handleMenuTap(e) {
const id = e.currentTarget.dataset.id
if (id === 'scan') {
this.doScanCode()
return
}
if (!this.data.isLoggedIn && id !== 'about') {
this.showLogin()
return
}
const routes = {
orders: '/pages/purchases/purchases',
referral: '/pages/referral/referral',
@@ -621,12 +631,47 @@ Page({
about: '/pages/about/about',
settings: '/pages/settings/settings'
}
if (routes[id]) {
wx.navigateTo({ url: routes[id] })
}
},
// 扫一扫:调起扫码,展示解析值
doScanCode() {
wx.scanCode({
onlyFromCamera: false,
scanType: ['qrCode', 'barCode'],
success: (res) => {
const result = res.result || ''
this.setData({
showScanResultModal: true,
scanResult: result
})
},
fail: (err) => {
if (err.errMsg && !err.errMsg.includes('cancel')) {
wx.showToast({ title: '扫码失败', icon: 'none' })
}
}
})
},
// 关闭扫码结果弹窗
closeScanResultModal() {
this.setData({ showScanResultModal: false, scanResult: '' })
},
// 复制扫码结果
copyScanResult() {
const text = this.data.scanResult || ''
if (!text) return
wx.setClipboardData({
data: text,
success: () => wx.showToast({ title: '已复制', icon: 'success' })
})
},
goToRead(e) {
const id = e.currentTarget.dataset.id
const mid = e.currentTarget.dataset.mid

View File

@@ -281,6 +281,21 @@
</view>
</view>
<!-- 扫一扫结果弹窗 -->
<view class="modal-overlay" wx:if="{{showScanResultModal}}" bindtap="closeScanResultModal">
<view class="modal-content scan-result-modal" catchtap="stopPropagation">
<view class="modal-close" bindtap="closeScanResultModal">✕</view>
<view class="scan-result-header">
<text class="scan-result-title">扫码解析结果</text>
</view>
<scroll-view class="scan-result-body" scroll-y><text class="scan-result-text">{{scanResult}}</text></scroll-view>
<view class="scan-result-actions">
<view class="scan-result-btn" bindtap="copyScanResult">复制</view>
<view class="scan-result-btn primary" bindtap="closeScanResultModal">关闭</view>
</view>
</view>
</view>
<!-- 底部留白 -->
<view class="bottom-space"></view>
</view>

View File

@@ -1236,3 +1236,28 @@
background: linear-gradient(135deg, #4CAF50 0%, #388E3C 100%);
color: #fff; font-size: 26rpx; font-weight: 500; border-radius: 20rpx;
}
/* ===== 扫一扫结果弹窗 ===== */
.scan-result-modal .modal-close { top: 24rpx; right: 24rpx; }
.scan-result-header { margin-bottom: 24rpx; }
.scan-result-title { font-size: 32rpx; font-weight: 600; color: #fff; }
.scan-result-body {
max-height: 320rpx;
padding: 24rpx;
background: rgba(255,255,255,0.06);
border-radius: 16rpx;
margin-bottom: 24rpx;
word-break: break-all;
}
.scan-result-text { font-size: 26rpx; color: rgba(255,255,255,0.9); line-height: 1.5; }
.scan-result-actions { display: flex; gap: 24rpx; }
.scan-result-btn {
flex: 1;
padding: 24rpx;
text-align: center;
font-size: 28rpx;
color: rgba(255,255,255,0.9);
background: rgba(255,255,255,0.1);
border-radius: 24rpx;
}
.scan-result-btn.primary { background: #00CED1; color: #000; }

View File

@@ -24,51 +24,9 @@
"miniprogram": {
"list": [
{
"name": "pages/addresses/addresses",
"pathName": "pages/addresses/addresses",
"name": "我的",
"pathName": "pages/my/my",
"query": "",
"scene": null,
"launchMode": "default"
},
{
"name": "pages/referral/referral",
"pathName": "pages/referral/referral",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "pages/read/read",
"pathName": "pages/read/read",
"query": "mid=11",
"launchMode": "default",
"scene": null
},
{
"name": "pages/referral/referral",
"pathName": "pages/referral/referral",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "ces",
"pathName": "pages/read/read",
"query": "scene=mid%3D3&ref%3DogpTW5a9ex",
"launchMode": "default",
"scene": null
},
{
"name": "pages/chapters/chapters",
"pathName": "pages/chapters/chapters",
"query": "",
"launchMode": "default",
"scene": null
},
{
"name": "pages/read/read",
"pathName": "pages/read/read",
"query": "id=1.2",
"launchMode": "default",
"scene": null
}