nodata.nvue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="nodata">
  3. <view class="nodata-content">
  4. <view class="text-view a-i-c j-c-c t-a-c">
  5. <text class="title">{{textTypes[networkType]}}</text>
  6. </view>
  7. <view class="icon-view"></view>
  8. <view class="opera-view">
  9. <view class="btn btn-default" v-if="networkType!='none'" @click="retry">
  10. <text class="btn-text">重试</text>
  11. </view>
  12. <view class="btn btn-default" v-if="networkType=='none'" @click="openSettings">
  13. <text class="btn-text">设置</text>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'nodata',
  22. data() {
  23. return {
  24. textTypes: {
  25. none: "暂无网络"
  26. },
  27. isConnected: false,
  28. networkType: "none"
  29. }
  30. },
  31. mounted() {
  32. this.isIOS = (uni.getSystemInfoSync().platform === 'ios');
  33. uni.onNetworkStatusChange((res) => {
  34. this.isConnected = res.isConnected;
  35. this.networkType = res.networkType;
  36. });
  37. uni.getNetworkType({
  38. success: (res) => {
  39. this.networkType = res.networkType;
  40. }
  41. });
  42. },
  43. methods: {
  44. retry() {
  45. this.$emit('retry');
  46. },
  47. async openSettings() {
  48. if (this.networkType == "none") {
  49. this.openSystemSettings();
  50. return;
  51. }
  52. },
  53. openAppSettings() {
  54. this.gotoAppSetting();
  55. },
  56. openSystemSettings() {
  57. if (this.isIOS) {
  58. this.gotoiOSSetting();
  59. } else {
  60. this.gotoAndroidSetting();
  61. }
  62. },
  63. network() {
  64. var result = null;
  65. var cellularData = plus.ios.newObject("CTCellularData");
  66. var state = cellularData.plusGetAttribute("restrictedState");
  67. if (state == 0) {
  68. result = null;
  69. console.log("StateUnknown");
  70. } else if (state == 2) {
  71. result = 1;
  72. console.log("已经开启了互联网权限:NotRestricted");
  73. } else if (state == 1) {
  74. result = 2;
  75. console.log("Restricted");
  76. }
  77. plus.ios.deleteObject(cellularData);
  78. return result;
  79. },
  80. gotoAppSetting() {
  81. if (this.isIOS) {
  82. var UIApplication = plus.ios.import("UIApplication");
  83. var application2 = UIApplication.sharedApplication();
  84. var NSURL2 = plus.ios.import("NSURL");
  85. var setting2 = NSURL2.URLWithString("app-settings:");
  86. application2.openURL(setting2);
  87. plus.ios.deleteObject(setting2);
  88. plus.ios.deleteObject(NSURL2);
  89. plus.ios.deleteObject(application2);
  90. } else {
  91. var Intent = plus.android.importClass("android.content.Intent");
  92. var Settings = plus.android.importClass("android.provider.Settings");
  93. var Uri = plus.android.importClass("android.net.Uri");
  94. var mainActivity = plus.android.runtimeMainActivity();
  95. var intent = new Intent();
  96. intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
  97. var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
  98. intent.setData(uri);
  99. mainActivity.startActivity(intent);
  100. }
  101. },
  102. gotoiOSSetting() {
  103. var UIApplication = plus.ios.import("UIApplication");
  104. var application2 = UIApplication.sharedApplication();
  105. var NSURL2 = plus.ios.import("NSURL");
  106. var setting2 = NSURL2.URLWithString("App-prefs:root=General");
  107. application2.openURL(setting2);
  108. plus.ios.deleteObject(setting2);
  109. plus.ios.deleteObject(NSURL2);
  110. plus.ios.deleteObject(application2);
  111. },
  112. gotoAndroidSetting() {
  113. var Intent = plus.android.importClass("android.content.Intent");
  114. var Settings = plus.android.importClass("android.provider.Settings");
  115. var mainActivity = plus.android.runtimeMainActivity();
  116. var intent = new Intent(Settings.ACTION_SETTINGS);
  117. mainActivity.startActivity(intent);
  118. }
  119. }
  120. }
  121. </script>
  122. <style>
  123. .a-i-c {
  124. align-items: center;
  125. }
  126. .j-c-c {
  127. justify-content: center;
  128. }
  129. .t-a-c {
  130. text-align: center;
  131. }
  132. .nodata {
  133. flex: 1;
  134. flex-direction: column;
  135. /* #ifndef APP-PLUS */
  136. display: flex;
  137. /* #endif */
  138. align-items: center;
  139. justify-content: center;
  140. padding: 30px;
  141. background-color: #f8f8f8;
  142. }
  143. .nodata-content {
  144. transform: translateY(-50px);
  145. }
  146. .text-view {
  147. margin-bottom: 40px;
  148. }
  149. .title {
  150. color: #999999;
  151. font-size: 18px;
  152. }
  153. .opera-view {
  154. flex-direction: column;
  155. align-items: center;
  156. justify-content: center;
  157. }
  158. .btn {
  159. padding: 5px 10px;
  160. width: 128px;
  161. flex-direction: row;
  162. align-items: center;
  163. justify-content: center;
  164. text-align: center;
  165. }
  166. .btn-text {
  167. color: #999999;
  168. font-size: 15px;
  169. }
  170. .btn-default {
  171. border-color: #999999;
  172. border-style: solid;
  173. border-width: 1px;
  174. border-radius: 3px;
  175. }
  176. </style>