const app = getApp<IAppOption>()

Page({
  data: {
    wikiList: [] as any[],
    showModal: false,
    currentItem: null as any
  },

  onLoad() {
    this.fetchWikiList();
  },

  fetchWikiList() {
    wx.showLoading({ title: '正在获取百科...' });
    wx.request({
      // 根据你的路由配置调整 URL
      url: `${app.globalData.baseUrl}/encyclopedia/api/list/`, 
      method: 'GET',
      success: (res: any) => {
        wx.hideLoading();
        if (res.data.code === 200) {
          this.setData({ wikiList: res.data.data });
        } else {
          wx.showToast({ title: '加载失败', icon: 'none' });
        }
      },
      fail: () => {
        wx.hideLoading();
        wx.showToast({ title: '网络请求失败', icon: 'none' });
      }
    });
  },

  showDetail(e: any) {
    const item = e.currentTarget.dataset.item;
    this.setData({ currentItem: item, showModal: true });
  },

  closeModal() { this.setData({ showModal: false }); },
  preventClose() { return; } // 防止点击内容区关闭弹窗
})