mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-26 04:32:50 +00:00
fix: custom domain selector
This commit is contained in:
parent
8cd7146bd6
commit
cd45c53867
|
|
@ -188,10 +188,7 @@ const WecomEditModal = ({
|
|||
<Flex>
|
||||
{feConfigs?.docUrl && (
|
||||
<Link
|
||||
href={
|
||||
feConfigs.openAPIDocUrl ||
|
||||
getDocPath('/docs/use-cases/external-integration/wecom')
|
||||
}
|
||||
href={getDocPath('/docs/use-cases/external-integration/wecom')}
|
||||
target={'_blank'}
|
||||
ml={2}
|
||||
color={'primary.500'}
|
||||
|
|
@ -232,6 +229,8 @@ const WecomEditModal = ({
|
|||
<ShareLinkContainer
|
||||
shareLink={`${baseUrl}/support/outLink/wecom/${shareId}`}
|
||||
img="/imgs/outlink/wecom-copylink-instruction.png"
|
||||
defaultDomain={false}
|
||||
showCustomDomainSelector={true}
|
||||
></ShareLinkContainer>
|
||||
</Box>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ import dynamic from 'next/dynamic';
|
|||
import MyMenu from '@fastgpt/web/components/common/MyMenu';
|
||||
import EmptyTip from '@fastgpt/web/components/common/EmptyTip';
|
||||
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
|
||||
import { getDocPath } from '@/web/common/system/doc';
|
||||
import { listCustomDomain } from '@/web/support/customDomain/api';
|
||||
|
||||
const WecomEditModal = dynamic(() => import('./WecomEditModal'));
|
||||
const ShowShareLinkModal = dynamic(() => import('../components/showShareLinkModal'));
|
||||
|
|
@ -59,22 +61,44 @@ const Wecom = ({ appId }: { appId: string }) => {
|
|||
|
||||
const [showShareLink, setShowShareLink] = useState<string | null>(null);
|
||||
|
||||
const { data: customDomains = [] } = useRequest2(listCustomDomain, {
|
||||
manual: false
|
||||
});
|
||||
|
||||
return (
|
||||
<Box position={'relative'} pt={3} px={5} minH={'50vh'}>
|
||||
<Flex justifyContent={'space-between'} flexDirection="row">
|
||||
<Box fontWeight={'bold'} fontSize={['md', 'lg']}>
|
||||
{t('publish:wecom.title')}
|
||||
</Box>
|
||||
<Flex alignItems={'center'}>
|
||||
<Box fontWeight={'bold'} fontSize={['md', 'lg']}>
|
||||
{t('publish:wecom.title')}
|
||||
</Box>
|
||||
{feConfigs?.docUrl && (
|
||||
<Link
|
||||
href={getDocPath('/docs/use-cases/external-integration/wecom')}
|
||||
target={'_blank'}
|
||||
ml={2}
|
||||
color={'primary.500'}
|
||||
fontSize={'sm'}
|
||||
>
|
||||
<Flex alignItems={'center'}>
|
||||
<MyIcon name="book" w={'17px'} h={'17px'} mr="1" />
|
||||
{t('common:read_doc')}
|
||||
</Flex>
|
||||
</Link>
|
||||
)}
|
||||
</Flex>
|
||||
<Flex gap={3}>
|
||||
<Button
|
||||
variant={'whitePrimary'}
|
||||
size={['sm', 'md']}
|
||||
onClick={() => {
|
||||
window.open('/account/customDomain', '_blank');
|
||||
}}
|
||||
>
|
||||
{t('publish:custom_domain_management')}
|
||||
</Button>
|
||||
{feConfigs.customDomain?.enable && (
|
||||
<Button
|
||||
variant={'whitePrimary'}
|
||||
size={['sm', 'md']}
|
||||
onClick={() => {
|
||||
window.open('/account/customDomain', '_blank');
|
||||
}}
|
||||
>
|
||||
{t('publish:custom_domain_management')}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant={'primary'}
|
||||
colorScheme={'blue'}
|
||||
|
|
@ -222,22 +246,25 @@ const Wecom = ({ appId }: { appId: string }) => {
|
|||
)}
|
||||
{shareChatList.length === 0 && !isFetching && (
|
||||
<EmptyTip
|
||||
text={
|
||||
<Trans
|
||||
i18nKey="app:publish_channel.wecom.empty"
|
||||
components={{
|
||||
a: (
|
||||
<Link
|
||||
color="primary.600"
|
||||
key="link"
|
||||
href="/account/customDomain"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
/>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
}
|
||||
{...(feConfigs.customDomain?.enable &&
|
||||
customDomains.length > 0 && {
|
||||
text: (
|
||||
<Trans
|
||||
i18nKey="app:publish_channel.wecom.empty"
|
||||
components={{
|
||||
a: (
|
||||
<Link
|
||||
color="primary.600"
|
||||
key="link"
|
||||
href="/account/customDomain"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
/>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
></EmptyTip>
|
||||
)}
|
||||
<Loading loading={isFetching} fixed={false} />
|
||||
|
|
@ -246,6 +273,8 @@ const Wecom = ({ appId }: { appId: string }) => {
|
|||
shareLink={showShareLink ?? ''}
|
||||
onClose={closeShowShareLinkModal}
|
||||
img="/imgs/outlink/wecom-copylink-instruction.png"
|
||||
defaultDomain={false}
|
||||
showCustomDomainSelector={true}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
|
|
|
|||
|
|
@ -7,22 +7,34 @@ import MyImage from '@fastgpt/web/components/common/Image/MyImage';
|
|||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
|
||||
import { listCustomDomain } from '@/web/support/customDomain/api';
|
||||
import { useState, useMemo } from 'react';
|
||||
import { useState, useMemo, useEffect } from 'react';
|
||||
import MySelect from '@fastgpt/web/components/common/MySelect';
|
||||
|
||||
export type ShowShareLinkModalProps = {
|
||||
shareLink: string;
|
||||
onClose: () => void;
|
||||
img: string;
|
||||
defaultDomain?: boolean;
|
||||
showCustomDomainSelector?: boolean;
|
||||
};
|
||||
|
||||
export const ShareLinkContainer = ({ shareLink, img }: { shareLink: string; img: string }) => {
|
||||
export const ShareLinkContainer = ({
|
||||
shareLink,
|
||||
img,
|
||||
defaultDomain = true,
|
||||
showCustomDomainSelector = false
|
||||
}: {
|
||||
shareLink: string;
|
||||
img: string;
|
||||
defaultDomain?: boolean;
|
||||
showCustomDomainSelector?: boolean;
|
||||
}) => {
|
||||
const { copyData } = useCopyData();
|
||||
const { t } = useTranslation();
|
||||
const [customDomain, setCustomDomain] = useState<string | undefined>(undefined);
|
||||
|
||||
const { data: customDomainList = [] } = useRequest2(listCustomDomain, {
|
||||
manual: false
|
||||
manual: !showCustomDomainSelector
|
||||
});
|
||||
|
||||
// 从 shareLink 中提取原始域名
|
||||
|
|
@ -45,9 +57,9 @@ export const ShareLinkContainer = ({ shareLink, img }: { shareLink: string; img:
|
|||
|
||||
// 处理域名选择选项
|
||||
const domainOptions = useMemo(() => {
|
||||
const options = [
|
||||
const defaultOption = [
|
||||
{
|
||||
label: t('publish:use_default_domain') || '使用默认域名',
|
||||
label: t('publish:use_default_domain'),
|
||||
value: ''
|
||||
}
|
||||
];
|
||||
|
|
@ -60,12 +72,22 @@ export const ShareLinkContainer = ({ shareLink, img }: { shareLink: string; img:
|
|||
value: item.domain
|
||||
}));
|
||||
|
||||
return [...options, ...activeDomains];
|
||||
}, [customDomainList, t]);
|
||||
return activeDomains.length === 0
|
||||
? [...defaultOption]
|
||||
: [...(defaultDomain ? defaultOption : []), ...activeDomains];
|
||||
}, [customDomainList, defaultDomain, t]);
|
||||
|
||||
// 当 defaultDomain=false 时,自动选择第一个自定义域名
|
||||
useEffect(() => {
|
||||
if (!defaultDomain && domainOptions.length > 0 && customDomain === undefined) {
|
||||
setCustomDomain(domainOptions[0].value || undefined);
|
||||
}
|
||||
}, [defaultDomain, domainOptions, customDomain]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* 自定义域名选择器 */}
|
||||
{domainOptions.length > 1 && (
|
||||
{showCustomDomainSelector && domainOptions.length > 1 && (
|
||||
<Box mb={4}>
|
||||
<MySelect
|
||||
value={customDomain || ''}
|
||||
|
|
@ -129,13 +151,24 @@ export const ShareLinkContainer = ({ shareLink, img }: { shareLink: string; img:
|
|||
);
|
||||
};
|
||||
|
||||
function ShowShareLinkModal({ shareLink, onClose, img }: ShowShareLinkModalProps) {
|
||||
function ShowShareLinkModal({
|
||||
shareLink,
|
||||
onClose,
|
||||
img,
|
||||
defaultDomain,
|
||||
showCustomDomainSelector
|
||||
}: ShowShareLinkModalProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<MyModal onClose={onClose} title={t('publish:show_share_link_modal_title')}>
|
||||
<ModalBody>
|
||||
<ShareLinkContainer shareLink={shareLink} img={img} />
|
||||
<ShareLinkContainer
|
||||
shareLink={shareLink}
|
||||
img={img}
|
||||
defaultDomain={defaultDomain}
|
||||
showCustomDomainSelector={showCustomDomainSelector}
|
||||
/>
|
||||
</ModalBody>
|
||||
</MyModal>
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue