feat(scene): 优化卡片样式、添加编辑和删除功能

master
钟良源 5 months ago
parent f1711ea739
commit 599d37c46d

@ -1,16 +1,45 @@
import React from 'react'; import React from 'react';
import styles from './style/cardWrap.module.less'; import styles from './style/cardWrap.module.less';
import { getImageUrl } from '@/utils/pubUse'; import { getImageUrl } from '@/utils/pubUse';
import { Image } from '@arco-design/web-react'; import { Image, Popconfirm } from '@arco-design/web-react';
import { IconEdit, IconDelete } from '@arco-design/web-react/icon'; import { IconEdit, IconDelete } from '@arco-design/web-react/icon';
interface CardWrapProps { interface CardWrapProps {
item: any; item: any;
onEdit?: (item: any, e: React.MouseEvent) => void;
onDelete?: (item: any, e: React.MouseEvent) => void;
onClick?: (item: any, e: React.MouseEvent) => void;
} }
const CardWrap: React.FC<CardWrapProps> = ({ item }) => { const CardWrap: React.FC<CardWrapProps> = ({ item, onEdit, onDelete, onClick }) => {
const handleEdit = (e: React.MouseEvent) => {
e.stopPropagation();
if (onEdit) {
onEdit(item, e);
}
};
const handleDelete = (e: React.MouseEvent) => {
e.stopPropagation();
};
const handleClick = (e: React.MouseEvent) => {
e.stopPropagation();
if (onClick) {
onClick(item, e);
}
};
const onOk = (e: React.MouseEvent) => {
e.stopPropagation();
// 这里可以添加确认删除的逻辑
if (onDelete) {
onDelete(item, e);
}
};
return ( return (
<div className={styles['card-wrap']}> <div className={styles['card-wrap']} onClick={handleClick}>
<div className={styles['card-header']}> <div className={styles['card-header']}>
<Image <Image
preview={false} preview={false}
@ -29,8 +58,19 @@ const CardWrap: React.FC<CardWrapProps> = ({ item }) => {
<span>{item.createUser}</span> <span>{item.createUser}</span>
</div> </div>
<div className={styles['operation']}> <div className={styles['operation']}>
<IconEdit /> <span className={styles['icon-hover']} onClick={handleEdit}>
<IconDelete /> <IconEdit />
</span>
<Popconfirm
trigger="click"
title="确认删除该工程?"
onOk={(e: React.MouseEvent) => onOk(e)}
onCancel={(e: React.MouseEvent) => e.stopPropagation()}
>
<span className={styles['icon-hover']} onClick={handleDelete}>
<IconDelete />
</span>
</Popconfirm>
</div> </div>
</div> </div>
</div> </div>

@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import styles from './style/engineering.module.less'; import styles from './style/engineering.module.less';
import { Input, Grid, Card, Result, Pagination } from '@arco-design/web-react'; import { Input, Grid, Card, Result, Pagination, Message } from '@arco-design/web-react';
import { IconPlus, IconApps } from '@arco-design/web-react/icon'; import { IconPlus, IconApps } from '@arco-design/web-react/icon';
import { openWindow, OpenWindowOptions } from '@/utils/common'; import { openWindow, OpenWindowOptions } from '@/utils/common';
import { getPublicSceneList, getMySceneList } from '@/api/scene'; import { getPublicSceneList, getMySceneList } from '@/api/scene';
@ -15,17 +15,21 @@ interface EngineeringProps {
showAdd?: boolean, showAdd?: boolean,
} }
const DEFAULT_PAGE_SIZE = 11;
const Engineering: React.FC<EngineeringProps> = ({ dataType, showAdd = true }) => { const Engineering: React.FC<EngineeringProps> = ({ dataType, showAdd = true }) => {
const [searchValue, setSearchValue] = useState<string>(''); const [searchValue, setSearchValue] = useState<string>('');
const [sceneData, setSceneData] = useState({ const [sceneData, setSceneData] = useState({
list: [] list: [],
totalCount: 0
}); });
const [count, setCount] = useState<number>(12); const [currentPage, setCurrentPage] = useState<number>(1);
const [pageSize, setPageSize] = useState<number>(DEFAULT_PAGE_SIZE);
const onSearchHandle = (value: string) => { const onSearchHandle = (value: string) => {
if (!value) return; // 搜索时重置到第一页
console.log('状态值:', searchValue); setCurrentPage(1);
fetchData(1, pageSize, value);
}; };
const handleChange = (value: string) => { const handleChange = (value: string) => {
@ -42,37 +46,57 @@ const Engineering: React.FC<EngineeringProps> = ({ dataType, showAdd = true }) =
openWindow(url, params); openWindow(url, params);
}; };
const handleEdit = (item, e) => {
e.stopPropagation();
Message.info(`编辑项目: ${item.name}`);
// TODO 在这里添加编辑逻辑
};
useEffect(() => { const handleDelete = (item, e) => {
const fetchData = async () => { e.stopPropagation();
console.log('dataType:', dataType); // TODO 在这里添加删除逻辑
// currPage?: number name?: string pageSize?: number console.log("删除");
// getPublicSceneList() };
// getMySceneList()
const functions = { const handlePageChange = (page: number) => {
public: getPublicSceneList, setCurrentPage(page);
my: getMySceneList fetchData(page, pageSize, searchValue);
}; };
const params = {
currPage: 1, const handlePageSizeChange = (size: number) => {
pageSize: 11, setPageSize(size);
name: '' setCurrentPage(1); // 重置到第一页
}; fetchData(1, size, searchValue);
const res: any = await functions[dataType](params); };
if (res.code === 200) {
console.log('res:', res); const fetchData = async (page: number = currentPage, size: number = pageSize, search: string = searchValue) => {
const { data } = res; const functions = {
setSceneData(data); public: getPublicSceneList,
setCount(data.totalCount); my: getMySceneList
} };
const params = {
currPage: page,
pageSize: size,
name: search
}; };
const res: any = await functions[dataType](params);
if (res.code === 200) {
const { data } = res;
setSceneData({
list: data.list || [],
totalCount: data.totalCount || 0
});
}
};
fetchData(); useEffect(() => {
setCurrentPage(1);
fetchData(1, pageSize, searchValue);
}, [dataType]); }, [dataType]);
return ( return (
<> <>
<div className={styles["engineering-container"]}> <div className={styles['engineering-container']}>
{/*搜索*/} {/*搜索*/}
<Row> <Row>
<Col span={24}> <Col span={24}>
@ -100,7 +124,7 @@ const Engineering: React.FC<EngineeringProps> = ({ dataType, showAdd = true }) =
{/*新建工程按钮*/} {/*新建工程按钮*/}
{showAdd && ( {showAdd && (
<Card <Card
className={styles["card-style"]} className={styles['card-style']}
> >
<Result <Result
status="info" status="info"
@ -120,15 +144,28 @@ const Engineering: React.FC<EngineeringProps> = ({ dataType, showAdd = true }) =
lg={6} lg={6}
xl={6} xl={6}
xxl={6}> xxl={6}>
<Card className={styles["card-style"]} hoverable onClick={() => openEngineHandle(item)}> <Card className={styles['card-style']} hoverable>
<CardWrap item={item}></CardWrap> <CardWrap
item={item}
onEdit={handleEdit}
onDelete={handleDelete}
onClick={openEngineHandle}
></CardWrap>
</Card> </Card>
</Col> </Col>
))} ))}
</Row> </Row>
<Row> <Row>
<Col> <Col>
<Pagination style={{ float: 'right' }} total={count} /> <Pagination
style={{ float: 'right' }}
total={sceneData.totalCount}
current={currentPage}
pageSize={pageSize}
showTotal
onChange={handlePageChange}
onPageSizeChange={handlePageSizeChange}
/>
</Col> </Col>
</Row> </Row>
</div> </div>

@ -24,12 +24,28 @@
.card-footer { .card-footer {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
padding: 0 0 15px 12px; padding: 0 12px 15px 12px;
.operation { .operation {
svg { display: flex;
margin-right: 15px; align-items: center;
font-size: 18px;
.icon-hover {
display: flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
border-radius: 50%;
transition: all 0.1s;
svg {
font-size: 18px;
}
}
.icon-hover:hover {
background-color: rgb(var(--gray-2));
} }
} }
} }

Loading…
Cancel
Save