fh-no-network.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <view
  3. v-if="show"
  4. class="no-network-main"
  5. :style="{ height: backgroundHeight + 'px', width: backgroundWidth + 'px' }"
  6. >
  7. <view class="no-network-area">
  8. <view
  9. class="no-network-picture"
  10. :style="{ height: backgroundImageHeight, width: backgroundImageWidth }"
  11. ></view>
  12. <view class="no-network-content">哎呀,网络信号丢失</view>
  13. <view class="no-network-handle">
  14. 请检查网络,或前往
  15. <span class="go-to-sitting" @click="gotoSitting">设置</span>
  16. </view>
  17. <view class="no-network-retry" @click="retry">重试</view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import gotoAppPermissionSetting from './utils.js'
  23. export default {
  24. name: 'FhNoNetwork',
  25. mounted() {
  26. const that = this
  27. // #ifdef APP-PLUS
  28. uni.getNetworkType({
  29. success: function(res) {
  30. console.log(res)
  31. if (res.networkType == 'none' || res.networkType == 'unknown') {
  32. that.shrink()
  33. } else {
  34. that.unfold()
  35. }
  36. }
  37. })
  38. // #endif
  39. uni.onNetworkStatusChange(function(res) {
  40. if (res.isConnected) {
  41. that.unfold()
  42. console.log(res.networkType)
  43. } else {
  44. that.shrink()
  45. }
  46. })
  47. },
  48. computed: {
  49. backgroundImageWidth() {
  50. if (this.backgroundWidth < 768) {
  51. return this.backgroundWidth + 'px'
  52. }
  53. return '439.46rpx'
  54. },
  55. backgroundImageHeight() {
  56. if (this.backgroundWidth < 768) {
  57. return this.backgroundWidth / 2 + 'px'
  58. }
  59. return '219.73rpx'
  60. }
  61. },
  62. data() {
  63. return {
  64. show: false,
  65. backgroundHeight: uni.getSystemInfoSync().screenHeight,
  66. backgroundWidth: uni.getSystemInfoSync().screenWidth
  67. }
  68. },
  69. methods: {
  70. shrink: function() {
  71. this.show = true
  72. },
  73. unfold: function() {
  74. this.show = false
  75. },
  76. gotoSitting: function() {
  77. gotoAppPermissionSetting()
  78. },
  79. retry: function() {
  80. uni.getNetworkType({
  81. success: function(res) {
  82. console.log(res)
  83. if (res.networkType == 'none' || res.networkType == 'unknown') {
  84. uni.showToast({
  85. title: '无网络连接',
  86. icon: 'none'
  87. })
  88. }
  89. }
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .no-network-main {
  97. position: absolute;
  98. top: 0;
  99. background-color: #ffffff;
  100. z-index: 10000;
  101. display: flex;
  102. justify-content: center;
  103. align-items: center;
  104. .no-network-area {
  105. .no-network-picture {
  106. background-image: url(../../static/fh-no-network/no-network.png);
  107. background-repeat: no-repeat;
  108. background-size: contain;
  109. }
  110. .no-network-content {
  111. width: 100%;
  112. text-align: center;
  113. height: 18.32rpx;
  114. line-height: 18.32rpx;
  115. color: #333333;
  116. font-family: PingFangSC-Medium;
  117. font-size: 13.19rpx;
  118. margin-bottom: 6.6rpx;
  119. }
  120. .no-network-handle {
  121. width: 100%;
  122. text-align: center;
  123. height: 14.65rpx;
  124. line-height: 14.65rpx;
  125. font-family: PingFangSC-Regular;
  126. font-size: 10.26rpx;
  127. color: #666666;
  128. margin-bottom: 29.3rpx;
  129. }
  130. .go-to-sitting {
  131. height: 14.65rpx;
  132. line-height: 14.65rpx;
  133. font-family: PingFangSC-Regular;
  134. font-size: 10.26rpx;
  135. color: #1677ff;
  136. }
  137. .no-network-retry {
  138. width: 209.48rpx;
  139. height: 33.7rpx;
  140. border: 1.47rpx solid #333333;
  141. border-radius: 16.48rpx;
  142. line-height: 32.23rpx;
  143. text-align: center;
  144. font-size: 11.72rpx;
  145. font-family: PingFangSC-Medium;
  146. letter-spacing: 1.18rpx;
  147. margin: 0 auto;
  148. }
  149. }
  150. }
  151. </style>