uni-load-state.vue 3.6 KB
Newer Older
雪洛's avatar
雪洛 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 84 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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
<template>
	<view @appear="appear">
		<view v-if="state.error">
			<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">{{noNetwork}}</text>
				<view class="btn btn-default" @click="openSettings">
					<text class="btn-text">{{toSet}}</text>
				</view>
			</view>
			<text class="error" v-else>{{error}}{{JSON.stringify(state.error)}}</text>
		</view>
		<template v-else>
			<!-- #ifdef APP-NVUE -->
			<text class="state-text">{{state.loading?'加载中...':(state.hasMore?'上拉加载更多':'没有更多数据了')}}</text>
			<!-- #endif -->
			<!-- #ifndef APP-NVUE -->
			<uni-load-more class="uni-load-more" :status="state.loading?'loading':(state.hasMore?'hasMore':'noMore')"></uni-load-more>
			<!-- #endif -->
		</template>
		
	</view>
</template>

<script>
	import {
		initVueI18n
	} from '@dcloudio/uni-i18n'
	import messages from './i18n/index.js'
	const {
		t
	} = initVueI18n(messages)

	export default {
		name: "uni-load-state",
		computed: {
			noData() {
				return t('noData')
			},
			noNetwork() {
				return t('noNetwork')
			},
			toSet() {
				return t('toSet')
			},
			error() {
				return t('error')
			}
		},
		data() {
			return {
				"networkType": ""
			};
		},
		props: {
			state: {
				type: Object,
				default () {
					return {
						"loading": true,
						"hasMore": false,
						"pagination": {
							"pages": 0
						},
						"data": [],
						"error": {}
					}
				}
			}
		},
		mounted() {
			uni.onNetworkStatusChange(({
				networkType
			}) => {
				if (this.networkType == 'none' && networkType != 'none') { //之前没网现在有了
					this.$emit('networkResume')
				}
				this.networkType = networkType;
			});
			uni.getNetworkType({
				success: ({
					networkType
				}) => {
					this.networkType = networkType;
				}
			});
		},
		methods: {
			appear() {
				if (!this.state.loading && this.state.hasMore) {
					this.$emit('loadMore')
				}
			},
			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 {
		flex: 1;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.uni-load-more{
		align-items: center;
		justify-content: center;
		width: 690rpx;
	}
	.state-text {
		text-align: center;
		font-size: 26rpx;
		width: 690rpx;
		padding: 10rpx;
		color: #999999;
	}

	.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;
	}

	.error {
		width: 690rpx;
		color: #DD524D;
	}
</style>