feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import React from 'react';
|
||||
import { ModalForm, ProFormDigit, ProFormSelect, ProFormText } from '@ant-design/pro-components';
|
||||
|
||||
export interface HomeCarouselItem {
|
||||
id?: number;
|
||||
imageUrl?: string;
|
||||
linkUrl?: string;
|
||||
sort?: number;
|
||||
status?: number;
|
||||
}
|
||||
|
||||
export interface HomeCarouselFormProps {
|
||||
open: boolean;
|
||||
title: string;
|
||||
initialValues?: Partial<HomeCarouselItem>;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
onFinish: (values: HomeCarouselItem) => Promise<boolean>;
|
||||
}
|
||||
|
||||
const HomeCarouselForm: React.FC<HomeCarouselFormProps> = ({ open, title, initialValues, onOpenChange, onFinish }) => {
|
||||
return (
|
||||
<ModalForm<HomeCarouselItem>
|
||||
title={title}
|
||||
visible={open}
|
||||
onVisibleChange={onOpenChange}
|
||||
onFinish={onFinish}
|
||||
initialValues={initialValues}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
>
|
||||
<ProFormText name="imageUrl" label="图片地址" rules={[{ required: true, message: '请输入图片地址' }]} />
|
||||
<ProFormText name="linkUrl" label="跳转链接" />
|
||||
<ProFormDigit name="sort" label="排序" min={1} fieldProps={{ precision: 0 }} initialValue={1} />
|
||||
<ProFormSelect name="status" label="状态" valueEnum={{ 1: '启用', 0: '禁用' }} initialValue={1} />
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default HomeCarouselForm;
|
||||
@@ -0,0 +1,96 @@
|
||||
import React, { useState } from 'react';
|
||||
import { PageContainer, ProTable } from '@ant-design/pro-components';
|
||||
import { Popconfirm, Space, Tag, message } from 'antd';
|
||||
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import HomeCarouselForm, { HomeCarouselItem } from './components/HomeCarouselForm';
|
||||
|
||||
const HomeCarouselPage: React.FC = () => {
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [current, setCurrent] = useState<HomeCarouselItem | undefined>(undefined);
|
||||
|
||||
const columns: any[] = [
|
||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
||||
{ title: '图片', dataIndex: 'imageUrl', render: (v: string) => <img src={v} alt="img" style={{ width: 80, height: 40, objectFit: 'cover' }} /> },
|
||||
{ title: '跳转链接', dataIndex: 'linkUrl', ellipsis: true },
|
||||
{ title: '排序', dataIndex: 'sort' },
|
||||
{ title: '状态', dataIndex: 'status', render: (v: number) => <Tag color={v === 1 ? 'green' : 'default'}>{v === 1 ? '启用' : '禁用'}</Tag> },
|
||||
{
|
||||
title: '操作', key: 'action',
|
||||
render: (_: any, record: HomeCarouselItem) => (
|
||||
<Space>
|
||||
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
|
||||
<Popconfirm title={`确认删除?`} onConfirm={async () => {
|
||||
const hide = message.loading('删除中...');
|
||||
try {
|
||||
await ordersApi.deleteHomeCarousel(record.id!);
|
||||
message.success('删除成功');
|
||||
} catch (e) {
|
||||
message.error('删除失败');
|
||||
} finally { hide(); }
|
||||
}}>
|
||||
<a style={{ color: '#1677ff' }}>删除</a>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '首页轮播' }}>
|
||||
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => { /* 切换后后端生效 */ }} />
|
||||
|
||||
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
|
||||
|
||||
<GlassCard>
|
||||
<ProTable<HomeCarouselItem>
|
||||
rowKey="id"
|
||||
request={(p) => ordersApi.homeCarouselList(p as any)}
|
||||
columns={columns}
|
||||
search={false}
|
||||
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
||||
/>
|
||||
</GlassCard>
|
||||
|
||||
<HomeCarouselForm
|
||||
title="新增轮播"
|
||||
open={createOpen}
|
||||
onOpenChange={setCreateOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('保存中...');
|
||||
try {
|
||||
await ordersApi.saveOrUpdateHomeCarousel(values);
|
||||
message.success('新增成功');
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('保存失败');
|
||||
return false;
|
||||
} finally { hide(); }
|
||||
}}
|
||||
/>
|
||||
|
||||
<HomeCarouselForm
|
||||
title="编辑轮播"
|
||||
open={editOpen}
|
||||
initialValues={current}
|
||||
onOpenChange={setEditOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('保存中...');
|
||||
try {
|
||||
await ordersApi.saveOrUpdateHomeCarousel({ ...(current as any), ...values });
|
||||
message.success('修改成功');
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('修改失败');
|
||||
return false;
|
||||
} finally { hide(); }
|
||||
}}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default HomeCarouselPage;
|
||||
|
||||
Reference in New Issue
Block a user