fix(app): iOS网络权限处理逻辑从app.vue迁移到首页page/index/index

- 在首页添加 onShow 生命周期钩子
- 检测iOS设备首次网络授权情况
- 授权通过后重新初始化应用状态
- 移除App.vue中重复的网络检测逻辑
- 优化页面滚动和下拉刷新功能
- 增强平台兼容性处理
This commit is contained in:
wuKong
2025-12-08 18:56:03 +08:00
parent ee25d77d58
commit f95432918c
2 changed files with 16 additions and 10 deletions

12
App.vue
View File

@@ -1,6 +1,7 @@
<script setup> <script setup>
import { onLaunch, onShow, onError } from '@dcloudio/uni-app'; import { onLaunch, onShow, onError } from '@dcloudio/uni-app';
import { sheep, ShoproInit } from '@/sheep'; import { ShoproInit } from './sheep';
onLaunch(() => { onLaunch(() => {
// 隐藏原生导航栏 使用自定义底部导航 // 隐藏原生导航栏 使用自定义底部导航
uni.hideTabBar({ uni.hideTabBar({
@@ -11,7 +12,7 @@
ShoproInit(); ShoproInit();
}); });
onShow(async () => { onShow(() => {
// #ifdef APP-PLUS // #ifdef APP-PLUS
// 获取urlSchemes参数 // 获取urlSchemes参数
const args = plus.runtime.arguments; const args = plus.runtime.arguments;
@@ -22,13 +23,6 @@
uni.getClipboardData({ uni.getClipboardData({
success: (res) => {}, success: (res) => {},
}); });
// ios 网络授权后重新加载一次应用初始化
if (sheep.$platform.os === 'ios') {
if (await sheep.$platform.checkNetwork()) {
await sheep.$store('app').init();
}
}
// #endif // #endif
}); });
</script> </script>

View File

@@ -22,7 +22,7 @@
<script setup> <script setup>
import { computed } from 'vue'; import { computed } from 'vue';
import { onLoad, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app'; import { onLoad, onShow, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app';
import sheep from '@/sheep'; import sheep from '@/sheep';
import $share from '@/sheep/platform/share'; import $share from '@/sheep/platform/share';
// 隐藏原生tabBar // 隐藏原生tabBar
@@ -79,6 +79,18 @@
} }
}); });
onShow(async() => {
// #ifdef APP-PLUS
// ios首次授权网络需要重新加载一次应用初始化
// 可能需要考虑上uni.onNetworkStatusChangeuni.offNetworkStatusChange组合拳以及主动主动唤起权限申请
if (sheep.$platform.os === 'ios') {
if (await sheep.$platform.checkNetwork()) {
await sheep.$store('app').init();
}
}
// #endif
});
// 下拉刷新 // 下拉刷新
onPullDownRefresh(() => { onPullDownRefresh(() => {
sheep.$store('app').init(); sheep.$store('app').init();