|
- // pages/FirstPage/index.js
- import {getAnnounce, getOnlive} from '../../api/home.js'
- import {getUserInfo} from '../../utils/getUserInfo.js'
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- announcementList: [], // 公告列表
- // 快捷入口
- entersList: [
- {
- title:'上报问题',
- iconPath: '../../assets/first/upload.png',
- path: '/pages/all/index',
- type: 'tabbar'
- },
- {
- title:'问河长',
- iconPath: '../../assets/first/ask.png',
- path: '/package_first/pages/askAdmin/index',
- type: 'page'
- },
- {
- title:'大好河山',
- iconPath: '../../assets/first/rivers.png',
- path: '/package_first/pages/beautyList/index',
- type: 'page'
- },
- {
- title:'敬请期待',
- iconPath: '../../assets/first/more.png',
- path: '/package_first/pages/more/index',
- type: 'page'
- }
- ],
- infoList: ['name', 'location', 'note'],
- liveNum: 0, // 在线人数
- list: [], // 河道展示
- current: '',
- params: {
- provinceCode: '',
- cityCode: '',
- districtCode: '',
- page: 1,
- limit: 3
- }
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.getTabBar().setData({
- selected: 0
- })
- let positionParams = wx.getStorageSync('positionParams')
- if(Object.keys(positionParams).length) {
- let params = this.data.params
- let data = {}
- data.provinceCode = positionParams.provinceCode || ''
- data.cityCode = positionParams.cityCode || ''
- data.districtCode = positionParams.districtCode || ''
- params = Object.assign(this.data.params, data)
- this.setData({params, current:'/stream/index'})
- this.getAnnouncementList(data)
- } else {
- const path = '/pages/FirstPage/index'
- const fromType = 'tabbar'
- wx.redirectTo({
- url: `/pages/login/login?path=${path}&fromType=${fromType}`,
- })
- }
- },
-
- onShow() {
- this.getOnliveNum()
- },
-
- // 获取公告数据
- async getAnnouncementList(data) {
- const params = {
- page: 1,
- limit: 1,
- ...data
- }
- const res = await getAnnounce(params)
- if(res.code === 0) {
- const announcementList = res.data.records
- this.setData({announcementList})
- }
- },
-
- /* 更新数据 */
- updateList(e) {
- let list = this.data.list.concat(e.detail || [])
- this.setData({ list })
- },
- /* 重置数据 */
- resetList() {
- this.setData({ list: [] })
- },
- // 获取在线人数
- getOnliveNum() {
- let params = {}
- if(wx.getStorageSync('positionParams')) {
- const {provinceCode, cityCode, districtCode} = wx.getStorageSync('positionParams')
- params = {
- provinceCode: provinceCode|| '',
- cityCode: cityCode || '',
- districtCode:districtCode|| ''
- }
- }
- getOnlive(params).then(res=> {
- if(res.code === 0) {
- this.setData({liveNum: res.data})
- }
- })
- },
-
- // 公告详情
- showAnnouncementDetail() {
- wx.navigateTo({
- url:"/package_first/pages/announceList/index"
- })
- },
-
- // 获取点击详情
- getCurrentData(dataKey, e) {
- let index = e.currentTarget.dataset.current;
- return this.data[dataKey][index]
- },
-
- // 进入对应页面
- goPage(e) {
- // 判断是否有权限
- let positionParams = wx.getStorageSync('positionParams')
- let path = e.currentTarget.dataset.path
- let type = e.currentTarget.dataset.type
- if(Object.keys(positionParams).length) {
- if(type === 'tabbar') {
- wx.switchTab({
- url: path,
- })
- } else {
- wx.navigateTo({
- url: path,
- })
- }
- } else {
- wx.redirectTo({
- url: `/pages/login/login?path=${path}&fromType=${type}`,
- })
- }
- },
-
- // 上报问题
- uploadProblem(e) {
- let detail = e.currentTarget.dataset.detail
- let openId = wx.getStorageSync('openId')
- if(openId) {
- wx.navigateTo({
- url: '/package_A/pages/report/index?data=' + JSON.stringify(detail),
- })
- } else {
- getUserInfo().then(res=> {
- wx.navigateTo({
- url: '/package_A/pages/report/index?data=' + JSON.stringify(detail),
- })
- })
- }
- },
-
- /* 跳转至筛选页 */
- goSelectLocation(e) {
- const path = '/pages/FirstPage/index'
- wx.redirectTo({
- url: `/pages/login/login?path=${path}`,
- })
- },
-
- /* 跳转至详情页 */
- showDetail(e) {
- let data = e.currentTarget.dataset.item
- wx.navigateTo({
- url: '/package_A/pages/riverDetail/index?data='+ JSON.stringify(data),
- })
- }
- })
|