Skip to content

Commit 293c0cd

Browse files
authored
url params filter logic (#4694)
1 parent ca8adbb commit 293c0cd

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

projects/app/src/components/Markdown/A.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const A = ({ children, ...props }: any) => {
8989
/>
9090
</Button>
9191
</PopoverTrigger>
92-
<PopoverContent boxShadow={'lg'} w={'500px'} py={4}>
92+
<PopoverContent boxShadow={'lg'} w={'500px'} maxW={'90vw'} py={4}>
9393
<MyBox isLoading={loading}>
9494
<PopoverArrow />
9595
<PopoverBody py={0} px={0} fontSize={'sm'}>

projects/app/src/web/context/useInitApp.ts

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,57 @@ import {
1717
} from '../support/marketing/utils';
1818
import { ShortUrlParams } from '@fastgpt/global/support/marketing/type';
1919

20+
type MarketingQueryParams = {
21+
hiId?: string;
22+
bd_vid?: string;
23+
k?: string;
24+
sourceDomain?: string;
25+
utm_source?: string;
26+
utm_medium?: string;
27+
utm_content?: string;
28+
utm_workflow?: string;
29+
};
30+
31+
const MARKETING_PARAMS: (keyof MarketingQueryParams)[] = [
32+
'hiId',
33+
'bd_vid',
34+
'k',
35+
'sourceDomain',
36+
'utm_source',
37+
'utm_medium',
38+
'utm_content',
39+
'utm_workflow'
40+
];
41+
2042
export const useInitApp = () => {
2143
const router = useRouter();
2244
const { hiId, bd_vid, k, sourceDomain, utm_source, utm_medium, utm_content, utm_workflow } =
23-
router.query as {
24-
hiId?: string;
25-
bd_vid?: string;
26-
k?: string;
27-
sourceDomain?: string;
28-
utm_source?: string;
29-
utm_medium?: string;
30-
utm_content?: string;
31-
utm_workflow?: string;
32-
};
45+
router.query as MarketingQueryParams;
3346
const { loadGitStar, setInitd, feConfigs } = useSystemStore();
3447
const { userInfo } = useUserStore();
3548
const [scripts, setScripts] = useState<FastGPTFeConfigsType['scripts']>([]);
3649
const [title, setTitle] = useState(process.env.SYSTEM_NAME || 'AI');
3750

51+
const getPathWithoutMarketingParams = () => {
52+
const filteredQuery = { ...router.query };
53+
MARKETING_PARAMS.forEach((param) => {
54+
delete filteredQuery[param];
55+
});
56+
57+
const newQuery = new URLSearchParams();
58+
Object.entries(filteredQuery).forEach(([key, value]) => {
59+
if (value) {
60+
if (Array.isArray(value)) {
61+
value.forEach((v) => newQuery.append(key, v));
62+
} else {
63+
newQuery.append(key, value);
64+
}
65+
}
66+
});
67+
68+
return `${router.pathname}${newQuery.toString() ? `?${newQuery.toString()}` : ''}`;
69+
};
70+
3871
const initFetch = useMemoizedFn(async () => {
3972
const {
4073
feConfigs: { scripts, isPlus, systemTitle }
@@ -98,7 +131,8 @@ export const useInitApp = () => {
98131
setUtmParams(utmParams);
99132
setFastGPTSem({ keyword: k, ...utmParams });
100133

101-
router.replace(router.pathname);
134+
const newPath = getPathWithoutMarketingParams();
135+
router.replace(newPath);
102136
});
103137

104138
return {

0 commit comments

Comments
 (0)