hookehuyr

feat(网络): 添加弱网络处理逻辑和页面

在弱网络情况下显示提示弹窗并跳转
添加弱网络配置页面
统一处理网络检测失败情况
1 <!-- 1 <!--
2 * @Date: 2024-01-16 10:06:47 2 * @Date: 2024-01-16 10:06:47
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2026-01-13 15:24:06 4 + * @LastEditTime: 2026-01-13 16:21:40
5 * @FilePath: /xyxBooking-weapp/src/pages/bookingCode/index.vue 5 * @FilePath: /xyxBooking-weapp/src/pages/bookingCode/index.vue
6 * @Description: 预约码页面 6 * @Description: 预约码页面
7 --> 7 -->
...@@ -48,15 +48,43 @@ const go = useGo(); ...@@ -48,15 +48,43 @@ const go = useGo();
48 48
49 useDidShow(() => { 49 useDidShow(() => {
50 Taro.getNetworkType({ 50 Taro.getNetworkType({
51 - success: (res) => { 51 + success: async (res) => {
52 const isConnected = is_usable_network(res.networkType); 52 const isConnected = is_usable_network(res.networkType);
53 - if (!isConnected) { 53 + if (isConnected) return
54 +
55 + if (has_offline_booking_cache()) {
56 + Taro.redirectTo({ url: '/pages/offlineBookingList/index' })
57 + return
58 + }
59 +
60 + try {
61 + await Taro.showModal({
62 + title: '网络连接不畅',
63 + content: '当前网络信号较弱,暂无法使用小程序,请到网络更好的地方重试。',
64 + confirmText: '知道了',
65 + showCancel: false,
66 + })
67 + } catch (e) {
68 + console.error('show weak network modal failed:', e)
69 + }
70 + Taro.redirectTo({ url: '/pages/index/index' })
71 + },
72 + fail: async () => {
54 if (has_offline_booking_cache()) { 73 if (has_offline_booking_cache()) {
55 Taro.redirectTo({ url: '/pages/offlineBookingList/index' }) 74 Taro.redirectTo({ url: '/pages/offlineBookingList/index' })
56 - } else { 75 + return
57 - Taro.redirectTo({ url: '/pages/weakNetwork/index' })
58 } 76 }
77 + try {
78 + await Taro.showModal({
79 + title: '网络连接不畅',
80 + content: '当前网络信号较弱,暂无法使用小程序,请到网络更好的地方重试。',
81 + confirmText: '知道了',
82 + showCancel: false,
83 + })
84 + } catch (e) {
85 + console.error('show weak network modal failed:', e)
59 } 86 }
87 + Taro.redirectTo({ url: '/pages/index/index' })
60 } 88 }
61 }); 89 });
62 }) 90 })
......
1 +/*
2 + * @Date: 2025-06-28 10:33:00
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2026-01-13 16:19:56
5 + * @FilePath: /xyxBooking-weapp/src/pages/weakNetwork/index.config.js
6 + * @Description: 网络连接不畅配置
7 + */
8 +export default {
9 + navigationBarTitleText: '网络连接不畅'
10 +}
...@@ -32,11 +32,28 @@ ...@@ -32,11 +32,28 @@
32 import Taro from '@tarojs/taro' 32 import Taro from '@tarojs/taro'
33 import { IconFont } from '@nutui/icons-vue-taro' 33 import { IconFont } from '@nutui/icons-vue-taro'
34 import { useGo } from '@/hooks/useGo' 34 import { useGo } from '@/hooks/useGo'
35 +import { onMounted } from 'vue'
36 +import { has_offline_booking_cache } from '@/composables/useOfflineBookingCache'
35 37
36 import icon_invite from '@/assets/images/二维码@2x2.png' 38 import icon_invite from '@/assets/images/二维码@2x2.png'
37 39
38 const go = useGo(); 40 const go = useGo();
39 41
42 +onMounted(async () => {
43 + if (has_offline_booking_cache()) return
44 + try {
45 + await Taro.showModal({
46 + title: '网络连接不畅',
47 + content: '当前网络信号较弱,暂无法使用小程序,请到网络更好的地方重试。',
48 + confirmText: '知道了',
49 + showCancel: false,
50 + })
51 + } catch (e) {
52 + console.error('show weak network modal failed:', e)
53 + }
54 + Taro.reLaunch({ url: '/pages/index/index' })
55 +})
56 +
40 const toOfflineCode = () => { 57 const toOfflineCode = () => {
41 go('/pages/offlineBookingList/index'); 58 go('/pages/offlineBookingList/index');
42 } 59 }
......