diff --git a/src/components/Conditional.ts b/src/components/Conditional.ts index 400712f..e102de9 100644 --- a/src/components/Conditional.ts +++ b/src/components/Conditional.ts @@ -1,4 +1,4 @@ -import React, { ReactNode } from 'react' +import { ReactNode } from 'react' export type ConditionalProps = { /** @@ -15,6 +15,10 @@ export type ConditionalProps = { whenFalse: ReactNode } -export function Conditional({ condition, whenFalse, whenTrue }: ConditionalProps) { - return condition ? whenTrue : whenFalse; -} \ No newline at end of file +export function Conditional({ + condition, + whenFalse, + whenTrue, +}: ConditionalProps) { + return condition ? whenTrue : whenFalse +} diff --git a/src/stores/SnippetStore.js b/src/stores/SnippetStore.js index 64b22a6..2f8cdce 100644 --- a/src/stores/SnippetStore.js +++ b/src/stores/SnippetStore.js @@ -8,22 +8,59 @@ const useSnippetStore = create(devtools((set, get) => ({ ownerList: [], typeList: [], + snippetList: [], + drawerOpen: false, + + openDrawer: () => { + set(() => ({ + drawerOpen: true + })) + }, + + closeDrawer: () => { + set(() => ({ + drawerOpen: false + })) + }, fetchParamList: async () => { - let fetchOwnerUrl = `${API_HOST}/v2/GetAutoDocParameters` + const fetchOwnerUrl = `${API_HOST}/v2/GetAutoDocParameters` const params = {}; return fetchJSON(fetchOwnerUrl, params) .then(json => { if (json.errcode === 0) { console.info(json) + const mapTypeList = json?.result?.type.map(item => { + return { value: item.vsn, label: item.vname } + }) + mapTypeList.unshift({ value: '', label: '全部' }) set(() => ({ ownerList: json?.result?.owner.map(item => { return { value: item.vsn, label: item.vname } }), - typeList: json?.result?.type.map(item => { - return { value: item.vsn, label: item.vname } - }) + typeList: mapTypeList + })) + } else { + throw new Error(json?.errmsg + ': ' + json.errcode) + } + }) + + }, + + fetchSnippetList: async (formValues) => { + const fetchSnippetListUrl = `${API_HOST}/v2/QueryAutoDocInfo` + const params = {owner: '1/1', type: '234004', title: '中国'}; + + return fetchJSON(fetchSnippetListUrl, formValues) + .then(json => { + if (json.errcode === 0) { + console.info(json) + set(() => ({ + snippetList: json?.result + // ownerList: json?.result?.owner.map(item => { + // return { value: item.vsn, label: item.vname } + // }), })) } else { throw new Error(json?.errmsg + ': ' + json.errcode) @@ -31,6 +68,22 @@ const useSnippetStore = create(devtools((set, get) => ({ }) }, + + fetchSnippetDetail: async (snippetId) => { + const fetchSnippetDetailUrl = `${API_HOST}/v2/GetAutoDocInfoDetail` + const params = {adi_sn: snippetId}; + + return fetchJSON(fetchSnippetDetailUrl, params) + .then(json => { + if (json.errcode === 0 && json?.result.length > 0) { + console.info(json) + return json?.result[0].adi_content + } else { + throw new Error(json?.errmsg + ': ' + json.errcode) + } + }) + + }, }), { name: 'snippetStore' })) export default useSnippetStore \ No newline at end of file diff --git a/src/views/DesktopApp.jsx b/src/views/DesktopApp.jsx index 9bb5774..7e51214 100644 --- a/src/views/DesktopApp.jsx +++ b/src/views/DesktopApp.jsx @@ -1,4 +1,5 @@ import useAuthStore from '@/stores/AuthStore' +import useSnippetStore from '@/stores/SnippetStore' import useConversationStore from '@/stores/ConversationStore' import { useThemeContext } from '@/stores/ThemeContext' import { DownOutlined } from '@ant-design/icons' @@ -40,11 +41,19 @@ function DesktopApp() { const totalNotify = useConversationStore((state) => state.totalNotify) - const [drawerOpen, setDrawerOpen] = useState(false) + const [ + openDrawer, + closeDrawer, + drawerOpen, + ] = useSnippetStore((state) => [ + state.openDrawer, + state.closeDrawer, + state.drawerOpen, + ]) const onClick = ({ key }) => { if (key === 'snippet-list') { - setDrawerOpen(true) + openDrawer() } } @@ -101,8 +110,9 @@ function DesktopApp() { title='图文集管理' placement={'top'} size={'large'} - onClose={() => setDrawerOpen(false)} - open={drawerOpen}> + onClose={() => closeDrawer()} + open={drawerOpen} + > diff --git a/src/views/accounts/HtmlPreview.jsx b/src/views/accounts/HtmlPreview.jsx new file mode 100644 index 0000000..42b67dd --- /dev/null +++ b/src/views/accounts/HtmlPreview.jsx @@ -0,0 +1,61 @@ +import { Empty, Skeleton, Divider, Flex, Button } from 'antd' +import { Conditional } from '@/components/Conditional' +import { isEmpty, isNotEmpty } from '@/utils/commons' + +const decodeHtml = (text) => { + + if (isEmpty(text)) return + + const temp = document.createElement('div') + temp.innerHTML = text + + return temp.innerText || temp.textContent +} + +const HtmlPreview = (props) => { + const { loading = false, value } = props + + const html = decodeHtml(value) + + if (loading) { + return + } + + return ( +
+ + {html} + + } + whenFalse={} + /> + + + + + + +
+ ) +} + +export default HtmlPreview diff --git a/src/views/accounts/SnippetList.jsx b/src/views/accounts/SnippetList.jsx index 7b4872d..9db2d41 100644 --- a/src/views/accounts/SnippetList.jsx +++ b/src/views/accounts/SnippetList.jsx @@ -9,28 +9,42 @@ import { Button, Space, Modal, - Select + Select, + Divider, + Empty, } from 'antd' import { useState, useRef, useEffect } from 'react' import LexicalEditorInput from './LexicalEditorInput' +import HtmlPreview from './HtmlPreview' import useSnippetStore from '@/stores/SnippetStore' +import { isEmpty, isNotEmpty } from '@/utils/commons' function SnippetList() { - const [form] = Form.useForm() + const [searchform] = Form.useForm() const [snippetForm] = Form.useForm() - const editorRef = useRef(null) - const [fetchParamList, ownerList, typeList] = - useSnippetStore(state => [state.fetchParamList, state.ownerList, state.typeList]) + const [ + fetchParamList, + ownerList, + typeList, + fetchSnippetList, + snippetList, + fetchSnippetDetail, + ] = useSnippetStore((state) => [ + state.fetchParamList, + state.ownerList, + state.typeList, + state.fetchSnippetList, + state.snippetList, + state.fetchSnippetDetail, + ]) const [isSnippetModalOpen, setSnippetModalOpen] = useState(false) - const [editorContent, setEditorContent] = useState( - "

Discover the best of the world with one of the best-rated tour companies for personalized travel. With over 10,000+ reviews and a 98.8% 5-star rating, we focus on streamlining your planning and ensuring joyful travels. Whether it's a milestone celebration or a relaxing getaway, let us help create your beautiful journey.

", - ) + const [editorContent, setEditorContent] = useState('') + const [isHtmlLoading, setHtmlLoading] = useState(false) const onSnippetFinish = (values) => { console.log('onSnippetFinish:', values) - // console.info(JSON.stringify(editorRef.current.getEditorState())) } @@ -39,6 +53,20 @@ function SnippetList() { // form.resetFields() } + const handleSearchFinish = (values) => { + console.log('handleSearchFinish:', values) + fetchSnippetList(values) + } + + const handleSnippetSelected = (snippetId) => { + setHtmlLoading(true) + fetchSnippetDetail(snippetId) + .then((content) => { + setEditorContent(content) + }) + .finally(() => setHtmlLoading(false)) + } + useEffect(() => { fetchParamList() }, []) @@ -93,10 +121,10 @@ function SnippetList() { }, ]}>
- - - - - - - - - - + + - @@ -153,7 +173,7 @@ function SnippetList() { onClick={() => { snippetForm.setFieldsValue({ title: 'Title....', - content: editorContent + content: editorContent, }) setSnippetModalOpen(true) }}> @@ -165,27 +185,17 @@ function SnippetList() { ( { - console.info(item) - setEditorContent('' + item + '') + onClick={() => { + handleSnippetSelected(item.adi_sn) }}> - - 类型 - {item} - - -
王静
+ {item.adi_title} + + {item.adi_type_name}
@@ -193,51 +203,7 @@ function SnippetList() { /> -
- -
-                  

- Discover China with the award-winning and{' '} - best-rated tour company for{' '} - personalized travel in China. Honored as{' '} - China is Leading Tour Operator by the{' '} - World Travel Awards, we boast{' '} - 10,000+ reviews and a remarkable{' '} - 98.8% 5-star rating. Our expertise in - customizing personalized China explorations is backed by our - company-managed local services across China. Explore and - kickstart your personalized travel experience with just a - click! -

-
- - - - - -
-
+