feat(website): 文章发布时间精确到秒
This commit is contained in:
@@ -8,6 +8,16 @@
|
|||||||
|
|
||||||
**记录规则**:每条写“范围、变更、影响、回滚、关联”五项;回滚优先 `git revert <提交>`,提交含多项改动时按文件还原(`git checkout <提交>^ -- <文件>`),不整仓 reset。本文不作为规则依据。
|
**记录规则**:每条写“范围、变更、影响、回滚、关联”五项;回滚优先 `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
|
## 2026-11-13
|
||||||
|
|
||||||
### UI · 两个超市的响应式留白与卡片布局
|
### UI · 两个超市的响应式留白与卡片布局
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
|
DatePicker,
|
||||||
Form,
|
Form,
|
||||||
Input,
|
Input,
|
||||||
Modal,
|
Modal,
|
||||||
@@ -150,12 +151,15 @@ export default function ArticleEditor({ initial, insights, onApply, onClose }) {
|
|||||||
{field(
|
{field(
|
||||||
'date',
|
'date',
|
||||||
'发布日期',
|
'发布日期',
|
||||||
<Input
|
<DatePicker
|
||||||
aria-label='发布日期'
|
aria-label='发布日期'
|
||||||
validateStatus={errors.date ? 'error' : 'default'}
|
status={errors.date ? 'error' : undefined}
|
||||||
aria-invalid={Boolean(errors.date)}
|
aria-invalid={Boolean(errors.date)}
|
||||||
type='date'
|
type='dateTime'
|
||||||
value={draft.date}
|
format='YYYY-MM-DD HH:mm:ss'
|
||||||
|
placeholder='请选择发布日期'
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
value={draft.date || undefined}
|
||||||
onChange={(value) => change('date', value)}
|
onChange={(value) => change('date', value)}
|
||||||
/>,
|
/>,
|
||||||
true,
|
true,
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ export default function InsightsPanel({ value, onChange, disabled, error }) {
|
|||||||
? '全部内容'
|
? '全部内容'
|
||||||
: value.categories.find((c) => c.id === id)?.name || '未分类',
|
: value.categories.find((c) => c.id === id)?.name || '未分类',
|
||||||
},
|
},
|
||||||
{ title: '发布日期', dataIndex: 'date', width: 140 },
|
{ title: '发布日期', dataIndex: 'date', width: 180 },
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'actions',
|
key: 'actions',
|
||||||
|
|||||||
@@ -53,9 +53,31 @@ export function categoryError(name, categories, id) {
|
|||||||
return '';
|
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') {
|
export function newArticle(category = 'all') {
|
||||||
const now = new Date();
|
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 {
|
return {
|
||||||
id: '',
|
id: '',
|
||||||
title: '',
|
title: '',
|
||||||
@@ -89,11 +111,7 @@ export function articleErrors(article, insights) {
|
|||||||
)
|
)
|
||||||
errors.category = '请选择所属分类';
|
errors.category = '请选择所属分类';
|
||||||
const date = String(article.date ?? '');
|
const date = String(article.date ?? '');
|
||||||
if (
|
if (!isValidPublishDate(date))
|
||||||
!/^\d{4}-\d{2}-\d{2}$/.test(date) ||
|
|
||||||
!Number.isFinite(Date.parse(date)) ||
|
|
||||||
new Date(date).toISOString().slice(0, 10) !== date
|
|
||||||
)
|
|
||||||
errors.date = date ? '请选择有效的发布日期' : '请选择发布日期';
|
errors.date = date ? '请选择有效的发布日期' : '请选择发布日期';
|
||||||
const body = String(article.body ?? '');
|
const body = String(article.body ?? '');
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user