feat(website): 对齐官网文章配置与展示顺序

This commit is contained in:
zhanjunhao
2026-11-17 00:38:40 +08:00
parent 4f33cfcc0e
commit 25dbef4f1d
9 changed files with 291 additions and 245 deletions
+76 -32
View File
@@ -40,6 +40,7 @@ import {
categoryError,
createContentId,
filterArticles,
moveArticle,
newArticle,
removeArticle,
} from './insightsModel';
@@ -56,6 +57,9 @@ export default function InsightsPanel({ value, onChange, disabled, error }) {
? category
: 'all';
const rows = filterArticles(value, keyword, activeCategory);
// Reordering only makes sense on the full list, which is the official site order.
const sortable = activeCategory === 'all' && !keyword.trim();
const hasCategories = value.categories.length > 0;
const count = (id) =>
id === 'all'
? value.articles.length
@@ -91,7 +95,7 @@ export default function InsightsPanel({ value, onChange, disabled, error }) {
};
const deleteCategory = (item) => {
if (count(item.id)) {
showError('该分类下仍有文章,请先调整文章所属分类,再删除分类。');
showError('该分类下仍有文章,请先将文章调整到其他分类,再删除分类。');
return;
}
Modal.confirm({
@@ -158,37 +162,68 @@ export default function InsightsPanel({ value, onChange, disabled, error }) {
title: '所属分类',
dataIndex: 'category',
width: 140,
render: (id) =>
id === 'all'
? '全部内容'
: value.categories.find((c) => c.id === id)?.name || '未分类',
render: (id) => value.categories.find((c) => c.id === id)?.name,
},
{ title: '发布日期', dataIndex: 'date', width: 180 },
{
title: '角标',
dataIndex: 'tag',
width: 100,
render: (tag) => tag || '-',
},
{ title: '发布日期', dataIndex: 'date', width: 140 },
{
title: '操作',
key: 'actions',
width: 160,
render: (_, item) => (
<div className='website-insights-row-actions'>
<Button
type='link'
size='small'
disabled={disabled}
onClick={() => setArticle({ ...item, related: [...item.related] })}
>
编辑
</Button>
<Button
type='link'
size='small'
danger
disabled={disabled}
onClick={() => deleteArticle(item)}
>
删除
</Button>
</div>
),
width: 220,
render: (_, item) => {
const index = value.articles.findIndex((a) => a.id === item.id);
const move = (offset) => onChange(moveArticle(value, item.id, offset));
return (
<div className='website-insights-row-actions'>
<Button
type='link'
size='small'
disabled={disabled}
onClick={() =>
setArticle({ ...item, related: [...item.related] })
}
>
编辑
</Button>
<Button
type='link'
size='small'
aria-label={`上移${item.title}`}
title={sortable ? undefined : '请在全部分类且无搜索时调整顺序'}
disabled={disabled || !sortable || index <= 0}
onClick={() => move(-1)}
>
上移
</Button>
<Button
type='link'
size='small'
aria-label={`下移${item.title}`}
title={sortable ? undefined : '请在全部分类且无搜索时调整顺序'}
disabled={
disabled || !sortable || index >= value.articles.length - 1
}
onClick={() => move(1)}
>
下移
</Button>
<Button
type='link'
size='small'
danger
disabled={disabled}
onClick={() => deleteArticle(item)}
>
删除
</Button>
</div>
);
},
},
];
return (
@@ -304,7 +339,8 @@ export default function InsightsPanel({ value, onChange, disabled, error }) {
<Button
icon={<IconPlus />}
theme='solid'
disabled={disabled}
disabled={disabled || !hasCategories}
title={hasCategories ? undefined : '请先新增内容分类'}
onClick={() => {
setArticle(newArticle(activeCategory));
}}
@@ -313,11 +349,19 @@ export default function InsightsPanel({ value, onChange, disabled, error }) {
</Button>
</div>
</TableToolbar>
{!hasCategories && (
<Typography.Paragraph type='tertiary'>
请先新增内容分类,文章需归属一个分类后才能在官网展示。
</Typography.Paragraph>
)}
<Typography.Paragraph type='tertiary'>
列表顺序即官网展示顺序,新增文章默认排在最前,可在“全部分类”下上移或下移调整。
</Typography.Paragraph>
<CardTable
rowKey='id'
columns={columns}
dataSource={rows}
scroll={{ x: 860 }}
scroll={{ x: 1040 }}
empty={<TableEmpty />}
hidePagination
/>
@@ -337,12 +381,12 @@ export default function InsightsPanel({ value, onChange, disabled, error }) {
}
>
<Typography.Paragraph type='tertiary'>
“全部内容”为默认分类,也汇总展示全部文章;已有文章的自定义分类需先迁移文章再删除。
“全部内容”为官网默认筛选项,汇总展示全部文章,不能作为文章分类;已有文章的分类需先将文章调整到其他分类再删除。
</Typography.Paragraph>
<div className='website-insights-manage-row'>
<span>全部内容</span>
<Typography.Text type='tertiary'>
默认分类(不可删除)
默认筛选项(不可删除)
</Typography.Text>
</div>
{value.categories.map((c) => (