Skip to content

Commit

Permalink
feat: 小鱼干列表/测试环境
Browse files Browse the repository at this point in the history
  • Loading branch information
JavanCheng committed Nov 8, 2023
1 parent 83cca58 commit 808d339
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 2 deletions.
10 changes: 10 additions & 0 deletions config/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export default [
path: '/community-admin/carousel',
component: './Carousel',
},
{
name: '小鱼干计划管理',
path: '/community-admin/dried-fish',
component: './CommunityAdmin/DriedFish',
},
],
},
{
Expand Down Expand Up @@ -103,6 +108,11 @@ export default [
path: '/super-admin/super-admin',
component: './SuperAdmin/SuperAdmin',
},
{
name: '小鱼干计划管理',
path: '/super-admin/dried-fish',
component: './CommunityAdmin/DriedFish',
},
],
},
{
Expand Down
140 changes: 140 additions & 0 deletions src/pages/CommunityAdmin/DriedFish/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import CommunitySelector from '@/components/CommunitySelector';
import { fetchDriedFishList } from '@/services/dried-fish';
import { PlusOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { PageContainer, ProTable } from '@ant-design/pro-components';
import { Button } from 'antd';
import { useRef } from 'react';
import { OPERATIONS } from '@/pages/commonSettings';
// import Create from './components/Create';
// import Delete from './components/Delete';
// import Edit from './components/Edit';
import { CAROUSEL_COLUMNS } from './settings';

const DriedFish: React.FC = () => {
const actionRef = useRef<ActionType>();
// const [currentCarousel, setCurrentCarousel] = useState({});
// const [createVisible, setCreateVisible] = useState(false);
// const [deleteVisible, setDeleteVisible] = useState(false);
// const [editVisible, setEditVisible] = useState(false);

const requestTable = async (
params: any & {
pageSize: number;
current: number;
},
) => {
const data = await fetchDriedFishList({
...params,
page: params.current - 1,
});
return {
data: data.plans,
success: true,
total: data.total,
};
};

const access = localStorage.getItem('access');

const columns: ProColumns[] = [
...CAROUSEL_COLUMNS,
{
...OPERATIONS,
width: 200,
render: () => (
<>
<Button
type="link"
size="small"
key="complete"
onClick={() => {
// setCurrentCarousel(record);
// setEditVisible(true);
}}
>
完成计划
</Button>
<Button
type="link"
size="small"
key="detail"
onClick={() => {
// setCurrentCarousel(record);
// setEditVisible(true);
}}
>
详情
</Button>
<Button
type="link"
size="small"
key="edit"
onClick={() => {
// setCurrentCarousel(record);
// setEditVisible(true);
}}
>
编辑
</Button>
<Button
type="link"
size="small"
danger
key="delete"
onClick={() => {
// setCurrentCarousel(record);
// setDeleteVisible(true);
}}
>
删除
</Button>
</>
),
},
];

return (
<PageContainer>
{access === 'superAdmin' ? <CommunitySelector actionRef={actionRef} /> : <></>}
<ProTable<API.RuleListItem, API.PageParams>
headerTitle="小鱼干计划信息"
actionRef={actionRef}
rowKey="id"
search={false}
toolBarRender={() => [
<Button
type="primary"
key="primary"
onClick={() => {
// setCreateVisible(true);
}}
>
<PlusOutlined />
新建
</Button>,
]}
request={requestTable}
columns={columns}
pagination={{
pageSize: 20,
}}
/>
{/* <Create open={createVisible} setCreateVisible={setCreateVisible} actionRef={actionRef} />
<Delete
open={deleteVisible}
setDeleteVisible={setDeleteVisible}
actionRef={actionRef}
currentCarousel={currentCarousel}
/>
<Edit
open={editVisible}
setEditVisible={setEditVisible}
actionRef={actionRef}
currentCarousel={currentCarousel}
/> */}
</PageContainer>
);
};

export default DriedFish;
75 changes: 75 additions & 0 deletions src/pages/CommunityAdmin/DriedFish/settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { NAME, USER } from '@/pages/commonSettings';
import type { ProColumns } from '@ant-design/pro-components';
import { Progress, Tag } from 'antd';

const MAX_ORDER = 10;

const transferType = (type: number) => {
let newType;
switch (type) {
case 0:
newType = '加餐';
break;
case 1:
newType = '绝育';
break;
case 2:
newType = '治病';
break;
case 3:
newType = '其他';
break;
default:
newType = '';
}
return newType;
};

const PLAN_COLOR = new Map([
[0, '#108ee9'],
[1, '#f50'],
[2, '#87d068'],
[3, 'default'],
]);

export const PLAN_TYPE: ProColumns = {
title: '计划类型',
dataIndex: 'planType',
hideInSearch: true,
render: (_: any) => <Tag color={PLAN_COLOR.get(_)}>{transferType(_)}</Tag>,
};

export const PLAN_PROGRESS: ProColumns = {
title: '计划进度',
dataIndex: 'planType',
hideInSearch: true,
render: (_, record) => (
<div style={{ paddingRight: 20 }}>
<Progress percent={record.nowFish / record.maxFish} size="small" />
</div>
),
};

export const CAROUSEL_COLUMNS = [
{
order: MAX_ORDER + 8,
...NAME,
title: '计划名',
width: 80,
},
{
order: MAX_ORDER + 6,
...PLAN_TYPE,
width: 50,
},
{
order: MAX_ORDER + 4,
...PLAN_PROGRESS,
width: 180,
},
{
order: MAX_ORDER + 2,
...USER,
width: 100,
},
];
26 changes: 25 additions & 1 deletion src/pages/Welcome/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { PageContainer } from '@ant-design/pro-components';
import { Card } from 'antd';
import { Button, Card, Space } from 'antd';
import React from 'react';

const Welcome: React.FC = () => {
const access = localStorage.getItem('access') || '';

const redirectProd = () => {
localStorage.removeItem('environment');
};

const redirectTest = () => {
localStorage.setItem('environment', 'test');
};

return (
<PageContainer>
<Card
Expand Down Expand Up @@ -33,6 +43,20 @@ const Welcome: React.FC = () => {
</div>
</div>
</Card>
{access === 'superAdmin' && (
<>
<Card>
<Space>
<Button onClick={redirectProd} type="primary">
生产环境
</Button>
<Button onClick={redirectTest} type="primary">
测试环境
</Button>
</Space>
</Card>
</>
)}
</PageContainer>
);
};
Expand Down
8 changes: 7 additions & 1 deletion src/requestErrorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ export const errorConfig: RequestConfig = {
requestInterceptors: [
(config: RequestOptions) => {
// 拦截请求配置,进行个性化处理。
const headers = { ...config?.headers, Authorization: getAccessToken() }
const headers = { ...config?.headers, Authorization: getAccessToken() };
if (location.search === '?environment=test') {
localStorage.setItem('environment', 'test');
}
if (localStorage.getItem('environment') === 'test') {
headers['x-xh-env'] = 'test';
}
return { ...config, headers };
},
],
Expand Down
66 changes: 66 additions & 0 deletions src/services/dried-fish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { request } from '@umijs/max';
import { DEFAULT_URL } from '.';

/**
* 获取轮播图列表
* @param params
* @returns
*/
export const fetchDriedFishList = async (
params: {
page?: number;
},
options?: { [key: string]: any },
) =>
request(`${DEFAULT_URL}/plan/get_plan_previews`, {
method: 'GET',
params: {
...params,
},
...(options || {}),
});

/**
* 新增轮播图
* @param params
* @returns
*/
// export const createCarousel = async (data: any, options?: { [key: string]: any }) => {
// return request(`${DEFAULT_URL}/notice/new_news`, {
// method: 'POST',
// data: {
// ...data,
// },
// ...(options || {}),
// });
// };

/**
* 删除轮播图
* @param params
* @returns
*/
// export const deleteCarousel = async (data: any, options?: { [key: string]: any }) => {
// return request(`${DEFAULT_URL}/notice/remove_news`, {
// method: 'POST',
// data: {
// ...data,
// },
// ...(options || {}),
// });
// };

/**
* 编辑轮播图
* @param params
* @returns
*/
// export const editCarousel = async (data: any, options?: { [key: string]: any }) => {
// return request(`${DEFAULT_URL}/notice/new_news`, {
// method: 'POST',
// data: {
// ...data,
// },
// ...(options || {}),
// });
// };

0 comments on commit 808d339

Please sign in to comment.