123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <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>
-
-
- <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>
-
- <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';
-
- 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() {
-
-
- 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>
|