nodata.nvue 4.5 KB

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