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

312

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