123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- //index.js
- //获取应用实例
- // 获取授权登录
- import {
- getOpenidSessionKey
- } from '../../utils/httpUtil';
- // 不用获取授权登录
- import {
- getOpenidNoLogin
- } from '../../utils/httpUtilNoLogin';
- 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 httpRequestApi from '../../utils/APIClient';
- import httputil from '../../utils/httpUtil';
- import {
- GetQueryString
- } from '../../utils/util';
- Page({
- data: {
- tab: [{
- name: '推荐',
- templates: 'recommend',
- },
- {
- name: '关注',
- templates: 'follow',
- },
- {
- name: '资源',
- templates: 'courses',
- },
- {
- name: '我的',
- templates: 'my',
- }
- ],
- winH: 568,
- myIndex: 0,
- 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,
- videoList: [],
- nextMargin: '400rpx' // 视频下边距
- },
- jurisdiction: function () {
- //隐藏弹框
- this.setData({
- hide: !this.data.hide
- })
- //登录页信息
- this.updateData(0)
- },
- //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,
- })
- getOpenidSessionKey((res) => {
- console.log(res)
- myInit(this);
- }, (error) => {
- console.log(error)
- wx.setStorageSync('userSourseType', 'normal')
- this.setData({
- hide: !this.data.hide
- })
- return;
- });
- }
- 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) => {
- console.log('系统', res)
- this.setData({
- winH: res.windowHeight,
- devicePixelRatio: res.pixelRatio
- });
- }
- });
- 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)
- },
- onShow: function () {
- wx.setNavigationBarTitle({
- title: '小学语文朗读配音'
- })
- // this.init();
- getOpenidNoLogin((res) => {
- let winH = this.data.winH * 2;
- // let minusNumber = 860;
- let minusNumber = (winH * 860) / 1206;
- // if(winH < 510){
- // minusNumber = 400;
- // }
- // let nextMargin = parseInt(winH *(1 - (834 / winH)) );
- let nextMargin = parseInt(winH - minusNumber);
- console.log(123, winH)
- console.log(321, nextMargin)
- this.setData({
- nextMargin: nextMargin + 'rpx'
- })
- this.getHotRecommend(this.uid);
- // 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
- });
- },
- /* 两个接口维护同一个数组,手动的结束后添加算法的 */
- // 推荐页信息 获取消息和手动推荐内容
- getHotRecommend: function (uid) {
- httpRequestApi.getHotRecommend(
- uid
- ).success((res) => {
- // 点击切换按钮时 只刷新我的课程和未读消息 官方推荐和热门不加载
- const recommendRes = res.data.data;
- console.log(res)
- recommendRes.hotReader.forEach(item => {
- const temp = {};
- temp.title = item.userRead ? item.userRead.title : '';
- temp.img = item.userRead.iconImg;
- temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
- temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
- temp.classId = item.userRead.id;
- temp.time = formatDate(item.userRead.gmtCreated, 3);
- temp.avatar = item.user ? item.user.avatar : '';
- temp.uid = item.user ? item.user.uid : '';
- temp.url = item.userRead.originVideo;
- // temp.avatar = item.user.avatar;
- temp.nickName = item.user ? item.user.wechatName : '';
- temp.id = item.id;
- // recommendWorks.push(temp);
- // that.data.hotData.hotWorks.push(temp);
- this.data.videoList.push(temp);
- });
- this.setData({
- videoList: this.data.videoList
- })
- this.getHotRecommendSecond(this.uid, 1, 5)
- const hotStr = 'hotData.hotWorks'
- const myCourseStr = 'hotData.myCourse'
- const isMessageNormal = 'hotData.isMessageNormal'
- const unReadMessageContent = 'hotData.unReadMessageContent'
- // that.setData({
- // })
- })
- },
- // 获取热门作品 算法出来的
- getHotRecommendSecond: function (uid, pageNo, pageSize) {
- httpRequestApi.getHotRecommendSecond(uid, pageNo, pageSize).success(res => {
- console.log(res)
- const recommendRes = res.data.data.list;
- if (recommendRes.length === 0) return;
- // const recommendWorks = [];
- recommendRes.forEach(item => {
- const temp = {};
- temp.title = item.userRead.title;
- temp.summary = item.userRead.summary;
- temp.img = item.userRead.iconImg;
- temp.plays = item.userRead.playAmount ? item.userRead.playAmount : 0;
- temp.likes = item.userRead.likeAmount ? item.userRead.likeAmount : 0;
- temp.classId = item.userRead.id;
- temp.time = formatDate(item.userRead.gmtCreated, 3);
- temp.avatar = item.user.avatar;
- temp.profession = item.user.profession;
- temp.uid = item.user.uid;
- temp.url = item.userRead.originVideo;
- // temp.avatar = item.user.avatar;
- temp.nickName = item.user.wechatName;
- // recommendWorks.push(temp);
- this.data.videoList.push(temp);
- });
- this.setData({
- videoList: this.data.videoList
- })
- console.log('dangqian', this.data.videoList)
- })
- },
- // 获取用户信息
- 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);
- },
- 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();
- },
- getUserAuth: function () {
- httpRequestApi.getUserAuth().success(res => {
- console.log(res)
- const str = 'myData.isVIP'
- if (res.data.data) {
- this.setData({
- [str]: true
- })
- } else {
- this.setData({
- [str]: false
- })
- }
- })
- }
- })
|