Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
xyxBooking-weapp
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2026-01-13 13:53:23 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3fa343d9a353e94250ef5f85c45412c09fc27756
3fa343d9
1 parent
46908120
feat(网络): 添加弱网检测和离线模式处理逻辑
在应用启动时检测网络状态,当网络较弱时提示用户使用缓存的预约码进入离线模式
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
1 deletions
src/app.js
src/app.js
View file @
3fa343d
/*
* @Date: 2025-06-28 10:33:00
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-13
00:28:35
* @LastEditTime: 2026-01-13
13:49:42
* @FilePath: /xyxBooking-weapp/src/app.js
* @Description: 应用入口文件
*/
...
...
@@ -14,6 +14,8 @@ import Taro from '@tarojs/taro'
import
{
qrcodeListAPI
}
from
'@/api/index'
import
{
formatDatetime
}
from
'@/utils/tools'
let
has_shown_network_modal
=
false
/**
* 格式化支付记录,按 pay_id 分组,相同 pay_id 下的记录 sort 为 0,否则为 1
* @param {*} data 支付记录数组
...
...
@@ -99,6 +101,69 @@ const App = createApp({
return
[
'wifi'
,
'4g'
,
'5g'
,
'3g'
].
includes
(
network_type
)
}
const
get_network_type
=
async
()
=>
{
try
{
const
result
=
await
new
Promise
((
resolve
,
reject
)
=>
{
Taro
.
getNetworkType
({
success
:
resolve
,
fail
:
reject
,
})
})
return
result
?.
networkType
||
'unknown'
}
catch
(
e
)
{
return
'unknown'
}
}
const
has_offline_qr_cache
=
()
=>
{
try
{
const
data
=
Taro
.
getStorageSync
(
'OFFLINE_QR_DATA'
)
return
Array
.
isArray
(
data
)
&&
data
.
length
>
0
}
catch
(
e
)
{
return
false
}
}
const
handle_bad_network_on_launch
=
async
()
=>
{
if
(
has_shown_network_modal
)
return
false
const
network_type
=
await
get_network_type
()
const
is_none_network
=
network_type
===
'none'
const
is_weak_network
=
!
is_usable_network
(
network_type
)
if
(
!
is_weak_network
)
return
false
has_shown_network_modal
=
true
if
(
has_offline_qr_cache
())
{
try
{
const
modal_res
=
await
Taro
.
showModal
({
title
:
'网络连接不畅'
,
content
:
'当前网络信号较弱,可使用已缓存的预约码进入离线模式'
,
confirmText
:
'预约码'
,
cancelText
:
'知道了'
,
})
if
(
modal_res
?.
confirm
)
{
await
Taro
.
reLaunch
({
url
:
'/pages/offlineBookingCode/index'
})
return
true
}
}
catch
(
e
)
{
return
is_none_network
}
}
else
{
try
{
await
Taro
.
showToast
({
title
:
'网络连接不畅'
,
icon
:
'none'
,
duration
:
2000
})
}
catch
(
e
)
{
return
is_none_network
}
}
return
is_none_network
}
const
should_stop
=
await
handle_bad_network_on_launch
()
if
(
should_stop
)
return
/**
* 尝试在网络可用时预加载二维码数据
* - 仅在有授权时调用
...
...
Please
register
or
login
to post a comment