拓恒河湖长制全民护河平台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.

205 lines
5.9KB

  1. // pages/FirstPage/index.js
  2. import {getOnlive} from '../../api/home.js'
  3. import {getOpenidData} from '../../utils/getUserInfo.js'
  4. import { env } from '../../environment.js'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. areaName: '', // 当前区域位置
  11. announcementList: [], // 公告列表
  12. // 快捷入口
  13. entersList: [
  14. {
  15. title:'护河行动',
  16. iconPath: '../../assets/first/new.png',
  17. path: '/package_first/pages/announceList/index',
  18. type: 'page'
  19. },
  20. {
  21. title:'热点资讯',
  22. iconPath: '../../assets/first/ask.png',
  23. path: '/package_first/pages/askAdmin/index',
  24. type: 'page'
  25. },
  26. {
  27. title:'大好河山',
  28. iconPath: '../../assets/first/rivers.png',
  29. path: '/package_first/pages/beautyList/index',
  30. type: 'page'
  31. },
  32. {
  33. title:'积分商城',
  34. iconPath: '../../assets/first/stores.png',
  35. path: '/package_A/pages/stores/index',
  36. type: 'mini'
  37. },
  38. {
  39. title:'护河活动',
  40. iconPath: '../../assets/first/activity.png',
  41. path: '/package_first/pages/ProtectionActivity/index',
  42. type: 'page'
  43. },
  44. {
  45. title:'护河建议',
  46. iconPath: '../../assets/first/suggestion.png',
  47. path: '/package_first/pages/ProtectionSuggestion/index',
  48. type: 'page'
  49. },
  50. ],
  51. liveNum: 0, // 在线人数
  52. list: [], // 河道展示
  53. current: '',
  54. params: {
  55. page: 1,
  56. limit: 3
  57. }
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad(options) {
  63. this.getTabBar().setData({
  64. selected: 0
  65. })
  66. let tenant = wx.getStorageSync('tenant')
  67. if(!Object.keys(tenant).length) {
  68. const path = '/pages/FirstPage/index'
  69. const fromType = 'tabbar'
  70. wx.redirectTo({
  71. url: `/pages/login/login?path=${path}&fromType=${fromType}`,
  72. })
  73. } else {
  74. this.setData({current: '/stream/index',})
  75. }
  76. },
  77. onShow() {
  78. let tenant = wx.getStorageSync('tenant')
  79. if(Object.keys(tenant).length) {
  80. this.getOnliveNum()
  81. }
  82. let areaName = wx.getStorageSync('positionParams').areaName
  83. this.setData({areaName})
  84. },
  85. /* 更新数据 */
  86. updateList(e) {
  87. let list = this.data.list.concat(e.detail || [])
  88. this.setData({ list })
  89. },
  90. /* 重置数据 */
  91. resetList() {
  92. this.setData({ list: [] })
  93. },
  94. // 获取在线人数
  95. getOnliveNum() {
  96. getOnlive().then(res=> {
  97. if(res.code === 0) {
  98. this.setData({liveNum: res.data})
  99. }
  100. })
  101. },
  102. // 公告详情
  103. showAnnouncementDetail() {
  104. wx.navigateTo({
  105. url:"/package_first/pages/announceList/index"
  106. })
  107. },
  108. // 获取点击详情
  109. getCurrentData(dataKey, e) {
  110. let index = e.currentTarget.dataset.current;
  111. return this.data[dataKey][index]
  112. },
  113. // 进入对应页面
  114. goPage(e) {
  115. let title = e.currentTarget.dataset.title
  116. if(title !== '敬请期待') {
  117. // 判断是否有权限
  118. let tenant = wx.getStorageSync('tenant')
  119. let path = e.currentTarget.dataset.path
  120. let type = e.currentTarget.dataset.type
  121. if(Object.keys(tenant).length) {
  122. if(type === 'tabbar') {
  123. wx.switchTab({
  124. url: path,
  125. })
  126. } else if(type === 'mini'){
  127. const { tenantCode, tenantId } = wx.getStorageSync('tenant')
  128. if(tenantId === 5){
  129. wx.navigateToMiniProgram({
  130. appId: 'wx57d8902569fbf5e1',
  131. path: `pages/index/index?tenantCode=${tenantCode}`,
  132. extraData: {
  133. tenantCode
  134. },
  135. envVersion: env,
  136. success(res) {
  137. }
  138. })
  139. }else{
  140. wx.navigateTo({
  141. url: path,
  142. })
  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. // 查看更多
  157. showMoreRivers() {
  158. wx.switchTab({
  159. url: '/pages/all/index',
  160. })
  161. },
  162. // 上报问题
  163. uploadProblem(e) {
  164. let detail = e.currentTarget.dataset.detail
  165. let openid = wx.getStorageSync('openid')
  166. if(openid) {
  167. wx.navigateTo({
  168. url: '/package_A/pages/report/index?data=' + JSON.stringify(detail),
  169. })
  170. } else {
  171. getOpenidData().then(res=> {
  172. wx.navigateTo({
  173. url: '/package_A/pages/report/index?data=' + JSON.stringify(detail),
  174. })
  175. })
  176. }
  177. },
  178. /* 跳转至筛选页 */
  179. goSelectLocation(e) {
  180. const path = '/pages/FirstPage/index'
  181. wx.redirectTo({
  182. url: `/pages/login/login?path=${path}`,
  183. })
  184. },
  185. /* 跳转至详情页 */
  186. showDetail(e) {
  187. let data = e.currentTarget.dataset.item
  188. wx.navigateTo({
  189. url: '/package_A/pages/riverDetail/index?data='+ JSON.stringify(data),
  190. })
  191. }
  192. })