提交 5be43ca2 编写于 作者: DCloud_JSON's avatar DCloud_JSON

312

上级 019f116e
...@@ -90,7 +90,13 @@ export default function() { ...@@ -90,7 +90,13 @@ export default function() {
}); });
} }
} }
}) })
// #ifdef APP-PLUS
// 设备网络状态变化事件
eventListenerNetwork()
// #endif
} }
/** /**
* // 初始化appVersion * // 初始化appVersion
...@@ -126,31 +132,52 @@ function initAppVersion() { ...@@ -126,31 +132,52 @@ function initAppVersion() {
// 设备网络状态变化事件 // 设备网络状态变化事件
function eventListenerNetwork() { function eventListenerNetwork() {
uni.onNetworkStatusChange(function(res) { //网络掉线
console.log(res.isConnected); uni.getNetworkType({
console.log(res.networkType); success:res=>{
if (!res.isConnected) { console.log(res);
uni.showModal({ if(res.networkType=='none'){
content: "你未打开网络连接", showNetworkErrPage()
confirmText: "前往打开", }
complete: (e) => { uni.showToast({
console.log(e); title:'当前网络类型:'+res.networkType,
if (uni.getSystemInfoSync().platform == "ios") { icon:'none',
plus.runtime.launchApplication({ duration:3000
action: 'App-Prefs:root=WIFI' })
}, function(e) { }
console.log(JSON.stringify(e)); });
}); //监听网络变化
} else { uni.onNetworkStatusChange(res=> {
var main = plus.android.runtimeMainActivity(); console.log(res.isConnected);
var Intent = plus.android.importClass("android.content.Intent"); console.log(res.networkType);
var mIntent = new Intent('android.settings.DATA_ROAMING_SETTINGS'); if(res.networkType!='none'){
main.startActivity(mIntent); uni.showToast({
} title:'当前网络类型:'+res.networkType,
} icon:'none',
}); duration:3000
} })
}); }else{
showNetworkErrPage()
uni.showToast({
title:'网络类型:'+res.networkType,
icon:'none',
duration:3000
})
}
});
function showNetworkErrPage(){
let pages = getCurrentPages();
console.log('pages.length',pages.length);
if(pages.length===0|| pages[pages.length - 1].route!='/pages/networkErr/networkErr.vue'){
uni.navigateTo({
url:'/pages/networkErr/networkErr'
})
}else{
console.log('已经打开');
}
}
} }
function openAppPermissionSetting(){ function openAppPermissionSetting(){
......
...@@ -5,22 +5,21 @@ ...@@ -5,22 +5,21 @@
//#ifndef MP //#ifndef MP
"navigationStyle": "custom", "navigationStyle": "custom",
//#endif //#endif
"enablePullDownRefresh": true, "enablePullDownRefresh": true
"app-plus":{
"subNVues":[
{
"id":"networkErr",
"path":"pages/list/networkErr/networkErr",
"style":{
"height":"0",
"width":"100%",
"background":"transparent"
}
}
]
}
} }
}, },
{
"path": "pages/networkErr/networkErr",
"style": {
"navigationStyle": "custom",
"backgroundColor": "transparent",
"app-plus": {
"animationType": "fade-in",
"background": "transparent",
"popGesture": "none"
}
}
},
{ {
"path": "pages/list/news-list", "path": "pages/list/news-list",
"style": { "style": {
...@@ -219,8 +218,7 @@ ...@@ -219,8 +218,7 @@
"backgroundColor": "#F8F8F8" "backgroundColor": "#F8F8F8"
}, },
"condition": { "condition": {
"list": [ "list": [{
{
"path": "pages/list/list" "path": "pages/list/list"
}, },
{ {
...@@ -234,7 +232,7 @@ ...@@ -234,7 +232,7 @@
} }
], ],
"current": 0 "current": 0
}, },
"tabBar": { "tabBar": {
"color": "#7A7E83", "color": "#7A7E83",
"selectedColor": "#007AFF", "selectedColor": "#007AFF",
...@@ -257,4 +255,4 @@ ...@@ -257,4 +255,4 @@
"text": "我的" "text": "我的"
}] }]
} }
} }
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
}, },
onLoad() { onLoad() {
checkIsAgree(); checkIsAgree();
uni.getSubNVueById('networkErr').show()
}, },
onShow(options) { onShow(options) {
this.searchText = getApp().globalData.searchText; this.searchText = getApp().globalData.searchText;
......
<template> <template>
<view class="box" :style="{'padding-top':statusBarHeight}"> <view class="box">
<text class="networkErr">网络连接不可用</text> <view class="content">
<text @click="toSet">去设置</text> <text class="networkErr">网络连接不可用</text>
<button type="default" @click="toSet">去设置</button>
</view>
</view> </view>
</template> </template>
...@@ -13,42 +15,17 @@ ...@@ -13,42 +15,17 @@
} }
}, },
mounted() { mounted() {
this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
const getCurrentSubNVue = uni.getCurrentSubNVue();
getCurrentSubNVue.setStyle({
"height":this.statusBarHeight+60+'px'
})
uni.getNetworkType({
success:res=>{
console.log(res);
if(res.networkType!='none'){
getCurrentSubNVue.hide()
}else{
getCurrentSubNVue.show()
}
}
});
uni.onNetworkStatusChange(res=> { uni.onNetworkStatusChange(res=> {
console.log(res.isConnected); console.log(res.isConnected);
console.log(res.networkType); console.log(res.networkType);
if(res.networkType!='none'){ if(res.networkType!='none'){
uni.showToast({ uni.showToast({
title:'当前网络类型:'+res.networkType, title:'当前网络类型:'+res.networkType,
icon:'none', icon:'none',
duration:3000 duration:3000
}) })
if(this.old=='none'){ uni.navigateBack({
this.$parent.reLink(); animationType:'fade-out'
}
getCurrentSubNVue.hide()
}else{
getCurrentSubNVue.show()
uni.showToast({
title:'网络类型:'+res.networkType,
icon:'none',
duration:3000
}) })
} }
}); });
...@@ -72,10 +49,20 @@ ...@@ -72,10 +49,20 @@
} }
</script> </script>
<style lang="scss" scoped> <style >
page {
background: transparent;
}
.box{ .box{
display: flex;
width: 750rpx;
height: 100vh;
justify-content: center;
align-items: center;
}
.content{
height: 100px;
width: 400rpx;
background-color: #DD524D; background-color: #DD524D;
height:100%;
flex: 1;
} }
</style> </style>
{ {
"bsonType": "object", "bsonType": "object",
"required": ["user_id", "score", "balance"], "required": ["user_id", "score", "balance"],
"permission":{
"read":true
},
"properties": { "properties": {
"_id": { "_id": {
"description": "ID,系统自动生成" "description": "ID,系统自动生成"
......
...@@ -370,7 +370,7 @@ $list-item-pd: $uni-spacing-col-lg $uni-spacing-row-lg; ...@@ -370,7 +370,7 @@ $list-item-pd: $uni-spacing-col-lg $uni-spacing-row-lg;
/* #endif */ /* #endif */
height: $uni-img-size-base; height: $uni-img-size-base;
width: $uni-img-size-base; width: $uni-img-size-base;
marin-right: 10px; margin-right: 10px;
} }
.uni-icon-wrapper { .uni-icon-wrapper {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册