增加网络 异常提示
This commit is contained in:
@@ -1,5 +1,60 @@
|
||||
import { showAlert } from '@/utils/message.js'
|
||||
|
||||
|
||||
// 验证是否有网络
|
||||
export const isNetwork=()=>{
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.getNetworkType({
|
||||
success: function (res) {
|
||||
resolve(res.networkType)
|
||||
},fail:function(err){
|
||||
reject(err)
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 打开网络设置
|
||||
export const openNetworkSettings = () => {
|
||||
// 根据不同平台打开网络设置
|
||||
// #ifdef APP-PLUS
|
||||
// App端
|
||||
const platform = uni.getSystemInfoSync().platform;
|
||||
if (platform === 'ios') {
|
||||
// iOS打开设置页面
|
||||
plus.runtime.openURL('App-Prefs:root')
|
||||
} else if (platform === 'android') {
|
||||
// Android打开网络设置
|
||||
// 方式1:使用原生API
|
||||
const main = plus.android.runtimeMainActivity()
|
||||
const Intent = plus.android.importClass('android.content.Intent')
|
||||
const Settings = plus.android.importClass('android.provider.Settings')
|
||||
const intent = new Intent(Settings.ACTION_WIFI_SETTINGS)
|
||||
main.startActivity(intent)
|
||||
|
||||
// 方式2:使用scheme(某些设备可能不支持)
|
||||
// plus.runtime.openURL('android.settings.WIFI_SETTINGS')
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
// H5端无法直接跳转系统设置,只能提示
|
||||
uni.showToast({
|
||||
title: '请手动打开网络设置',
|
||||
icon: 'none'
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序无法跳转系统设置,可以引导用户检查网络
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '请检查手机网络或WiFi连接',
|
||||
showCancel: false
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
|
||||
// 递归算法
|
||||
export const initTree = (arr, parentId = '0', id) => {
|
||||
const tree = [];
|
||||
|
||||
Reference in New Issue
Block a user