校园论坛
This commit is contained in:
@@ -0,0 +1,203 @@
|
||||
import { Tag, Typography } from 'antd';
|
||||
import React from 'react';
|
||||
import XinTable from '@/components/XinTable';
|
||||
import type { XinTableColumn, XinTableProps } from '@/components/XinTable/typings';
|
||||
import type IForumPost from '@/domain/iForumPost';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import dayjs from 'dayjs';
|
||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||
|
||||
const { Title, Text } = Typography;
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
const Table: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const columns: XinTableColumn<IForumPost>[] = [
|
||||
{
|
||||
title: t('forum.post.id'),
|
||||
dataIndex: 'id',
|
||||
hideInForm: true,
|
||||
sorter: true,
|
||||
align: 'center',
|
||||
width: 80,
|
||||
},
|
||||
{
|
||||
title: t('forum.post.title'),
|
||||
dataIndex: 'title',
|
||||
valueType: 'text',
|
||||
align: 'center',
|
||||
required: true,
|
||||
rules: [{ required: true, message: t('forum.post.title.required') }],
|
||||
},
|
||||
{
|
||||
title: t('forum.post.user_id'),
|
||||
dataIndex: 'user_id',
|
||||
valueType: 'text',
|
||||
align: 'center',
|
||||
required: true,
|
||||
hideInSearch: true,
|
||||
},
|
||||
{
|
||||
title: t('forum.post.category_id'),
|
||||
dataIndex: 'category_id',
|
||||
valueType: 'text',
|
||||
align: 'center',
|
||||
hideInSearch: true,
|
||||
},
|
||||
{
|
||||
title: t('forum.post.content'),
|
||||
dataIndex: 'content',
|
||||
valueType: 'text',
|
||||
hideInTable: true,
|
||||
hideInSearch: true,
|
||||
required: true,
|
||||
rules: [{ required: true, message: t('forum.post.content.required') }],
|
||||
},
|
||||
{
|
||||
title: t('forum.post.view_count'),
|
||||
dataIndex: 'view_count',
|
||||
hideInForm: true,
|
||||
hideInSearch: true,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: t('forum.post.comment_count'),
|
||||
dataIndex: 'comment_count',
|
||||
hideInForm: true,
|
||||
hideInSearch: true,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: t('forum.post.like_count'),
|
||||
dataIndex: 'like_count',
|
||||
hideInForm: true,
|
||||
hideInSearch: true,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: t('forum.post.favorite_count'),
|
||||
dataIndex: 'favorite_count',
|
||||
hideInForm: true,
|
||||
hideInSearch: true,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: t('forum.post.is_hot'),
|
||||
dataIndex: 'is_hot',
|
||||
valueType: 'radioButton',
|
||||
fieldProps: {
|
||||
options: [
|
||||
{ value: 0, label: t('forum.post.is_hot.0') },
|
||||
{ value: 1, label: t('forum.post.is_hot.1') },
|
||||
],
|
||||
},
|
||||
render: (value: number) => {
|
||||
return value === 1
|
||||
? <Tag color="red">{t('forum.post.is_hot.1')}</Tag>
|
||||
: <Tag>{t('forum.post.is_hot.0')}</Tag>;
|
||||
},
|
||||
filters: [
|
||||
{ text: t('forum.post.is_hot.0'), value: 0 },
|
||||
{ text: t('forum.post.is_hot.1'), value: 1 },
|
||||
],
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: t('forum.post.is_top'),
|
||||
dataIndex: 'is_top',
|
||||
valueType: 'radioButton',
|
||||
fieldProps: {
|
||||
options: [
|
||||
{ value: 0, label: t('forum.post.is_top.0') },
|
||||
{ value: 1, label: t('forum.post.is_top.1') },
|
||||
],
|
||||
},
|
||||
render: (value: number) => {
|
||||
return value === 1
|
||||
? <Tag color="blue">{t('forum.post.is_top.1')}</Tag>
|
||||
: <Tag>{t('forum.post.is_top.0')}</Tag>;
|
||||
},
|
||||
filters: [
|
||||
{ text: t('forum.post.is_top.0'), value: 0 },
|
||||
{ text: t('forum.post.is_top.1'), value: 1 },
|
||||
],
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: t('forum.post.status'),
|
||||
dataIndex: 'status',
|
||||
valueType: 'radioButton',
|
||||
fieldProps: {
|
||||
options: [
|
||||
{ value: 0, label: t('forum.post.status.0') },
|
||||
{ value: 1, label: t('forum.post.status.1') },
|
||||
{ value: 2, label: t('forum.post.status.2') },
|
||||
],
|
||||
},
|
||||
render: (value: number) => {
|
||||
const colorMap: Record<number, string> = { 0: 'default', 1: 'success', 2: 'warning' };
|
||||
const labelMap: Record<number, string> = { 0: t('forum.post.status.0'), 1: t('forum.post.status.1'), 2: t('forum.post.status.2') };
|
||||
return <Tag color={colorMap[value] || 'default'}>{labelMap[value] || '-'}</Tag>;
|
||||
},
|
||||
filters: [
|
||||
{ text: t('forum.post.status.0'), value: 0 },
|
||||
{ text: t('forum.post.status.1'), value: 1 },
|
||||
{ text: t('forum.post.status.2'), value: 2 },
|
||||
],
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: t('forum.post.created_at'),
|
||||
hideInForm: true,
|
||||
hideInSearch: true,
|
||||
dataIndex: 'created_at',
|
||||
align: 'center',
|
||||
render: (value: string) => (value ? dayjs(value).fromNow() : '-'),
|
||||
},
|
||||
{
|
||||
title: t('forum.post.updated_at'),
|
||||
hideInForm: true,
|
||||
hideInSearch: true,
|
||||
dataIndex: 'updated_at',
|
||||
align: 'center',
|
||||
render: (value: string) => (value ? dayjs(value).fromNow() : '-'),
|
||||
},
|
||||
];
|
||||
|
||||
const tableProps: XinTableProps<IForumPost> = {
|
||||
api: '/forum/post',
|
||||
columns,
|
||||
rowKey: 'id',
|
||||
accessName: 'forum.post',
|
||||
scroll: { x: 1600 },
|
||||
formProps: {
|
||||
grid: true,
|
||||
colProps: { span: 12 },
|
||||
rowProps: { gutter: [30, 0] },
|
||||
layout: 'vertical',
|
||||
},
|
||||
modalProps: {
|
||||
width: 800,
|
||||
},
|
||||
cardProps: {
|
||||
variant: 'borderless',
|
||||
},
|
||||
pagination: {
|
||||
size: 'small',
|
||||
style: { marginBottom: 0 },
|
||||
},
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="mb-5">
|
||||
<Title level={3}>{t('forum.post.page.title')}</Title>
|
||||
<Text type="secondary">{t('forum.post.page.description')}</Text>
|
||||
</div>
|
||||
<XinTable<IForumPost> {...tableProps} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Table;
|
||||
Reference in New Issue
Block a user