From 68c5ef7d9fea3f911e250fb5f8b300bc76099e49 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期四, 26 十月 2023 13:55:49 +0800
Subject: [PATCH] 小程序
---
minipro_standard/uni_modules/uview-ui/components/u-no-network/u-no-network.vue | 220 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 220 insertions(+), 0 deletions(-)
diff --git a/minipro_standard/uni_modules/uview-ui/components/u-no-network/u-no-network.vue b/minipro_standard/uni_modules/uview-ui/components/u-no-network/u-no-network.vue
new file mode 100644
index 0000000..9710729
--- /dev/null
+++ b/minipro_standard/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骞冲彴锛屾墠鑳借烦杞缃〉锛屽洜涓洪渶瑕佽皟鐢╬lus鐜 -->
+ <!-- #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 缁勪欢鐨剒-index鍊�
+ * @property {String} image 鏃犵綉缁滅殑鍥剧墖鎻愮ず锛屽彲鐢ㄧ殑src鍦板潃鎴朾ase64鍥剧墖
+ * @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.9.3