/* eslint-disable eqeqeq */
/* eslint-disable react/jsx-no-duplicate-props */
import IconFont from '@/components/IconFont';
import Limit from '@/components/Limit';
import Reply from '@/components/Reply';
import { doFetch, getFetch } from '@/utils/doFetch';
import {
ApiOutlined,
CloseOutlined,
EditFilled,
EllipsisOutlined,
MessageFilled,
PlayCircleFilled,
ShareAltOutlined,
} from '@ant-design/icons';
import { history, useModel, useOutletContext } from '@umijs/max';
import { Avatar, Empty, message, Modal, Popconfirm, Select, Tag, Tooltip } from 'antd';
import dayjs from 'dayjs';
import { memo, useEffect, useState } from 'react';
import { Draggable, Droppable } from 'react-beautiful-dnd';
import styles from './index.less';
const items = {
0: {
value: '0',
statusName: '未开始',
icon: (
),
},
1: {
value: '1',
statusName: '进行中',
color: 'green',
icon: (
),
},
2: {
value: '2',
statusName: '已完成',
color: 'grey',
icon: (
),
},
3: {
value: '3',
statusName: '挂起',
color: 'grey',
icon: (
),
},
};
function getUserInfo(userList, id) {
return userList?.filter((it) => it.id === id)[0];
}
const QuoteList = ({ listId, datas, edit, userList, refresh, type }) => {
const { setdom } = useOutletContext();
const {
initialState: { currentUser, curitem, activeUserIdList },
setInitialState,
} = useModel('@@initialState');
const [loading, setloading] = useState(false);
const [drawer, setdrawer] = useState({
open: false,
onClose: () => {
setInitialState((s) => ({
...s,
curitem: null,
}));
setdrawer((s) => ({
...s,
open: false,
}));
},
});
const Header = ({ userList, id, noname, click, size }) => {
return (
{getUserInfo(userList, id)?.head_url && getUserInfo(userList, id)?.head_url !== '' ? (
{
e.stopPropagation();
noname && click();
}}
size={size ?? 'large'}
src={getUserInfo(userList, id)?.head_url}
style={{
filter:
activeUserIdList.indexOf(id.toString()) !== -1 || currentUser?.id == id
? 'grayscale(0%)'
: 'grayscale(100%)',
}}
>
) : (
{
e.stopPropagation();
noname && click();
}}
size={size ?? 'large'}
style={
!getUserInfo(userList, id)?.user_name?.charAt(0)
? { backgroundColor: '#fde3cf', color: '#f56a00' }
: {
filter:
activeUserIdList.indexOf(id.toString()) !== -1 || currentUser?.id == id
? 'grayscale(0%)'
: 'grayscale(100%)',
}
}
>
{getUserInfo(userList, id)?.user_name?.charAt(0) ?? '无'}
)}
{!noname &&
{getUserInfo(userList, id)?.user_name}}
);
};
//点击消息内容自动打开详情
useEffect(() => {
const { project_id, item_id } = curitem ?? {};
if (item_id) {
const selecteditem = datas?.filter?.((it) => it?.id == item_id)?.[0] || null;
if (!selecteditem) return;
console.log('====================================');
console.log(curitem);
console.log('====================================');
history.push(`/share/${project_id}?project_id=${project_id}&item_id=${item_id}`);
}
}, [curitem]);
const ActionBar = ({ item, content }) => (
{
e.stopPropagation();
}}
>
{items[item?.status]?.statusName}
{content ? null : item.deadline ? (
{dayjs(item.deadline).endOf('day').diff(dayjs(), 'day') > 0 ? (
`剩余${dayjs(item.deadline).endOf('day').diff(dayjs(), 'day')}天`
) : dayjs(item.deadline).endOf('day').diff(dayjs(), 'hour') < 24 &&
dayjs(item.deadline).endOf('day').diff(dayjs(), 'hour') > 0 ? (
`剩余${dayjs(item.deadline).endOf('day').diff(dayjs(), 'hour')}小时`
) : (
{item?.status === '2' ? '已完成' : '超时'}
{dayjs().diff(dayjs(item.deadline).endOf('day'), 'hour') < 24
? `${dayjs().diff(dayjs(item.deadline).endOf('day'), 'hour')}小时`
: `${dayjs().diff(dayjs(item.deadline).endOf('day'), 'day')}天`}
)}
) : (
-
)}
{content ? null : (
{
const text = `${location?.origin}#/share/${item?.project_id}?project_id=${item?.project_id}&item_id=${item?.id}`;
try {
await navigator.clipboard.writeText(text);
message.success('复制成功!');
} catch (err) {
console.error('复制到剪贴板失败:', err);
const textarea = document.createElement('textarea');
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
message.success('复制成功!');
}
}}
>
)}
{
if (
item.status === '2' ||
item.status === '3' ||
currentUser?.id !== item.userid ||
loading
)
return;
setloading(true);
let res;
if (item.status === '0') {
res = await doFetch({
url: '/webtool/v1/item/' + item.id,
params: { status: '1' },
method: 'PUT',
});
} else if (item.status === '1') {
res = await doFetch({
url: '/webtool/v1/item/' + item.id,
params: { status: '2' },
method: 'PUT',
});
}
await refresh();
if (content) {
const detail = await getFetch({ url: '/webtool/v1/item/' + item.id });
console.log(detail?.data);
setdrawer((s) => ({
...s,
...detail?.data,
}));
}
setTimeout(() => {
setloading(false);
}, 1000);
}}
>
{items[item?.status]?.icon}
);
const Content = () => (
{drawer?.tags?.map((it) => {
const isLongTag = it?.tag_name?.length > 20;
return (
{isLongTag ? `${it?.tag_name?.slice(0, 20)}...` : it.tag_name}
);
})}
{drawer?.content ? (
) : (
)}
附件:
{drawer?.other?.map?.((it, i) => (
{it?.fileName}
))}
截止日期:{drawer?.deadline ? dayjs(drawer?.deadline).format('YYYY-MM-DD') : '未设置'}
);
return (
[
{
await setdrawer((s) => ({
...s,
open: false,
}));
edit?.({
mission_name: drawer?.title,
remark: drawer?.content,
deadline: drawer?.deadline,
userid: drawer?.userid,
id: drawer?.id,
tags: drawer?.tags?.map((it) => it?.id),
other: drawer?.other ? drawer?.other : [],
});
}}
>
,
{
setdoreply(getUserInfo(userList, drawer?.userid));
}}
>
,
]}
>
{(dropProvided, dropSnapshot) => (
{datas
?.sort((a, b) => a.sort - b.sort)
.map((item, index) => (
{(provided, snapshot) => (
{
setdrawer((s) => ({
...s,
...item,
open: true,
title: item?.mission_name,
content: item?.remark,
deadline: item?.deadline,
userid: item?.userid,
id: item?.id,
tags: item?.tags,
other: item?.other ? JSON.parse(item?.other) : [],
val: 'reply',
userInfo: getUserInfo(userList, item?.userid),
}));
}}
>
{item.mission_name}
{currentUser?.id === item.userid && (
{
e.stopPropagation();
setloading(true);
doFetch({
url: `/webtool/v1/item/${item.id}`,
params: {},
method: 'DELETE',
}).then((res) => {
refresh();
setTimeout(() => {
setloading(false);
}, 1000);
});
}}
onCancel={(e) => {
e.stopPropagation();
}}
okButtonProps={{
loading: loading,
}}
>
{
e.stopPropagation();
}}
style={{ fontSize: 12 }}
/>
)}
{item?.tags
?.filter((it, i) => i < 3)
.map((it) => {
const isLongTag = it?.tag_name?.length > 4;
return (
{isLongTag ? `${it?.tag_name?.slice(0, 4)}` : it.tag_name}
);
})}
{item?.tags?.length > 3 &&
}
{
Modal.confirm({
title: '修改执行人',
maskClosable: true,
content: (
),
footer: false,
});
}}
>
)}
))}
{datas?.length === 0 && (
)}
{dropProvided.placeholder}
)}
);
};
export default memo(QuoteList, (prev, next) => {
if (JSON.stringify(prev.datas) === JSON.stringify(next.datas)) {
return true;
}
return false;
});