Browse Source

开发直接进入分类页面相关功能

bayi 1 year ago
parent
commit
93302af911
4 changed files with 28 additions and 17 deletions
  1. 2 0
      api/works.js
  2. 0 1
      app.js
  3. 23 11
      pages/childClassify/index.js
  4. 3 5
      pages/resource/index.js

+ 2 - 0
api/works.js

@@ -4,6 +4,8 @@ import {
 module.exports = {
     // 获取作品类目
     getCategoryList: data => request('/v3/column', 'get', data),
+    // 获取二级分类
+    getCategoryLowerList: data => request(`/v3/column/${data}`, 'get'),
     // 获取作品二级类目内容
     getCategoryWorks: data => request('/v3/column/opus', 'get', data),
     // 作品查询

+ 0 - 1
app.js

@@ -60,7 +60,6 @@ App({
                 getApp().callBack();
             }
         } else {
-            console.log(shareUid, 'shareUid');
             wx.login({
                 success: async (res) => {
                     if (res.code) {

+ 23 - 11
pages/childClassify/index.js

@@ -1,7 +1,11 @@
 import {
     getCategoryWorks,
+    getCategoryLowerList,
     searchWorks
 } from '~/api/works';
+import {
+    setUserInfo
+} from '~/api/user'
 import reachBottom from '~/mixins/reachBottom';
 import {
     createStoreBindings
@@ -28,23 +32,25 @@ Page({
     /**
      * 生命周期函数--监听页面加载
      */
-    onLoad(options) {
-        // 没有二级分类
+    async onLoad(options) {
+        console.log(options, 'options');
         if (options.id) {
-            this.setData({
-                childType: options.id
-            });
-            this.resetData();
-        } else if (options.list) {
-            let categoryList = JSON.parse(decodeURIComponent(options.list));
-            this.setData({
-                categoryList
-            });
+            let categoryList = await getCategoryLowerList(options.id)
+            if (categoryList.length == 0) {
+                this.setData({
+                    childType: options.id
+                });
+            } else {
+                this.setData({
+                    categoryList
+                });
+            }
             this.resetData();
         }
         wx.setNavigationBarTitle({
             title: options.title || '搜索'
         });
+
         this.setData({
             type: options.type,
             historySearch: wx.getStorageSync('search'),
@@ -58,6 +64,12 @@ Page({
         });
         // 立刻更新
         this.storeBindings.updateStoreBindings();
+        console.log(this.data.userInfo);
+        if (options.grade && !this.data.userInfo.grade) {
+            setUserInfo({
+                grade: options.grade
+            }, 'put')
+        }
     },
     // 获取分类的内容
     loadMore() {

+ 3 - 5
pages/resource/index.js

@@ -64,9 +64,8 @@ Page({
         currentTarget
     }) {
         let firstInfo = currentTarget.dataset.item
-        let params = firstInfo.childList.length > 0 ? `list=${encodeURIComponent(JSON.stringify(firstInfo.childList))}` : `id=${firstInfo.id}`
         wx.navigateTo({
-            url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&${params}`,
+            url: `/pages/childClassify/index?type=class&title=${firstInfo.title}&id=${firstInfo.id}`,
         })
     },
     showTips() {
@@ -74,9 +73,8 @@ Page({
             title: '新栏目更新中',
             content: '敬请期待….',
             showCancel: false,
-            confirmColor:'#333333',
-            success(res) {
-            }
+            confirmColor: '#333333',
+            success(res) {}
         })
     },
     onUnload() {