uni-load-state.vue 2.8 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1
<template>
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
	<view style="flex:1">
		<template v-if="!state.error">
			<uni-load-more v-if="state.loading||state.pagination.current!=1||state.data.length!=0" :status="state.loading?'loading':(state.hasMore?'hasMore':'noMore')"></uni-load-more>
			<text class="noData" v-else>暂无数据</text>
		</template>
		<view v-else>
			<view class="box" v-if="networkType == 'none'">
				<image class="icon-image" src="@/static/uni-load-state/disconnection.png" mode="widthFix"></image>
				<text class="tip-text">网络异常</text>
				<view class="btn btn-default" @click="openSettings">
					<text class="btn-text">前往设置</text>
				</view>
			</view>
			<view v-else>
				错误:{{state.error}}
			</view>
DCloud_JSON's avatar
DCloud_JSON 已提交
18 19 20 21
		</view>
	</view>
</template>

22
<script>
DCloud_JSON's avatar
DCloud_JSON 已提交
23
	export default {
24
		name: "uni-load-state",
DCloud_JSON's avatar
DCloud_JSON 已提交
25 26 27 28
		data() {
			return {
				"networkType": ""
			};
29 30 31 32 33 34 35 36 37 38 39 40 41 42
		},
		props: {
			state:{
				type: Object,
				default(){
					return {
						"loading":true,
						"hasMore":false,
						"pagination":{"pages":0},
						"data":[],
						"error":{}
					}
				}
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
43
		},
44
		mounted() {
DCloud_JSON's avatar
DCloud_JSON 已提交
45 46 47
			uni.onNetworkStatusChange(({
				networkType
			}) => {
48 49
				if(this.networkType == 'none' && networkType != 'none'){ //之前没网现在有了
					this.$emit('networkResume')
DCloud_JSON's avatar
DCloud_JSON 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
				}
				this.networkType = networkType;
			});
			uni.getNetworkType({
				success: ({
					networkType
				}) => {
					this.networkType = networkType;
				}
			});
		},
		methods:{
			openSettings(){
				if (uni.getSystemInfoSync().platform == "ios") {
					var UIApplication = plus.ios.import("UIApplication");
					var application2 = UIApplication.sharedApplication();
					var NSURL2 = plus.ios.import("NSURL");
					var setting2 = NSURL2.URLWithString("App-prefs:root=General");
					application2.openURL(setting2);
					plus.ios.deleteObject(setting2);
					plus.ios.deleteObject(NSURL2);
					plus.ios.deleteObject(application2);
				} else {
					var Intent = plus.android.importClass("android.content.Intent");
					var Settings = plus.android.importClass("android.provider.Settings");
					var mainActivity = plus.android.runtimeMainActivity();
					var intent = new Intent(Settings.ACTION_SETTINGS);
					mainActivity.startActivity(intent);
				}
			}
		}
	}
</script>

<style scoped>
	.box{
DCloud_JSON's avatar
DCloud_JSON 已提交
86
		flex: 1;
DCloud_JSON's avatar
DCloud_JSON 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
		margin:100rpx 0;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	
	.icon-image{
		width: 300rpx;
	}
	.tip-text{
		color: #999999;
		font-size: 32rpx;
		margin-bottom: 30rpx;
	}
	
	.btn {
		padding: 5px 10px;
		width: 128px;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		text-align: center;
	}

	.btn-text {
		color: #999999;
		font-size: 15px;
	}

	.btn-default {
		border-color: #999999;
		border-style: solid;
		border-width: 1px;
		border-radius: 3px;
121 122 123 124 125
	}
	
	.noData{
		text-align: center;
		padding: 30rpx;
DCloud_JSON's avatar
DCloud_JSON 已提交
126 127
	}
</style>