// pages/main/travel/travel.ts import config from "../../../config/index"; export type Luggage = { gao: LuggageItem[]; yu: LuggageItem[]; } export type LuggageItem = { name: string; isTaken: boolean; } type Guide = { title: string; images: string[]; } interface ITravelData { luggage?: Luggage; guides: Guide[]; guidesDB: Guide[]; activeCollapse?: number; } Page({ data: { luggage: undefined, guides: [], guidesDB: [], activeCollapse: undefined }, onLoad() { wx.request({ url: `${config.url}/journal/travel`, method: "GET", header: { Key: wx.getStorageSync("key") }, success: async (resp: any) => { this.setData({ luggage: resp.data.data.luggage, guides: resp.data.data.guides.map((item: any) => { return { title: item.title, images: [] // 留空分批加载 } }), guidesDB: resp.data.data.guides }) } }); }, onShow() { wx.request({ url: `${config.url}/journal/travel`, method: "GET", header: { Key: wx.getStorageSync("key") }, success: async (resp: any) => { this.setData({ luggage: resp.data.data.luggage }); } }); }, toLuggageList(e: WechatMiniprogram.BaseEvent) { const name = e.target.dataset.name; wx.setStorageSync("luggage", { name, luggage: this.data.luggage }); wx.navigateTo({ "url": "/pages/main/travel/luggage/index" }) }, onCollapseChange(e: any) { const index = e.detail.value; if (this.data.guides[index].images.length === 0) { this.data.guides[index].images = this.data.guidesDB[index].images.map((item: any) => { return `${config.url}/attachment/read/${item}`; }); this.setData({ guides: this.data.guides }) } this.setData({ activeCollapse: index }) }, preview(e: WechatMiniprogram.BaseEvent) { const index = e.target.dataset.index; const imageIndex = e.target.dataset.imageIndex; const images = this.data.guides[index].images; wx.previewMedia({ current: imageIndex, sources: images.map((image: any) => { return { url: image, type: "image" } }) }) }, });