networkErr.vue 1.4 KB
Newer Older
DCloud_JSON's avatar
123  
DCloud_JSON 已提交
1
<template>
DCloud_JSON's avatar
312  
DCloud_JSON 已提交
2 3 4 5 6
	<view class="box">
		<view class="content">
			<text class="networkErr">网络连接不可用</text>
			<button type="default" @click="toSet">去设置</button>
		</view>
DCloud_JSON's avatar
123  
DCloud_JSON 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight:0
			}
		},
		mounted() {
			uni.onNetworkStatusChange(res=> {
			    console.log(res.isConnected);
			    console.log(res.networkType);
				if(res.networkType!='none'){
					uni.showToast({
						title:'当前网络类型:'+res.networkType,
						icon:'none',
						duration:3000
					})
DCloud_JSON's avatar
312  
DCloud_JSON 已提交
27 28
					uni.navigateBack({
						animationType:'fade-out'
DCloud_JSON's avatar
123  
DCloud_JSON 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
					})
				}
			});
		},
		methods: {
			toSet(){
				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);
				}
			}
		},
	}
</script>

DCloud_JSON's avatar
312  
DCloud_JSON 已提交
52 53 54 55
<style >
	page {
		background: transparent;
	}
DCloud_JSON's avatar
123  
DCloud_JSON 已提交
56
	.box{
DCloud_JSON's avatar
312  
DCloud_JSON 已提交
57 58 59 60 61 62 63 64 65
		display: flex;
		width: 750rpx;
		height: 100vh;
		justify-content: center;
		align-items: center;
	}
	.content{
		height: 100px;
		width: 400rpx;
DCloud_JSON's avatar
123  
DCloud_JSON 已提交
66 67 68
		background-color: #DD524D;
	}
</style>