feat: 保存草稿;

dev/ckeditor
Lei OT 4 months ago
parent 01dbcabdd7
commit fe3cde0c89

@ -164,7 +164,7 @@ const todoTypes = {
*/
export const getEmailDirAction = async (params = { opi_sn: '' }) => {
const defaultParams = { opi_sn: 0, year: dayjs().year(), by_start_date: -1, by_success: -1, important: -1, if_want_book: -1, if_thinking: -1 }
const { errcode, result } = await fetchJSON(`http://202.103.68.144:8889/v3/email_dir`, { ...defaultParams, ...params })
const { errcode, result } = await fetchJSON(`${API_HOST}/v3/email_dir`, { ...defaultParams, ...params })
const mailboxSort = result //.sort(sortBy('MDR_Order'));
let tree = buildTree(mailboxSort, { key: 'VKey', parent: 'VParent', name: 'VName', iconIndex: 'ImageIndex', rootKeys: [1], ignoreKeys: [-227001, -227002] })
tree = tree.filter((ele) => ele.key !== 1)
@ -306,7 +306,7 @@ export const queryEmailListAction = async ({ opi_sn = '', pagesize = 10, last_id
}
_params.mai_senddate1 = dayjs(_params.mai_senddate1).format(DATE_FORMAT)
const cacheKey = isEmpty(_params.coli_sn) ? `dir-${node.vkey}` : `order-${node.vkey}`;
const { errcode, result } = await fetchJSON(`http://202.103.68.144:8889/v3/mail_list`, _params)
const { errcode, result } = await fetchJSON(`${API_HOST}/v3/mail_list`, _params)
const ret = errcode === 0 ? result : []
if (!isEmpty(ret)) {
writeIndexDB([{key: cacheKey, data: ret}], 'maillist', 'mailbox')
@ -333,7 +333,8 @@ export const getEmailTemplateAction = async (template_name, params = { coli_sn:
/**
* 保存邮件草稿
*/
export const saveEmailDraftAction = async (body) => {
export const saveEmailDraftOrSendAction = async (body, isDraft = false) => {
const url = isDraft !== false ? `${API_HOST}/v3/email_draft_save` : `${EMAIL_HOST}/sendmail`;
const { attaList=[], atta, content, ...bodyData } = body;
bodyData.ordertype = 227001;
const formData = new FormData();
@ -343,7 +344,7 @@ export const saveEmailDraftAction = async (body) => {
attaList.forEach(function (item) {
formData.append('attachment', item);
});
const { result } = await postForm(`${EMAIL_HOST}/email-draft/save`, formData);
const { result } = await postForm(url, formData);
return result;
};

@ -157,6 +157,7 @@ export const useEmailList = (mailboxDirNode) => {
key: ele.MAI_SN,
}))
setMailList(_x)
setLoading(false)
}
try {
const nodeParam = { coli_sn: COLI_SN, order_source_type: OrderSourceType, vkey: VKey, vparent: VParent, mai_senddate1: ApplyDate }

@ -12,14 +12,13 @@ import LexicalEditor from '@/components/LexicalEditor'
import { v4 as uuid } from 'uuid'
import { cloneDeep, debounce, isEmpty, writeIndexDB, readIndexDB, deleteIndexDBbyKey } from '@/utils/commons'
import '@/views/Conversations/Online/Input/EmailEditor.css'
import { parseHTMLString, postSendEmail } from '@/actions/EmailActions'
import { parseHTMLString, postSendEmail, saveEmailDraftOrSendAction } from '@/actions/EmailActions'
import { sentMsgTypeMapped } from '@/channel/bubbleMsgUtils'
import { EmailBuilder, useEmailDetail, useEmailSignature } from '@/hooks/useEmail'
import useSnippetStore from '@/stores/SnippetStore'
// import { useOrderStore } from '@/stores/OrderStore'
import PaymentlinkBtn from '@/views/Conversations/Online/Input/PaymentlinkBtn'
import { TextIcon } from '@/components/Icons';
import GenerateAutoDocDrawer from './Conversations/Online/Components/GenerateAutoDocDrawer';
import { POPUP_FEATURES } from '@/config';
//
@ -68,7 +67,7 @@ const generateQuoteContent = (mailData, isRichText = true) => {
return isRichText ? html : parseHTMLText(html)
}
const generateMailContent = (mailData) => `<br><br><p>${mailData.content}</p>`
const generateMailContent = (mailData) => `<br><p>${mailData.content}</p><br>`
/**
* ! 无状态管理
@ -313,6 +312,7 @@ const NewEmail = () => {
to: info?.MAI_To || '',
cc: info?.MAI_CS || '',
subject: info?.MAI_Subject || '',
id: pageParam.quoteid,
}
form.setFieldsValue(thisFormValues)
const thisBody = generateMailContent(mailData)
@ -468,10 +468,12 @@ const NewEmail = () => {
const [sendLoading, setSendLoading] = useState(false)
const onHandleSend = async () => {
const onHandleSaveOrSend = async (isDraft = false) => {
// console.log('onSend callback', '\nisRichText', isRichText);
// console.log(form.getFieldsValue());
const body = structuredClone(form.getFieldsValue())
body.mailtype = ''; // todo:
// body.id = ''; // todo: 稿
body.from = newFromEmail
body.attaList = fileList
body.opi_sn = emailOPI
@ -511,7 +513,8 @@ const NewEmail = () => {
// console.log('postSendEmail', body, '\n', msgObj);
// return;
const result = await postSendEmail(body)
// todo: 稿,
const result = await saveEmailDraftOrSendAction(body, isDraft)
const mailSavedId = result.id || ''
bubbleMsg.email.mai_sn = mailSavedId
// console.log('invokeEmailMessage', bubbleMsg);
@ -526,6 +529,8 @@ const NewEmail = () => {
// description: error.message,
placement: 'top',
duration: 2,
showProgress: true,
pauseOnHover: true,
onClose: () => {
deleteIndexDBbyKey(editorKey, 'draft', 'mailbox');
window.close();
@ -578,7 +583,7 @@ const NewEmail = () => {
<>
<ConfigProvider theme={{ token: { colorPrimary: '#6366f1' } }}>
<div className='w-full flex gap-4 justify-start items-center text-indigo-600 pb-1 mb-2 border-x-0 border-t-0 border-b border-solid border-neutral-200'>
<Button type='primary' onClick={onHandleSend} loading={sendLoading} icon={<SendOutlined />}>
<Button type='primary' onClick={onHandleSaveOrSend} loading={sendLoading} icon={<SendOutlined />}>
发送
</Button>
<Select labelInValue options={emailListOption} value={{ key: newFromEmail, value: newFromEmail, label: newFromEmail }} onChange={handleSwitchEmail} labelRender={item => `发件人: ${item.label || '选择'}`} variant={'borderless'} className='[&_.ant-select-selection-item]:font-bold' />
@ -594,7 +599,7 @@ const NewEmail = () => {
{/* <Button type='link' size='small' icon={<TextIcon />} className=' ' >纯文本</Button> */}
<Radio.Group options={[{label: '纯文本', value: false}, {label: '富文本', value: true}]} optionType="button" buttonStyle="solid" onChange={handlePlainTextOpenChange} value={isRichText} size='small' />
</Popconfirm>
<Button type='dashed' icon={<SaveOutlined />} size='small' className='' >存草稿</Button>
<Button onClick={() => onHandleSaveOrSend(true)} type='dashed' icon={<SaveOutlined />} size='small' className='' >存草稿</Button>
</div>
<Form
form={form}
@ -667,6 +672,9 @@ const NewEmail = () => {
<Form.Item name='abstract' hidden>
<Input />
</Form.Item>
<Form.Item name='id' hidden>
<Input />
</Form.Item>
</Form>
<LexicalEditor {...{ isRichText }} onChange={handleEditorChange} defaultValue={initialContent} />
{pageParam.quoteid && pageParam.action!=='edit' && !showQuoteContent && (

Loading…
Cancel
Save