feat: 完善官网配置、预约管理与文章编辑

This commit is contained in:
zhanjunhao
2026-10-31 19:02:58 +08:00
parent b8659d0a9a
commit 2e6fe73939
54 changed files with 4898 additions and 203 deletions
+26
View File
@@ -0,0 +1,26 @@
# 预约演示列表
页面复用 CardPro、CardTable、CompactModeToggle 和 createCardProPagination。
桌面端搜索栏靠左,移动端沿用系统的操作区展开和卡片展示方式。
## 已接入接口
GET /api/website/demo-requests,通过项目共享 API 实例发送 Cookie 和 New-Api-User。
不再使用本地演示列表。业务 success 必须严格为 true,否则显示后端 message 或错误提示。
筛选字段:name、contact、companyName,去除首尾空白并以 URLSearchParams 编码。
模糊搜索由后端执行,三个条件为 AND。请求分页为 p 和 page_size;
响应读取 data.items、data.total、data.page 和 data.page_size。
查询、重置和切换每页条数回到第一页;翻页保留已提交的筛选条件。
页面忽略过期请求结果,错误时清空表格并显示错误原因。
公司名称与需求分别使用 companyName 和 requirement,不使用原型字段 company/requirements。
需求列表最多显示三行,保留内部换行,不提供查看完整需求按钮或弹窗。
## 模拟提交与验收
本地脚本 scripts/seed-demo-requests.mjs 默认仅预览,添加 --submit 才真实新增三条联调测试预约。
页面初始化不会新增数据。脚本和测试文件已加入 Git 忽略规则。
运行 npm run test:e2e 验证桌面与移动端交互;npm run test:e2e:report 查看本地报告。
完整验收要求见 docs/website-api-acceptance.md,模拟接口验收与真实服务验收分别记录。
+294
View File
@@ -0,0 +1,294 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useEffect, useMemo, useRef, useState } from 'react';
import {
Banner,
Button,
Empty,
Form,
Select,
Spin,
Typography,
} from '@douyinfe/semi-ui';
import { useTranslation } from 'react-i18next';
import CardPro from '../../components/common/ui/CardPro';
import CardTable from '../../components/common/ui/CardTable';
import CompactModeToggle from '../../components/common/ui/CompactModeToggle';
import {
IllustrationNoResult,
IllustrationNoResultDark,
} from '../../components/common/illustrations';
import { createCardProPagination } from '../../helpers/utils';
import { useIsMobile } from '../../hooks/common/useIsMobile';
import { useTableCompactMode } from '../../hooks/common/useTableCompactMode';
import { fetchDemoReservations } from './reservationsApi';
const EMPTY_FILTERS = { name: '', contact: '', companyName: '' };
export default function DemoReservations() {
const { t } = useTranslation();
const isMobile = useIsMobile();
const [compactMode, setCompactMode] =
useTableCompactMode('demo-reservations');
const formRef = useRef(null);
const [query, setQuery] = useState({
...EMPTY_FILTERS,
page: 1,
pageSize: 10,
});
const [result, setResult] = useState({ items: [], total: 0 });
const [loading, setLoading] = useState(true);
const [error, setError] = useState('');
useEffect(() => {
let active = true;
setLoading(true);
setError('');
fetchDemoReservations(query)
.then((data) => {
if (active) setResult(data);
})
.catch((error) => {
if (active) {
setError(error.message || '预约信息加载失败,请重新查询');
setResult({ items: [], total: 0 });
}
})
.finally(() => {
if (active) setLoading(false);
});
return () => {
active = false;
};
}, [query]);
const columns = useMemo(
() =>
[
['name', '姓名', 100],
['contact', '联系方式', 210],
['companyName', '公司名称', 180],
['position', '职位', 140],
['industry', '行业', 160],
['interest', '关注方向', 190],
['requirement', '需求', 360],
].map(([dataIndex, title, width]) => ({
title: t(title),
dataIndex,
key: dataIndex,
...(compactMode ? {} : { width }),
render: (value) =>
dataIndex === 'requirement' && value ? (
<div>
<span
style={{
display: '-webkit-box',
WebkitLineClamp: 3,
WebkitBoxOrient: 'vertical',
overflow: 'hidden',
overflowWrap: 'anywhere',
whiteSpace: 'pre-wrap',
}}
>
{value}
</span>
</div>
) : (
<span style={{ overflowWrap: 'anywhere', whiteSpace: 'pre-wrap' }}>
{value || '—'}
</span>
),
})),
[t, compactMode],
);
const reset = () => {
formRef.current?.reset();
setQuery((previous) => ({
...EMPTY_FILTERS,
page: 1,
pageSize: previous.pageSize,
}));
};
const changePageSize = (pageSize) =>
setQuery((previous) => ({ ...previous, page: 1, pageSize }));
const pagination = createCardProPagination({
currentPage: result.page ?? query.page,
pageSize: result.page_size ?? query.pageSize,
total: result.total,
onPageChange: (page) => setQuery((previous) => ({ ...previous, page })),
onPageSizeChange: changePageSize,
preventPageChangeOnPageSizeChange: true,
isMobile,
t,
});
return (
<div className='mt-[60px] px-2' aria-busy={loading}>
<Spin
spinning={loading}
size='large'
style={{ minHeight: 200, width: '100%' }}
data-testid='demo-reservations-loading'
>
<CardPro
type='type1'
t={t}
descriptionArea={
<div className='flex w-full flex-col items-start justify-between gap-2 md:flex-row md:items-center'>
<div>
<Typography.Title heading={4} style={{ marginBottom: 8 }}>
{t('预约演示')}
</Typography.Title>
<Typography.Text type='tertiary' size='small'>
{t('查看官网访客提交的预约信息,支持模糊查询与分页。')}
</Typography.Text>
</div>
<CompactModeToggle
compactMode={compactMode}
setCompactMode={setCompactMode}
t={t}
/>
</div>
}
actionsArea={
<div className='flex w-full justify-start'>
<Form
initValues={EMPTY_FILTERS}
getFormApi={(api) => (formRef.current = api)}
onSubmit={(values) =>
setQuery((previous) => ({
name: (values.name || '').trim(),
contact: (values.contact || '').trim(),
companyName: (values.companyName || '').trim(),
page: 1,
pageSize: previous.pageSize,
}))
}
allowEmpty
autoComplete='off'
layout='horizontal'
className='w-full md:w-auto'
>
<div className='flex w-full flex-col items-center gap-2 md:w-auto md:flex-row'>
{[
['name', '请输入姓名'],
['contact', '请输入联系方式'],
['companyName', '请输入公司名称'],
].map(([field, placeholder]) => (
<div key={field} className='w-full md:w-44'>
<Form.Input
field={field}
aria-label={t(placeholder)}
placeholder={t(placeholder)}
showClear
pure
size='small'
maxLength={254}
/>
</div>
))}
<div className='flex w-full gap-2 md:w-auto'>
<Button
type='tertiary'
htmlType='submit'
loading={loading}
size='small'
className='flex-1 md:flex-initial'
>
{t('查询')}
</Button>
<Button
type='tertiary'
onClick={reset}
size='small'
className='flex-1 md:flex-initial'
>
{t('重置')}
</Button>
</div>
</div>
</Form>
</div>
}
paginationArea={
isMobile && result.total > 0 ? (
<div className='flex w-full flex-col items-center gap-3'>
<div className='flex items-center gap-3'>
<Typography.Text type='tertiary'>
{t('共')} {result.total} {t('条')}
</Typography.Text>
<Select
aria-label={t('每页条数')}
size='small'
value={result.page_size ?? query.pageSize}
onChange={changePageSize}
optionList={[10, 20, 50, 100].map((value) => ({
value,
label: `${value} ${t('条/页')}`,
}))}
/>
</div>
{pagination}
</div>
) : (
pagination
)
}
>
{error && (
<Banner
type='danger'
closeIcon={null}
description={t(error)}
className='mb-4'
/>
)}
<CardTable
rowKey='id'
columns={columns}
dataSource={result.items}
scroll={compactMode ? undefined : { x: 'max-content' }}
hidePagination
className='overflow-hidden'
size='middle'
empty={
<Empty
image={
<IllustrationNoResult style={{ width: 150, height: 150 }} />
}
darkModeImage={
<IllustrationNoResultDark
style={{ width: 150, height: 150 }}
/>
}
description={t(
error ? '预约信息加载失败' : '暂无符合条件的预约信息',
)}
style={{ padding: 30 }}
/>
}
/>
</CardPro>
</Spin>
</div>
);
}
@@ -0,0 +1,54 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import { requestWebsite } from '../../helpers/websiteApi';
export async function fetchDemoReservations({
name = '',
contact = '',
companyName = '',
page = 1,
pageSize = 10,
} = {}) {
const params = new URLSearchParams({
name: name.trim(),
contact: contact.trim(),
companyName: companyName.trim(),
p: String(page),
page_size: String(pageSize),
});
const data = await requestWebsite(
'get',
`/api/website/demo-requests?${params}`,
undefined,
'预约信息加载失败,请重新查询',
);
if (
!data ||
!Array.isArray(data.items) ||
!Number.isInteger(data.total) ||
data.total < 0 ||
!Number.isInteger(data.page) ||
data.page < 1 ||
!Number.isInteger(data.page_size) ||
data.page_size < 1
)
throw new Error('预约列表响应格式不正确,请联系管理员检查');
return data;
}