|
|
|
@ -1,48 +1,43 @@
|
|
|
|
|
import { Upload, Button, message, Tooltip } from 'antd';
|
|
|
|
|
import { App, Upload, Button, message, Tooltip } from 'antd';
|
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
import { FileAddOutlined } from '@ant-design/icons';
|
|
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
|
import { API_HOST } from '@/config';
|
|
|
|
|
import useConversationStore from '@/stores/ConversationStore';
|
|
|
|
|
import { whatsappSupportFileTypes } from '@/lib/msgUtils';
|
|
|
|
|
import { isEmpty, } from '@/utils/utils';
|
|
|
|
|
// import useConversationStore from '@/stores/ConversationStore';
|
|
|
|
|
|
|
|
|
|
const aliOSSHost = `https://haina-sale-system.oss-cn-shenzhen.aliyuncs.com/WAMedia/`;
|
|
|
|
|
/**
|
|
|
|
|
* image
|
|
|
|
|
* ext: ani;bmp;gif;ico;jpe;jpeg;jpg;pcx;png;psd;tga;tif;tiff;wmf
|
|
|
|
|
*
|
|
|
|
|
* audio
|
|
|
|
|
* ext: aac;ac3;aif;aifc;aiff;au;cda;dts;fla;flac;it;m1a;m2a;m3u;m4a;mid;midi;mka;mod;mp2;mp3;mpa;ogg;ra;rmi;spc;rmi;snd;umx;voc;wav;wma;xm
|
|
|
|
|
*
|
|
|
|
|
* video
|
|
|
|
|
* ext: 3g2;3gp;3gp2;3gpp;amr;amv;asf;avi;bdmv;bik;d2v;divx;drc;dsa;dsm;dss;dsv;evo;f4v;flc;fli;flic;flv;hdmov;ifo;ivf;m1v;m2p;m2t;m2ts;m2v;m4b;m4p;m4v;mkv;mp2v;mp4;mp4v;mpe;mpeg;mpg;mpls;mpv2;mpv4;mov;mts;ogm;ogv;pss;pva;qt;ram;ratdvd;rm;rmm;rmvb;roq;rpm;smil;smk;swf;tp;tpr;ts;vob;vp6;webm;wm;wmp;wmv
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
const fileTypesExt = {
|
|
|
|
|
sticker: ['webp'],
|
|
|
|
|
photo: ['jpeg', 'jpg', 'png'],
|
|
|
|
|
video: ['gif', 'mp4', '3gp'],
|
|
|
|
|
document: ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'csv'],
|
|
|
|
|
audio: ['aac', 'mp4', 'm4a', 'mp3', 'amr', 'ogg'],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const ImageUpload = ({ disabled, invokeUploadFileMessage, invokeSendUploadMessage }) => {
|
|
|
|
|
|
|
|
|
|
const { message: appMessage } = App.useApp();
|
|
|
|
|
|
|
|
|
|
// const setComplexMsg = useConversationStore(state => state.setComplexMsg);
|
|
|
|
|
// const complexMsg = useConversationStore(state => state.complexMsg);
|
|
|
|
|
|
|
|
|
|
const [fileObj, setFileObj] = useState();
|
|
|
|
|
const beforeUpload = async (file) => {
|
|
|
|
|
const fileTypeSupport = Object.keys(whatsappSupportFileTypes).find((msgType) => whatsappSupportFileTypes[msgType].types.includes(file.type));
|
|
|
|
|
if (isEmpty(fileTypeSupport)) {
|
|
|
|
|
appMessage.warning('不支持的文件格式');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const waFile = whatsappSupportFileTypes[fileTypeSupport];
|
|
|
|
|
if (file.size > waFile.size) {
|
|
|
|
|
appMessage.warning('超过大小限制');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// 使用 FileReader 读取文件对象
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
const suffix = file.name.slice(file.name.lastIndexOf('.')+1);
|
|
|
|
|
const type = Object.keys(fileTypesExt).find((type) => fileTypesExt[type].includes(suffix));
|
|
|
|
|
const rename = Date.now() + '.' + suffix;
|
|
|
|
|
const dataUri = aliOSSHost + rename;
|
|
|
|
|
// 读取完毕后获取结果
|
|
|
|
|
reader.onload = (event) => {
|
|
|
|
|
const previewSrc = event.target.result;
|
|
|
|
|
const msgObj = {
|
|
|
|
|
type: type,
|
|
|
|
|
type: fileTypeSupport,
|
|
|
|
|
name: file.name,
|
|
|
|
|
// status: 'loading',
|
|
|
|
|
data: { uri: previewSrc, dataUri: dataUri, link: dataUri, width: '100%', height: 150, loading: 0.01 },
|
|
|
|
@ -66,7 +61,7 @@ const ImageUpload = ({ disabled, invokeUploadFileMessage, invokeSendUploadMessag
|
|
|
|
|
showUploadList: false,
|
|
|
|
|
beforeUpload,
|
|
|
|
|
maxCount: 1,
|
|
|
|
|
accept: 'audio/aac, audio/mp4, audio/mpeg, audio/amr, audio/ogg,image/jpeg, image/png,video/mp4, video/3gp,image/webp,text/plain, application/pdf, application/vnd.ms-powerpoint, application/msword, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
|
|
|
accept: Object.values(whatsappSupportFileTypes).reduce((r, c) => r.concat(c.types), []).join(',')
|
|
|
|
|
};
|
|
|
|
|
return (
|
|
|
|
|
<Upload
|
|
|
|
|