const { get } = require("../../utils/api"); const { showError } = require("../../utils/page-helpers"); function formatDateTime(value) { if (!value) return ""; return String(value).replace("T", " ").slice(0, 16); } Page({ data: { id: null, item: null, loading: false }, onLoad(options) { wx.setNavigationBarTitle({ title: "公告详情" }); this.setData({ id: options.id || null }); this.load(options.id); }, async onPullDownRefresh() { await this.load(this.data.id); wx.stopPullDownRefresh(); }, async load(id) { if (!id) return; this.setData({ loading: true }); try { const item = await get(`/api/announcements/${id}`); this.setData({ item: { ...item, created_at_text: formatDateTime(item.created_at), updated_at_text: formatDateTime(item.updated_at) } }); } catch (error) { showError(error, "加载公告失败"); } finally { this.setData({ loading: false }); } } });