feat(wiki): 二十四节气详情抓取百度百科并图文展示
Publish Mini Program Dev Version / publish (push) Successful in 1m12s
Build and Publish Server / build (push) Successful in 8m24s

数据源:百度百科开放接口 BaikeLemmaCardApi(无反爬,返回结构化 JSON)
与「历史上的今天」(维基)完全解耦,维基代码原样保留可随时恢复:

服务端:
- WikiEntry 增加 image(配图)和 extra(结构化字段 JSON)字段
- 新建 BaikeTermSyncLog 独立日志表(不污染维基 WikiSyncLog)
- 新建 BaikeTermSyncService 独立同步服务(24 节气,间隔 1.2s)
- 启动时缺详情自动补齐,之后按配置间隔定时增量刷新
- 管理 API:GET/POST /admin/api/wiki/term-sync*

管理后台:
- 百科条目 Tab 顶部加节气同步卡片(X/24 + 状态 + 同步按钮)
- 条目编辑器加配图 URL(含预览)和节气扩展字段编辑

小程序:
- 百科页展开详情图文展示:配图 + 简介 + 物候/习俗/养生等分块

本地验证:24/24 节气抓取成功,image/extra 全部填充,维基数据不受影响
This commit is contained in:
gouki
2026-08-13 00:31:43 +00:00
parent 0ce1a1ef97
commit fec383f257
12 changed files with 759 additions and 6 deletions
+30
View File
@@ -41,6 +41,34 @@ const TERM_EXPLAINS = [
{ title: '胎神方位', brief: '孕妇需避开的方位', content: '胎神是传统民俗中保护胎儿的神灵,每日所在方位不同。孕妇不宜在胎神方位动土、钉钉或搬动重物,以免惊动胎神。' }
];
// 节气扩展字段的展示顺序与中文标签
const EXTRA_LABELS = [
{ key: 'alias', name: '别名' },
{ key: 'english', name: '外文名' },
{ key: 'meaning', name: '涵义' },
{ key: 'solarDate', name: '公历时间' },
{ key: 'ecliptic', name: '黄道位置' },
{ key: 'climate', name: '气候特点' },
{ key: 'phenology', name: '物候现象' },
{ key: 'farming', name: '农事活动' },
{ key: 'customs', name: '传统习俗' },
{ key: 'health', name: '起居养生' },
{ key: 'flower', name: '花信' }
];
// buildExtraList 把服务端 extra JSON 字符串解析为 [{name, value}] 展示列表(仅保留非空项,按定义顺序)
function buildExtraList(extraStr) {
if (!extraStr) return [];
let obj = {};
try { obj = JSON.parse(extraStr); } catch (e) { return []; }
const list = [];
EXTRA_LABELS.forEach(f => {
const v = (obj[f.key] || '').trim();
if (v) list.push({ name: f.name, value: v });
});
return list;
}
function buildEntries() {
const entries = [];
@@ -139,6 +167,8 @@ Page({
title: s.title,
brief: s.brief,
content: s.content,
image: s.image || '',
extraList: buildExtraList(s.extra),
open: false
};
if (titleIndex[s.title] !== undefined) {
+11 -1
View File
@@ -26,7 +26,17 @@
</view>
<view class="text-sm text-muted mt-1" wx:if="{{!item.open}}">{{item.brief}}</view>
<view class="entry-detail mt-2" wx:if="{{item.open}}">
<text class="text-base">{{item.content}}</text>
<!-- 配图(仅服务端条目有图时显示) -->
<image wx:if="{{item.image}}" class="entry-image" src="{{item.image}}" mode="widthFix" lazy-load/>
<!-- 详细简介 -->
<text class="text-base entry-content">{{item.content}}</text>
<!-- 结构化扩展字段(节气:物候/习俗/养生等) -->
<view class="extra-list" wx:if="{{item.extraList && item.extraList.length > 0}}">
<view class="extra-item" wx:for="{{item.extraList}}" wx:key="name" wx:for-item="field">
<text class="extra-name">{{field.name}}</text>
<text class="extra-value">{{field.value}}</text>
</view>
</view>
</view>
</view>
+47
View File
@@ -51,6 +51,53 @@
line-height: 1.7;
}
/* 节气配图 */
.entry-image {
width: 100%;
border-radius: 12rpx;
margin-bottom: 16rpx;
background: #F5F0EA;
}
/* 详细简介 */
.entry-content {
display: block;
color: #4A4036;
}
/* 结构化扩展字段列表 */
.extra-list {
margin-top: 16rpx;
background: #FBF7F1;
border-radius: 12rpx;
padding: 8rpx 20rpx;
}
.extra-item {
display: flex;
padding: 12rpx 0;
border-bottom: 1rpx solid #F0E6DA;
}
.extra-item:last-child {
border-bottom: none;
}
.extra-name {
flex-shrink: 0;
width: 140rpx;
font-size: 26rpx;
color: #A08B76;
font-weight: 500;
}
.extra-value {
flex: 1;
font-size: 26rpx;
color: #4A4036;
line-height: 1.6;
}
.empty-tip {
padding: 80rpx 0;
}