12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397 |
- //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',
- }
- ],
- winH: 568,
- statusBarHeight: getApp().globalData.statusBarHeight,
- myIndex: 0,
- followData: [],
- recommendPageNo: 1,
- recommendPageSize: 3,
- recommendTotalNo: 1,
- myData: {},
- templates: '',
- title: 'index中的title',
- jurisdictionFlag: true,
- hotInput: '12345',
- mineSettingInfo: '528',
- hide: true,
- ifHaveMore: true,
- indexSignDialog: false,
- indexMissionDialog: false,
- unfinishedCount: 0,
- videoList: [],
- nextMargin: '400rpx', // 视频下边距
- commentShow: false,
- commentList: [],
- commentNum: 0,
- followPageNo: 1,
- followPageSize: 3,
- coursePageNo: 1,
- coursesData: [],
- updateId: 0, // 刷新id
- statusbarobj: {
- isshowbtn: true, //是否显示按钮
- title: "小学语文朗读配音", //标题
- },
- grade: wx.getStorageSync('grade'),
- noMoreWork: false, // 没有更多作品 已经到底了
- upgradeHide: true,
- gradeActivity: '',
- helpPayHide: true,
- tipsType: '',
- helpPayImg: '',
- tipsImg: '',
- payPrice: '',
- iphoneType: '',
- isVip: null,
- isIos: null,
- temporaryGrade: null
- },
- jurisdiction: function() {
- //隐藏弹框
- this.setData({
- hide: !this.data.hide
- })
- //登录页信息
- this.updateData(0)
- },
- // 隐藏升级弹窗
- hideUpgrade() {
- this.setData({
- upgradeHide: true
- })
- },
- jumpMy() {
- wx.redirectTo({
- url: '/pages/my/index'
- });
- },
- //tab点击
- switcher: function({
- currentTarget
- }) {
- if (currentTarget.dataset.index === this.data.myIndex) return;
- this.updateData(currentTarget.dataset.index);
- },
- // 根据index 更新template
- updateData: function(index) {
- let myIndex = parseInt(index);
- this.setData({
- myIndex,
- noMoreWork: false
- });
- // 获取推荐列表
- if (myIndex == 0) {
- this.setData({
- recommendPageNo: 1,
- videoList: [],
- isSwiper: false
- }, () => {
- // 转为异步
- setTimeout(() => {
- this.getHotRecommend(this.uid);
- }, 0)
- })
- return;
- }
- /* 关注和我的需要登陆后查看 */
- if (!this.data.isLogin) {
- wx.navigateTo({
- url: `../../pages/login/login?index=${myIndex}`
- });
- return;
- }
- // 刷新关注列表
- if (myIndex == 1) {
- this.setData({
- videoList: [],
- isSwiper: false,
- followPageNo: 1
- }, () => {
- this.getFollowData()
- })
- return;
- }
- // 刷新资源
- if (myIndex == 2) {
- this.setData({
- videoList: [],
- coursesData: [],
- templates: 'courses',
- coursePageNo: 1
- }, () => {
- this.getCoursesList();
- })
- return;
- }
- // 刷新我的
- /* if (myIndex == 3) {
- this.setData({
- videoList: [],
- templates: 'my',
- isSwiper: false
- }, () => {
- myInit(this);
- httpRequestApi.userEvent('MY');
- })
- return;
- } */
- },
- showPage: function() {
- let options = this.data.options;
- if (this.data.workId) {
- // 需要在推荐第一个上插入一条分享或者刚朗读完数据
- let id = this.data.workId;
- this.setData({
- workId: null,
- myIndex: 0,
- videoList: [],
- isSwiper: false,
- recommendTotalNo: 1
- })
- httpRequestApi.getClassDetail(id).success(res => {
- let tempList = [];
- tempList.push(res.data.data);
- this.setData({
- videoList: [],
- isSwiper: false,
- recommendTotalNo: 1
- }, () => {
- this.formatWorksList(tempList, true);
- this.getHotRecommend(this.uid);
- })
- })
- } else {
- console.log('没有分享')
- if (options && options.index) {
- this.updateData(options.index)
- } else {
- console.log('又加载一边')
- this.updateData(0)
- }
- }
- 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)
- },
- onLoad: function(options) {
- if (wx.getStorageSync('uid')) {
- this.setData({
- isLogin: true
- })
- }
- //网络原因,还没有拿到登陆数据,这里调用全局的callback
- getApp().callBack = (res) => {
- /**获取权限和订单信息 */
- // 获取商品信息
- httpRequestApi.getProductActivity().success(res => {
- wx.setStorageSync('price', res.data.data.price / 100)
- wx.setStorageSync('productId', res.data.data.id)
- if (options.type && options.type === 'iphone') {
- this.setData({
- payPrice: res.data.data.price / 100
- })
- }
- }).fail(error => {
- console.log(error)
- })
- // 获取用户权限
- this.getHelpAuth()
- if (!res.data.data.grade) {
- this.setData({
- isGradeShow: true,
- options,
- isLogin: true,
- workId: options.scene ? options.scene : options.readId ? options.readId : undefined
- })
- return
- } else {
- this.setData({
- isLogin: true
- }, () => {
- this.showPage();
- })
- }
- // 获取商品信息
- httpRequestApi.getProductActivity().success(res => {
- wx.setStorageSync('price', res.data.data.price / 100)
- wx.setStorageSync('productId', res.data.data.id)
- if (options.type && options.type === 'iphone') {
- this.setData({
- payPrice: res.data.data.price / 100
- })
- }
- }).fail(error => {
- console.log(error)
- })
- // 获取用户权限
- this.getHelpAuth()
- }
- this.setData({
- isIos: app.globalData.isIOS
- })
- if (options.scene) {
- let optionsStr = decodeURIComponent(options.scene);
- let optionsArr = optionsStr.split('&');
- // 暂时这样写
- if (optionsArr[0].split("=")[0] === "type") {
- console.log('我是团购分享')
- options.type = optionsArr[0].split("=")[1];
- options.sid = optionsArr[1].split("=")[1];
- } else {
- options.readId = optionsArr[0];
- options.activity = optionsArr[1];
- }
- }
- if (options.readId) {
- this.setData({
- workId: options.readId
- })
- }
- /**
- * 活动统计
- */
- if (options.activity) {
- httpRequestApi.shareAddHotAmount(options.readId).success(res => {
- console.log(res)
- })
- }
- /**团购弹窗时间紧逻辑越写越乱功能越加越多 */
- this.setData({
- iphoneType: options.type || ''
- })
- console.log('onload', options);
- if (options.tabbarIndx) {
- this.updateData(options.tabbarIndx);
- }
- this.uid = wx.getStorageSync('uid');
- if (options.sid) {
- httpRequestApi.getUserRec(options.sid).success(res => {
- options.uid = res.data.data;
- this.shareGetPage(options)
- })
- } else {
- this.shareGetPage(options)
- }
- wx.getSystemInfo({
- success: (res) => {
- let ratio = (res.screenHeight / res.screenWidth) * 1.1;
- let winH = res.windowHeight * ratio;
- let x1 = 465 * ratio;
- let x2 = 603 * ratio;
- let minusNumber = (winH * x1) / x2;
- let nextMargin = parseInt(winH - minusNumber);
- app.globalData.nextMargin = nextMargin;
- this.setData({
- winH: winH,
- devicePixelRatio: res.pixelRatio,
- nextMargin: nextMargin + 'rpx'
- });
- }
- });
- },
- // 封装分享方法之后跳到页面方法
- shareGetPage(options) {
- console.log(this.uid, options.uid, this.uid !== options.uid)
- if (options.type && options.type === 'iphone' && !app.globalData.isIOS && this.uid !== options.uid) {
- this.setData({
- helpPayHide: false,
- tipsType: 'helpPay',
- helpPayImg: 'http://reader-wx.ai160.com/images/reader/pay/buy.png',
- })
- }
- if (options.type && options.type === 'ios' && this.uid !== options.uid) {
- this.setData({
- helpPayHide: false,
- tipsType: 'helpPay',
- helpPayImg: 'http://reader-wx.ai160.com/images/reader/pay/help.png',
- })
- console.log(options.uid)
- }
- const recOsType = options.type === 'iphone' ? 'ANDROID' : (options.type === 'ios' && 'IOS');
- if (options.type && options.uid) {
- httpRequestApi.settingUserInfo({
- rec_uid: options.uid,
- recOsType,
- }).success(res => {
- console.log(res)
- })
- }
- },
- onShow: function() {
- let grade = wx.getStorageSync('grade');
- this.setData({
- gradeActivity: grade
- })
- if (this.data.myIndex === 3) {
- this.getUserWorksInfo(1)
- this.getHelpAuth()
- }
- wx.setNavigationBarTitle({
- title: '小学语文朗读配音'
- })
- console.log('页面返回页面返回', this.data.fromLoginIndex)
- if (this.data.fromLoginIndex || this.data.fromLoginIndex == 0) {
- console.log('页面返回页面返回', this.data.fromLoginIndex)
- let index = this.data.fromLoginIndex;
- let userInfo = wx.getStorageSync('user');
- this.setData({
- fromLoginIndex: null,
- isLogin: userInfo.nickName ? true : false
- }, () => {
- this.updateData(index)
- })
- }
- if (this.data.fromReading) {
- this.setData({
- fromReading: false
- })
- this.updateData('0')
- }
- // 刷新课程资源的收藏数等
- if (this.data.myIndex === 2) {
- this.refreshCourseAmount()
- }
- this.setData({
- shareImg: '',
- shareId: ''
- })
- },
- onHide: function() {
- const str = 'hotData.inputFocus'
- this.setData({
- [str]: false
- });
- },
- /* 两个接口维护同一个数组,手动的结束后添加算法的 */
- // 推荐页信息 获取消息和手动推荐内容
- // 获取热门作品 算法出来的
- getHotRecommend: function() {
- let grade = wx.getStorageSync('grade')
- let pageNo = this.data.recommendPageNo;
- let pageSize = this.data.recommendPageSize;
- httpRequestApi.getHotRecommendSecond(grade, pageNo, pageSize).success(res => {
- console.log(res)
- const recommendRes = res.data.data.list;
- if (recommendRes.length <= 0) {
- this.setData({
- noMoreWork: true
- })
- return
- };
- // const recommendWorks = [];
- this.formatWorksList(recommendRes);
- });
- httpRequestApi.userEvent('RECOMMEND');
- },
- // 组装list
- formatWorksList(list, notSet) {
- // const tempList = [];
- console.log('列表长度列表长度', list.length)
- if (list.length < 3 || list.length === 0) {
- this.setData({
- noMoreWork: true
- })
- }
- list.forEach((item, index) => {
- /* if (index === list.length - 2 && list.length > 2) {
- console.log('设置当前id', item.id)
- this.setData({
- updateId: item.userRead.id
- })
- } */
- console.log(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.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
- temp.shareAmount = item.userRead.shareAmount;
- temp.favoritesAmount = item.userRead.favoritesAmount;
- temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
- temp.time = formatDate(item.userRead.gmtCreated, 3);
- temp.avatar = item.user.avatar;
- temp.profession = item.user.profession;
- temp.uid = item.user.uid;
- temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
- temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
- temp.id = item.userRead.id;
- temp.type = item.userRead.type;
- temp.nickName = item.user.nickName || item.user.eid;
- temp.isLike = item.isLike;
- temp.isFans = item.isFans ? true : item.user.uid === this.uid ? true : false;
- temp.isFavorite = item.isFavorites;
- temp.isEfun = item.user.profession === '官方' ? true : false;
- temp.hasTag = item.userRead.tag && item.userRead.tag !== 'EXAMPLE' ? true : false;
- temp.tagUrl = item.userRead.tag ? item.userRead.tag === 'HOT' ? '../../static/index/hot_tag.png' : '../../static/index/new_tag.png' : ''
- temp.status = item.userRead.status;
- temp.coverImg = item.userRead.coverImg;
- temp.shareImg = item.userRead.shareImg;
- temp.grade = item.userRead.grade;
- temp.videoShow = false;
- item.isActivity && (temp.activity = true);
- this.data.videoList.push(temp);
- // tempList.push(temp);
- });
- console.log('当前list', this.data.videoList)
- // if (!notSet) {
- this.setData({
- videoList: this.data.videoList
- })
- // }
- },
- // 获取用户信息
- getUserWorksInfo: function(flag) {
- if (flag) {
- httpRequestApi.getUserWorksInfo().success(res => {
- const userInfo = this.formatGrade(res.data.data.user);
- const str = 'myData.userInfo.nickName';
- const avatarStr = 'myData.userInfo.avatar';
- const gradeTextStr = 'myData.userInfo.gradeText';
- this.setData({
- [str]: userInfo.nickName,
- [avatarStr]: userInfo.avatar,
- [gradeTextStr]: userInfo.gradeText
- })
- })
- return;
- }
- httpRequestApi.getUserWorksInfo().success(res => {
- this.data.myData.user = res.data.data;
- httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {})
- if (res.data.data.myRead) {
- res.data.data.myRead.gmtCreated = formatDate(this.data.myData.user.myRead.gmtCreated, 4)
- }
- res.data.data.user = this.formatGrade(res.data.data.user);
- this.setData({
- // myData: res.data.data,
- ['myData.user']: res.data.data,
- ['myData.userInfo']: res.data.data.user,
- ['myData.isIOS']: app.globalData.isIOS
- }, () => {
- this.getMyRead()
- });
- }).fail(error => {
- console.log(error)
- })
- },
- formatGrade(userInfo) {
- switch (userInfo.grade) {
- case 'PRESCHOOL':
- userInfo.gradeText = '学前班'
- break;
- case 'PRIMARY_FIRST_GRADE':
- userInfo.gradeText = '一年级'
- break;
- case 'PRIMARY_SECOND_GRADE':
- userInfo.gradeText = '二年级'
- break;
- case 'PRIMARY_THREE_GRADE':
- userInfo.gradeText = '三年级'
- break;
- case 'PRIMARY_SENIOR_GRADE':
- userInfo.gradeText = '四年级';
- break;
- }
- return userInfo;
- },
- videoChange: function(e) {
- if (e.detail.activeId === this.data.updateId) {
- console.log('应该刷新')
- if (this.data.myIndex === 1) {
- this.setData({
- followPageNo: this.data.followPageNo + 1
- }, () => {
- this.getFollowData()
- })
- }
- if (this.data.myIndex === 0) {
- console.log('首页加载第二页')
- this.setData({
- recommendPageNo: this.data.recommendPageNo + 1
- }, () => {
- this.getHotRecommend()
- })
- }
- }
- },
- // 触底加载
- onReachBottom: function() {
- if (this.data.myIndex === 2) {
- this.setData({
- coursePageNo: this.data.coursePageNo + 1
- }, () => {
- this.getCoursesList()
- })
- }
- if (this.data.myIndex === 1) {
- this.setData({
- followPageNo: this.data.followPageNo + 1
- }, () => {
- this.getFollowData()
- })
- }
- if (this.data.myIndex === 0) {
- console.log('首页加载第二页')
- this.setData({
- recommendPageNo: this.data.recommendPageNo + 1
- }, () => {
- this.getHotRecommend()
- })
- }
- },
- onPullDownRefresh: function() {
- //当前在团购页下拉加载
- this.updateData(this.data.myIndex)
- wx.showNavigationBarLoading() //在标题栏中显示加载
- //模拟加载
- setTimeout(function() {
- wx.hideNavigationBarLoading() //完成停止加载
- wx.stopPullDownRefresh() //停止下拉刷新
- }, 1000);
- },
- goToMessage: function() {
- wx.navigateTo({
- url: `../../pages/social/insideMessage/insideMessage`
- });
- const str = 'hotData.unReadMessageNum';
- httpRequestApi.userEvent('MESSAGE');
- this.setData({
- [str]: 0
- })
- },
- goToService: function() {
- httpRequestApi.userEvent('SERVICE');
- },
- 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`
- });
- httpRequestApi.userEvent('INTEGRAL');
- },
- 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
- })
- }
- })
- },
- delHideMyWork: function() {
- this.getMyRead()
- },
- // 获取我的朗读
- getMyRead: function() {
- httpRequestApi.myRead().success(res => {
- console.log(123123, res)
- console.log('mydata', this.data.myData)
- const myList = res.data.data;
- if (myList.length === 0) {
- this.setData({
- videoList: []
- })
- return
- }
- // this.formatWorksList(myList)
- // const recommendWorks = [];
- const myWorks = [];
- myList.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.commentAmount = item.userRead.commentAmount ? item.userRead.commentAmount : 0;
- temp.shareAmount = item.userRead.shareAmount;
- temp.favoritesAmount = item.userRead.favoritesAmount;
- temp.classId = item.userRead.exampleId ? item.userRead.exampleId : 1605097720036046;
- temp.time = formatDate(item.userRead.gmtCreated, 3);
- temp.avatar = item.user.avatar;
- temp.profession = item.user.profession;
- temp.uid = item.user.uid;
- temp.markPath = item.userRead.markPath ? item.userRead.markPath : item.userRead.videoPath;
- temp.url = item.userRead.videoPath ? item.userRead.videoPath : item.userRead.originVideo;
- temp.id = item.userRead.id;
- temp.type = item.userRead.type;
- temp.nickName = item.user.nickName;
- temp.isLike = item.isLike;
- temp.isFavorite = item.isFavorites;
- temp.showMyBtn = true;
- temp.nickName = this.data.myData.userInfo.nickName;
- temp.status = item.userRead.status;
- temp.ifCheck = item.userRead.status === 'CHECK' ? true : false;
- temp.coverImg = item.userRead.coverImg;
- temp.grade = item.userRead.grade
- temp.isFans = true;
- temp.videoShow = false;
- temp.shareImg = item.userRead.shareImg;
- item.isActivity && (temp.activity = true);
- myWorks.push(temp);
- });
- if (this.data.myIndex === 3) {
- this.setData({
- videoList: myWorks,
- noMoreWork: true
- })
- }
- })
- },
- // 评论区点击
- commentTap: function(e) {
- console.log('点击评论区', e)
- if (e.target.dataset.type === 'blank') {
- if (this.data.commentShow && this.data.commentId) {
- httpRequestApi.getClassDetail(this.data.commentId).success(res => {
- let str = `videoList[${this.data.commentIndex}].commentAmount`;
- this.setData({
- [str]: res.data.data.userRead.commentAmount
- })
- })
- }
- this.setData({
- commentShow: false
- })
- }
- },
- touchMove: function(e) {
- return
- },
- // 打开评论
- openComment: function(e) {
- //
- console.log('id', e.detail.activeId)
- console.log('id', e)
- this.setData({
- commentShow: !this.data.commentShow,
- commentId: e.detail.activeId,
- commentIndex: e.detail.activeIndex
- // commentList: []
- });
- // this.getReply(e.detail.activeId);
- },
- // 获取评论信息
- getReply: function(columnId) {
- debugger
- // let columnId = this.data.id;
- console.log(123123123, columnId)
- // let pageNo = this.data.pageNo;
- // let pageSize = this.data.pageSize;
- httpRequestApi.getReply(this.uid, columnId, 1, 10).success((res) => {
- console.log('reply', res)
- const commentList = res.data.data.list;
- const commentNum = res.data.data.totalSize;
- console.log('评论数量', commentNum)
- commentList.forEach((item) => {
- const temp = {};
- temp.nickName = item.user.nickName;
- temp.avatar = item.user.avatar;
- temp.uid = item.user.uid;
- temp.text = item.detailDesc;
- temp.id = item.id;
- temp.replyCount = item.replyCount;
- temp.time = formatDate(item.gmtCreated, 3);
- temp.likes = item.postsAttributeInfo.favors || 0;
- temp.isLike = item.isLike;
- temp.replyList = item.replyVOList;
- this.data.commentList.push(temp);
- });
- this.setData({
- commentList: this.data.commentList,
- commentNum: commentNum
- })
- });
- },
- // 发布回复
- sendReply: function(e) {
- console.log('triger', e.detail.content);
- let data = {
- columnId: this.data.commentId,
- colunmNames: 'what',
- detailDesc: e.detail.content,
- // productId: this.data.productId
- }
- httpRequestApi.postReply(this.uid, data).success(res => {
- console.log(res)
- this.setData({
- pageNo: 1,
- commentList: []
- }, () => {
- this.getReply(this.data.commentId);
- })
- });
- },
- gradeTap: function() {
- // console.log("组件回调,返回上一页");
- this.setData({
- isGradeShow: true
- })
- },
- onShareAppMessage: function(res) {
- if (res.from === 'button') {
- return {
- title: '请欣赏我的课文朗读作品,点赞+评论。',
- path: `/pages/index/index?readId=${this.data.shareId}&activity=${this.data.ifTapActivity}&uid=${wx.getStorageSync('uid')}`,
- imageUrl: this.data.shareImg
- }
- } else {
- return {
- title: '课文朗读,从未如此有趣。',
- path: '/pages/index/index',
- }
- }
- },
- openShare: function(e) {
- console.log('点击分享', e)
- /* this.setData({
- shareTitle: e.detail.currentTarget.dataset.title,
- shareId: e.detail.currentTarget.dataset.id,
- shareImg: e.detail.currentTarget.dataset.shareimg,
- goToShare: true,
- ifTapActivity: e.detail.currentTarget.dataset.activity
- }) */
- },
- // 选择年纪
- selectGrade({
- target
- }) {
- let code = target.dataset.code
- if (!code) {
- return
- }
- this.setData({
- temporaryGrade: code
- })
- console.log(code);
- },
- // 修改年级
- changeGrade: function(e) {
- const grade = this.data.temporaryGrade
- if (!grade) {
- return wx.showToast({
- title: '请选择年级',
- icon: 'none',
- duration: 2000
- })
- }
- wx.setStorageSync('grade', grade)
- this.setData({
- isGradeShow: false,
- grade
- })
- let data = {
- grade
- };
- httpRequestApi.settingUserInfo(data).success(res => {
- this.showPage()
- })
- return;
- },
- getFollowData: function() {
- httpRequestApi.getFollowWorks(this.data.followPageNo, this.data.followPageSize).success(res => {
- if (res.data.data.totalSize === 0) {
- this.setData({
- videoList: [],
- noFollow: true
- })
- console.log('没有关注人或关注的人没有发过作品')
- return
- } else {
- this.setData({
- noFollow: false
- })
- }
- console.log('关注列表', res)
- const followData = res.data.data.list;
- // const videoList = [];
- this.formatWorksList(followData);
- });
- httpRequestApi.userEvent('SUBSCRIBE');
- },
- // 点击用户头像区域
- headTapHandler: function(e) {
- console.log('点击头像', e)
- let tapId = e.detail.activeId;
- // 点击头像既关注 测试
- httpRequestApi.followUser(this.uid, tapId).success(res => {
- console.log(res)
- })
- },
- getCoursesList: function() {
- const grade = wx.getStorageSync('grade');
- const data = {
- pageNo: this.data.coursePageNo,
- pageSize: 6,
- grade,
- type: 'EXAMPLE'
- };
- console.log('资源', data)
- httpRequestApi.getClassRead(data).success(res => {
- console.log('资源', this.data.coursesData)
- this.setData({
- coursesData: this.data.coursesData.concat(res.data.data.list),
- noMoreWork: res.data.data.list.length <= 0 ? true : false
- }, () => {
- console.log(this.data.coursesData)
- })
- })
- httpRequestApi.userEvent('RESOURCES');
- },
- goToReading: function(e) {
- console.log('去朗读', e)
- const id = e.detail.activeId ? e.detail.activeId : e.currentTarget.dataset.id;
- const index = e.currentTarget.dataset.index;
- this.setData({
- goToCoursesId: id,
- goToCoursesIndex: index
- })
- wx.navigateTo({
- url: `../../pages/reading/reading?id=${id}`
- });
- httpRequestApi.userEvent('REC_READ');
- },
- refreshCourseAmount() {
- console.log(this.data.goToCoursesId)
- console.log(this.data.goToCoursesIndex)
- if (this.data.goToCoursesId && (this.data.goToCoursesIndex || this.data.goToCoursesIndex === 0)) {
- httpRequestApi.getClassDetail(this.data.goToCoursesId).success(res => {
- console.log('刷新', res.data.data.userRead)
- let likeStr = `coursesData[${this.data.goToCoursesIndex}].userRead.likeAmount`;
- let commentStr = `coursesData[${this.data.goToCoursesIndex}].userRead.commentAmount`;
- let playStr = `coursesData[${this.data.goToCoursesIndex}].userRead.playAmount`;
- let shareStr = `coursesData[${this.data.goToCoursesIndex}].userRead.shareAmount`;
- let collectStr = `coursesData[${this.data.goToCoursesIndex}].userRead.collectAmount`;
- console.log(1, this.data.coursesData[this.data.goToCoursesIndex].userRead.likeAmount)
- console.log(2, res.data.data.userRead.likeAmount)
- this.setData({
- [likeStr]: res.data.data.userRead.likeAmount,
- [commentStr]: res.data.data.userRead.commentAmount,
- [playStr]: res.data.data.userRead.playAmount,
- [shareStr]: res.data.data.userRead.shareAmount,
- [collectStr]: res.data.data.userRead.collectAmount,
- }, () => {
- console.log(111222333, this.data.coursesData[this.data.goToCoursesIndex])
- })
- })
- }
- },
- courseCollectTap: function collectClass(e) {
- console.log('收藏按钮', e);
- const data = {
- targetCode: e.target.dataset.id ? e.target.dataset.id : e.currentTarget.dataset.id,
- favoritesType: e.target.dataset.type ? e.target.dataset.type : e.currentTarget.dataset.type
- }
- const index = e.target.dataset.index ? e.target.dataset.index : e.currentTarget.dataset.index;
- let str = `coursesData[${index}].isFavorites`
- httpRequestApi.collectClass(data).success((res) => {
- console.log('this.data.coursesData[index]', this.data.coursesData[index])
- this.setData({
- [str]: !this.data.coursesData[index].isFavorites
- })
- });
- },
- coursesOpenShare: function coursesOpenShare(e) {
- const obj = e.currentTarget.dataset
- console.log('分享', obj)
- console.log('分享', e)
- if (1) {
- this.shareDialog = this.selectComponent("#share-dialog");
- const data = {
- avatar: obj.avatar,
- author: obj.author,
- iconImg: obj.iconImg,
- title: obj.title,
- path: `pages/index/index`,
- scene: obj.id,
- productId: 1
- // tip: this.data.tip,
- }
- // console.log(data)
- this.setData({
- noScroll: 'noScroll',
- shareTitle: obj.title,
- shareId: obj.id,
- shareImg: obj.shareimg
- })
- this.shareDialog.share(data);
- }
- },
- collectTap: function(e) {
- const index = e.detail.index;
- let str = `videoList[${index}].isFavorite`;
- let str2 = `videoList[${index}].favoritesAmount`;
- let favoritesAmount = e.detail.isCollect ? this.data.videoList[index].favoritesAmount + 1 : this.data.videoList[index].favoritesAmount - 1
- this.setData({
- [str]: e.detail.isCollect,
- [str2]: favoritesAmount
- })
- },
- likeTap: function(e) {
- console.log('点赞', e)
- const index = e.detail.index;
- let likeStr = `videoList[${index}].isLike`;
- let likeNumStr = `videoList[${index}].likes`;
- this.setData({
- [likeStr]: true,
- [likeNumStr]: this.data.videoList[index].likes + 1
- })
- },
- addShareAmount: function(e) {
- let str = `videoList[${e.detail.index}].shareAmount`;
- this.setData({
- [str]: this.data.videoList[e.detail.index].shareAmount + 1
- })
- },
- /**
- * 跳转到活动页
- */
- goToActivity() {
- httpRequestApi.postActEvent('BANNER').success(res => {
- console.log('活动banner', res)
- })
- // wx.navigateTo({
- // url: `../activity/index/index`
- // // url: `../activity/rule/rule`
- // });
- wx.navigateTo({
- url: `../activity/goodList/goodList`
- });
- },
- /**
- * banner点击
- */
- bannerTap() {
- if (!this.data.isLogin) {
- wx.navigateTo({
- url: `../../pages/login/login?index=0`
- });
- return;
- }
- if (this.data.isIos || this.data.isVip) {
- this.myPlase();
- } else {
- this.messageAuth();
- }
- },
- /**活动改版 */
- // myPlase() {
- // if (!wx.getStorageSync('message')) {
- // wx.requestSubscribeMessage({
- // tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
- // '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
- // ],
- // success: (res) => {
- // console.log(res)
- // if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
- // console.log('用户不同意订阅')
- // // 用户不同意订阅
- // wx.setStorageSync('message', false)
- // } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
- // console.log('订阅成功')
- // // 用户点击统一订阅
- // wx.setStorageSync('message', true)
- // }
- // wx.navigateTo({
- // url: `../vipActivity/vipActivity`
- // });
- // },
- // fail: () => {
- // wx.navigateTo({
- // url: `../vipActivity/vipActivity`
- // });
- // }
- // })
- // } else {
- // wx.navigateTo({
- // url: `../vipActivity/vipActivity`
- // });
- // }
- // },
- // 弹窗提示
- helpPayHideEvent() {
- this.setData({
- helpPayHide: !this.data.helpPayHide
- })
- },
- // 支付或者助力
- payAndHelp() {
- if (!this.data.isLogin) {
- wx.navigateTo({
- url: `../../pages/login/login?index=0`
- });
- return;
- }
- if (this.data.iphoneType === 'ios') {
- httpRequestApi.postUserHelp().success(res => {
- console.log(res)
- if (res.data.data) {
- this.setData({
- tipsType: 'tips',
- tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/help_success.png'
- })
- } else {
- this.setData({
- tipsType: 'tips',
- tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/helped.png'
- })
- }
- })
- } else {
- // 去支付需要获取权限
- this.messageAuth();
- }
- },
- // 去产品页
- goToPruduct() {
- wx.navigateTo({
- url: `../product/product?price=${this.data.myData.price}`
- });
- },
- // 授权
- messageAuth() {
- if (!wx.getStorageSync('message')) {
- wx.requestSubscribeMessage({
- tmplIds: ['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY',
- '-2ZZpWFoyKvAtX1HwEIQLQ92LnN8cryamB94LqLGo98'
- ],
- success: (res) => {
- console.log(res)
- if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'reject') {
- console.log('用户不同意订阅')
- wx.setStorageSync('message', false)
- } else if (res['KJ0YtcAacJNSXDBsE27JXqoaFrcJ1-N6Jcu85yTtQuY'] === 'accept') {
- console.log('订阅成功')
- wx.setStorageSync('message', true)
- }
- this.order();
- },
- fail: () => {
- this.order();
- }
- })
- } else {
- this.order();
- }
- },
- // 支付
- order() {
- // 渠道id
- const productId = wx.getStorageSync('productId');
- httpRequestApi.createOrder(productId).success(res => {
- console.log(res.data.data.package);
- const timeStamp = res.data.data.timeStamp;
- const nonceStr = res.data.data.nonceStr;
- const packages = res.data.data.package;
- const paySign = res.data.data.sign;
- wx.requestPayment({
- timeStamp,
- nonceStr,
- package: packages,
- signType: 'MD5',
- paySign,
- success: (res) => {
- if (this.data.iphoneType === 'iphone') {
- this.setData({
- tipsType: 'tips',
- tipsImg: 'http://reader-wx.ai160.com/images/reader/pay/success.png'
- })
- }
- httpRequestApi.getAuthActivity().success(res => {
- if (!res.data.data) {
- wx.setStorageSync('vip', false)
- wx.setStorageSync('date', '')
- } else {
- wx.setStorageSync('vip', true)
- wx.setStorageSync('date', res.data.data)
- this.setData({
- ['myData.isVIP']: true,
- ['myData.date']: res.data.data
- })
- this.showGift();
- }
- }).fail(error => {
- console.log(error)
- })
- },
- fail(res) {}
- })
- })
- },
- // 助力或者支付提示
- tips() {
- console.log('支付完了')
- this.setData({
- helpPayHide: true
- })
- this.updateData("2");
- },
- // 购买成功告诉首页显示邀请有礼
- showGift() {
- console.log('通知')
- this.setData({
- isVip: true
- })
- },
- // 首页获取权限
- getHelpAuth() {
- httpRequestApi.getAuthActivity().success(res => {
- if (!res.data.data) {
- wx.setStorageSync('vip', false)
- wx.setStorageSync('date', '')
- this.setData({
- isVip: false
- })
- } else {
- wx.setStorageSync('vip', true)
- wx.setStorageSync('date', res.data.data)
- this.setData({
- isVip: true
- })
- }
- }).fail(error => {
- console.log(error)
- })
- },
- // 分享作品逻辑
- creatShare(video) {
- return new Promise((resolve, reject) => {
- let context = wx.createSelectorQuery();
- context
- .select('#share')
- .fields({
- node: true,
- size: true
- }).exec((res) => {
- const canvas = res[0].node;
- const ctx = canvas.getContext('2d');
- const dpr = wx.getSystemInfoSync().pixelRatio;
- canvas.width = res[0].width * dpr;
- canvas.height = res[0].height * dpr;
- ctx.scale(dpr, dpr);
- ctx.font = '14px PingFang';
- let pic = canvas.createImage();
- pic.src = video.coverImg; //可以是本地,也可以是网络图片
- pic.onload = () => {
- ctx.drawImage(pic, 0, 0, 375, 211);
- }
- let peiyin = canvas.createImage();
- peiyin.src = '/static/image/peiyin.jpg';
- peiyin.onload = () => {
- ctx.drawImage(peiyin, 0, 211, 375, 89);
- // 收藏,一个一个渲染
- let sc = canvas.createImage();
- sc.src = '/static/image/no_collect.png'
- sc.onload = () => {
- ctx.drawImage(sc, 12, 220, 20, 20)
- ctx.fillText('收藏', 36, 238)
- //分享
- let fx = canvas.createImage();
- fx.src = '/static/index/share.png'
- fx.onload = () => {
- ctx.drawImage(fx, 78, 220, 22, 22)
- ctx.fillText('分享', 104, 238)
- //点赞
- let dz = canvas.createImage();
- dz.src = video.isLike ? '/static/index/heart_colored.png' : '/static/index/heart.png'
- dz.onload = () => {
- ctx.drawImage(dz, 258, 222, 22, 22)
- ctx.fillText(video.likes, 284, 238)
- //评论
- let pl = canvas.createImage();
- pl.src = '/static/index/comment.png'
- pl.onload = () => {
- ctx.drawImage(pl, 318, 222, 22, 22)
- ctx.fillText(video.commentAmount, 340, 238)
- setTimeout(() => {
- wx.canvasToTempFilePath({
- canvas: canvas,
- success(res) {
- resolve({
- title: '请欣赏我的课文朗读作品,点赞+评论。',
- path: `/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
- imageUrl: res.tempFilePath
- })
- },
- fail(res) {
- reject()
- }
- }, this)
- }, 500)
- }
- }
- }
- }
- }
- })
- })
- },
- onShareTimeline: function() {
- return {
- title: '终于找到适合孩子的朗读神器了!动画配音,边玩边学!',
- query: `uid=${wx.getStorageSync('uid')}`,
- imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/yuwen.jpg'
- }
- },
- onShareAppMessage({
- from,
- target
- }) {
- if (from == 'button') {
- let video = target.dataset.info
- const promise = new Promise(resolve => {
- this.creatShare(video).then(res => {
- resolve(res)
- })
- })
- return {
- title: '请欣赏我的课文朗读作品,点赞+评论。',
- path: `/pages/index/index?readId=${video.id}&uid=${wx.getStorageSync('uid')}`,
- imageUrl: video.coverImg,
- promise
- }
- } else {
- return {
- title: '课文朗读,从未如此有趣。',
- path: `/pages/index/index?&uid=${wx.getStorageSync('uid')}`,
- imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/shareContent.png'
- }
- }
- }
- })
|