feat: 完成图文集新增

2.0/email-builder
Jimmy Liow 11 months ago
parent eac43e49c0
commit 5903993f79

@ -1,4 +1,5 @@
import { create } from 'zustand' import { create } from 'zustand'
import { devtools } from 'zustand/middleware'
import { fetchJSON, postForm } from '@/utils/request' import { fetchJSON, postForm } from '@/utils/request'
import { isEmpty, isNotEmpty } from '@/utils/commons' import { isEmpty, isNotEmpty } from '@/utils/commons'
import { API_HOST } from '@/config' import { API_HOST } from '@/config'
@ -6,7 +7,7 @@ import { API_HOST } from '@/config'
export const PERM_MERGE_CONVERSATION = 'merge-conversation' export const PERM_MERGE_CONVERSATION = 'merge-conversation'
export const PERM_ASSIGN_NEW_CONVERSATION = 'assign-new-conversation' export const PERM_ASSIGN_NEW_CONVERSATION = 'assign-new-conversation'
const useAuthStore = create((set, get) => ({ const useAuthStore = create(devtools((set, get) => ({
loginUser: { loginUser: {
userId: -1, userId: -1,
userIdStr: '-1', userIdStr: '-1',
@ -158,6 +159,6 @@ const useAuthStore = create((set, get) => ({
} }
}) })
}, },
})) }), { name: 'authStore' }))
export default useAuthStore export default useAuthStore

@ -11,6 +11,13 @@ const useSnippetStore = create(devtools((set, get) => ({
typeAllList: [], typeAllList: [],
snippetList: [], snippetList: [],
drawerOpen: false, drawerOpen: false,
currentSnippet: {
snippetId: 0,
title: '',
owner: '',
category: '',
content: {html: ''}
},
openDrawer: () => { openDrawer: () => {
set(() => ({ set(() => ({
@ -25,7 +32,7 @@ const useSnippetStore = create(devtools((set, get) => ({
}, },
fetchParamList: async () => { fetchParamList: async () => {
const fetchOwnerUrl = `${API_HOST}/v2/GetAutoDocParameters` const fetchOwnerUrl = `${API_HOST}/GetAutoDocParameters`
const params = {}; const params = {};
return fetchJSON(fetchOwnerUrl, params) return fetchJSON(fetchOwnerUrl, params)
@ -50,7 +57,7 @@ const useSnippetStore = create(devtools((set, get) => ({
}, },
fetchSnippetList: async (formValues) => { fetchSnippetList: async (formValues) => {
const fetchSnippetListUrl = `${API_HOST}/v2/QueryAutoDocInfo` const fetchSnippetListUrl = `${API_HOST}/QueryAutoDocInfo`
return fetchJSON(fetchSnippetListUrl, formValues) return fetchJSON(fetchSnippetListUrl, formValues)
.then(json => { .then(json => {
@ -64,15 +71,25 @@ const useSnippetStore = create(devtools((set, get) => ({
}) })
}, },
fetchSnippetDetail: async (snippetId) => { fetchSnippetDetail: async (snippet) => {
const fetchSnippetDetailUrl = `${API_HOST}/v2/GetAutoDocInfoDetail` const fetchSnippetDetailUrl = `${API_HOST}/GetAutoDocInfoDetail`
const params = {adi_sn: snippetId}; const params = {adi_sn: snippet.adi_sn};
return fetchJSON(fetchSnippetDetailUrl, params) return fetchJSON(fetchSnippetDetailUrl, params)
.then(json => { .then(json => {
if (json.errcode === 0 && json?.result.length > 0) { if (json.errcode === 0 && json?.result.length > 0) {
console.info(json) const detail = json?.result[0]
return json?.result[0].adi_content const content = detail.adi_content
set(() => ({
currentSnippet: {
snippetId: snippet.adi_sn,
title: snippet.adi_title,
owner: snippet.adi_owner,
category: snippet.adi_type,
content: { html: detail.adi_content}
}
}))
return content
} else { } else {
throw new Error(json?.errmsg + ': ' + json.errcode) throw new Error(json?.errmsg + ': ' + json.errcode)
} }
@ -80,10 +97,10 @@ const useSnippetStore = create(devtools((set, get) => ({
}, },
saveOrUpdateSnippet: async (formValues) => { saveOrUpdateSnippet: async (formValues) => {
const postSnippetUrl = `${API_HOST}/v2/AddAutoDocInfo` const postSnippetUrl = `${API_HOST}/AddAutoDocInfo`
const formData = new FormData() const formData = new FormData()
formData.append('adi_sn', formValues.snippetId) formData.append('adi_sn', formValues.snippetId)
formData.append('owner', 383) formData.append('owner', formValues.owner)
formData.append('type', formValues.category) formData.append('type', formValues.category)
formData.append('title', formValues.title) formData.append('title', formValues.title)
formData.append('adi_content', formValues.content.html) formData.append('adi_content', formValues.content.html)
@ -92,7 +109,15 @@ const useSnippetStore = create(devtools((set, get) => ({
return postForm(postSnippetUrl, formData) return postForm(postSnippetUrl, formData)
.then(json => { .then(json => {
if (json.errcode === 0) { if (json.errcode === 0) {
console.info(json) set(() => ({
currentSnippet: {
snippetId: formValues.snippetId,
title: formValues.title,
owner: formValues.owner,
category: formValues.category,
content: formValues.content
}
}))
} else { } else {
throw new Error(json?.errmsg + ': ' + json.errcode) throw new Error(json?.errmsg + ': ' + json.errcode)
} }

@ -7,7 +7,6 @@ function Profile() {
const [loginUser, setWhatsAppBusiness] = useAuthStore((state) => [state.loginUser, state.setWhatsAppBusiness]) const [loginUser, setWhatsAppBusiness] = useAuthStore((state) => [state.loginUser, state.setWhatsAppBusiness])
useEffect(() => { useEffect(() => {
console.info(loginUser)
// //
// throw new Error('💥 CABOOM 💥') // throw new Error('💥 CABOOM 💥')
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps

@ -17,7 +17,7 @@ import { useState, useRef, useEffect } from 'react'
import LexicalEditorInput from './LexicalEditorInput' import LexicalEditorInput from './LexicalEditorInput'
import HtmlPreview from './HtmlPreview' import HtmlPreview from './HtmlPreview'
import useSnippetStore from '@/stores/SnippetStore' import useSnippetStore from '@/stores/SnippetStore'
import LexicalEditor from '@/components/LexicalEditor' import useAuthStore from '@/stores/AuthStore'
import { isEmpty, isNotEmpty } from '@/utils/commons' import { isEmpty, isNotEmpty } from '@/utils/commons'
function SnippetList() { function SnippetList() {
@ -35,6 +35,7 @@ function SnippetList() {
fetchSnippetList, fetchSnippetList,
snippetList, snippetList,
fetchSnippetDetail, fetchSnippetDetail,
currentSnippet,
saveOrUpdateSnippet saveOrUpdateSnippet
] = useSnippetStore((state) => [ ] = useSnippetStore((state) => [
state.fetchParamList, state.fetchParamList,
@ -44,22 +45,22 @@ function SnippetList() {
state.fetchSnippetList, state.fetchSnippetList,
state.snippetList, state.snippetList,
state.fetchSnippetDetail, state.fetchSnippetDetail,
state.currentSnippet,
state.saveOrUpdateSnippet state.saveOrUpdateSnippet
]) ])
const [loginUser] = useAuthStore((state) => [state.loginUser])
const [isSnippetModalOpen, setSnippetModalOpen] = useState(false) const [isSnippetModalOpen, setSnippetModalOpen] = useState(false)
const [editorContent, setEditorContent] = useState('')
const [isHtmlLoading, setHtmlLoading] = useState(false) const [isHtmlLoading, setHtmlLoading] = useState(false)
const onSnippetFinish = (values) => { const onSnippetFinish = (values) => {
console.log('onSnippetFinish:', values) console.log('onSnippetFinish:', values)
saveOrUpdateSnippet(values) saveOrUpdateSnippet(values)
// console.info(JSON.stringify(editorRef.current.getEditorState()))
} }
const onSnippetFailed = (error) => { const onSnippetFailed = (error) => {
console.log('Failed:', error) console.log('Failed:', error)
// form.resetFields()
} }
const handleSearchFinish = (values) => { const handleSearchFinish = (values) => {
@ -67,15 +68,17 @@ function SnippetList() {
fetchSnippetList(values) fetchSnippetList(values)
} }
const handleSnippetSelected = (snippetId) => { const handleSnippetSelected = (snippet) => {
setHtmlLoading(true) setHtmlLoading(true)
fetchSnippetDetail(snippetId) fetchSnippetDetail(snippet)
.then((content) => {
setEditorContent(content)
})
.finally(() => setHtmlLoading(false)) .finally(() => setHtmlLoading(false))
} }
const handelSnippetEdit = () => {
snippetForm.setFieldsValue(currentSnippet)
setSnippetModalOpen(true)
}
useEffect(() => { useEffect(() => {
fetchParamList() fetchParamList()
}, []) }, [])
@ -115,18 +118,31 @@ function SnippetList() {
rules={[ rules={[
{ {
required: true, required: true,
message: 'title required', message: '标题必填',
}, },
]}> ]}>
<Input /> <Input />
</Form.Item> </Form.Item>
<Form.Item label='所有者' name='owner'
rules={[
{
required: true,
message: '所有者必选',
},
]}>
<Select
options={ownerList}
showSearch
optionFilterProp='label'
notFoundContent={'找不到'}></Select>
</Form.Item>
<Form.Item <Form.Item
label='类型' label='类型'
name='category' name='category'
rules={[ rules={[
{ {
required: true, required: true,
message: 'title required', message: '类型必选',
}, },
]}> ]}>
<Select options={typeList}> <Select options={typeList}>
@ -138,7 +154,7 @@ function SnippetList() {
rules={[ rules={[
{ {
required: true, required: true,
message: 'content required', message: '内容必填',
}, },
]}> ]}>
<LexicalEditorInput /> <LexicalEditorInput />
@ -151,7 +167,7 @@ function SnippetList() {
form={searchform} form={searchform}
onFinish={handleSearchFinish} onFinish={handleSearchFinish}
initialValues={{ initialValues={{
owner: '', // owner: loginUser.userId + '/2', //
type: '', type: '',
}}> }}>
<Form.Item label='所有者' name='owner'> <Form.Item label='所有者' name='owner'>
@ -188,16 +204,16 @@ function SnippetList() {
<List <List
bordered bordered
dataSource={snippetList} dataSource={snippetList}
renderItem={(item) => ( renderItem={(snippet) => (
<List.Item <List.Item
className='hover:bg-stone-50' className='hover:bg-stone-50'
onClick={() => { onClick={() => {
handleSnippetSelected(item.adi_sn) handleSnippetSelected(snippet)
}}> }}>
<Row gutter={16} className='w-full'> <Row gutter={16} className='w-full'>
<Col span={20}>{item.adi_title}</Col> <Col span={20}>{snippet.adi_title}</Col>
<Col span={4}> <Col span={4}>
<Tag color='blue'>{item.adi_type_name}</Tag> <Tag color='blue'>{snippet.adi_type_name}</Tag>
</Col> </Col>
</Row> </Row>
</List.Item> </List.Item>
@ -205,8 +221,8 @@ function SnippetList() {
/> />
</Col> </Col>
<Col span={16}> <Col span={16}>
<HtmlPreview value={editorContent} loading={isHtmlLoading} <HtmlPreview value={currentSnippet.content.html} loading={isHtmlLoading}
onEdit={() => console.info('onEdit')} onEdit={() => handelSnippetEdit()}
onCopied={() => messageApi.success('已复制')} onCopied={() => messageApi.success('已复制')}
onDelete={() => console.info('onDelete')} /> onDelete={() => console.info('onDelete')} />
</Col> </Col>

Loading…
Cancel
Save