From beac9835d464ef0922f5e232c7db139ed014154d Mon Sep 17 00:00:00 2001 From: JavanCheng <51914311+JavanCheng@users.noreply.github.com> Date: Wed, 28 Dec 2022 01:24:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=8C=AB=E5=92=AA=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=AF=A6=E6=83=85=20(#2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CatMessage/components/View/index.tsx | 59 +++++++++++++++++++ src/pages/CatMessage/index.tsx | 50 ++++++++++------ src/pages/CatMessage/settings.tsx | 13 ++-- src/pages/commonSettings.tsx | 2 +- src/services/auth.ts | 40 ++++++++----- src/services/cat.ts | 21 ++++++- 6 files changed, 144 insertions(+), 41 deletions(-) create mode 100644 src/pages/CatMessage/components/View/index.tsx diff --git a/src/pages/CatMessage/components/View/index.tsx b/src/pages/CatMessage/components/View/index.tsx new file mode 100644 index 0000000..cc4fcba --- /dev/null +++ b/src/pages/CatMessage/components/View/index.tsx @@ -0,0 +1,59 @@ +import { formatTime } from '@/scripts/utils'; +import { fetchCurrentCatInfo } from '@/services/cat'; +import { Avatar, Descriptions, Modal } from 'antd'; +import { useEffect, useState } from 'react'; + +const View = ({ open, setViewVisible, currentCat }: any) => { + const [data, setData] = useState({}); + + const handleOk = () => { + setViewVisible(false); + }; + + const handleCancel = () => { + setViewVisible(false); + }; + + useEffect(() => { + if (open) { + fetchCurrentCatInfo({ catId: currentCat }).then((res) => setData(res)); + } + }, [open]); + + const { cat } = data; + const { + age, + area, + avatars, + color, + createAt, + details, + // isSnipped, + isSterilized, + name, + popularity, + sex, + // status, + } = cat; + + return ( + + + + + + {name ?? ''} + {color ?? ''} + {age ?? ''} + {sex ?? ''} + {area ?? ''} + {popularity ?? ''} + {isSterilized ?? '' ? '是' : '否'} + {formatTime(createAt ?? '')} + {details ?? ''} + + + ); +}; + +export default View; diff --git a/src/pages/CatMessage/index.tsx b/src/pages/CatMessage/index.tsx index cc309e1..b6f74ee 100644 --- a/src/pages/CatMessage/index.tsx +++ b/src/pages/CatMessage/index.tsx @@ -2,9 +2,10 @@ import { fetchCatList } from '@/services/cat'; import { PlusOutlined } from '@ant-design/icons'; import type { ActionType, ProColumns } from '@ant-design/pro-components'; import { FooterToolbar, PageContainer, ProTable } from '@ant-design/pro-components'; -import { Button, Space } from 'antd'; +import { Button } from 'antd'; import React, { useRef, useState } from 'react'; import { OPERATIONS } from '../commonSettings'; +import View from './components/View'; import { CAT_MESSAGE_COLUMNS } from './settings'; // const handleAdd = async (fields: API.RuleListItem) => { @@ -14,19 +15,11 @@ const handleRemove = async (selectedRows: API.RuleListItem[]) => { console.log(selectedRows); }; -export type CatMessageItems = { - key: number; - cat_name: string; - create_by: string; - update_by: string; - date_at: number; - cat_status: number; - content_collect: string; -}; - const CatMessage: React.FC = () => { const actionRef = useRef(); const [selectedRowsState, setSelectedRows] = useState([]); + const [currentCat, setCurrentCat] = useState(''); + const [viewVisible, setViewVisible] = useState(false); const fetchCommunityInfo = () => { return '637ce159b15d9764c31f9c84'; @@ -54,12 +47,34 @@ const CatMessage: React.FC = () => { ...CAT_MESSAGE_COLUMNS, { ...OPERATIONS, - render: () => ( - - 编辑 - 查看 - 删除 - + render: (_, record) => ( + <> + + + + ), }, ]; @@ -87,6 +102,7 @@ const CatMessage: React.FC = () => { }, }} /> + {selectedRowsState?.length > 0 && ( , }; export const COLOR: ProColumns = { - title: '颜色', + title: '花色', dataIndex: 'color', hideInSearch: true, }; @@ -50,8 +51,8 @@ export const CAT_MESSAGE_COLUMNS = [ order: MAX_ORDER - 4, ...AREA, }, - { - order: MAX_ORDER - 2, - ...IS_COLLECTED, - }, + // { + // order: MAX_ORDER - 2, + // ...IS_COLLECTED, + // }, ]; diff --git a/src/pages/commonSettings.tsx b/src/pages/commonSettings.tsx index e1aa757..afe23e6 100644 --- a/src/pages/commonSettings.tsx +++ b/src/pages/commonSettings.tsx @@ -20,7 +20,7 @@ export const OPERATIONS: ProColumns = { }; export const NAME: ProColumns = { - title: '名称', + title: '昵称', dataIndex: 'name', }; diff --git a/src/services/auth.ts b/src/services/auth.ts index 061fa58..814f402 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -2,24 +2,32 @@ import { request } from '@umijs/max'; const DEFAULT_URL = 'https://meowchat.xhpolaris.com'; -/** 获取当前的用户 GET /user/get_user_info */ +/** + * 获取当前的用户 + * @param params + * @returns + */ export async function currentUser(options?: { [key: string]: any }) { - return request<{ - user: API.CurrentUser; - }>(`${DEFAULT_URL}/user/get_user_info`, { - method: 'GET', - ...(options || {}), - }); + return request<{ + user: API.CurrentUser; + }>(`${DEFAULT_URL}/user/get_user_info`, { + method: 'GET', + ...(options || {}), + }); } -/** 登录接口 POST /auth/sign_in */ +/** + * 登录接口 + * @param params + * @returns + */ export async function login(body: API.LoginParams, options?: { [key: string]: any }) { - return request(`${DEFAULT_URL}/auth/sign_in`, { - method: 'POST', - data: { - ...body, - authType: 'email', - }, - ...(options || {}), - }); + return request(`${DEFAULT_URL}/auth/sign_in`, { + method: 'POST', + data: { + ...body, + authType: 'email', + }, + ...(options || {}), + }); } diff --git a/src/services/cat.ts b/src/services/cat.ts index 445e328..202e486 100644 --- a/src/services/cat.ts +++ b/src/services/cat.ts @@ -20,7 +20,26 @@ export const fetchCatList = async ( params: { ...params, page: (params.current || 1) - 1, - // communityId: '637ce159b15d9764c31f9c84' }, ...(options || {}), }); + +/** + * 获取猫咪具体信息 + * @param params + * @returns + */ +export const fetchCurrentCatInfo = async ( + params: { + catId: string; + }, + options?: { [key: string]: any }, +) => { + return request(`${DEFAULT_URL}/collection/get_cat_detail`, { + method: 'GET', + params: { + ...params, + }, + ...(options || {}), + }); +};