fix(App.vue): 解决鸿蒙元服务版本,TabBar 就能正常显示了;修复多平台下API调用可能不存在的报错
1. 给options.query访问增加存在性校验,避免空指针报错 2. 给uni.getUpdateManager、uni.onNetworkStatusChange调用增加兼容性判断,防止在不支持的平台抛出错误
This commit is contained in:
64
App.vue
64
App.vue
@@ -26,8 +26,8 @@
|
|||||||
configExternal.loadTheme(presetName);
|
configExternal.loadTheme(presetName);
|
||||||
|
|
||||||
// ---- 1) uniacid 立即写入(后续所有 HTTP 都要用到)
|
// ---- 1) uniacid 立即写入(后续所有 HTTP 都要用到)
|
||||||
const uniacidChanged = options.query.uniacid && String(uni.getStorageSync('uniacid') || '') !== String(options.query.uniacid);
|
const uniacidChanged = options.query && options.query.uniacid && String(uni.getStorageSync('uniacid') || '') !== String(options.query.uniacid);
|
||||||
if (options.query.uniacid) {
|
if (options.query && options.query.uniacid) {
|
||||||
uni.setStorageSync('uniacid', options.query.uniacid);
|
uni.setStorageSync('uniacid', options.query.uniacid);
|
||||||
}
|
}
|
||||||
if (uniacidChanged) {
|
if (uniacidChanged) {
|
||||||
@@ -83,27 +83,29 @@
|
|||||||
uni.hideTabBar();
|
uni.hideTabBar();
|
||||||
|
|
||||||
// #ifdef MP
|
// #ifdef MP
|
||||||
const updateManager = uni.getUpdateManager();
|
if (uni.getUpdateManager) {
|
||||||
updateManager.onCheckForUpdate(function(res) {
|
const updateManager = uni.getUpdateManager();
|
||||||
// 请求完新版本信息的回调
|
updateManager.onCheckForUpdate(function(res) {
|
||||||
});
|
// 请求完新版本信息的回调
|
||||||
|
|
||||||
updateManager.onUpdateReady(function(res) {
|
|
||||||
uni.showModal({
|
|
||||||
title: '更新提示',
|
|
||||||
content: '新版本已经准备好,是否重启应用?',
|
|
||||||
success(res) {
|
|
||||||
if (res.confirm) {
|
|
||||||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
||||||
updateManager.applyUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
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
|
// #endif
|
||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
@@ -112,15 +114,17 @@
|
|||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
uni.onNetworkStatusChange(function(res) {
|
if (uni.onNetworkStatusChange) {
|
||||||
if (!res.isConnected) {
|
uni.onNetworkStatusChange(function(res) {
|
||||||
uni.showModal({
|
if (!res.isConnected) {
|
||||||
title: '网络失去链接',
|
uni.showModal({
|
||||||
content: '请检查网络链接',
|
title: '网络失去链接',
|
||||||
showCancel: false
|
content: '请检查网络链接',
|
||||||
});
|
showCancel: false
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// /api/config/init 拉服务器侧数据(包含真正该用的 preset name)
|
// /api/config/init 拉服务器侧数据(包含真正该用的 preset name)
|
||||||
// 内部: success 回调里再次 dispatch('applyThemeWithRemote', serverPreset)
|
// 内部: success 回调里再次 dispatch('applyThemeWithRemote', serverPreset)
|
||||||
|
|||||||
Reference in New Issue
Block a user