Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoubichuan committed Nov 2, 2023
1 parent 06da2f5 commit e94b189
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion config/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
{
name: '项目',
icon: 'smile',
path: '/list/search/projects/1',
path: '/list/search/projects',
},
{
path: '/list/search/projects/:id',
Expand Down
7 changes: 7 additions & 0 deletions src/pages/list/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ const TableList: React.FC = () => {
}
}
setTemplateData(template);
if (location.href.includes('id')) {
const arr = location.href.split('?id=');
const id: string = arr[arr.length - 1];
const result = await list({ current: 1, pageSize: 1 }, { id });
setCurrentRow(result.data[0]);
setShowDetail(true);
}
};
useEffect(() => {
getTemplateData(params.id);
Expand Down
36 changes: 20 additions & 16 deletions src/pages/list/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ type SearchProps = {
const Search: FC<SearchProps> = (props) => {
const path: string = location.pathname.replace('/antdpro-demo', '');
const [templateData, setTemplateData] = useState<any>([]);
const getTabKey = () => {
const { match, location } = props;
const url = match.path === '/' ? '' : match.path;
const tabKey = location.pathname.replace(`${url}/`, '');
if (tabKey.includes('articles')) {
return 'articles';
}
if (tabKey.includes('projects')) {
return 'projects';
}
if (tabKey.includes('applications')) {
return 'applications';
}
};
const [activeKey, setActiveKey] = useState<string>('');
const getTemplateData = async () => {
let template: any = [];
const result = await list('type/1', {
Expand All @@ -26,6 +41,9 @@ const Search: FC<SearchProps> = (props) => {
});
template = result.data;
setTemplateData(template);
if (!activeKey) {
setActiveKey(getTabKey() + '/' + template[0].value);
}
};
useEffect(() => {
getTemplateData();
Expand All @@ -34,27 +52,13 @@ const Search: FC<SearchProps> = (props) => {
const { match } = props;
const url = match.url === '/' ? '' : match.url;
history.push(`${url}/${key}`);
setActiveKey(getTabKey() + '/' + key);
};

const handleFormSubmit = (value: string) => {
console.log(value);
};

const getTabKey = () => {
const { match, location } = props;
const url = match.path === '/' ? '' : match.path;
const tabKey = location.pathname.replace(`${url}/`, '');
if (tabKey.includes('articles')) {
return 'articles';
}
if (tabKey.includes('projects')) {
return 'projects';
}
if (tabKey.includes('applications')) {
return 'applications';
}
};

return (
<PageContainer
content={
Expand All @@ -72,7 +76,7 @@ const Search: FC<SearchProps> = (props) => {
key: getTabKey() + '/' + item.value,
tab: item.name,
}))}
tabActiveKey={getTabKey()}
tabActiveKey={activeKey}
onTabChange={handleTabChange}
>
{props.children}
Expand Down
36 changes: 14 additions & 22 deletions src/pages/list/search/projects/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Card, Col, Form, List, Row, Select, Typography } from 'antd';
import moment from 'moment';
import type { FC } from 'react';
import { useRequest, Link } from 'umi';
import AvatarList from './components/AvatarList';
import StandardFormRow from './components/StandardFormRow';
import TagSelect from './components/TagSelect';
import type { ListItemDataType } from './data.d';
Expand All @@ -14,8 +13,6 @@ const { Option } = Select;
const FormItem = Form.Item;
const { Paragraph } = Typography;

const getKey = (id: string, index: number) => `${id}-${index}`;

const Projects: FC = () => {
const path: string = location.pathname.replace('/antdpro-demo', '');
const [templateData, setTemplateData] = useState<any>([]);
Expand Down Expand Up @@ -112,21 +109,27 @@ const Projects: FC = () => {
rowKey="id"
grid={{
gutter: 16,
xs: 1,
sm: 2,
md: 3,
lg: 3,
xl: 4,
xxl: 4,
xs: 2,
sm: 4,
md: 6,
lg: 6,
xl: 8,
xxl: 8,
}}
dataSource={lists}
renderItem={(item: any) => (
<List.Item>
<Link to={`/list/data/1?type=${item.type}`} target="_blank">
<Link to={`/list/data/1?id=${item.id}`} target="_blank">
<Card
className={styles.card}
hoverable
cover={<img alt={item.name} src={item.images[0]} />}
cover={
<img
style={{ height: '250px', objectFit: 'contain' }}
alt={item.name}
src={item.images[0]}
/>
}
>
<Card.Meta
title={<a>{item.name}</a>}
Expand All @@ -138,17 +141,6 @@ const Projects: FC = () => {
/>
<div className={styles.cardItemContent}>
<span>{moment(item.updatedAt).fromNow()}</span>
<div className={styles.avatarList}>
<AvatarList size="small">
{item.members?.map((member, i) => (
<AvatarList.Item
key={getKey(item.id, i)}
src={member.avatar}
tips={member.name}
/>
))}
</AvatarList>
</div>
</div>
</Card>
</Link>
Expand Down

0 comments on commit e94b189

Please sign in to comment.