From 2e85cfd78c5788b1cd20daa063d83c927ec46cac Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Tue, 23 Jun 2026 16:57:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(App.vue):=20=E8=A7=A3=E5=86=B3=E9=B8=BF?= =?UTF-8?q?=E8=92=99=E5=85=83=E6=9C=8D=E5=8A=A1=E7=89=88=E6=9C=AC=EF=BC=8C?= =?UTF-8?q?TabBar=20=E5=B0=B1=E8=83=BD=E6=AD=A3=E5=B8=B8=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=BA=86=EF=BC=9B=E4=BF=AE=E5=A4=8D=E5=A4=9A=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E4=B8=8BAPI=E8=B0=83=E7=94=A8=E5=8F=AF=E8=83=BD=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 给options.query访问增加存在性校验,避免空指针报错 2. 给uni.getUpdateManager、uni.onNetworkStatusChange调用增加兼容性判断,防止在不支持的平台抛出错误 --- App.vue | 64 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/App.vue b/App.vue index ae9a76e..9945a8b 100644 --- a/App.vue +++ b/App.vue @@ -26,8 +26,8 @@ configExternal.loadTheme(presetName); // ---- 1) uniacid 立即写入(后续所有 HTTP 都要用到) - const uniacidChanged = options.query.uniacid && String(uni.getStorageSync('uniacid') || '') !== String(options.query.uniacid); - if (options.query.uniacid) { + const uniacidChanged = options.query && options.query.uniacid && String(uni.getStorageSync('uniacid') || '') !== String(options.query.uniacid); + if (options.query && options.query.uniacid) { uni.setStorageSync('uniacid', options.query.uniacid); } if (uniacidChanged) { @@ -83,27 +83,29 @@ uni.hideTabBar(); // #ifdef MP - const updateManager = uni.getUpdateManager(); - updateManager.onCheckForUpdate(function(res) { - // 请求完新版本信息的回调 - }); - - updateManager.onUpdateReady(function(res) { - uni.showModal({ - title: '更新提示', - content: '新版本已经准备好,是否重启应用?', - success(res) { - if (res.confirm) { - // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 - updateManager.applyUpdate(); - } - } + if (uni.getUpdateManager) { + const updateManager = uni.getUpdateManager(); + updateManager.onCheckForUpdate(function(res) { + // 请求完新版本信息的回调 }); - }); - updateManager.onUpdateFailed(function(res) { - // 新的版本下载失败 - }); + updateManager.onUpdateReady(function(res) { + uni.showModal({ + title: '更新提示', + content: '新版本已经准备好,是否重启应用?', + success(res) { + if (res.confirm) { + // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 + updateManager.applyUpdate(); + } + } + }); + }); + + updateManager.onUpdateFailed(function(res) { + // 新的版本下载失败 + }); + } // #endif // #ifdef H5 @@ -112,15 +114,17 @@ } // #endif - uni.onNetworkStatusChange(function(res) { - if (!res.isConnected) { - uni.showModal({ - title: '网络失去链接', - content: '请检查网络链接', - showCancel: false - }); - } - }); + if (uni.onNetworkStatusChange) { + uni.onNetworkStatusChange(function(res) { + if (!res.isConnected) { + uni.showModal({ + title: '网络失去链接', + content: '请检查网络链接', + showCancel: false + }); + } + }); + } // /api/config/init 拉服务器侧数据(包含真正该用的 preset name) // 内部: success 回调里再次 dispatch('applyThemeWithRemote', serverPreset)