url params filter logic (#4694)
This commit is contained in:
parent
ca8adbbf95
commit
293c0cdb40
@ -89,7 +89,7 @@ const A = ({ children, ...props }: any) => {
|
|||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent boxShadow={'lg'} w={'500px'} py={4}>
|
<PopoverContent boxShadow={'lg'} w={'500px'} maxW={'90vw'} py={4}>
|
||||||
<MyBox isLoading={loading}>
|
<MyBox isLoading={loading}>
|
||||||
<PopoverArrow />
|
<PopoverArrow />
|
||||||
<PopoverBody py={0} px={0} fontSize={'sm'}>
|
<PopoverBody py={0} px={0} fontSize={'sm'}>
|
||||||
|
|||||||
@ -17,24 +17,57 @@ import {
|
|||||||
} from '../support/marketing/utils';
|
} from '../support/marketing/utils';
|
||||||
import { ShortUrlParams } from '@fastgpt/global/support/marketing/type';
|
import { ShortUrlParams } from '@fastgpt/global/support/marketing/type';
|
||||||
|
|
||||||
|
type MarketingQueryParams = {
|
||||||
|
hiId?: string;
|
||||||
|
bd_vid?: string;
|
||||||
|
k?: string;
|
||||||
|
sourceDomain?: string;
|
||||||
|
utm_source?: string;
|
||||||
|
utm_medium?: string;
|
||||||
|
utm_content?: string;
|
||||||
|
utm_workflow?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const MARKETING_PARAMS: (keyof MarketingQueryParams)[] = [
|
||||||
|
'hiId',
|
||||||
|
'bd_vid',
|
||||||
|
'k',
|
||||||
|
'sourceDomain',
|
||||||
|
'utm_source',
|
||||||
|
'utm_medium',
|
||||||
|
'utm_content',
|
||||||
|
'utm_workflow'
|
||||||
|
];
|
||||||
|
|
||||||
export const useInitApp = () => {
|
export const useInitApp = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { hiId, bd_vid, k, sourceDomain, utm_source, utm_medium, utm_content, utm_workflow } =
|
const { hiId, bd_vid, k, sourceDomain, utm_source, utm_medium, utm_content, utm_workflow } =
|
||||||
router.query as {
|
router.query as MarketingQueryParams;
|
||||||
hiId?: string;
|
|
||||||
bd_vid?: string;
|
|
||||||
k?: string;
|
|
||||||
sourceDomain?: string;
|
|
||||||
utm_source?: string;
|
|
||||||
utm_medium?: string;
|
|
||||||
utm_content?: string;
|
|
||||||
utm_workflow?: string;
|
|
||||||
};
|
|
||||||
const { loadGitStar, setInitd, feConfigs } = useSystemStore();
|
const { loadGitStar, setInitd, feConfigs } = useSystemStore();
|
||||||
const { userInfo } = useUserStore();
|
const { userInfo } = useUserStore();
|
||||||
const [scripts, setScripts] = useState<FastGPTFeConfigsType['scripts']>([]);
|
const [scripts, setScripts] = useState<FastGPTFeConfigsType['scripts']>([]);
|
||||||
const [title, setTitle] = useState(process.env.SYSTEM_NAME || 'AI');
|
const [title, setTitle] = useState(process.env.SYSTEM_NAME || 'AI');
|
||||||
|
|
||||||
|
const getPathWithoutMarketingParams = () => {
|
||||||
|
const filteredQuery = { ...router.query };
|
||||||
|
MARKETING_PARAMS.forEach((param) => {
|
||||||
|
delete filteredQuery[param];
|
||||||
|
});
|
||||||
|
|
||||||
|
const newQuery = new URLSearchParams();
|
||||||
|
Object.entries(filteredQuery).forEach(([key, value]) => {
|
||||||
|
if (value) {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
value.forEach((v) => newQuery.append(key, v));
|
||||||
|
} else {
|
||||||
|
newQuery.append(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return `${router.pathname}${newQuery.toString() ? `?${newQuery.toString()}` : ''}`;
|
||||||
|
};
|
||||||
|
|
||||||
const initFetch = useMemoizedFn(async () => {
|
const initFetch = useMemoizedFn(async () => {
|
||||||
const {
|
const {
|
||||||
feConfigs: { scripts, isPlus, systemTitle }
|
feConfigs: { scripts, isPlus, systemTitle }
|
||||||
@ -98,7 +131,8 @@ export const useInitApp = () => {
|
|||||||
setUtmParams(utmParams);
|
setUtmParams(utmParams);
|
||||||
setFastGPTSem({ keyword: k, ...utmParams });
|
setFastGPTSem({ keyword: k, ...utmParams });
|
||||||
|
|
||||||
router.replace(router.pathname);
|
const newPath = getPathWithoutMarketingParams();
|
||||||
|
router.replace(newPath);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user