|
|
|
@ -17,9 +17,9 @@ import {
|
|
|
|
|
YoutubeOutlined,
|
|
|
|
|
AudioOutlined, PlayCircleOutlined, LoadingOutlined, CheckCircleOutlined, FileOutlined
|
|
|
|
|
} from '@ant-design/icons';
|
|
|
|
|
import { isEmpty, olog } from '@/utils/utils';
|
|
|
|
|
import { isEmpty, } from '@/utils/utils';
|
|
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
|
import { sentMsgTypeMapped } from '@/lib/msgUtils';
|
|
|
|
|
import { sentMsgTypeMapped, whatsappSupportFileTypes } from '@/lib/msgUtils';
|
|
|
|
|
import InputTemplate from './Input/Template';
|
|
|
|
|
import InputEmoji from './Input/Emoji';
|
|
|
|
|
import InputMediaUpload from './Input/MediaUpload';
|
|
|
|
@ -28,24 +28,6 @@ import ExpireTimeClock from './ExpireTimeClock';
|
|
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
|
|
|
|
|
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 InputComposer = ({ mobile }) => {
|
|
|
|
|
const userId = useAuthStore((state) => state.loginUser.userId);
|
|
|
|
@ -124,17 +106,26 @@ const InputComposer = ({ mobile }) => {
|
|
|
|
|
websocket.sendMessage({ ...contentToSend, opi_sn: userId, coli_sn: currentConversation.coli_sn });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const { message } = App.useApp();
|
|
|
|
|
const { message: appMessage } = App.useApp();
|
|
|
|
|
const [pastedUploading, setPastedUploading] = useState(false);
|
|
|
|
|
const readPasted = async (file, rename = false) => {
|
|
|
|
|
const readPasted = 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 newName = `${uuid()}.${suffix}`; // rename ? `${uuid()}.${suffix}` : file.name;
|
|
|
|
|
const type = Object.keys(fileTypesExt).find((type) => fileTypesExt[type].includes(suffix));
|
|
|
|
|
const dataUri = aliOSSHost + newName;
|
|
|
|
|
const msgObj = {
|
|
|
|
|
type: type,
|
|
|
|
|
type: fileTypeSupport,
|
|
|
|
|
name: file.name,
|
|
|
|
|
uploadStatus: 'loading',
|
|
|
|
|
data: { dataUri: dataUri, link: dataUri, width: '100%', height: 150, loading: 0.01 },
|
|
|
|
@ -156,7 +147,7 @@ const InputComposer = ({ mobile }) => {
|
|
|
|
|
let tmpfile = null;
|
|
|
|
|
if (!items || items.length === 0) {
|
|
|
|
|
// 当前浏览器不支持本地
|
|
|
|
|
message.warning('当前浏览器不支持本地');
|
|
|
|
|
appMessage.warning('当前浏览器不支持本地');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let isNotFile = true;
|
|
|
|
@ -173,11 +164,14 @@ const InputComposer = ({ mobile }) => {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!tmpfile) {
|
|
|
|
|
message.warning('没有读取到粘贴内容');
|
|
|
|
|
appMessage.warning('没有读取到粘贴内容');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const shouldRename = tmpfile.type.indexOf('image') !== -1;
|
|
|
|
|
const _tmpFile = await readPasted(tmpfile, shouldRename);
|
|
|
|
|
if (_tmpFile === false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setComplexMsg(_tmpFile.msgData);
|
|
|
|
|
setPastedUploading(true);
|
|
|
|
|
const { file_url } = await postUploadFileItem(tmpfile, _tmpFile.newName);
|
|
|
|
|