上传图片
parent
d5ff6e08ca
commit
77b3a135ee
@ -0,0 +1,59 @@
|
||||
import { createContext, useContext, useEffect, useState } from 'react';
|
||||
import { Upload, Button, message } from 'antd';
|
||||
import {
|
||||
SendOutlined,
|
||||
MessageOutlined,
|
||||
SmileOutlined,
|
||||
PictureOutlined,
|
||||
FileImageOutlined,
|
||||
CommentOutlined,
|
||||
UploadOutlined,
|
||||
CloudUploadOutlined,
|
||||
FolderAddOutlined,
|
||||
FilePdfOutlined,
|
||||
CloseCircleOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import useConversationStore from '@/stores/ConversationStore';
|
||||
|
||||
const props = {
|
||||
name: 'file',
|
||||
action: 'https://run.mocky.io/v3/435e224c-44fb-4773-9faf-380c5e6a2188',
|
||||
headers: {
|
||||
authorization: 'authorization-text',
|
||||
},
|
||||
showUploadList: false,
|
||||
};
|
||||
|
||||
const ImageUpload = ({ disabled, invokeSendMessage }) => {
|
||||
const { currentConversation, referenceMsg, setReferenceMsg } = useConversationStore();
|
||||
const [uploading, setUploading] = useState(false);
|
||||
|
||||
const handleSendImage = (src) => {
|
||||
const msgObj = {
|
||||
type: 'photo',
|
||||
data: { uri: src, },
|
||||
};
|
||||
invokeSendMessage(msgObj);
|
||||
};
|
||||
return (
|
||||
<Upload
|
||||
{...props}
|
||||
onChange={(info) => {
|
||||
setUploading(info.file.status === 'uploading');
|
||||
if (info.file.status !== 'uploading') {
|
||||
console.log(info.file, info.fileList);
|
||||
}
|
||||
if (info.file.status === 'done') {
|
||||
// message.success(`${info.file.name} file uploaded successfully`);
|
||||
// test: src
|
||||
// handleSendImage('blob:https://web.whatsapp.com/bbe878fc-7bde-447f-aa28-a4b929621a50');
|
||||
// handleSendImage('https://images.chinahighlights.com//allpicture/2020/04/9330cd3c78a34c81afd3b1fb.jpg');
|
||||
} else if (info.file.status === 'error') {
|
||||
message.error(`图片添加失败`);
|
||||
}
|
||||
}}>
|
||||
<Button key={'addPic'} type='text' loading={uploading} disabled={disabled} icon={<PictureOutlined />} size={'middle'} className='text-primary rounded-none' />
|
||||
</Upload>
|
||||
);
|
||||
};
|
||||
export default ImageUpload;
|
Loading…
Reference in New Issue