gerson
2024-08-10 ed459ba52b9d994acc87e5d45f9293069a2f4aaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { getSectionByAllList } from "@/api/chat";
 
const app = getApp();
// pages/scene.ts
Component({
 
  /**
   * 页面的初始数据
   */
  data: {
    sectionList: [],
    iconList: ['bengzhan1', 'sanweiditu', 'jiankong']
  },
  methods:{
    sectionBClick(e){
      const item = e.currentTarget.dataset.item;
      console.log('this.data.sectionList',this.data.sectionList);
      const foundA = this.data.sectionList.find(sectionItem=>sectionItem.childrenChunkList?.some(childrenItem=>childrenItem.some(subItem=>subItem.section_id===item.section_id)) );
      if(!foundA ) return;
      // 前一个页面传递参数
      const jumpUrl = '/pages/question/question';
      wx.switchTab({
        url: jumpUrl,
      });
      app.globalData.sectionAId = foundA.section_id;
      app.globalData.sectionB = item;
    }
  },
  lifetimes: {
 
    async attached() {
      const res = await getSectionByAllList();
      if(!res?.json_ok)return;
      this.setData({
        sectionList: res?.sections?.map(item => {
          item.childrenChunkList = wx.$_.chunk(item.children, 3);
          Reflect.deleteProperty(item, 'children');
          return item;
        })
      })
    },
 
    detached(){
      app.globalData.sectionAId = '';
    }
  },
  pageLifetimes: {
    show() {
 
      if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: 1
        })
      }
    }
  }
})