diff --git a/packages/client/src/components/document/share/index.tsx b/packages/client/src/components/document/share/index.tsx index 9420f24a..1efa6182 100644 --- a/packages/client/src/components/document/share/index.tsx +++ b/packages/client/src/components/document/share/index.tsx @@ -1,12 +1,12 @@ import { IconLink } from '@douyinfe/semi-icons'; -import { Button, Input, Modal, Toast, Typography } from '@douyinfe/semi-ui'; +import { Button, Input, Popover, Space, Toast, Typography } from '@douyinfe/semi-ui'; import { isPublicDocument } from '@think/domains'; -import { DataRender } from 'components/data-render'; import { useDocumentDetail } from 'data/document'; import { getDocumentShareURL } from 'helpers/url'; +import { IsOnMobile } from 'hooks/use-on-mobile'; import { useToggle } from 'hooks/use-toggle'; import { ShareIllustration } from 'illustrations/share'; -import React, { useEffect, useMemo, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; interface IProps { documentId: string; @@ -17,23 +17,104 @@ interface IProps { const { Text } = Typography; export const DocumentShare: React.FC = ({ documentId, disabled = false, render }) => { + const { isMobile } = IsOnMobile.useHook(); + const ref = useRef(); const [visible, toggleVisible] = useToggle(false); - const { data, loading, error, toggleStatus } = useDocumentDetail(documentId, { enabled: visible }); + const { data, loading, toggleStatus } = useDocumentDetail(documentId, { enabled: visible }); const [sharePassword, setSharePassword] = useState(''); const isPublic = useMemo(() => data && isPublicDocument(data.document.status), [data]); const shareUrl = useMemo(() => data && getDocumentShareURL(data.document.id), [data]); - const handleOk = () => { + const copyable = useMemo( + () => ({ + onCopy: () => Toast.success({ content: '复制文本成功' }), + }), + [] + ); + + const prevent = useCallback((e) => { + e.stopPropagation(); + }, []); + + const viewUrl = useCallback(() => { + window.open(shareUrl, '_blank'); + }, [shareUrl]); + + const handleOk = useCallback(() => { toggleStatus({ sharePassword: isPublic ? '' : sharePassword }); - }; + }, [isPublic, sharePassword, toggleStatus]); useEffect(() => { if (loading || !data) return; setSharePassword(data.document && data.document.sharePassword); }, [loading, data]); + useEffect(() => { + if (visible) { + setTimeout(() => ref.current?.focus(), 100); + } + }, [visible]); + return ( - <> + +
+ +
+ {isPublic ? ( + } + copyable={copyable} + style={{ + width: 240, + }} + > + {shareUrl} + + ) : ( + + )} +
+ + {isPublic + ? '分享开启后,该页面包含的所有内容均可访问,请谨慎开启' + : ' 分享关闭后,其他人将不能继续访问该页面'} + +
+ + + + {isPublic && ( + + )} + + + } + > {render ? ( render({ isPublic, disabled, toggleVisible }) ) : ( @@ -41,76 +122,6 @@ export const DocumentShare: React.FC = ({ documentId, disabled = false, {isPublic ? '分享中' : '分享'} )} - toggleVisible(false)} - style={{ maxWidth: '96vw' }} - footer={ - <> - - - {isPublic && ( - - )} - - } - > - { - return ( -
-
- -
- {isPublic ? ( - } - copyable={{ - onCopy: () => Toast.success({ content: '复制文本成功' }), - }} - style={{ - width: 320, - }} - > - {shareUrl} - - ) : ( - - )} -
- - {isPublic - ? '分享开启后,该页面包含的所有内容均可访问,请谨慎开启' - : ' 分享关闭后,其他人将不能继续访问该页面'} - -
-
- ); - }} - /> -
- +
); };