25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

232 satır
5.1 KiB

  1. const app = getApp()
  2. const config = require("../../config/config")
  3. const Http = require("../../utils/HttpBasics.js")
  4. const navigationBarHeight = (getApp().statusBarHeight + 44)+"px"
  5. Page({
  6. data: {
  7. imgHttps:app.globalData.imgHttps,
  8. column:[],
  9. topFlag:0,
  10. swiperLsit:[],
  11. inputValue:'',
  12. navigationBarHeight,
  13. deyList:[],//今天推荐
  14. deyPageNum:1,
  15. classLsit:[],//精选类容
  16. classpageNum:1,
  17. autho:[],//推荐作者
  18. authoPageNum:1,
  19. rankingList:[],//热门排行
  20. rankingPageNum:1,
  21. },
  22. goXq(e){//跳转详情
  23. let id = e.currentTarget.dataset.id
  24. let title = e.currentTarget.dataset.title
  25. tt.navigateTo({
  26. url: `/pages/classDetails/classDetails?id=${id}&title=${title}` // 指定页面的url
  27. });
  28. },
  29. goPublicity(e){
  30. let id = e.currentTarget.dataset.id
  31. let type = e.currentTarget.dataset.type
  32. tt.navigateTo({
  33. url: `/pages/publicity/publicity?id=${id}&type=${type}` // 指定页面的url
  34. });
  35. },
  36. getNweDataLsit(){//今天推荐
  37. Http.get({
  38. url:config.api.columnLsit,
  39. data:{
  40. pageNum:this.data.deyPageNum,
  41. pageSize:4,
  42. sortOrder:"desc"
  43. }
  44. }).then(res=>{
  45. let temp = this.data.list
  46. if(this.data.pageNum>1){
  47. temp.push(...res.data.list)
  48. }else{
  49. temp = res.data.list
  50. }
  51. this.setData({
  52. deyList:temp
  53. })
  54. }).catch(err=>{
  55. tt.showToast({
  56. title: err.message, // 内容
  57. icon: "none"
  58. });
  59. })
  60. },
  61. getSwiperLsit(){//获取轮播图
  62. Http.get({
  63. url:config.api.getPublicity,
  64. data:{
  65. pageSize:7,
  66. pageNum:1
  67. }
  68. }).then(res=>{
  69. console.log(res.data,"轮播图");
  70. this.setData({
  71. swiperLsit:res.data.list
  72. })
  73. }).catch(err=>{
  74. tt.showToast({
  75. title: err.message, // 内容
  76. icon: "none"
  77. });
  78. })
  79. },
  80. getClassLsit(){//精选课程
  81. Http.get({
  82. url:config.api.columnLsit,
  83. data:{
  84. pageNum:this.data.classpageNum,
  85. pageSize:3,
  86. mark:1,
  87. sortColumn: "markTime",
  88. sortOrder: "desc"
  89. }
  90. }).then(res=>{
  91. let temp = this.data.list
  92. if(this.data.pageNum>1){
  93. temp.push(...res.data.list)
  94. }else{
  95. temp = res.data.list
  96. }
  97. this.setData({
  98. classLsit:temp
  99. })
  100. }).catch(err=>{
  101. tt.showToast({
  102. title: err.message, // 内容
  103. icon: "none"
  104. });
  105. })
  106. },
  107. getRanking(){//排行榜
  108. Http.get({
  109. url:config.api.columnLsit,
  110. data:{
  111. pageNum:this.data.rankingPageNum,
  112. pageSize:6,
  113. sortColumn:"popularity",
  114. sortOrder:"desc"
  115. }
  116. }).then(res=>{
  117. let temp = this.data.list
  118. if(this.data.pageNum>1){
  119. temp.push(...res.data.list)
  120. }else{
  121. temp = res.data.list
  122. }
  123. this.setData({
  124. rankingList:temp
  125. })
  126. }).catch(err=>{
  127. tt.showToast({
  128. title: err.message, // 内容
  129. icon: "none"
  130. });
  131. })
  132. },
  133. getAuthor(){//推荐作者
  134. Http.get({
  135. url:config.api.getAuthor,
  136. data:{
  137. pageNum:this.data.authoPageNum,
  138. pageSize:4,
  139. mark:1,
  140. sortColumn: "markTime",
  141. sortOrder: "desc"
  142. }
  143. }).then(res=>{
  144. let text =""
  145. let arr=res.data.list
  146. if(res.data.list[0].businessTypes){
  147. arr.map(item1=>{
  148. JSON.parse(item1.businessTypes).map(item2=>{
  149. text += " "+item2.title
  150. })
  151. item1.authoRemark = text
  152. })
  153. }
  154. console.log(arr);
  155. this.setData({
  156. autho:arr,
  157. })
  158. })
  159. },
  160. search(){
  161. console.log(this.data.inputValue);
  162. },
  163. setTopFlag(e){
  164. let index = e.currentTarget.dataset.index
  165. let itemId = e.currentTarget.dataset.itemid
  166. console.log(itemId);
  167. this.setData({
  168. topFlag:index
  169. })
  170. tt.navigateTo({
  171. url: `/pages/category/category?itemId=${itemId}` // 指定页面的url
  172. });
  173. },
  174. getColumn(){
  175. Http.get({
  176. url:config.api.getColumn
  177. }).then(res=>{
  178. let tempData = res.data
  179. tempData.unshift({
  180. id:"",
  181. title:"推荐"
  182. })
  183. this.setData({
  184. column:tempData
  185. })
  186. }).catch(err=>{
  187. tt.showToast({
  188. title: err.data, // 内容
  189. });
  190. })
  191. },
  192. getWeapNote(){//初始化
  193. if (app.globalData.token){//登录
  194. this.getColumn()
  195. this.getNweDataLsit()
  196. this.getClassLsit()
  197. this.getRanking()
  198. this.getAuthor()
  199. this.getSwiperLsit()
  200. }else{//未登录
  201. app.tokenCallback = token => {
  202. this.getColumn()
  203. this.getNweDataLsit()
  204. this.getClassLsit()
  205. this.getRanking()
  206. this.getAuthor()
  207. this.getSwiperLsit()
  208. }
  209. }
  210. },
  211. onLoad: function () {
  212. this.getWeapNote()
  213. },
  214. onPullDownRefresh() {
  215. this.getColumn()
  216. this.getNweDataLsit()
  217. this.getClassLsit()
  218. this.getRanking()
  219. this.getAuthor()
  220. this.getSwiperLsit()
  221. tt.stopPullDownRefresh();
  222. },
  223. })