feat: 航线管理页面优化
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { PageContainer, ProTable, QueryFilter, ProFormText, ProFormSelect } from '@ant-design/pro-components';
|
||||
import { Popconfirm, message, Typography, Image as AntImage } from 'antd';
|
||||
import { PageContainer, ProTable, ProFormText, ProFormSelect } from '@ant-design/pro-components';
|
||||
import { Popconfirm, message, Space, Image as AntImage, Typography } from 'antd';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import HomeCarouselForm from './components/HomeCarouselForm';
|
||||
import CreateForm from './components/CreateForm';
|
||||
import type { HomeCarouselItem } from './components/HomeCarouselForm';
|
||||
import styles from './index.less';
|
||||
import type { HomeCarouselItem } from './components/CreateForm';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
@@ -25,8 +24,7 @@ const TYPE_OPTIONS = [
|
||||
|
||||
const HomeCarouselPage: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [formOpen, setFormOpen] = useState(false);
|
||||
const [current, setCurrent] = useState<HomeCarouselItem | undefined>(undefined);
|
||||
const [searchParams, setSearchParams] = useState<Record<string, any>>({});
|
||||
|
||||
@@ -58,30 +56,6 @@ const HomeCarouselPage: React.FC = () => {
|
||||
ellipsis: true,
|
||||
copyable: true,
|
||||
},
|
||||
{
|
||||
title: '图片',
|
||||
dataIndex: 'imageUrl',
|
||||
width: 120,
|
||||
render: (imageUrl: string) => (
|
||||
<AntImage
|
||||
src={imageUrl}
|
||||
width={100}
|
||||
placeholder={
|
||||
<div style={{ background: '#f5f5f5', height: 100, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||
加载中...
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '跳转链接',
|
||||
dataIndex: 'linkUrl',
|
||||
ellipsis: true,
|
||||
render: (url: string) => (
|
||||
url ? <Link href={url} target="_blank">{url}</Link> : '-'
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '类型',
|
||||
dataIndex: 'type',
|
||||
@@ -91,6 +65,34 @@ const HomeCarouselPage: React.FC = () => {
|
||||
[curr.value]: { text: curr.label },
|
||||
}), {}),
|
||||
},
|
||||
{
|
||||
title: '图片',
|
||||
dataIndex: 'imageUrl',
|
||||
width: 120,
|
||||
render: (_: any, record: HomeCarouselItem) => (
|
||||
record.imageUrl ? (
|
||||
<AntImage
|
||||
src={record.imageUrl}
|
||||
width={100}
|
||||
placeholder={
|
||||
<div style={{ background: '#f5f5f5', height: 100, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||
加载中...
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<span>-</span>
|
||||
)
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '跳转链接',
|
||||
dataIndex: 'redirectUrl',
|
||||
ellipsis: true,
|
||||
render: (_: any, record: HomeCarouselItem) => (
|
||||
record.linkUrl ? <Link href={record.linkUrl} target="_blank">{record.linkUrl}</Link> : '-'
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'description',
|
||||
@@ -98,7 +100,7 @@ const HomeCarouselPage: React.FC = () => {
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
dataIndex: 'sort',
|
||||
dataIndex: 'sortOrder',
|
||||
width: 80,
|
||||
},
|
||||
{
|
||||
@@ -115,117 +117,106 @@ const HomeCarouselPage: React.FC = () => {
|
||||
valueType: 'option',
|
||||
width: 180,
|
||||
fixed: 'right',
|
||||
render: (_, record) => [
|
||||
<a
|
||||
key="edit"
|
||||
onClick={() => {
|
||||
console.log('编辑按钮被点击', record);
|
||||
setCurrent(record);
|
||||
setEditOpen(true);
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</a>,
|
||||
<Popconfirm
|
||||
key="delete"
|
||||
title="确认删除?"
|
||||
description="删除后将无法恢复,请谨慎操作"
|
||||
onConfirm={() => handleDelete(record)}
|
||||
okText="确认"
|
||||
cancelText="取消"
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>,
|
||||
],
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<a
|
||||
onClick={() => {
|
||||
setCurrent(record);
|
||||
setFormOpen(true);
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</a>
|
||||
<Popconfirm
|
||||
title="确认删除轮播图?"
|
||||
onConfirm={() => handleDelete(record)}
|
||||
okText="确认"
|
||||
cancelText="取消"
|
||||
>
|
||||
<a style={{ color: '#1677ff' }}>删除</a>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<QueryFilter
|
||||
defaultCollapsed={false}
|
||||
split
|
||||
span={8}
|
||||
className={styles['query-filter']}
|
||||
onFinish={async (values) => {
|
||||
setSearchParams(values);
|
||||
actionRef.current?.reload();
|
||||
}}
|
||||
style={{ marginBottom: 16 }}
|
||||
>
|
||||
<ProFormText
|
||||
name="title"
|
||||
label="标题"
|
||||
placeholder="请输入标题关键字"
|
||||
fieldProps={{
|
||||
allowClear: true,
|
||||
}}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="status"
|
||||
label="状态"
|
||||
placeholder="请选择状态"
|
||||
options={STATUS_OPTIONS}
|
||||
fieldProps={{
|
||||
allowClear: true,
|
||||
}}
|
||||
/>
|
||||
</QueryFilter>
|
||||
<PageContainer header={{ title: '轮播图管理' }}>
|
||||
{/*<SearchBarPlus*/}
|
||||
{/* defaultCollapsed*/}
|
||||
{/* split*/}
|
||||
{/* span={8}*/}
|
||||
{/* hideReset*/}
|
||||
{/* showTenant={false}*/}
|
||||
{/* onFinish={async (values) => {*/}
|
||||
{/* setSearchParams(values);*/}
|
||||
{/* actionRef.current?.reload();*/}
|
||||
{/* }}*/}
|
||||
{/*>*/}
|
||||
{/* <ProFormText*/}
|
||||
{/* name="title"*/}
|
||||
{/* label="标题"*/}
|
||||
{/* placeholder="请输入标题关键字"*/}
|
||||
{/* />*/}
|
||||
{/* <ProFormSelect*/}
|
||||
{/* name="status"*/}
|
||||
{/* label="状态"*/}
|
||||
{/* placeholder="请选择状态"*/}
|
||||
{/* options={STATUS_OPTIONS}*/}
|
||||
{/* fieldProps={{*/}
|
||||
{/* allowClear: true,*/}
|
||||
{/* }}*/}
|
||||
{/* />*/}
|
||||
{/*</SearchBarPlus>*/}
|
||||
|
||||
<ProTable<HomeCarouselItem>
|
||||
rowKey="id"
|
||||
headerTitle="轮播图列表"
|
||||
actionRef={actionRef}
|
||||
columns={columns}
|
||||
request={(p) => ordersApi.homeCarousel({ ...(p as any), ...searchParams })}
|
||||
search={false}
|
||||
pagination={{
|
||||
defaultPageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
toolBarRender={() => [
|
||||
<a
|
||||
key="add"
|
||||
onClick={() => {
|
||||
console.log('新增按钮被点击');
|
||||
setCreateOpen(true);
|
||||
}}
|
||||
style={{ color: '#1890ff', cursor: 'pointer' }}
|
||||
>
|
||||
<PlusOutlined /> 新增轮播图
|
||||
</a>,
|
||||
]}
|
||||
<ActionBar
|
||||
left={
|
||||
<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => {
|
||||
setCurrent(undefined);
|
||||
setFormOpen(true);
|
||||
}}>
|
||||
新增轮播图
|
||||
</GradientButton>
|
||||
}
|
||||
/>
|
||||
|
||||
<GlassCard>
|
||||
<ProTable<HomeCarouselItem>
|
||||
rowKey="id"
|
||||
actionRef={actionRef}
|
||||
columns={columns}
|
||||
request={(p) => ordersApi.homeCarousel({ ...(p as any), ...searchParams })}
|
||||
search={false}
|
||||
pagination={{
|
||||
defaultPageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
toolBarRender={false}
|
||||
/>
|
||||
</GlassCard>
|
||||
|
||||
<CreateForm
|
||||
open={createOpen}
|
||||
onOpenChange={setCreateOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('保存中...');
|
||||
try {
|
||||
await ordersApi.saveOrUpdateHomeCarousel(values);
|
||||
message.success('新增成功');
|
||||
actionRef.current?.reload();
|
||||
return true;
|
||||
} catch (e) {
|
||||
message.error('保存失败');
|
||||
return false;
|
||||
} finally {
|
||||
hide();
|
||||
open={formOpen}
|
||||
initialValues={current}
|
||||
onOpenChange={(visible) => {
|
||||
setFormOpen(visible);
|
||||
if (!visible) {
|
||||
setCurrent(undefined);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
<HomeCarouselForm
|
||||
open={editOpen}
|
||||
initialValues={current}
|
||||
onOpenChange={setEditOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading('保存中...');
|
||||
try {
|
||||
await ordersApi.saveOrUpdateHomeCarousel({ ...(current as any), ...values });
|
||||
message.success('修改成功');
|
||||
if (current?.id) {
|
||||
// 编辑模式
|
||||
await ordersApi.saveOrUpdateHomeCarousel({ ...(current as any), ...values });
|
||||
message.success('修改成功');
|
||||
} else {
|
||||
// 新增模式
|
||||
await ordersApi.saveOrUpdateHomeCarousel(values);
|
||||
message.success('新增成功');
|
||||
}
|
||||
actionRef.current?.reload();
|
||||
return true;
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user