|
|
|
@ -46,14 +46,15 @@ const parseHTMLText = (html) => {
|
|
|
|
|
const parser = new DOMParser()
|
|
|
|
|
const dom = parser.parseFromString(html, 'text/html')
|
|
|
|
|
// Replace <br> and <p> with line breaks
|
|
|
|
|
Array.from(dom.body.querySelectorAll('br, p')).forEach((el) => {
|
|
|
|
|
el.textContent = '\n' + el.textContent
|
|
|
|
|
})
|
|
|
|
|
// Array.from(dom.body.querySelectorAll('br, p')).forEach((el) => {
|
|
|
|
|
// el.textContent = '<br>' + el.textContent
|
|
|
|
|
// })
|
|
|
|
|
// Replace <hr> with a line of dashes
|
|
|
|
|
Array.from(dom.body.querySelectorAll('hr')).forEach((el) => {
|
|
|
|
|
el.textContent = '\n------------------------------------------------------------------\n'
|
|
|
|
|
})
|
|
|
|
|
return dom.body.textContent || ''
|
|
|
|
|
// Array.from(dom.body.querySelectorAll('hr')).forEach((el) => {
|
|
|
|
|
// el.innerHTML = '<p><hr>------------------------------------------------------------------</p>'
|
|
|
|
|
// })
|
|
|
|
|
const line = '<p>------------------------------------------------------------------</p>'
|
|
|
|
|
return line+(dom.body.innerHTML || '')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const generateQuoteContent = (mailData, isRichText = true) => {
|
|
|
|
@ -199,6 +200,8 @@ const NewEmail = () => {
|
|
|
|
|
mat_sn: emailAccount?.mat_sn || info?.MAI_MAT_SN || defaultMAT,
|
|
|
|
|
opi_sn: emailAccount?.opi_sn || info?.MAI_OPI_SN || orderDetail.opi_sn || '',
|
|
|
|
|
}
|
|
|
|
|
const originalContentType = info?.mailType === 'text/html';
|
|
|
|
|
setIsRichText(originalContentType)
|
|
|
|
|
|
|
|
|
|
let readyToInitialContent = '';
|
|
|
|
|
let _formValues = {};
|
|
|
|
@ -225,6 +228,7 @@ const NewEmail = () => {
|
|
|
|
|
subject: `Re: ${info.MAI_Subject || ''}`,
|
|
|
|
|
..._form2
|
|
|
|
|
}
|
|
|
|
|
readyToInitialContent += generateQuoteContent(mailData, originalContentType)
|
|
|
|
|
break
|
|
|
|
|
case 'replyall':
|
|
|
|
|
_formValues = {
|
|
|
|
@ -235,6 +239,7 @@ const NewEmail = () => {
|
|
|
|
|
subject: `Re: ${info.MAI_Subject || ''}`,
|
|
|
|
|
..._form2
|
|
|
|
|
}
|
|
|
|
|
readyToInitialContent += generateQuoteContent(mailData, originalContentType)
|
|
|
|
|
break
|
|
|
|
|
case 'forward':
|
|
|
|
|
_formValues = {
|
|
|
|
@ -243,6 +248,7 @@ const NewEmail = () => {
|
|
|
|
|
// coli_sn: pageParam.oid,
|
|
|
|
|
..._form2
|
|
|
|
|
}
|
|
|
|
|
readyToInitialContent += generateQuoteContent(mailData, originalContentType)
|
|
|
|
|
break
|
|
|
|
|
case 'edit':
|
|
|
|
|
_formValues = {
|
|
|
|
@ -341,12 +347,14 @@ const NewEmail = () => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleEditorChange = ({ editorStateJSON, htmlContent, textContent }) => {
|
|
|
|
|
// console.log('textContent', textContent);
|
|
|
|
|
const _text = textContent.replace(/\r\n/g, '\n').replace(/\n{2,}/g, '\n')
|
|
|
|
|
// console.log('textContent---\n', textContent, 'textContent');
|
|
|
|
|
// console.log('html', html);
|
|
|
|
|
setHtmlContent(htmlContent)
|
|
|
|
|
setTextContent(textContent)
|
|
|
|
|
setTextContent(_text)
|
|
|
|
|
form.setFieldValue('content', htmlContent)
|
|
|
|
|
const { bodyText: abstract } = parseHTMLString(htmlContent, true);
|
|
|
|
|
const abstract = _text;
|
|
|
|
|
// const { bodyText: abstract } = parseHTMLString(htmlContent, true);
|
|
|
|
|
// form.setFieldValue('abstract', getAbstract(textContent))
|
|
|
|
|
const formValues = omitEmpty(form.getFieldsValue());
|
|
|
|
|
if (!isEmpty(formValues)) {
|
|
|
|
@ -496,8 +504,8 @@ const NewEmail = () => {
|
|
|
|
|
body.attaList = fileList;
|
|
|
|
|
// console.log('body', body, '\n', fileList);
|
|
|
|
|
const values = await form.validateFields()
|
|
|
|
|
const preQuoteBody = !['edit', 'new'].includes(pageParam.action) && pageParam.quoteid ? (quoteContent ? quoteContent : generateQuoteContent(mailData, isRichText)) : ''
|
|
|
|
|
body.mailcontent = isRichText ? EmailBuilder({ subject: values.subject, content: htmlContent + preQuoteBody }) : textContent + preQuoteBody
|
|
|
|
|
// const preQuoteBody = !['edit', 'new'].includes(pageParam.action) && pageParam.quoteid ? (quoteContent ? quoteContent : generateQuoteContent(mailData, isRichText)) : ''
|
|
|
|
|
body.mailcontent = isRichText ? EmailBuilder({ subject: values.subject, content: htmlContent }) : textContent
|
|
|
|
|
body.cc = values.cc || ''
|
|
|
|
|
body.bcc = values.bcc || ''
|
|
|
|
|
body.bcc = values.mailtype || ''
|
|
|
|
@ -517,6 +525,8 @@ const NewEmail = () => {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
// console.log('postSendEmail', body, '\n');
|
|
|
|
|
// console.log('🎈postSendEmail mailContent', body.mailcontent, '\n');
|
|
|
|
|
// throw new Error('test')
|
|
|
|
|
// return;
|
|
|
|
|
const mailSavedId = await postEmailSaveOrSend(body, isDraft)
|
|
|
|
|
form.setFieldsValue({
|
|
|
|
@ -703,20 +713,17 @@ const NewEmail = () => {
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Form>
|
|
|
|
|
<LexicalEditor {...{ isRichText }} onChange={handleEditorChange} defaultValue={initialContent} />
|
|
|
|
|
{!isEmpty(Number(pageParam.quoteid)) && pageParam.action!=='edit' && !showQuoteContent && (
|
|
|
|
|
{/* {!isEmpty(Number(pageParam.quoteid)) && pageParam.action!=='edit' && !showQuoteContent && (
|
|
|
|
|
<div className='flex justify-start items-center ml-2'>
|
|
|
|
|
<Button className='flex gap-2 ' type='link' onClick={() => {
|
|
|
|
|
setShowQuoteContent(!showQuoteContent);
|
|
|
|
|
setInitialContent(pre => pre + generateQuoteContent(mailData))
|
|
|
|
|
}}>
|
|
|
|
|
显示引用内容 ↓ {/*(不可更改)*/}
|
|
|
|
|
显示引用内容 ↓
|
|
|
|
|
</Button>
|
|
|
|
|
{/* <Button className='flex gap-2 ' type='link' danger onClick={() => {setMergeQuote(false);setShowQuoteContent(false)}}>
|
|
|
|
|
删除引用内容
|
|
|
|
|
</Button> */}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{/* {showQuoteContent && (
|
|
|
|
|
{showQuoteContent && (
|
|
|
|
|
<blockquote
|
|
|
|
|
// contentEditable
|
|
|
|
|
className='border-0 outline-none cursor-text'
|
|
|
|
|