Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

277 linhas
6.7 KiB

  1. const app = getApp()
  2. const config = require("../../config/config")
  3. const { log } = require("../../utils/HttpBasics.js")
  4. const Http = require("../../utils/HttpBasics.js")
  5. const navigationBarHeight = (getApp().statusBarHeight + 44) + "px"
  6. const convert = require("../../utils/util.js")
  7. Page({
  8. data: {
  9. imgHttps: app.globalData.imgHttps,
  10. column: [],
  11. topFlag: 0,
  12. swiperLsit: [],
  13. inputValue: '',
  14. navigationBarHeight,
  15. deyList: [],//今天推荐
  16. deyPageNum: 1,
  17. classLsit: [],//精选类容
  18. classpageNum: 1,
  19. autho: [],//推荐作者
  20. authoPageNum: 1,
  21. rankingList: [],//热门排行
  22. rankingPageNum: 1,
  23. },
  24. goXq(e) {//跳转详情
  25. let id = e.currentTarget.dataset.id
  26. let title = e.currentTarget.dataset.title
  27. tt.navigateTo({
  28. url: `/pages/classDetails/classDetails?id=${id}&title=${title}` // 指定页面的url
  29. });
  30. },
  31. goPublicity(e) {
  32. let id = e.currentTarget.dataset.id
  33. let type = e.currentTarget.dataset.type
  34. if(type==4){
  35. tt.navigateTo({
  36. url: `/pages/upEnter/upEnter` // 指定页面的url
  37. });
  38. }else{
  39. tt.navigateTo({
  40. url: `/pages/publicity/publicity?id=${id}&type=${type}` // 指定页面的url
  41. });
  42. }
  43. },
  44. getNweDataLsit() {//今天推荐
  45. Http.get({
  46. url: config.api.columnLsit,
  47. data: {
  48. pageNum: this.data.deyPageNum,
  49. pageSize: 4,
  50. sortOrder: "desc"
  51. }
  52. }).then(res => {
  53. let temp = this.data.list
  54. if (this.data.pageNum > 1) {
  55. temp.push(...res.data.list)
  56. } else {
  57. temp = res.data.list
  58. }
  59. temp.map(item => {
  60. item.popularity = convert.moodsText(item.popularity)
  61. })
  62. this.setData({
  63. deyList: temp
  64. })
  65. }).catch(err => {
  66. tt.showToast({
  67. title: err.message, // 内容
  68. icon: "none"
  69. });
  70. })
  71. },
  72. getSwiperLsit() {//获取轮播图
  73. Http.get({
  74. url: config.api.getPublicity,
  75. data: {
  76. pageSize: 7,
  77. pageNum: 1
  78. }
  79. }).then(res => {
  80. console.log(res.data, "轮播图");
  81. this.setData({
  82. swiperLsit: res.data.list
  83. })
  84. }).catch(err => {
  85. tt.showToast({
  86. title: err.message, // 内容
  87. icon: "none"
  88. });
  89. })
  90. },
  91. getClassLsit() {//精选课程
  92. Http.get({
  93. url: config.api.columnLsit,
  94. data: {
  95. pageNum: this.data.classpageNum,
  96. pageSize: 3,
  97. mark: 1,
  98. sortColumn: "markTime",
  99. sortOrder: "desc"
  100. }
  101. }).then(res => {
  102. let temp = this.data.list
  103. if (this.data.pageNum > 1) {
  104. temp.push(...res.data.list)
  105. } else {
  106. temp = res.data.list
  107. }
  108. temp.map(item => {
  109. item.popularity = convert.moodsText(item.popularity)
  110. })
  111. this.setData({
  112. classLsit: temp
  113. })
  114. }).catch(err => {
  115. tt.showToast({
  116. title: err.message, // 内容
  117. icon: "none"
  118. });
  119. })
  120. },
  121. getRanking() {//排行榜
  122. Http.get({
  123. url: config.api.columnLsit,
  124. data: {
  125. pageNum: this.data.rankingPageNum,
  126. pageSize: 6,
  127. sortColumn: "popularity",
  128. sortOrder: "desc"
  129. }
  130. }).then(res => {
  131. let temp = this.data.list
  132. if (this.data.pageNum > 1) {
  133. temp.push(...res.data.list)
  134. } else {
  135. temp = res.data.list
  136. }
  137. temp.map(item => {
  138. item.popularity = convert.moodsText(item.popularity)
  139. })
  140. this.setData({
  141. rankingList: temp
  142. })
  143. }).catch(err => {
  144. tt.showToast({
  145. title: err.message, // 内容
  146. icon: "none"
  147. });
  148. })
  149. },
  150. getAuthor() {//推荐作者
  151. Http.get({
  152. url: config.api.getAuthor,
  153. data: {
  154. pageNum: this.data.authoPageNum,
  155. pageSize: 7,
  156. mark: 1,
  157. sortColumn: "markTime",
  158. sortOrder: "desc"
  159. }
  160. }).then(res => {
  161. let arr = res.data.list
  162. if (arr.length == 0) return
  163. if (res.data.list[0].businessTypes) {
  164. arr.map(item1 => {
  165. let text = ""
  166. JSON.parse(item1.businessTypes).map(item2 => {
  167. text += " " + item2.title
  168. })
  169. item1.authoRemark = text
  170. })
  171. }
  172. console.log(arr);
  173. this.setData({
  174. autho: arr,
  175. })
  176. })
  177. },
  178. search() {
  179. console.log(this.data.inputValue);
  180. },
  181. setTopFlag(e) {
  182. let index = e.currentTarget.dataset.index
  183. let itemId = e.currentTarget.dataset.itemid
  184. console.log(itemId);
  185. this.setData({
  186. topFlag: index
  187. })
  188. tt.navigateTo({
  189. url: `/pages/category/category?itemId=${itemId}` // 指定页面的url
  190. });
  191. },
  192. getColumn() {
  193. Http.get({
  194. url: config.api.getColumn
  195. }).then(res => {
  196. let tempData = res.data
  197. tempData.unshift({
  198. id: "",
  199. title: "推荐"
  200. })
  201. this.setData({
  202. column: tempData
  203. })
  204. }).catch(err => {
  205. tt.showToast({
  206. title: err.message, // 内容
  207. });
  208. })
  209. },
  210. onLoad: function () {
  211. if (app.globalData.token) {
  212. this.getColumn()
  213. this.getNweDataLsit()
  214. this.getClassLsit()
  215. this.getRanking()
  216. this.getAuthor()
  217. this.getSwiperLsit()
  218. } else {
  219. app.tokenCallback = token => {
  220. this.getColumn()
  221. this.getNweDataLsit()
  222. this.getClassLsit()
  223. this.getRanking()
  224. this.getAuthor()
  225. this.getSwiperLsit()
  226. }
  227. }
  228. },
  229. onPullDownRefresh() {
  230. this.getColumn()
  231. this.getNweDataLsit()
  232. this.getClassLsit()
  233. this.getRanking()
  234. this.getAuthor()
  235. this.getSwiperLsit()
  236. tt.stopPullDownRefresh();
  237. },
  238. onShareAppMessage: function (shareOption) {
  239. let that = this
  240. if (shareOption.channel == 'video') { // 判断是是不是分享视频
  241. return {
  242. channel: 'video', // 必写 video
  243. //     templateId: '',   // 分享的模版 id (如果未设置就是默认,下面会说如何设置)
  244. title: '小程序 | 看视频,学知识,有趣好玩内容尽在知播堂。',     // 分享的标题
  245. //     desc: '我是简介',     // 分享的内容介绍目前没有用
  246. //     path: `/pages/index/index`,  // 分享的路径
  247. extra: {
  248. videoTopics: ["知播堂"] // 只有抖音才会有的属性
  249. },
  250. }
  251. } else { // 右上角分享
  252. return {
  253. templateId: '',         //分享的模版 id
  254. title: '',            //分享的标题
  255. desc: '',           // 分享的内容
  256. //      path: ``, // 分享的路径
  257. imageUrl:"../../assets/images/1.png"
  258. }
  259. }
  260. },
  261. })