拓恒河湖长制全民护河平台WEB端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
5.4KB

  1. // pages/FirstPage/index.js
  2. import {getAnnounce, getOnlive} from '../../api/home.js'
  3. import {getUserInfo} from '../../utils/getUserInfo.js'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. announcementList: [], // 公告列表
  10. // 快捷入口
  11. entersList: [
  12. {
  13. title:'上报问题',
  14. iconPath: '../../assets/first/upload.png',
  15. path: '/pages/all/index',
  16. type: 'tabbar'
  17. },
  18. {
  19. title:'问河长',
  20. iconPath: '../../assets/first/ask.png',
  21. path: '/package_first/pages/askAdmin/index',
  22. type: 'page'
  23. },
  24. {
  25. title:'大好河山',
  26. iconPath: '../../assets/first/rivers.png',
  27. path: '/package_first/pages/beautyList/index',
  28. type: 'page'
  29. },
  30. {
  31. title:'敬请期待',
  32. iconPath: '../../assets/first/more.png',
  33. path: '/package_first/pages/more/index',
  34. type: 'page'
  35. }
  36. ],
  37. infoList: ['name', 'location', 'note'],
  38. liveNum: 0, // 在线人数
  39. list: [], // 河道展示
  40. current: '',
  41. params: {
  42. provinceCode: '',
  43. cityCode: '',
  44. districtCode: '',
  45. page: 1,
  46. limit: 3
  47. }
  48. },
  49. /**
  50. * 生命周期函数--监听页面加载
  51. */
  52. onLoad(options) {
  53. this.getTabBar().setData({
  54. selected: 0
  55. })
  56. let positionParams = wx.getStorageSync('positionParams')
  57. if(Object.keys(positionParams).length) {
  58. let params = this.data.params
  59. let data = {}
  60. data.provinceCode = positionParams.provinceCode || ''
  61. data.cityCode = positionParams.cityCode || ''
  62. data.districtCode = positionParams.districtCode || ''
  63. params = Object.assign(this.data.params, data)
  64. this.setData({params, current:'/stream/index'})
  65. this.getAnnouncementList(data)
  66. } else {
  67. const path = '/pages/FirstPage/index'
  68. const fromType = 'tabbar'
  69. wx.redirectTo({
  70. url: `/pages/login/login?path=${path}&fromType=${fromType}`,
  71. })
  72. }
  73. },
  74. onShow() {
  75. this.getOnliveNum()
  76. },
  77. // 获取公告数据
  78. async getAnnouncementList(data) {
  79. const params = {
  80. page: 1,
  81. limit: 1,
  82. ...data
  83. }
  84. const res = await getAnnounce(params)
  85. if(res.code === 0) {
  86. const announcementList = res.data.records
  87. this.setData({announcementList})
  88. }
  89. },
  90. /* 更新数据 */
  91. updateList(e) {
  92. let list = this.data.list.concat(e.detail || [])
  93. this.setData({ list })
  94. },
  95. /* 重置数据 */
  96. resetList() {
  97. this.setData({ list: [] })
  98. },
  99. // 获取在线人数
  100. getOnliveNum() {
  101. let params = {}
  102. if(wx.getStorageSync('positionParams')) {
  103. const {provinceCode, cityCode, districtCode} = wx.getStorageSync('positionParams')
  104. params = {
  105. provinceCode: provinceCode|| '',
  106. cityCode: cityCode || '',
  107. districtCode:districtCode|| ''
  108. }
  109. }
  110. getOnlive(params).then(res=> {
  111. if(res.code === 0) {
  112. this.setData({liveNum: res.data})
  113. }
  114. })
  115. },
  116. // 公告详情
  117. showAnnouncementDetail() {
  118. wx.navigateTo({
  119. url:"/package_first/pages/announceList/index"
  120. })
  121. },
  122. // 获取点击详情
  123. getCurrentData(dataKey, e) {
  124. let index = e.currentTarget.dataset.current;
  125. return this.data[dataKey][index]
  126. },
  127. // 进入对应页面
  128. goPage(e) {
  129. // 判断是否有权限
  130. let positionParams = wx.getStorageSync('positionParams')
  131. let path = e.currentTarget.dataset.path
  132. let type = e.currentTarget.dataset.type
  133. if(Object.keys(positionParams).length) {
  134. if(type === 'tabbar') {
  135. wx.switchTab({
  136. url: path,
  137. })
  138. } else {
  139. wx.navigateTo({
  140. url: path,
  141. })
  142. }
  143. } else {
  144. wx.redirectTo({
  145. url: `/pages/login/login?path=${path}&fromType=${type}`,
  146. })
  147. }
  148. },
  149. // 上报问题
  150. uploadProblem(e) {
  151. let detail = e.currentTarget.dataset.detail
  152. let openId = wx.getStorageSync('openId')
  153. if(openId) {
  154. wx.navigateTo({
  155. url: '/package_A/pages/report/index?data=' + JSON.stringify(detail),
  156. })
  157. } else {
  158. getUserInfo().then(res=> {
  159. wx.navigateTo({
  160. url: '/package_A/pages/report/index?data=' + JSON.stringify(detail),
  161. })
  162. })
  163. }
  164. },
  165. /* 跳转至筛选页 */
  166. goSelectLocation(e) {
  167. const path = '/pages/FirstPage/index'
  168. wx.redirectTo({
  169. url: `/pages/login/login?path=${path}`,
  170. })
  171. },
  172. /* 跳转至详情页 */
  173. showDetail(e) {
  174. let data = e.currentTarget.dataset.item
  175. wx.navigateTo({
  176. url: '/package_A/pages/riverDetail/index?data='+ JSON.stringify(data),
  177. })
  178. }
  179. })