//index.js //获取应用实例 import { getOpenidSessionKey } from '../../utils/httpUtil'; import { formatDate } from '../../utils/util'; const app = getApp() import { hotInit } from '../../component/hot/hot'; import { groupInit } from '../../component/group/group'; import { myInit } from '../../component/my/my'; // import { // followInit // } from '../../component/follow/follow'; // import '../../utils/hls'; import httpRequestApi from '../../utils/APIClient'; import httputil from '../../utils/httpUtil'; import { GetQueryString } from '../../utils/util'; Page({ data: { tab: [{ name: '我的', templates: 'my', }, { name: '发现', templates: 'hot', }, // { // name: '热团', // templates: 'group', // }, // { // name: '动态', // templates: 'follow', // }, ], winH: 568, myIndex: 1, followData: [], recommendPageNo: 0, recommendTotalNo: 1, followPageNo: 1, followPageTotalNo: 1, myData: {}, templates: 'hot', title: 'index中的title', jurisdictionFlag: true, hotInput: '12345', mineSettingInfo: '528', hide: true, isIOS: app.globalData.isIOS, ifHaveMore: true, indexSignDialog: false, indexMissionDialog: false, unfinishedCount: 0 }, jurisdiction: function() { //隐藏弹框 this.setData({ hide: !this.data.hide }) //登录页信息 this.onShow(); }, //tab点击 switcher: function({ currentTarget }) { if (currentTarget.dataset.index === this.data.myIndex) return; this.updateData(currentTarget.dataset.index); }, // 根据index 更新template updateData: function(index) { let myIndex = index; let templates = this.data.tab[myIndex].templates; this.setData({ myIndex, templates }); if (myIndex == 0) { // groupInit(this); this.setData({ followPageNo: 1, }) myInit(this); } if (myIndex == 1) { // this.setData({ // recommendPageNo: 0 // }) hotInit(this); } if (myIndex == 2) { groupInit(this); } }, onLoad: function(options) { this.uid = wx.getStorageSync('uid'); wx.getSystemInfo({ success: (res) => { this.setData({ winH: res.windowHeight }); } }); if (options.index) { this.updateData(options.index) } setTimeout(() => { if (wx.getStorageSync('uid')) { httpRequestApi.userLoginRecord().success(res => { if (res.data.data && res.data.data.length !== 0) { // 有数据弹签到 if (this.data.unfinishedCount > 0) { this.setData({ indexSignDialog: true }) } } else { // 没数据弹任务 let oldDay = wx.getStorageSync('oldDay'); let newDate = new Date(); let day = newDate.getDate() < 10 ? '0' + newDate.getDate() : newDate.getDate() let timeStep = (newDate.getMonth() + 1).toString() + day if (oldDay) { let temp = parseInt(timeStep) - parseInt(oldDay) if (temp > 0) { wx.setStorageSync('oldDay', timeStep); this.setData({ indexMissionDialog: true }) } } else { wx.setStorageSync('oldDay', timeStep); this.setData({ indexMissionDialog: true }) } } }) } }, 2800) // hotInit(this) // this.init(); }, onShow: function() { wx.setNavigationBarTitle({ title: '小学课文朗读配音' }) // this.init(); getOpenidSessionKey((res) => { hotInit(this) }, (error) => { // console.log(error) wx.setStorageSync('userSourseType', 'normal') this.setData({ hide: !this.data.hide }) return; }); if (this.data.myIndex === 0) { // 从修改信息页面退回 this.getUserWorksInfo(true); } }, onHide: function() { const str = 'hotData.inputFocus' this.setData({ [str]: false }); }, //初始化数据 // init: function () { // httputil.getOpenidSessionKey((res) => { // console.log('微信的用户信息', res) // }, (error) => { // console.log(1111111111111111) // // this.jurisdiction() // wx.navigateTo({ // url: '../../loginPage/loginPage' // }) // }); // }, // 获取用户信息 getUserWorksInfo: function(flag) { console.log(flag) if (flag) { httpRequestApi.getUserWorksInfo().success(res => { const str = 'myData.user.user.nickName'; const avatarStr = 'myData.user.user.avatar'; this.setData({ [str]: res.data.data.user.nickName, [avatarStr]: res.data.data.user.avatar }) }) return; } const userLocal = wx.getStorageSync('user') console.log(userLocal) const str = 'myData.user'; this.setData({ [str]: userLocal }) httpRequestApi.getUserWorksInfo().success(res => { this.data.myData.user = res.data.data; httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {}) if (this.data.myData.user.myRead) { this.data.myData.user.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4) } this.setData({ myData: this.data.myData, }); }).fail(error => { console.log(error) }) }, // 触底加载 onReachBottom: function() { console.log(this.data.myIndex) if (this.data.myIndex === 0) { this.setData({ followPageNo: this.data.followPageNo + 1 }) if (this.data.followPageNo <= this.data.followPageTotalNo) { this.getFollowWorks(this.data.followPageNo, 3); } else { console.log('没有更多') this.setData({ ifHaveMore: false }) } } // 当前在推荐页面 加载推荐 if (this.data.myIndex === 1) { console.log(this.data.recommendPageNo) console.log(this.data.recommendTotalNo) this.setData({ recommendPageNo: this.data.recommendPageNo + 1 }) if (this.data.recommendPageNo <= this.data.recommendTotalNo) { this.getHotRecommendSecond(this.uid, this.data.recommendPageNo, 3); } else { console.log('没有更多') } } }, onPullDownRefresh: function() { //当前在团购页下拉加载 if (this.data.myIndex === 0) { // groupInit(this); } wx.showNavigationBarLoading() //在标题栏中显示加载 //模拟加载 setTimeout(function() { wx.hideNavigationBarLoading() //完成停止加载 wx.stopPullDownRefresh() //停止下拉刷新 }, 1500); }, // 获取全部课本 // getBookList: function () { // httpRequestApi.getAllBooks(1, 10).success((res) => { // this.data.bookList = res.data.data.list; // res.data.data.list.forEach(element => { // this.data.selectFlag.push(true); // }); // this.setData({ // bookList: this.data.bookList // }) // }).fail((error) => { // console.log('错误', error) // }) // }, goToMessage: function() { wx.navigateTo({ url: `../../pages/social/insideMessage/insideMessage` }); const str = 'hotData.unReadMessageNum'; this.setData({ [str]: 0 }) }, toMyCollage: function(e) { if (app.globalData.isIOS) { wx.navigateTo({ url: `../../pages/groupPage/my-group/my-group?title=我的助力` }); } else { wx.navigateTo({ url: `../../pages/groupPage/my-group/my-group?title=我的拼团` }); } }, toMyCourse: function() { wx.navigateTo({ url: `../../pages/user/mycourse/mycourse?title=我的课程` }); }, goToFlower: function() { wx.navigateTo({ url: `../../pages/social/littleFlower/littleFlower` }); }, signInBtn: function(e) { this.setData({ indexSignDialog: false }) console.log(e.detail.formId) httpRequestApi.postFormId(e.detail.formId).success(res => { console.log(res) }) this.goToFlower(); }, missionBtn: function() { this.setData({ indexMissionDialog: false }) this.goToFlower(); } })