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