wujingjing
2024-08-12 4df2f8b18bca292d3cc4d147a8e844c9610bef3b
miniprogram/pages/scene/scene.js
@@ -1,7 +1,6 @@
import {
  SECTION_LIST
} from "./testData"
import { getSectionByAllList } from "@/api/chat";
const app = getApp();
// pages/scene.ts
Component({
@@ -9,20 +8,40 @@
   * 页面的初始数据
   */
  data: {
    sectionList: SECTION_LIST,
    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: {
    attached() {
    async attached() {
      const res = await getSectionByAllList();
      if(!res?.json_ok)return;
      this.setData({
        sectionList: SECTION_LIST.map(item => {
        sectionList: res?.sections?.map(item => {
          item.childrenChunkList = wx.$_.chunk(item.children, 3);
          Reflect.deleteProperty(item, 'children');
          return item;
        })
      })
    },
    detached(){
      app.globalData.sectionAId = '';
    }
  },
  pageLifetimes: {