import { DownOutlined, PlusOutlined } from '@ant-design/icons'; import { PageContainer } from '@ant-design/pro-components'; import { history, useRequest } from '@umijs/max'; import { Avatar, Button, Card, Dropdown, Input, List, Modal } from 'antd'; import type { FC } from 'react'; import React, { useState } from 'react'; import OperationModal from './components/OperationModal'; import type { StoryType } from './data.d'; import { addStory, deleteStory, queryTimelineList, updateStory } from './service'; import useStyles from './style.style'; import AuthorizeStoryModal from './components/AuthorizeStoryModal'; import {judgePermission} from "@/pages/story/utils/utils"; const { Search } = Input; const ListContent = ({ data: { storyTime, updateTime, updateName, ownerName, itemCount }, }: { data: StoryType; }) => { const { styles } = useStyles(); return (
创建人

{ownerName}

最近更新人

{updateName ?? ownerName}

节点数

{itemCount}

故事时间

{storyTime}

更新时间

{updateTime}

); }; export const BasicList: FC = () => { const { styles } = useStyles(); const [done, setDone] = useState(false); const [open, setVisible] = useState(false); const [authorizeModelOpen, setAuthorizeModelOpen] = useState(false); const [current, setCurrent] = useState | undefined>(undefined); const { data: listData, loading, run, } = useRequest((storyName?: string) => { return queryTimelineList({ count: 50, storyName, }); }); const { run: postRun } = useRequest( (method, params) => { if (method === 'remove') { return deleteStory(params); } if (method === 'update') { return updateStory(params); } return addStory(params); }, { manual: true, onSuccess: () => { run(); }, }, ); const list = listData || []; const paginationProps = { showSizeChanger: true, showQuickJumper: true, pageSize: 5, total: list.length, }; const showEditModal = (item: StoryType) => { setVisible(true); setCurrent(item); }; const deleteItem = (id: string) => { postRun('remove', { instanceId: id, }); }; const editAndDelete = (key: string | number, currentItem: StoryType) => { console.log(currentItem); if (key === 'edit') showEditModal(currentItem); else if (key === 'delete') { Modal.confirm({ title: '删除故事', content: '确定删除该故事吗?', okText: '确认', cancelText: '取消', onOk: () => deleteItem(currentItem.instanceId ?? ''), }); } }; const extraContent = (
{ run(value); }} />
); const MoreBtn: React.FC<{ item: StoryType; }> = ({ item }) => ( editAndDelete(key, item), items: [ { key: 'edit', label: '编辑', }, { key: 'delete', label: '删除', }, ], }} > 更多 ); const handleDone = () => { setDone(false); setVisible(false); setCurrent({}); }; const handleSubmit = (values: StoryType) => { setDone(true); const method = current?.instanceId ? 'update' : 'add'; postRun(method, { ...current, ...values }); run(); }; return (
( { e.preventDefault(); showEditModal(item); }} > 编辑 , // 增加授权操作,可以授权给其他用户 { e.preventDefault(); setCurrent(item); setAuthorizeModelOpen(true); }} > 授权 , { e.preventDefault(); deleteItem(item.instanceId ?? ''); }} > 删除 , ]} > } title={ { history.push(`/timeline/${item.instanceId}`); }} > {item.title} } description={item.description} /> )} />
{ if(flag) { run(); } setAuthorizeModelOpen(false); setCurrent({}); }} />
); }; export default BasicList;