|
|
|
@ -1,43 +1,17 @@
|
|
|
|
|
import {
|
|
|
|
|
Flex,
|
|
|
|
|
Row,
|
|
|
|
|
Col,
|
|
|
|
|
Tag,
|
|
|
|
|
List,
|
|
|
|
|
Form,
|
|
|
|
|
Input,
|
|
|
|
|
Button,
|
|
|
|
|
Space,
|
|
|
|
|
Modal,
|
|
|
|
|
Select,
|
|
|
|
|
Divider,
|
|
|
|
|
message,
|
|
|
|
|
} from 'antd'
|
|
|
|
|
import { useState, useRef, useEffect } from 'react'
|
|
|
|
|
import LexicalEditorInput from './LexicalEditorInput'
|
|
|
|
|
import { Row, Col, Tag, List, Form, Input, Button, Space, Modal, Select, message } from 'antd'
|
|
|
|
|
import { useState, useEffect } from 'react'
|
|
|
|
|
import EditorInput from '../../components/EditorInput'
|
|
|
|
|
import HtmlPreview from './HtmlPreview'
|
|
|
|
|
import useSnippetStore from '@/stores/SnippetStore'
|
|
|
|
|
import useAuthStore from '@/stores/AuthStore'
|
|
|
|
|
import { isEmpty, isNotEmpty } from '@/utils/commons'
|
|
|
|
|
|
|
|
|
|
function SnippetList() {
|
|
|
|
|
|
|
|
|
|
const [messageApi, contextHolder] = message.useMessage()
|
|
|
|
|
|
|
|
|
|
const [searchform] = Form.useForm()
|
|
|
|
|
const [snippetForm] = Form.useForm()
|
|
|
|
|
|
|
|
|
|
const [
|
|
|
|
|
fetchParamList,
|
|
|
|
|
ownerList,
|
|
|
|
|
typeList,
|
|
|
|
|
typeAllList,
|
|
|
|
|
fetchSnippetList,
|
|
|
|
|
snippetList,
|
|
|
|
|
fetchSnippetDetail,
|
|
|
|
|
currentSnippet,
|
|
|
|
|
saveOrUpdateSnippet
|
|
|
|
|
] = useSnippetStore((state) => [
|
|
|
|
|
const [fetchParamList, ownerList, typeList, typeAllList, fetchSnippetList, snippetList, fetchSnippetDetail, currentSnippet, saveOrUpdateSnippet] = useSnippetStore((state) => [
|
|
|
|
|
state.fetchParamList,
|
|
|
|
|
state.ownerList,
|
|
|
|
|
state.typeList,
|
|
|
|
@ -46,7 +20,7 @@ function SnippetList() {
|
|
|
|
|
state.snippetList,
|
|
|
|
|
state.fetchSnippetDetail,
|
|
|
|
|
state.currentSnippet,
|
|
|
|
|
state.saveOrUpdateSnippet
|
|
|
|
|
state.saveOrUpdateSnippet,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
const [loginUser] = useAuthStore((state) => [state.loginUser])
|
|
|
|
@ -70,8 +44,7 @@ function SnippetList() {
|
|
|
|
|
|
|
|
|
|
const handleSnippetSelected = (snippet) => {
|
|
|
|
|
setHtmlLoading(true)
|
|
|
|
|
fetchSnippetDetail(snippet)
|
|
|
|
|
.finally(() => setHtmlLoading(false))
|
|
|
|
|
fetchSnippetDetail(snippet).finally(() => setHtmlLoading(false))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handelSnippetEdit = () => {
|
|
|
|
@ -103,6 +76,7 @@ function SnippetList() {
|
|
|
|
|
form={snippetForm}
|
|
|
|
|
layout='vertical'
|
|
|
|
|
className='max-w-4xl'
|
|
|
|
|
initialValues={currentSnippet}
|
|
|
|
|
onFinish={onSnippetFinish}
|
|
|
|
|
onFinishFailed={onSnippetFailed}
|
|
|
|
|
autoComplete='off'>
|
|
|
|
@ -123,19 +97,17 @@ function SnippetList() {
|
|
|
|
|
]}>
|
|
|
|
|
<Input />
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item label='所有者' name='owner'
|
|
|
|
|
<Form.Item
|
|
|
|
|
label='所有者'
|
|
|
|
|
name='owner'
|
|
|
|
|
rules={[
|
|
|
|
|
{
|
|
|
|
|
required: true,
|
|
|
|
|
message: '所有者必选',
|
|
|
|
|
},
|
|
|
|
|
]}>
|
|
|
|
|
<Select
|
|
|
|
|
options={ownerList}
|
|
|
|
|
showSearch
|
|
|
|
|
optionFilterProp='label'
|
|
|
|
|
notFoundContent={'找不到'}></Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Select options={ownerList} showSearch optionFilterProp='label' notFoundContent={'找不到'}></Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
|
|
|
|
label='类型'
|
|
|
|
|
name='category'
|
|
|
|
@ -145,8 +117,7 @@ function SnippetList() {
|
|
|
|
|
message: '类型必选',
|
|
|
|
|
},
|
|
|
|
|
]}>
|
|
|
|
|
<Select options={typeList}>
|
|
|
|
|
</Select>
|
|
|
|
|
<Select options={typeList}></Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
|
|
|
|
label='内容'
|
|
|
|
@ -157,7 +128,7 @@ function SnippetList() {
|
|
|
|
|
message: '内容必填',
|
|
|
|
|
},
|
|
|
|
|
]}>
|
|
|
|
|
<LexicalEditorInput />
|
|
|
|
|
<EditorInput />
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
|
@ -171,12 +142,7 @@ function SnippetList() {
|
|
|
|
|
type: '',
|
|
|
|
|
}}>
|
|
|
|
|
<Form.Item label='所有者' name='owner'>
|
|
|
|
|
<Select
|
|
|
|
|
className='!w-40'
|
|
|
|
|
options={ownerList}
|
|
|
|
|
showSearch
|
|
|
|
|
optionFilterProp='label'
|
|
|
|
|
notFoundContent={'找不到'}></Select>
|
|
|
|
|
<Select className='!w-40' options={ownerList} showSearch optionFilterProp='label' notFoundContent={'找不到'}></Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item label='类别' name='type'>
|
|
|
|
|
<Select className='!w-40' options={typeAllList} />
|
|
|
|
@ -221,10 +187,13 @@ function SnippetList() {
|
|
|
|
|
/>
|
|
|
|
|
</Col>
|
|
|
|
|
<Col span={16}>
|
|
|
|
|
<HtmlPreview value={currentSnippet.content.html} loading={isHtmlLoading}
|
|
|
|
|
<HtmlPreview
|
|
|
|
|
value={currentSnippet.content.html}
|
|
|
|
|
loading={isHtmlLoading}
|
|
|
|
|
onEdit={() => handelSnippetEdit()}
|
|
|
|
|
onCopied={() => messageApi.success('已复制')}
|
|
|
|
|
onDelete={() => console.info('onDelete')} />
|
|
|
|
|
onDelete={() => console.info('onDelete')}
|
|
|
|
|
/>
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
|
|
|
|
</Space>
|
|
|
|
|