// pages/detail/detail.js const { get } = require('../../utils/request'); const { formatTime } = require('../../utils/util'); Page({ data: { id: '', detail: null, loading: true, isFavorite: false, relatedList: [] }, onLoad(options) { if (options.id) { this.setData({ id: options.id }); this.loadDetail(options.id); } }, onShareAppMessage() { return { title: this.data.detail?.title || '信息详情', path: `/pages/detail/detail?id=${this.data.id}` }; }, // 加载详情 async loadDetail(id) { this.setData({ loading: true }); // 模拟数据 setTimeout(() => { this.setData({ loading: false, detail: { id: id, title: '这是一个详情页面的标题,展示信息服务的详细内容', content: `

这是信息详情的正文内容。

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

更多详细的信息内容会在这里展示,包括图片、文字等富文本内容。

用户可以通过滑动查看完整的内容。

`, author: '信息服务平台', publishTime: new Date().getTime() - 3600000, views: 1234, category: '科技', image: '/assets/images/detail.png' }, relatedList: [ { id: 2, title: '相关信息标题1', views: 856 }, { id: 3, title: '相关信息标题2', views: 723 } ] }); // 设置导航栏标题 wx.setNavigationBarTitle({ title: this.data.detail.title.substring(0, 10) + '...' }); }, 500); }, // 收藏/取消收藏 onFavorite() { const isFavorite = !this.data.isFavorite; this.setData({ isFavorite }); wx.showToast({ title: isFavorite ? '收藏成功' : '已取消收藏', icon: 'success' }); }, // 分享 onShare() { // 触发分享 }, // 点击相关信息 onRelatedTap(e) { const { id } = e.currentTarget.dataset; wx.navigateTo({ url: `/pages/detail/detail?id=${id}` }); }, // 返回 onBack() { wx.navigateBack(); } });