From 808d3392fdd30e0bcfc5fc5e98aa37204221f02c Mon Sep 17 00:00:00 2001 From: Yufeng Cheng <1351416566@qq.com> Date: Thu, 9 Nov 2023 01:15:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B0=8F=E9=B1=BC=E5=B9=B2=E5=88=97?= =?UTF-8?q?=E8=A1=A8/=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.ts | 10 ++ src/pages/CommunityAdmin/DriedFish/index.tsx | 140 ++++++++++++++++++ .../CommunityAdmin/DriedFish/settings.tsx | 75 ++++++++++ src/pages/Welcome/index.tsx | 26 +++- src/requestErrorConfig.ts | 8 +- src/services/dried-fish.ts | 66 +++++++++ 6 files changed, 323 insertions(+), 2 deletions(-) create mode 100644 src/pages/CommunityAdmin/DriedFish/index.tsx create mode 100644 src/pages/CommunityAdmin/DriedFish/settings.tsx create mode 100644 src/services/dried-fish.ts diff --git a/config/routes.ts b/config/routes.ts index f178922..4b973f7 100644 --- a/config/routes.ts +++ b/config/routes.ts @@ -60,6 +60,11 @@ export default [ path: '/community-admin/carousel', component: './Carousel', }, + { + name: '小鱼干计划管理', + path: '/community-admin/dried-fish', + component: './CommunityAdmin/DriedFish', + }, ], }, { @@ -103,6 +108,11 @@ export default [ path: '/super-admin/super-admin', component: './SuperAdmin/SuperAdmin', }, + { + name: '小鱼干计划管理', + path: '/super-admin/dried-fish', + component: './CommunityAdmin/DriedFish', + }, ], }, { diff --git a/src/pages/CommunityAdmin/DriedFish/index.tsx b/src/pages/CommunityAdmin/DriedFish/index.tsx new file mode 100644 index 0000000..daa165f --- /dev/null +++ b/src/pages/CommunityAdmin/DriedFish/index.tsx @@ -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(); + // 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: () => ( + <> + + + + + + ), + }, + ]; + + return ( + + {access === 'superAdmin' ? : <>} + + headerTitle="小鱼干计划信息" + actionRef={actionRef} + rowKey="id" + search={false} + toolBarRender={() => [ + , + ]} + request={requestTable} + columns={columns} + pagination={{ + pageSize: 20, + }} + /> + {/* + + */} + + ); +}; + +export default DriedFish; diff --git a/src/pages/CommunityAdmin/DriedFish/settings.tsx b/src/pages/CommunityAdmin/DriedFish/settings.tsx new file mode 100644 index 0000000..130c292 --- /dev/null +++ b/src/pages/CommunityAdmin/DriedFish/settings.tsx @@ -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) => {transferType(_)}, +}; + +export const PLAN_PROGRESS: ProColumns = { + title: '计划进度', + dataIndex: 'planType', + hideInSearch: true, + render: (_, record) => ( +
+ +
+ ), +}; + +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, + }, +]; diff --git a/src/pages/Welcome/index.tsx b/src/pages/Welcome/index.tsx index d05c982..74598d7 100644 --- a/src/pages/Welcome/index.tsx +++ b/src/pages/Welcome/index.tsx @@ -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 ( { + {access === 'superAdmin' && ( + <> + + + + + + + + )} ); }; diff --git a/src/requestErrorConfig.ts b/src/requestErrorConfig.ts index d11eddb..494dff5 100644 --- a/src/requestErrorConfig.ts +++ b/src/requestErrorConfig.ts @@ -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 }; }, ], diff --git a/src/services/dried-fish.ts b/src/services/dried-fish.ts new file mode 100644 index 0000000..61ba00b --- /dev/null +++ b/src/services/dried-fish.ts @@ -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 || {}), +// }); +// };