拓恒河湖长制全民护河平台WEB端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

index.js 5.6KB

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