index.vue 3.2 KB

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