From d8b41fff43a2cee6a8f714ffa807623b15803786 Mon Sep 17 00:00:00 2001
From: quanyawei <401863037@qq.com>
Date: Fri, 20 Oct 2023 15:21:35 +0800
Subject: [PATCH] fix:立行立改Uniapp小程序新建项目

---
 uni_modules/uview-ui/components/u-no-network/u-no-network.vue |  220 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 220 insertions(+), 0 deletions(-)

diff --git a/uni_modules/uview-ui/components/u-no-network/u-no-network.vue b/uni_modules/uview-ui/components/u-no-network/u-no-network.vue
new file mode 100644
index 0000000..9710729
--- /dev/null
+++ b/uni_modules/uview-ui/components/u-no-network/u-no-network.vue
@@ -0,0 +1,220 @@
+<template>
+	<u-overlay
+	    :show="!isConnected"
+		:zIndex="zIndex"
+	    @touchmove.stop.prevent="noop"
+		:customStyle="{
+			backgroundColor: '#fff',
+			display: 'flex',
+			justifyContent: 'center',
+		}"
+	>
+		<view
+		    class="u-no-network"
+		>
+			<u-icon
+			    :name="image"
+			    size="150"
+			    imgMode="widthFit"
+			    class="u-no-network__error-icon"
+			></u-icon>
+			<text class="u-no-network__tips">{{tips}}</text>
+			<!-- ������APP���������������������������������������������������plus������ -->
+			<!-- #ifdef APP-PLUS -->
+			<view class="u-no-network__app">
+				<text class="u-no-network__app__setting">���������������������������</text>
+				<text
+				    class="u-no-network__app__to-setting"
+				    @tap="openSettings"
+				>������</text>
+			</view>
+			<!-- #endif -->
+			<view class="u-no-network__retry">
+				<u-button
+				    size="mini"
+				    text="������"
+				    type="primary"
+					plain
+				    @click="retry"
+				></u-button>
+			</view>
+		</view>
+	</u-overlay>
+</template>
+
+<script>
+	import props from './props.js';
+
+	/**
+	 * noNetwork ���������������
+	 * @description ���������������������������������������������������������������������������������������
+	 * @tutorial https://www.uviewui.com/components/noNetwork.html
+	 * @property {String}			tips 	��������������������������� ������������'���������������������������' ���
+	 * @property {String | Number}	zIndex	���������z-index��� 
+	 * @property {String}			image	������������������������������������src���������base64������ 
+	 * @event {Function}			retry	���������������������"������"���������������
+	 * @example <u-no-network></u-no-network>
+	 */
+	export default {
+		name: "u-no-network",
+		mixins: [uni.$u.mpMixin, uni.$u.mixin,props],
+		data() {
+			return {
+				isConnected: true, // ���������������������
+				networkType: "none", // ������������
+			}
+		},
+		mounted() {
+			this.isIOS = (uni.getSystemInfoSync().platform === 'ios')
+			uni.onNetworkStatusChange((res) => {
+				this.isConnected = res.isConnected
+				this.networkType = res.networkType
+				this.emitEvent(this.networkType)
+			})
+			uni.getNetworkType({
+				success: (res) => {
+					this.networkType = res.networkType
+					this.emitEvent(this.networkType)
+					if (res.networkType == 'none') {
+						this.isConnected = false
+					} else {
+						this.isConnected = true
+					}
+				}
+			})
+		},
+		methods: {
+			retry() {
+				// ������������������
+				uni.getNetworkType({
+					success: (res) => {
+						this.networkType = res.networkType
+						this.emitEvent(this.networkType)
+						if (res.networkType == 'none') {
+							uni.$u.toast('���������������')
+							this.isConnected = false
+						} else {
+							uni.$u.toast('���������������')
+							this.isConnected = true
+						}
+					}
+				})
+				this.$emit('retry')
+			},
+			// ������������������������
+			emitEvent(networkType) {
+				this.$emit(networkType === 'none' ? 'disconnected' : 'connected')
+			},
+			async openSettings() {
+				if (this.networkType == "none") {
+					this.openSystemSettings()
+					return
+				}
+			},
+			openAppSettings() {
+				this.gotoAppSetting()
+			},
+			openSystemSettings() {
+				// ������������������5+���������������������������������������������������
+				// https://ask.dcloud.net.cn/docs/
+				if (this.isIOS) {
+					this.gotoiOSSetting()
+				} else {
+					this.gotoAndroidSetting()
+				}
+			},
+			network() {
+				var result = null
+				var cellularData = plus.ios.newObject("CTCellularData")
+				var state = cellularData.plusGetAttribute("restrictedState")
+				if (state == 0) {
+					result = null
+				} else if (state == 2) {
+					result = 1
+				} else if (state == 1) {
+					result = 2
+				}
+				plus.ios.deleteObject(cellularData)
+				return result
+			},
+			gotoAppSetting() {
+				if (this.isIOS) {
+					var UIApplication = plus.ios.import("UIApplication")
+					var application2 = UIApplication.sharedApplication()
+					var NSURL2 = plus.ios.import("NSURL")
+					var setting2 = NSURL2.URLWithString("app-settings:")
+					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 Uri = plus.android.importClass("android.net.Uri")
+					var mainActivity = plus.android.runtimeMainActivity()
+					var intent = new Intent()
+					intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
+					var uri = Uri.fromParts("package", mainActivity.getPackageName(), null)
+					intent.setData(uri)
+					mainActivity.startActivity(intent)
+				}
+			},
+			gotoiOSSetting() {
+				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)
+			},
+			gotoAndroidSetting() {
+				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 lang="scss" scoped>
+	@import "../../libs/css/components.scss";
+
+	.u-no-network {
+		@include flex(column);
+		justify-content: center;
+		align-items: center;
+		margin-top: -100px;
+
+		&__tips {
+			color: $u-tips-color;
+			font-size: 14px;
+			margin-top: 15px;
+		}
+
+		&__app {
+			@include flex(row);
+			margin-top: 6px;
+
+			&__setting {
+				color: $u-light-color;
+				font-size: 13px;
+			}
+
+			&__to-setting {
+				font-size: 13px;
+				color: $u-primary;
+				margin-left: 3px;
+			}
+		}
+
+		&__retry {
+			@include flex(row);
+			justify-content: center;
+			margin-top: 15px;
+		}
+	}
+</style>

--
Gitblit v1.8.0