index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view>
  3. <t-i-navbar :mine_code="mine_code"></t-i-navbar>
  4. <!-- notice -->
  5. <t-i-notice :text="text"></t-i-notice>
  6. <!-- banner -->
  7. <t-i-banner :banner="banners" :mine_code="mine_code"></t-i-banner>
  8. <!-- 固定入口 -->
  9. <t-i-icon :iconList="iconList" :mine_code="mine_code"></t-i-icon>
  10. <!-- 常用功能 -->
  11. <t-i-common v-if="mine_code == 'ningdongyunying'"></t-i-common>
  12. <!-- 新闻列表 -->
  13. <t-i-news :newsList="newsList" :mine_code="mine_code"></t-i-news>
  14. <!-- 金家渠 -->
  15. <view v-if="mine_code == 'jinjiaqu'">
  16. <t-i-jinjiaqu :mine_code="mine_code"></t-i-jinjiaqu>
  17. </view>
  18. <!-- 羊场湾 -->
  19. <view v-if="mine_code == 'yangchangwan'">
  20. <t-i-yangchangwan :mine_code="mine_code" :home_link="home_link"></t-i-yangchangwan>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import {set_base_url} from '@/common/set_base_url.js'
  26. // 版本控制
  27. import upApp from "@/uni_modules/uni-upgrade-center-app/utils/check-update"
  28. export default {
  29. data() {
  30. return {
  31. // 当前煤矿编码
  32. mine_code: "",
  33. // 首页接口的基础请求路径 默认为当前矿编码的基础路径
  34. base_url: " ",
  35. // 轮播图
  36. banners: [],
  37. // 新闻列表
  38. newsList: "",
  39. // 值班公告
  40. text: "暂无公告。",
  41. // 固定入口
  42. iconList: [],
  43. // 首页链接
  44. home_link:[]
  45. }
  46. },
  47. onPullDownRefresh() {
  48. uni.reLaunch({
  49. url: "./index"
  50. })
  51. setTimeout(function() {
  52. uni.stopPullDownRefresh();
  53. }, 1000);
  54. },
  55. onLoad() {
  56. // 初始化当前煤矿编码
  57. this.mine_code = uni.getStorageSync('mine_code')
  58. // 检查更新
  59. upApp()
  60. // token过期验证
  61. this.$api.worksheet_classify_list({
  62. }).then((res) => {
  63. // console.log(res)
  64. if (res.data.code == 401) {
  65. uni.showToast({
  66. icon: "none",
  67. title: "登录失效、请重新登录"
  68. })
  69. setTimeout(function() {
  70. uni.redirectTo({
  71. url: "../../my/login/login"
  72. })
  73. }, 2000)
  74. } else {
  75. // console.log(res)
  76. }
  77. })
  78. },
  79. onShow() {
  80. // E信-切换矿
  81. uni.$on('update_kuang', (data) => {
  82. console.log('监听到事件来自 update_kuang ,携带参数 msg 为:' + data.msg);
  83. this.mine_code = data.msg
  84. console.log(this.mine_code)
  85. })
  86. this.$forceUpdate()
  87. // 根据矿编码切换首页接口不同的请求基础路径
  88. this.base_url = set_base_url(this.mine_code)
  89. // 获取轮播图
  90. this.get_banner()
  91. // 获取首页新闻列表
  92. this.getNews()
  93. // 值班公告
  94. this.get_notice()
  95. // 固定入口
  96. this.get_list()
  97. this.get_home_link()
  98. },
  99. methods: {
  100. // 获取轮播图
  101. get_banner() {
  102. uni.request({
  103. url: this.base_url + "/scrollImg/list",
  104. method: "GET",
  105. success: (res) => {
  106. this.banners = res.data.data.data
  107. }
  108. })
  109. },
  110. // 请求新闻动态
  111. getNews() {
  112. uni.request({
  113. url: this.base_url + "/article/list",
  114. method: "GET",
  115. data: {
  116. pageSize: 4
  117. },
  118. success: (res) => {
  119. this.newsList = res.data.data.data
  120. }
  121. })
  122. },
  123. // 值班公告
  124. get_notice() {
  125. uni.request({
  126. url: this.base_url + "/notice/list",
  127. method: "GET",
  128. success: (res) => {
  129. if (!res.data.data.content) {
  130. this.text = res.data.data.message
  131. } else {
  132. this.text = res.data.data.content.replace(/<br /g," ").replace(/>/g," ").replace(/\//g," ")
  133. // console.log(this.text)
  134. }
  135. }
  136. })
  137. },
  138. // 固定入口
  139. get_list() {
  140. uni.request({
  141. url: this.base_url + "/homeNav/list",
  142. method: "GET",
  143. success: (res) => {
  144. // this.iconList = res.data.data.data.slice(0, 5)
  145. this.iconList = res.data.data.data
  146. }
  147. })
  148. },
  149. // 首页链接
  150. get_home_link() {
  151. uni.request({
  152. url: this.base_url + "/home/links",
  153. method: "GET",
  154. success: (res) => {
  155. // console.log(res)
  156. this.home_link = res.data.data
  157. }
  158. })
  159. },
  160. }
  161. }
  162. </script>
  163. <style lang="scss">
  164. page {
  165. background-color: #F6FAF6;
  166. }
  167. </style>