const app = getApp() const config = require("../../config/config") const { log } = require("../../utils/HttpBasics.js") const Http = require("../../utils/HttpBasics.js") const navigationBarHeight = (getApp().statusBarHeight + 44) + "px" const convert = require("../../utils/util.js") Page({ data: { imgHttps: app.globalData.imgHttps, column: [], topFlag: 0, swiperLsit: [], inputValue: '', navigationBarHeight, deyList: [],//今天推荐 deyPageNum: 1, classLsit: [],//精选类容 classpageNum: 1, autho: [],//推荐作者 authoPageNum: 1, rankingList: [],//热门排行 rankingPageNum: 1, }, goXq(e) {//跳转详情 let id = e.currentTarget.dataset.id let title = e.currentTarget.dataset.title tt.navigateTo({ url: `/pages/classDetails/classDetails?id=${id}&title=${title}` // 指定页面的url }); }, goPublicity(e) { let id = e.currentTarget.dataset.id let type = e.currentTarget.dataset.type if(type==4){ tt.navigateTo({ url: `/pages/upEnter/upEnter` // 指定页面的url }); }else{ tt.navigateTo({ url: `/pages/publicity/publicity?id=${id}&type=${type}` // 指定页面的url }); } }, getNweDataLsit() {//今天推荐 Http.get({ url: config.api.columnLsit, data: { pageNum: this.data.deyPageNum, pageSize: 4, sortOrder: "desc" } }).then(res => { let temp = this.data.list if (this.data.pageNum > 1) { temp.push(...res.data.list) } else { temp = res.data.list } temp.map(item => { item.popularity = convert.moodsText(item.popularity) }) this.setData({ deyList: temp }) }).catch(err => { tt.showToast({ title: err.message, // 内容 icon: "none" }); }) }, getSwiperLsit() {//获取轮播图 Http.get({ url: config.api.getPublicity, data: { pageSize: 7, pageNum: 1 } }).then(res => { console.log(res.data, "轮播图"); this.setData({ swiperLsit: res.data.list }) }).catch(err => { tt.showToast({ title: err.message, // 内容 icon: "none" }); }) }, getClassLsit() {//精选课程 Http.get({ url: config.api.columnLsit, data: { pageNum: this.data.classpageNum, pageSize: 3, mark: 1, sortColumn: "markTime", sortOrder: "desc" } }).then(res => { let temp = this.data.list if (this.data.pageNum > 1) { temp.push(...res.data.list) } else { temp = res.data.list } temp.map(item => { item.popularity = convert.moodsText(item.popularity) }) this.setData({ classLsit: temp }) }).catch(err => { tt.showToast({ title: err.message, // 内容 icon: "none" }); }) }, getRanking() {//排行榜 Http.get({ url: config.api.columnLsit, data: { pageNum: this.data.rankingPageNum, pageSize: 6, sortColumn: "popularity", sortOrder: "desc" } }).then(res => { let temp = this.data.list if (this.data.pageNum > 1) { temp.push(...res.data.list) } else { temp = res.data.list } temp.map(item => { item.popularity = convert.moodsText(item.popularity) }) this.setData({ rankingList: temp }) }).catch(err => { tt.showToast({ title: err.message, // 内容 icon: "none" }); }) }, getAuthor() {//推荐作者 Http.get({ url: config.api.getAuthor, data: { pageNum: this.data.authoPageNum, pageSize: 7, mark: 1, sortColumn: "markTime", sortOrder: "desc" } }).then(res => { let arr = res.data.list if (arr.length == 0) return if (res.data.list[0].businessTypes) { arr.map(item1 => { let text = "" JSON.parse(item1.businessTypes).map(item2 => { text += " " + item2.title }) item1.authoRemark = text }) } console.log(arr); this.setData({ autho: arr, }) }) }, search() { console.log(this.data.inputValue); }, setTopFlag(e) { let index = e.currentTarget.dataset.index let itemId = e.currentTarget.dataset.itemid console.log(itemId); this.setData({ topFlag: index }) tt.navigateTo({ url: `/pages/category/category?itemId=${itemId}` // 指定页面的url }); }, getColumn() { Http.get({ url: config.api.getColumn }).then(res => { let tempData = res.data tempData.unshift({ id: "", title: "推荐" }) this.setData({ column: tempData }) }).catch(err => { tt.showToast({ title: err.message, // 内容 }); }) }, onLoad: function () { if (app.globalData.token) { this.getColumn() this.getNweDataLsit() this.getClassLsit() this.getRanking() this.getAuthor() this.getSwiperLsit() } else { app.tokenCallback = token => { this.getColumn() this.getNweDataLsit() this.getClassLsit() this.getRanking() this.getAuthor() this.getSwiperLsit() } } }, onPullDownRefresh() { this.getColumn() this.getNweDataLsit() this.getClassLsit() this.getRanking() this.getAuthor() this.getSwiperLsit() tt.stopPullDownRefresh(); }, onShareAppMessage: function (shareOption) { let that = this if (shareOption.channel == 'video') { // 判断是是不是分享视频 return { channel: 'video', // 必写 video //     templateId: '',   // 分享的模版 id (如果未设置就是默认,下面会说如何设置) title: '小程序 | 看视频,学知识,有趣好玩内容尽在知播堂。',     // 分享的标题 //     desc: '我是简介',     // 分享的内容介绍目前没有用 //     path: `/pages/index/index`,  // 分享的路径 extra: { videoTopics: ["知播堂"] // 只有抖音才会有的属性 }, } } else { // 右上角分享 return { templateId: '',         //分享的模版 id title: '',            //分享的标题 desc: '',           // 分享的内容 //      path: ``, // 分享的路径 imageUrl:"../../assets/images/1.png" } } }, })