2026-09-17 22:21:31 +08:00
|
|
|
/**
|
|
|
|
|
* U54 内容详情
|
|
|
|
|
*
|
|
|
|
|
* Phase 19:此前正文与标题**写死在 wxml**(任何文章都显示同一篇演示内容)。
|
|
|
|
|
* 现接入 GET /content/articles/{id},按 id 展示真实正文。
|
|
|
|
|
*
|
|
|
|
|
* 边界:用户端内容只做列表与详情,不做 Feed / 评论 / 点赞。
|
|
|
|
|
*/
|
|
|
|
|
const { contentService } = require('../../services');
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
loading: true,
|
|
|
|
|
error: '',
|
|
|
|
|
article: null,
|
|
|
|
|
paragraphs: [],
|
|
|
|
|
},
|
|
|
|
|
onLoad(options) {
|
|
|
|
|
this.articleId = (options && options.id) || '';
|
|
|
|
|
this.load();
|
|
|
|
|
},
|
|
|
|
|
async load() {
|
|
|
|
|
if (!this.articleId) {
|
|
|
|
|
this.setData({ loading: false, error: '未指定内容' });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.setData({ loading: true, error: '' });
|
|
|
|
|
try {
|
|
|
|
|
const article = await contentService.getArticleDetail(this.articleId);
|
|
|
|
|
if (!article) {
|
|
|
|
|
this.setData({ loading: false, error: '内容不存在或已下架' });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const paragraphs = String(article.content || '')
|
|
|
|
|
.split(/\n+/)
|
|
|
|
|
.map((line) => line.trim())
|
|
|
|
|
.filter(Boolean);
|
|
|
|
|
this.setData({ article, paragraphs, loading: false });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.setData({ loading: false, error: '加载失败,请稍后重试' });
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
report() {
|
|
|
|
|
wx.navigateTo({ url: '/pages/report/report?type=content' });
|
|
|
|
|
},
|
|
|
|
|
related() {
|
|
|
|
|
wx.navigateTo({ url: '/pages/counseling-intro/counseling-intro' });
|
|
|
|
|
},
|
|
|
|
|
});
|