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

This commit is contained in:
zhanjunhao
2026-10-31 19:02:58 +08:00
parent 7b80c3bbb3
commit 1bf13bc226
54 changed files with 4898 additions and 203 deletions
+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>
);
}