前端打包

This commit is contained in:
liu
2026-08-09 11:15:38 +08:00
parent f67567bdc9
commit 9153c4eead
32 changed files with 1235 additions and 27 deletions
+66 -1
View File
@@ -1,8 +1,11 @@
import XinTable from '@/components/XinTable';
import { Badge, Image, Typography } from 'antd';
import { Badge, Image, Tag, Typography } from 'antd';
import { useEffect, useState } from 'react';
import type { ICarousel } from '@/domain/iCarousel';
import type { ICategory } from '@/domain/iCategory';
import type { XinTableColumn } from '@/components/XinTable/typings';
import type { ISysFileInfo } from '@/domain/iSysFile';
import { List } from '@/api/common/table';
import { useTranslation } from 'react-i18next';
import dayjs from 'dayjs';
@@ -22,6 +25,20 @@ function getImageUrl(image: ISysFileInfo | string | null | undefined): string {
export default function CarouselPage() {
const { t } = useTranslation();
// 分类下拉选项
const [categoryOptions, setCategoryOptions] = useState<{ label: string; value: number }[]>([]);
useEffect(() => {
List<ICategory>('/system/category', { pageSize: 1000 }).then((res) => {
const list = res.data?.data?.data ?? [];
setCategoryOptions(list.map((item) => ({
label: item.name,
value: item.id as number,
})));
}).catch(() => {
// 分类加载失败不影响页面使用
});
}, []);
const columns: XinTableColumn<ICarousel>[] = [
{
title: t('system.carousel.id'),
@@ -64,6 +81,25 @@ export default function CarouselPage() {
);
},
},
{
title: t('system.carousel.linkType'),
dataIndex: 'link_type',
valueType: 'select',
colProps: { span: 12 },
initialValue: 0,
rules: [{ required: true, message: t('system.carousel.linkType.required') }],
fieldProps: {
options: [
{ label: t('system.carousel.linkType.link'), value: 0 },
{ label: t('system.carousel.linkType.category'), value: 1 },
],
},
render: (value: number) => {
return value === 1
? <Tag color="blue">{t('system.carousel.linkType.category')}</Tag>
: <Tag>{t('system.carousel.linkType.link')}</Tag>;
},
},
{
title: t('system.carousel.link'),
dataIndex: 'link',
@@ -73,6 +109,35 @@ export default function CarouselPage() {
fieldProps: {
placeholder: t('system.carousel.link.placeholder'),
},
render: (_, record) => {
if(record.link_type === 1) {
const name = record.category?.name;
return name ? <Tag>{name}</Tag> : '-';
}
return record.link || '-'
},
dependency: {
dependencies: ['link_type'],
visible: (values) => values.link_type !== 1,
},
},
{
title: t('system.carousel.category'),
dataIndex: 'category_id',
valueType: 'select',
colProps: { span: 12 },
hideInSearch: true,
hideInTable: true,
fieldProps: {
options: categoryOptions,
showSearch: true,
optionFilterProp: 'label',
placeholder: t('system.carousel.category.placeholder'),
},
dependency: {
dependencies: ['link_type'],
visible: (values) => values.link_type === 1,
},
},
{
title: t('system.carousel.status'),
+121
View File
@@ -0,0 +1,121 @@
import XinTable from '@/components/XinTable';
import { Badge, Button, Tooltip, Typography } from 'antd';
import { UnorderedListOutlined } from '@ant-design/icons';
import type { ICategory } from '@/domain/iCategory';
import type { XinTableColumn } from '@/components/XinTable/typings';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router';
import dayjs from 'dayjs';
const { Title, Text } = Typography;
/** 首页分类管理 */
export default function CategoryPage() {
const { t } = useTranslation();
const navigate = useNavigate();
const columns: XinTableColumn<ICategory>[] = [
{
title: t('system.category.id'),
dataIndex: 'id',
hideInForm: true,
width: 80,
sorter: true,
align: 'center',
},
{
title: t('system.category.name'),
dataIndex: 'name',
valueType: 'text',
colProps: { span: 12 },
rules: [{ required: true, message: t('system.category.name.required') }],
},
{
title: t('system.category.status'),
dataIndex: 'status',
valueType: 'select',
filters: [
{ text: t('system.category.status.normal'), value: 0 },
{ text: t('system.category.status.disabled'), value: 1 },
],
colProps: { span: 12 },
rules: [{ required: true, message: t('system.category.status.required') }],
fieldProps: {
options: [
{ label: t('system.category.status.normal'), value: 0 },
{ label: t('system.category.status.disabled'), value: 1 },
],
},
render: (value: number) => {
return value === 0
? <Badge status="success" text={t('system.category.status.normal')} />
: <Badge status="error" text={t('system.category.status.disabled')} />;
},
},
{
title: t('system.category.sort'),
dataIndex: 'sort',
valueType: 'digit',
colProps: { span: 12 },
hideInSearch: true,
initialValue: 0,
fieldProps: {
min: 0,
style: { width: '100%' },
},
},
{
title: t('system.category.createdAt'),
dataIndex: 'created_at',
render: (value: string) => (value ? dayjs(value).format('YYYY-MM-DD HH:mm') : '-'),
hideInForm: true,
hideInSearch: true,
width: 160,
},
];
// 跳转到分类项管理页面
const handleGoToItems = (record: ICategory) => {
navigate(`/system/category/item?categoryId=${record.id}&categoryName=${encodeURIComponent(record.name || '')}`);
};
return (
<>
<div className="mb-5">
<Title level={3}>{t('system.category.page.title')}</Title>
<Text type="secondary">{t('system.category.page.description')}</Text>
</div>
<XinTable<ICategory>
api="/system/category"
columns={columns}
rowKey="id"
accessName="system.category"
formProps={{
grid: true,
colProps: { span: 12 },
rowProps: { gutter: [30, 0] },
layout: 'vertical',
}}
modalProps={{ width: 600 }}
searchProps={false}
operateProps={{
fixed: 'right',
width: 180,
}}
scroll={{ x: 1000 }}
operateRender={(record, dom) => [
<Tooltip title={t('system.category.manageItems')} key="items">
<Button
type="default"
icon={<UnorderedListOutlined />}
size="small"
onClick={() => handleGoToItems(record)}
/>
</Tooltip>,
dom.edit,
dom.del,
]}
/>
</>
);
}
+206
View File
@@ -0,0 +1,206 @@
import XinTable from '@/components/XinTable';
import { Badge, Button, Image, Space, Typography } from 'antd';
import { LeftOutlined } from '@ant-design/icons';
import type { ICategoryItem } from '@/domain/iCategoryItem';
import type { XinTableColumn } from '@/components/XinTable/typings';
import type { ISysFileInfo } from '@/domain/iSysFile';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate, useSearchParams } from 'react-router';
import { Create, Update } from '@/api/common/table.ts';
import dayjs from 'dayjs';
const { Title } = Typography;
/**
* 从 image 字段中提取预览 URL
* image 字段可能是 ISysFileInfo 对象或 URL 字符串
*/
function getImageUrl(image: ISysFileInfo | string | null | undefined): string {
if (!image) return '';
if (typeof image === 'string') return image;
return image.preview_url || image.file_url || '';
}
/** 首页分类项管理 */
export default function CategoryItemPage() {
const { t } = useTranslation();
const navigate = useNavigate();
const [searchParams] = useSearchParams();
// 从 URL 参数获取分类信息
const categoryId = searchParams.get('categoryId');
const categoryName = searchParams.get('categoryName') || '';
const [currentCategory, setCurrentCategory] = useState({
id: categoryId ? parseInt(categoryId) : 0,
name: decodeURIComponent(categoryName),
});
// 监听 URL 参数变化
useEffect(() => {
if (categoryId) {
setCurrentCategory({
id: parseInt(categoryId),
name: decodeURIComponent(categoryName),
});
}
}, [categoryId, categoryName]);
const columns: XinTableColumn<ICategoryItem>[] = [
{
title: t('system.category.item.id'),
dataIndex: 'id',
hideInForm: true,
width: 80,
align: 'center',
},
{
title: t('system.category.item.title'),
dataIndex: 'title',
valueType: 'text',
colProps: { span: 12 },
rules: [{ required: true, message: t('system.category.item.title.required') }],
},
{
title: t('system.category.item.image'),
dataIndex: 'image_id',
valueType: 'image',
colProps: { span: 24 },
rules: [{ required: true, message: t('system.category.item.image.required') }],
hideInSearch: true,
fieldProps: {
action: '/system/file/list/upload',
mode: 'single',
maxCount: 1,
changeType: 'id',
},
render: (_value: ISysFileInfo | string, record: ICategoryItem) => {
const url = getImageUrl(record.image);
if (!url) return '-';
return (
<Image
src={url}
width={60}
height={60}
style={{ objectFit: 'cover', borderRadius: 4 }}
/>
);
},
},
{
title: t('system.category.item.link'),
dataIndex: 'link',
valueType: 'text',
colProps: { span: 12 },
hideInSearch: true,
fieldProps: {
placeholder: t('system.category.item.link.placeholder'),
},
},
{
title: t('system.category.item.status'),
dataIndex: 'status',
valueType: 'select',
colProps: { span: 12 },
initialValue: 0,
rules: [{ required: true, message: t('system.category.item.status.required') }],
fieldProps: {
options: [
{ label: t('system.category.item.status.normal'), value: 0 },
{ label: t('system.category.item.status.disabled'), value: 1 },
],
},
render: (value: number) => {
return value === 0
? <Badge status="success" text={t('system.category.item.status.normal')} />
: <Badge status="error" text={t('system.category.item.status.disabled')} />;
},
},
{
title: t('system.category.item.sort'),
dataIndex: 'sort',
valueType: 'digit',
colProps: { span: 12 },
hideInSearch: true,
initialValue: 0,
fieldProps: {
min: 0,
style: { width: '100%' },
},
},
{
title: t('system.category.item.createdAt'),
dataIndex: 'created_at',
render: (value: string) => (value ? dayjs(value).format('YYYY-MM-DD HH:mm') : '-'),
hideInForm: true,
hideInSearch: true,
width: 160,
},
];
// 返回分类列表
const handleGoBack = () => {
navigate('/system/category');
};
// 如果没有分类ID,显示提示
if (!currentCategory.id) {
return (
<div style={{ padding: 50, textAlign: 'center' }}>
<div style={{ marginTop: 50, color: '#999' }}>
{t('system.category.selectCategoryFirst')}
</div>
</div>
);
}
return (
<Space orientation={'vertical'} style={{ width: '100%' }}>
<div>
<Button type={'link'} onClick={handleGoBack} icon={<LeftOutlined />} classNames={{ root: 'p-0 mb-2' }}>
{t('system.category.backToList')}
</Button>
<Title level={3}>
<span className={'mr-2'}>{t('system.category.itemManagement')} - {currentCategory.name}</span>
</Title>
</div>
<XinTable<ICategoryItem>
api="/system/category/item"
columns={columns}
rowKey="id"
accessName="system.category.item"
formProps={{
grid: true,
colProps: { span: 12 },
rowProps: { gutter: [30, 0] },
layout: 'vertical',
}}
modalProps={{ width: 600 }}
requestParams={(params) => {
return {
...params,
category_id: currentCategory.id,
};
}}
searchShow={false}
handleFinish={async (values, mode, _form, defaultValue) => {
if (mode === 'create') {
await Create('/system/category/item', {
...values,
category_id: currentCategory.id,
});
window.$message?.success(t('system.category.item.createSuccess'));
} else {
await Update('/system/category/item/' + defaultValue?.id, {
...values,
category_id: currentCategory.id,
});
window.$message?.success(t('system.category.item.updateSuccess'));
}
return true;
}}
/>
</Space>
);
}
+66 -1
View File
@@ -1,8 +1,11 @@
import XinTable from '@/components/XinTable';
import { Badge, Image, Typography } from 'antd';
import { Badge, Image, Tag, Typography } from 'antd';
import { useEffect, useState } from 'react';
import type { IGridNav } from '@/domain/iGridNav';
import type { ICategory } from '@/domain/iCategory';
import type { XinTableColumn } from '@/components/XinTable/typings';
import type { ISysFileInfo } from '@/domain/iSysFile';
import { List } from '@/api/common/table';
import { useTranslation } from 'react-i18next';
import dayjs from 'dayjs';
@@ -22,6 +25,20 @@ function getImageUrl(image: ISysFileInfo | string | null | undefined): string {
export default function GridNavPage() {
const { t } = useTranslation();
// 分类下拉选项
const [categoryOptions, setCategoryOptions] = useState<{ label: string; value: number }[]>([]);
useEffect(() => {
List<ICategory>('/system/category', { pageSize: 1000 }).then((res) => {
const list = res.data?.data?.data ?? [];
setCategoryOptions(list.map((item) => ({
label: item.name,
value: item.id as number,
})));
}).catch(() => {
// 分类加载失败不影响页面使用
});
}, []);
const columns: XinTableColumn<IGridNav>[] = [
{
title: t('system.gridNav.id'),
@@ -64,6 +81,25 @@ export default function GridNavPage() {
);
},
},
{
title: t('system.gridNav.linkType'),
dataIndex: 'link_type',
valueType: 'select',
colProps: { span: 12 },
initialValue: 0,
rules: [{ required: true, message: t('system.gridNav.linkType.required') }],
fieldProps: {
options: [
{ label: t('system.gridNav.linkType.link'), value: 0 },
{ label: t('system.gridNav.linkType.category'), value: 1 },
],
},
render: (value: number) => {
return value === 1
? <Tag color="blue">{t('system.gridNav.linkType.category')}</Tag>
: <Tag>{t('system.gridNav.linkType.link')}</Tag>;
},
},
{
title: t('system.gridNav.link'),
dataIndex: 'link',
@@ -73,6 +109,35 @@ export default function GridNavPage() {
fieldProps: {
placeholder: t('system.gridNav.link.placeholder'),
},
render: (_, record) => {
if(record.link_type === 1) {
const name = record.category?.name;
return name ? <Tag>{name}</Tag> : '-';
}
return record.link || '-'
},
dependency: {
dependencies: ['link_type'],
visible: (values) => values.link_type !== 1,
},
},
{
title: t('system.carousel.category'),
dataIndex: 'category_id',
valueType: 'select',
colProps: { span: 12 },
hideInSearch: true,
hideInTable: true,
fieldProps: {
options: categoryOptions,
showSearch: true,
optionFilterProp: 'label',
placeholder: t('system.carousel.category.placeholder'),
},
dependency: {
dependencies: ['link_type'],
visible: (values) => values.link_type === 1,
},
},
{
title: t('system.gridNav.status'),