home - 副本.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view class="nav-pages">
  3. <!-- 政务 -->
  4. <view v-show="[1,2].includes(pattern)">
  5. <view v-show="pattern === 1">
  6. <top ref="affairTopRef" :active-pattern="pattern" :statusBarHeight="statusBarHeight" :pattern="1"
  7. :scrollTop="scrollTop" :topKongLimList="topKongLimList" :toQyKongLimList="toQyKongLimList"
  8. :weatherInfo="weatherInfo" />
  9. <affair ref="affairRef" :active-pattern="pattern" :statusBarHeight="statusBarHeight" />
  10. </view>
  11. <!-- 生活 -->
  12. <view v-show="pattern === 2">
  13. <top ref="lifeTopRef" :active-pattern="pattern" :statusBarHeight="statusBarHeight" :pattern="2"
  14. :scrollTop="scrollTop" :topKongLimList="topKongLimList" :toQyKongLimList="toQyKongLimList"
  15. :weatherInfo="weatherInfo" />
  16. <life ref="lifeRef" :active-pattern="pattern" :statusBarHeight="statusBarHeight" />
  17. </view>
  18. <template v-if="showSopupSwiper">
  19. <popup :pattern="pattern" />
  20. </template>
  21. </view>
  22. <!-- 关怀模式 -->
  23. <view v-if="pattern === 3">
  24. <care-top :statusBarHeight="statusBarHeight" :scrollTop="scrollTop" />
  25. <showSolicitude :statusBarHeight="statusBarHeight" />
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import affair from "./home/affair.vue"
  31. import life from "./home/life.vue"
  32. import showSolicitude from "./home/showSolicitude.vue"
  33. import top from "./home/module/top.vue"
  34. import careTop from "./home/module/care-top.vue"
  35. import popup from "./home/module/popup.vue"
  36. import {
  37. http
  38. } from '@/common/request';
  39. import {
  40. getAPPList,
  41. versionNewest
  42. } from "@/api/government.js"
  43. import {
  44. getWeather_Fn,
  45. getWeatherInfo_Fn
  46. } from "@/utils/weather/index.js"
  47. export default {
  48. components: {
  49. affair,
  50. life,
  51. top,
  52. showSolicitude,
  53. careTop,
  54. popup
  55. },
  56. provide() {
  57. return {
  58. home: this,
  59. };
  60. },
  61. data() {
  62. return {
  63. pattern: 1, // 1:政务 , 2:生活 , 3:关怀模式
  64. statusBarHeight: 0,
  65. scrollTop: 0,
  66. topKongLimList: [],
  67. toQyKongLimList: [],
  68. showSopupSwiper: false,
  69. weatherObj: null,
  70. weatherInfo: null
  71. }
  72. },
  73. onLoad() {
  74. // setTimeout(() => {
  75. // uni.navigateTo({
  76. // url: '/pages/government/demo'
  77. // })
  78. // },3000)
  79. // return
  80. this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
  81. // http.get('/protocol/?code=user_protocol').then(res => {})
  82. // #ifdef APP-PLUS
  83. if (plus.os.name == 'iOS') {
  84. // 首先获取一次网络状态
  85. uni.getNetworkType({
  86. success: (res) => {
  87. if (res.networkType != 'none') {
  88. this.getKongKim();
  89. this.getVersionNewest()
  90. this.getWeatherInfo();
  91. }
  92. }
  93. });
  94. // 监听网络变化
  95. uni.onNetworkStatusChange((res) => {
  96. console.log(res, 111111111)
  97. if (res.isConnected) {
  98. this.getKongKim();
  99. this.getVersionNewest()
  100. this.$refs.affairRef.init()
  101. this.$refs.affairTopRef.init();
  102. this.$refs.lifeRef.init()
  103. this.$refs.lifeTopRef.init();
  104. }
  105. });
  106. } else {
  107. this.getKongKim();
  108. this.getVersionNewest()
  109. this.getWeatherInfo();
  110. }
  111. // #endif
  112. // #ifdef H5
  113. this.getKongKim();
  114. this.getVersionNewest()
  115. this.getWeatherInfo();
  116. // #endif
  117. },
  118. onPullDownRefresh() {
  119. try {
  120. switch (this.pattern) {
  121. case 1:
  122. this.$refs.affairTopRef.init();
  123. this.$refs.affairRef.init();
  124. this.getKongKim();
  125. break;
  126. case 2:
  127. this.$refs.lifeTopRef.init();
  128. this.$refs.lifeRef.init();
  129. this.getKongKim();
  130. break;
  131. }
  132. } catch (e) {
  133. //TODO handle the exception
  134. }
  135. this.getWeatherInfo();
  136. setTimeout(() => {
  137. uni.stopPullDownRefresh();
  138. }, 2000)
  139. },
  140. onReachBottom() {
  141. if (this.pattern == 2) {
  142. this.$refs.lifeRef.moreGoods()
  143. }
  144. },
  145. methods: {
  146. getWeatherInfo() {
  147. getWeather_Fn().then(res => {
  148. this.weatherObj = res
  149. })
  150. },
  151. init(e) {
  152. this.pattern = e
  153. },
  154. getKongKim() {
  155. const keys = [this.$keys.SY_TOP_KONGKIM, this.$keys.SY_qiye_KONGKIM]
  156. keys.forEach(el => {
  157. getAPPList(el).then(res => {
  158. const list = res.data || []
  159. if (list.length > 0) {
  160. this.setService(list, el, keys)
  161. }
  162. }).catch(err => {
  163. this.setService([], el, keys)
  164. })
  165. })
  166. },
  167. setService(data, key, keys) {
  168. switch (key) {
  169. case keys[0]:
  170. // 首页顶金刚区
  171. this.topKongLimList = data || []
  172. break;
  173. case keys[1]:
  174. // 首页企业入口
  175. this.toQyKongLimList = data || []
  176. break;
  177. }
  178. },
  179. // 获取更新包
  180. getVersionNewest() {
  181. const systemInfo = uni.getSystemInfoSync();
  182. let version_number = systemInfo.appVersion;
  183. let platform = uni.getSystemInfoSync().platform;
  184. let type = 0
  185. if (platform == 'ios') {
  186. type = 1
  187. } else if (platform == 'android') {
  188. type = 0
  189. }
  190. versionNewest({
  191. type: type
  192. }).then(res => {
  193. this.newest = res.data;
  194. if (version_number < this.newest.version) {
  195. uni.navigateTo({
  196. url: "/components/appUpdatePop?type=1"
  197. })
  198. } else {
  199. this.showSopupSwiper = true
  200. }
  201. }).catch(err => {
  202. this.showSopupSwiper = true
  203. })
  204. }
  205. },
  206. watch: {
  207. weatherObj: {
  208. handler: function(newInfo) {
  209. this.weatherInfo = getWeatherInfo_Fn(newInfo)
  210. },
  211. immediate: true,
  212. deep: true
  213. }
  214. }
  215. }
  216. </script>
  217. <style>
  218. page {
  219. /* opacity: 0.2; */
  220. /* rgba(75,90,255,0.2), rgba(74,181,255,0.2) 8%, */
  221. background: #fcfcfc;
  222. }
  223. </style>