uni-load-state.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view @appear="appear">
  3. <view v-if="state.error">
  4. <view class="box" v-if="networkType == 'none'">
  5. <image class="icon-image" src="@/static/uni-load-state/disconnection.png" mode="widthFix"></image>
  6. <text class="tip-text">{{noNetwork}}</text>
  7. <view class="btn btn-default" @click="openSettings">
  8. <text class="btn-text">{{toSet}}</text>
  9. </view>
  10. </view>
  11. <text class="error" v-else>{{error}}:{{JSON.stringify(state.error)}}</text>
  12. </view>
  13. <template v-else>
  14. <!-- #ifdef APP-NVUE -->
  15. <text class="state-text">{{state.loading?'加载中...':(state.hasMore?'上拉加载更多':'没有更多数据了')}}</text>
  16. <!-- #endif -->
  17. <!-- #ifndef APP-NVUE -->
  18. <uni-load-more class="uni-load-more" :status="state.loading?'loading':(state.hasMore?'hasMore':'noMore')"></uni-load-more>
  19. <!-- #endif -->
  20. </template>
  21. </view>
  22. </template>
  23. <script>
  24. import {
  25. initVueI18n
  26. } from '@dcloudio/uni-i18n'
  27. import messages from './i18n/index.js'
  28. const {
  29. t
  30. } = initVueI18n(messages)
  31. export default {
  32. name: "uni-load-state",
  33. computed: {
  34. noData() {
  35. return t('noData')
  36. },
  37. noNetwork() {
  38. return t('noNetwork')
  39. },
  40. toSet() {
  41. return t('toSet')
  42. },
  43. error() {
  44. return t('error')
  45. }
  46. },
  47. data() {
  48. return {
  49. "networkType": ""
  50. };
  51. },
  52. props: {
  53. state: {
  54. type: Object,
  55. default () {
  56. return {
  57. "loading": true,
  58. "hasMore": false,
  59. "pagination": {
  60. "pages": 0
  61. },
  62. "data": [],
  63. "error": {}
  64. }
  65. }
  66. }
  67. },
  68. mounted() {
  69. uni.onNetworkStatusChange(({
  70. networkType
  71. }) => {
  72. if (this.networkType == 'none' && networkType != 'none') { //之前没网现在有了
  73. this.$emit('networkResume')
  74. }
  75. this.networkType = networkType;
  76. });
  77. uni.getNetworkType({
  78. success: ({
  79. networkType
  80. }) => {
  81. this.networkType = networkType;
  82. }
  83. });
  84. },
  85. methods: {
  86. appear() {
  87. if (!this.state.loading && this.state.hasMore) {
  88. this.$emit('loadMore')
  89. }
  90. },
  91. openSettings() {
  92. if (uni.getSystemInfoSync().platform == "ios") {
  93. var UIApplication = plus.ios.import("UIApplication");
  94. var application2 = UIApplication.sharedApplication();
  95. var NSURL2 = plus.ios.import("NSURL");
  96. var setting2 = NSURL2.URLWithString("App-prefs:root=General");
  97. application2.openURL(setting2);
  98. plus.ios.deleteObject(setting2);
  99. plus.ios.deleteObject(NSURL2);
  100. plus.ios.deleteObject(application2);
  101. } else {
  102. var Intent = plus.android.importClass("android.content.Intent");
  103. var Settings = plus.android.importClass("android.provider.Settings");
  104. var mainActivity = plus.android.runtimeMainActivity();
  105. var intent = new Intent(Settings.ACTION_SETTINGS);
  106. mainActivity.startActivity(intent);
  107. }
  108. }
  109. }
  110. }
  111. </script>
  112. <style scoped>
  113. .box {
  114. flex: 1;
  115. width: 700rpx;
  116. flex-direction: column;
  117. align-items: center;
  118. justify-content: center;
  119. }
  120. .uni-load-more{
  121. align-items: center;
  122. justify-content: center;
  123. }
  124. .state-text {
  125. text-align: center;
  126. font-size: 26rpx;
  127. width: 690rpx;
  128. padding: 10rpx;
  129. color: #999999;
  130. }
  131. .icon-image {
  132. width: 300rpx;
  133. }
  134. .tip-text {
  135. color: #999999;
  136. font-size: 32rpx;
  137. margin-bottom: 30rpx;
  138. }
  139. .btn {
  140. padding: 5px 10px;
  141. width: 128px;
  142. flex-direction: row;
  143. align-items: center;
  144. justify-content: center;
  145. text-align: center;
  146. }
  147. .btn-text {
  148. color: #999999;
  149. font-size: 15px;
  150. }
  151. .btn-default {
  152. border-color: #999999;
  153. border-style: solid;
  154. border-width: 1px;
  155. border-radius: 3px;
  156. }
  157. .error {
  158. width: 690rpx;
  159. color: #DD524D;
  160. }
  161. </style>