Преглед изворни кода

开发联调作品分类及搜索

bayi пре 2 година
родитељ
комит
5fe3e42ec9
3 измењених фајлова са 26 додато и 9 уклоњено
  1. 2 0
      api/works.js
  2. 23 8
      pages/childClassify/index.js
  3. 1 1
      pages/childClassify/index.wxml

+ 2 - 0
api/works.js

@@ -6,6 +6,8 @@ module.exports = {
   getCategoryList: data => request('/v3/column', 'get', data),
   // 获取作品二级类目内容
   getCategoryWorks: data => request('/v3/column/opus', 'get', data),
+  // 作品查询
+  searchWorks: data => request('/v3/recommend/query', 'get', data),
   // 获取优秀作品展播列表
   getHotrecommendList: data => request('/userRead/recommend', 'get', data),
   // 获取官方推荐作品列表

+ 23 - 8
pages/childClassify/index.js

@@ -1,5 +1,6 @@
 import {
-  getCategoryWorks
+  getCategoryWorks,
+  searchWorks
 } from '~/api/works'
 import reachBottom from '~/mixins/reachBottom'
 Page({
@@ -17,8 +18,7 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
-    let title = '分类'
-    console.log(options);
+    let title = '搜索'
     // 没有二级分类
     if (options.id) {
       this.setData({
@@ -43,6 +43,9 @@ Page({
   },
   // 获取分类的内容
   loadMore() {
+    if (this.data.type == 'search') {
+      return
+    }
     let columnId = this.data.childType ? this.data.childType : this.data.categoryList[this.data.currentIndex].id
     this.getData(getCategoryWorks, {
       columnId
@@ -67,15 +70,27 @@ Page({
       text: detail.value
     })
   },
-  search() {
-    console.log("搜索");
+  async search() {
+    if (!this.data.text) {
+      return
+    }
+    let res = await searchWorks({
+      title: this.data.text,
+      grade: 'PRIMARY_FIRST_GRADE'
+    })
+    let list = res.map(item => {
+      return {
+        readAmount: item.readAmount,
+        ...item.userRead
+      }
+    })
+    this.setData({
+      list
+    })
   },
   goRead({
     currentTarget
   }) {
-    console.log(
-      currentTarget.dataset
-    );
     wx.navigateTo({
       url: `/pages/reading/index?videoId=${currentTarget.dataset.id}`
     })

+ 1 - 1
pages/childClassify/index.wxml

@@ -24,7 +24,7 @@
           <view class="statistics">
             <view class="statistic">
               <image src="/static/zp.png" class="playImg" mode="" />
-              <view class="num">{{filters.numFilter(item.playAmount)|| 0}}</view>
+              <view class="num">{{filters.numFilter(item.readAmount)|| 0}}</view>
             </view>
             <view class="statistic">
               <image src="/static/play2.png" class="playImg" mode="" />