/* eslint-disable array-callback-return */
/* eslint-disable react/jsx-key */
/* eslint-disable eqeqeq */
import DragModal from '@/components/DragModal';
import { AddPro, CopyPro, Join } from '@/components/DragModal/formdoms';
import IconFont from '@/components/IconFont';
import { doFetch, getFetch } from '@/utils/doFetch';
import {
ArrowUpOutlined,
ClockCircleFilled,
CopyOutlined,
DeleteOutlined,
PlayCircleFilled,
PlusOutlined,
RedoOutlined,
SearchOutlined,
} from '@ant-design/icons';
import { history, useModel } from '@umijs/max';
import { useRequest } from 'ahooks';
import {
Avatar,
Card,
Col,
Grid,
Input,
message,
Popconfirm,
Progress,
Row,
Segmented,
Skeleton,
Tooltip,
} from 'antd';
import dayjs from 'dayjs';
import { useState } from 'react';
import './index.less';
const { useBreakpoint } = Grid;
let col = { xs: 24, sm: 24, md: 12, lg: 8, xl: 6, xxl: 4 };
let cold = { xs: 24, sm: 24, md: 12 },
cols = { xs: 24, sm: 24, md: 12 };
const items = {
0: {
value: '0',
statusName: '未开始',
icon: (
),
},
1: {
value: '1',
statusName: '进行中',
color: 'green',
icon: (
),
},
2: {
value: '2',
statusName: '已完成',
color: 'grey',
icon: (
),
},
},
itemc = {
0: {
value: '0',
statusName: '已延期',
icon: (
),
},
1: {
value: '1',
statusName: '进行中',
color: 'green',
icon: (
),
},
2: {
value: '2',
statusName: '已完成',
color: 'grey',
icon: (
),
},
};
function getRandomColor() {
let r = Math.floor(Math.random() * (255 - 150 + 1) + 150);
let g = Math.floor(Math.random() * (255 - 150 + 1) + 150);
let b = Math.floor(Math.random() * (255 - 150 + 1) + 150);
return `rgb(${r}, ${g}, ${b})`;
}
function ProCard({
project_name,
project_user_id,
id,
run,
user_info_list,
created_at,
deadline,
stastic,
total,
copyItem,
}) {
const {
initialState: { currentUser, activeUserIdList },
setInitialState,
} = useModel('@@initialState');
return (
{project_name}
{dayjs(deadline).endOf('day').diff(dayjs(), 'hour') > 0 ? (
dayjs(deadline).endOf('day').diff(dayjs(), 'hour') > 24 ? (
距截止{dayjs(deadline).endOf('day').diff(dayjs(), 'day')}天
) : (
距截止{dayjs(deadline).endOf('day').diff(dayjs(), 'hour')}小时
)
) : dayjs().diff(dayjs(deadline).endOf('day'), 'hour') > 24 ? (
{stastic[stastic.length - 1].num?.length !== total || total === 0
? '超过截止'
: '已完成'}
{dayjs().diff(dayjs(deadline).endOf('day'), 'day')}天
) : (
{stastic[stastic.length - 1].num?.length !== total || total === 0
? '超过截止'
: '已完成'}
{dayjs().diff(dayjs(deadline).endOf('day'), 'hour')}小时
)}
}
style={{ backgroundColor: 'rgba(255,255,255,0.25)', height: '100%' }}
hoverable
className="hovercard"
extra={[
{
e.stopPropagation();
copyItem?.();
}}
>
,
currentUser?.id == project_user_id && (
{
e.stopPropagation();
}}
>
{
e.stopPropagation();
doFetch({ url: '/webtool/v1/project/' + id, params: {}, method: 'DELETE' }).then(
(res) => {
if (res.code === 0) {
message.success('删除成功');
run?.();
}
},
);
}}
onCancel={(e) => {
e.stopPropagation();
}}
>
{
e.stopPropagation();
}}
>
),
]}
onClick={() => {
history.push(`/welcome/project/${id}`);
}}
>
{stastic?.map((item, index) => {
return (
{item.statusName}
{item?.num?.length ?? 0}
);
})}
{[
...user_info_list.filter((it) => it?.id === project_user_id),
...[
...user_info_list.filter(
(it) =>
it?.id !== project_user_id && activeUserIdList.includes(it.id.toString()),
),
...user_info_list.filter(
(it) =>
it?.id !== project_user_id && !activeUserIdList.includes(it.id.toString()),
),
],
]?.map((it, i) => {
if (it?.head_url && it?.head_url !== '') {
return (
);
} else {
return (
{it?.user_name?.charAt(0)}
);
}
})}
{dayjs().diff(dayjs(created_at), 'hour') > 24
? `${dayjs().diff(dayjs(created_at), 'day')}天前`
: dayjs().diff(dayjs(created_at), 'hour') < 1
? `${dayjs().diff(dayjs(created_at), 'minute')}分钟前`
: `${dayjs().diff(dayjs(created_at), 'hour')}小时前`}
);
}
function AddCard({ onClick }) {
const screens = useBreakpoint();
return (
新建小组
);
}
function Homepage(props) {
const {
initialState: { currentUser, activeUserIdList },
setInitialState,
} = useModel('@@initialState');
const screens = useBreakpoint();
const [modal, setmodal] = useState({
open: false,
});
const { data, loading, run } = useRequest(
async () => {
let res = await getFetch({ url: '/webtool/v1/project' });
return res?.data;
},
{
debounceWait: 300,
refreshDeps: [currentUser?.org_id],
},
);
const [sort, setsort] = useState({
time: true,
type: '-1',
});
return (
{
setsort((s) => ({
...s,
time: !s.time,
}));
}}
>
{
run();
}}
>
{
setsort((s) => ({
...s,
type: val,
}));
}}
options={[
{
label: '全部',
value: '-1',
},
].concat(
Object.values(itemc).map((it) => ({
label: it.statusName,
value: it.value,
})),
)}
/>
}
placeholder="按照项目名称筛选"
onChange={(e) => {
setsort((s) => ({
...s,
search: e.target.value,
}));
}}
/>
{
setmodal((s) => ({
...s,
open: false,
}));
}}
style={{ top: 20 }}
width={['新建小组', '复制小组'].includes(modal.title) ? 1000 : 800}
>
{modal?.title === '新建小组' && (
{
run();
setmodal((s) => ({
...s,
open: false,
}));
}}
/>
)}
{modal?.title === '复制小组' && (
{
run();
setmodal((s) => ({
...s,
open: false,
}));
}}
/>
)}
{modal?.title === '加入组织' && (
{
run();
setmodal((s) => ({
...s,
open: false,
}));
}}
/>
)}
{
setmodal((s) => ({
...s,
open: true,
title: '新建小组',
}));
}}
/>
{data
?.sort((a, b) => {
const aval = dayjs(a.deadline).valueOf() - dayjs().valueOf();
const bval = dayjs(b.deadline).valueOf() - dayjs().valueOf();
if (sort?.time) {
return aval - bval;
} else {
return bval - aval;
}
})
?.filter((it) => {
if (!sort?.search) {
return true;
}
return it?.project_name?.indexOf(sort?.search) !== -1;
})
?.filter((it) => {
if (sort?.type == '-1') {
return true;
}
if (sort?.type == '0') {
return (
dayjs(it.deadline).valueOf() < dayjs().valueOf() &&
it.total != it.stastic[it.stastic.length - 1].num?.length &&
it.total != 0
);
}
if (sort?.type == '1') {
return (
(dayjs(it.deadline).valueOf() > dayjs().valueOf() &&
it.total > it.stastic[it.stastic.length - 1].num?.length) ||
it.total == 0
);
}
if (sort?.type == '2') {
return it.total == it.stastic[it.stastic.length - 1].num?.length && it.total != 0;
}
})
?.map?.((it, i) => {
return (
{
setmodal((s) => ({
...s,
open: true,
title: '复制小组',
initialValues: { ...it },
}));
}}
/>
);
})}
);
}
export default Homepage;