uni-load-state.vue 2.9 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1
<template>
2
	<view style="width: 750rpx;">
3 4 5 6 7 8 9 10 11 12 13 14
		<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>
15
			<text class="err" v-else>错误:{{JSON.stringify(state.error)}}</text>
DCloud_JSON's avatar
DCloud_JSON 已提交
16 17 18 19
		</view>
	</view>
</template>

20
<script>
DCloud_JSON's avatar
DCloud_JSON 已提交
21
	export default {
22
		name: "uni-load-state",
DCloud_JSON's avatar
DCloud_JSON 已提交
23 24 25 26
		data() {
			return {
				"networkType": ""
			};
27 28 29 30 31 32 33 34 35 36 37 38 39 40
		},
		props: {
			state:{
				type: Object,
				default(){
					return {
						"loading":true,
						"hasMore":false,
						"pagination":{"pages":0},
						"data":[],
						"error":{}
					}
				}
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
41
		},
42
		mounted() {
DCloud_JSON's avatar
DCloud_JSON 已提交
43 44 45
			uni.onNetworkStatusChange(({
				networkType
			}) => {
46 47
				if(this.networkType == 'none' && networkType != 'none'){ //之前没网现在有了
					this.$emit('networkResume')
DCloud_JSON's avatar
DCloud_JSON 已提交
48 49 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
				}
				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 已提交
84
		flex: 1;
DCloud_JSON's avatar
DCloud_JSON 已提交
85 86 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
		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;
119 120 121 122 123
	}
	
	.noData{
		text-align: center;
		padding: 30rpx;
124 125 126 127
	}
	.err{
		width: 750rpx;
		color: #DD524D;
DCloud_JSON's avatar
DCloud_JSON 已提交
128 129
	}
</style>