diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4ac7c0db..9250c4c0 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,6 +8,16 @@ **记录规则**:每条写“范围、变更、影响、回滚、关联”五项;回滚优先 `git revert <提交>`,提交含多项改动时按文件还原(`git checkout <提交>^ -- <文件>`),不整仓 reset。本文不作为规则依据。 +## 2026-11-14 + +### 功能 · 官网设置文章发布时间精确到秒 + +- **范围**:`/console/website-setting` 动态与洞察页签的新增 / 编辑文章抽屉与文章列表。 +- **变更**:发布日期由原生日期输入改为 `DatePicker`(`dateTime`),存储格式 `YYYY-MM-DD HH:mm:ss`;新建文章默认当前时间;校验按本地时间逐项检查年月日时分秒;列表“发布日期”列宽 140 → 180。 +- **影响**:旧数据 `YYYY-MM-DD` 仍校验通过(编辑时显示 `00:00:00`),列表倒序排序对新旧格式均有效;官网前台读取 `date` 时需兼容带时分秒的值。 +- **回滚**:按文件还原 `src/pages/WebsiteSettings/{ArticleEditor.jsx,InsightsPanel.jsx,insightsModel.js,insightsModel.test.js}`,不涉及数据迁移。 +- **关联**:`src/pages/WebsiteSettings/README.md`。 + ## 2026-11-13 ### UI · 两个超市的响应式留白与卡片布局 diff --git a/src/pages/WebsiteSettings/ArticleEditor.jsx b/src/pages/WebsiteSettings/ArticleEditor.jsx index aca5ab86..e31ab389 100644 --- a/src/pages/WebsiteSettings/ArticleEditor.jsx +++ b/src/pages/WebsiteSettings/ArticleEditor.jsx @@ -21,6 +21,7 @@ import { Button, Card, Checkbox, + DatePicker, Form, Input, Modal, @@ -150,12 +151,15 @@ export default function ArticleEditor({ initial, insights, onApply, onClose }) { {field( 'date', '发布日期', - change('date', value)} />, true, diff --git a/src/pages/WebsiteSettings/InsightsPanel.jsx b/src/pages/WebsiteSettings/InsightsPanel.jsx index 9d2c921c..00ad0354 100644 --- a/src/pages/WebsiteSettings/InsightsPanel.jsx +++ b/src/pages/WebsiteSettings/InsightsPanel.jsx @@ -163,7 +163,7 @@ export default function InsightsPanel({ value, onChange, disabled, error }) { ? '全部内容' : value.categories.find((c) => c.id === id)?.name || '未分类', }, - { title: '发布日期', dataIndex: 'date', width: 140 }, + { title: '发布日期', dataIndex: 'date', width: 180 }, { title: '操作', key: 'actions', diff --git a/src/pages/WebsiteSettings/insightsModel.js b/src/pages/WebsiteSettings/insightsModel.js index 823bb5a7..531d6d05 100644 --- a/src/pages/WebsiteSettings/insightsModel.js +++ b/src/pages/WebsiteSettings/insightsModel.js @@ -53,9 +53,31 @@ export function categoryError(name, categories, id) { return ''; } +const pad = (value) => String(value).padStart(2, '0'); + +// Publish time is stored as local "YYYY-MM-DD HH:mm:ss"; legacy "YYYY-MM-DD" stays valid. +export function isValidPublishDate(value) { + const match = /^(\d{4})-(\d{2})-(\d{2})(?: (\d{2}):(\d{2}):(\d{2}))?$/.exec( + value, + ); + if (!match) return false; + const [year, month, day, hour = 0, minute = 0, second = 0] = match + .slice(1) + .map((part) => (part === undefined ? undefined : Number(part))); + const date = new Date(year, month - 1, day, hour, minute, second); + return ( + date.getFullYear() === year && + date.getMonth() === month - 1 && + date.getDate() === day && + date.getHours() === hour && + date.getMinutes() === minute && + date.getSeconds() === second + ); +} + export function newArticle(category = 'all') { const now = new Date(); - const date = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`; + const date = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`; return { id: '', title: '', @@ -89,11 +111,7 @@ export function articleErrors(article, insights) { ) errors.category = '请选择所属分类'; const date = String(article.date ?? ''); - if ( - !/^\d{4}-\d{2}-\d{2}$/.test(date) || - !Number.isFinite(Date.parse(date)) || - new Date(date).toISOString().slice(0, 10) !== date - ) + if (!isValidPublishDate(date)) errors.date = date ? '请选择有效的发布日期' : '请选择发布日期'; const body = String(article.body ?? ''); if (