Skip to content

Commit

Permalink
feat paste upload file
Browse files Browse the repository at this point in the history
  • Loading branch information
zjy365 committed Oct 17, 2024
1 parent 46f46f6 commit 1bcd571
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { fetchEventSource } from '@fortaine/fetch-event-source';
import { throttle } from 'lodash';
import { useTranslation } from 'next-i18next';
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';

const statusAnimation = keyframes`
0% {
Expand Down Expand Up @@ -331,6 +331,25 @@ const AppMainInfo = ({
}
}, [app?.dialogs, isManuallyHandled]);

const handlePaste = useCallback(async (e: React.ClipboardEvent) => {
const items = e.clipboardData.items;
const files: File[] = [];

for (let i = 0; i < items.length; i++) {
if (items[i].type.indexOf('image') !== -1) {
const blob = items[i].getAsFile();
if (blob) {
files.push(blob);
}
}
}

if (files.length > 0) {
e.preventDefault();
await uploadFiles(files);
}
}, []);

return (
<>
<Text fontSize={'18px'} fontWeight={500} color={'#24282C'} mt="24px" ml="36px">
Expand Down Expand Up @@ -449,6 +468,7 @@ const AppMainInfo = ({
}
border={'1px solid #EAEBF0'}
flexDirection={'column'}
onPaste={handlePaste}
>
{uploadedFiles && (
<Flex alignItems={'center'} gap={'4px'} wrap={'wrap'} mb={'4px'}>
Expand Down Expand Up @@ -517,7 +537,7 @@ const AppMainInfo = ({

<Textarea
ref={TextareaDom}
placeholder="在这里输入你的消息..."
placeholder="在此输入消息,可粘贴图片直接上传"
variant={'unstyled'}
value={text}
p={'0'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ const Header = ({
alignItems={'center'}
cursor={'pointer'}
onClick={() => {
router.replace({
router.push({
pathname: '/workorders',
query: {
page: router.query?.page,
status: router.query?.status
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function Home() {
const queryPage = Number(router.query.page);
return !isNaN(queryPage) && queryPage > 0 ? queryPage : 1;
});
const [pageSize, setPageSize] = useState(10);
const [pageSize, setPageSize] = useState(1);
const [orderStatus, setOrderStatus] = useState<WorkOrderStatus>(
(router.query?.status as WorkOrderStatus) || WorkOrderStatus.All
);
Expand Down

0 comments on commit 1bcd571

Please sign in to comment.