Fix share page feedback auth (#3284)

* fix: share page mark auth

* perf: lang check

* perf: load share
This commit is contained in:
Archer
2024-12-01 21:09:13 +08:00
committed by GitHub
parent d0e8c9c62e
commit 1cef206c13
7 changed files with 39 additions and 76 deletions

View File

@@ -50,8 +50,8 @@ const SelectUsingWayModal = ({ share, onClose }: { share: OutLinkSchema; onClose
defaultValues: {
usingWay: UsingWayEnum.link,
showHistory: true,
scriptIconCanDrag: true,
scriptDefaultOpen: true,
scriptIconCanDrag: false,
scriptDefaultOpen: false,
scriptOpenIcon:
'data:image/svg+xml;base64,PHN2ZyB0PSIxNjkwNTMyNzg1NjY0IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjQxMzIiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIj48cGF0aCBkPSJNNTEyIDMyQzI0Ny4wNCAzMiAzMiAyMjQgMzIgNDY0QTQxMC4yNCA0MTAuMjQgMCAwIDAgMTcyLjQ4IDc2OEwxNjAgOTY1LjEyYTI1LjI4IDI1LjI4IDAgMCAwIDM5LjA0IDIyLjRsMTY4LTExMkE1MjguNjQgNTI4LjY0IDAgMCAwIDUxMiA4OTZjMjY0Ljk2IDAgNDgwLTE5MiA0ODAtNDMyUzc3Ni45NiAzMiA1MTIgMzJ6IG0yNDQuOCA0MTZsLTM2MS42IDMwMS43NmExMi40OCAxMi40OCAwIDAgMS0xOS44NC0xMi40OGw1OS4yLTIzMy45MmgtMTYwYTEyLjQ4IDEyLjQ4IDAgMCAxLTcuMzYtMjMuMzZsMzYxLjYtMzAxLjc2YTEyLjQ4IDEyLjQ4IDAgMCAxIDE5Ljg0IDEyLjQ4bC01OS4yIDIzMy45MmgxNjBhMTIuNDggMTIuNDggMCAwIDEgOCAyMi4wOHoiIGZpbGw9IiM0ZTgzZmQiIHAtaWQ9IjQxMzMiPjwvcGF0aD48L3N2Zz4=',
scriptCloseIcon:
@@ -96,6 +96,7 @@ const SelectUsingWayModal = ({ share, onClose }: { share: OutLinkSchema; onClose
[UsingWayEnum.script]: {
blockTitle: t('common:core.app.outLink.Script block title'),
code: `<script
type="text/javascript"
src="${baseUrl}/js/iframe.js"
id="chatbot-iframe"
data-bot-src="${linkUrl}"
@@ -104,10 +105,7 @@ const SelectUsingWayModal = ({ share, onClose }: { share: OutLinkSchema; onClose
data-open-icon="${getValues('scriptOpenIcon')}"
data-close-icon="${getValues('scriptCloseIcon')}"
defer
></script>
<script>
console.log("Chat box loaded")
</script>`
></script>`
}
};

View File

@@ -84,10 +84,11 @@ const OutLink = (props: Props) => {
const chatRecords = useContextSelector(ChatRecordContext, (v) => v.chatRecords);
const totalRecordsCount = useContextSelector(ChatRecordContext, (v) => v.totalRecordsCount);
const isChatRecordsLoaded = useContextSelector(ChatRecordContext, (v) => v.isChatRecordsLoaded);
const initSign = useRef(false);
const [chatData, setChatData] = useState<InitChatResponse>(defaultChatData);
const { loading: isLoading } = useRequest2(
const { data, loading: isLoading } = useRequest2(
async () => {
const shareId = outLinkAuthData.shareId;
const outLinkUid = outLinkAuthData.outLinkUid;
@@ -104,19 +105,12 @@ const OutLink = (props: Props) => {
resetVariables({
variables: res.variables
});
return res;
},
{
manual: false,
refreshDeps: [shareId, outLinkAuthData, chatId],
onSuccess() {
// send init message
if (!initSign.current) {
initSign.current = true;
if (window !== top) {
window.top?.postMessage({ type: 'shareChatReady' }, '*');
}
}
},
onError(e: any) {
if (chatId) {
onChangeChatId('');
@@ -127,6 +121,14 @@ const OutLink = (props: Props) => {
}
}
);
useEffect(() => {
if (initSign.current === false && data && isChatRecordsLoaded) {
initSign.current = true;
if (window !== top) {
window.top?.postMessage({ type: 'shareChatReady' }, '*');
}
}
}, [data, isChatRecordsLoaded]);
const startChat = useCallback(
async ({
@@ -295,8 +297,6 @@ const Render = (props: Props) => {
const { localUId, loaded } = useShareChatStore();
const { source, chatId, setSource, setAppId, setOutLinkAuthData } = useChatStore();
const [isLoaded, setIsLoaded] = useState(false);
const chatHistoryProviderParams = useMemo(() => {
return { shareId, outLinkUid: authToken || customUid || localUId };
}, [authToken, customUid, localUId, shareId]);
@@ -311,11 +311,8 @@ const Render = (props: Props) => {
}, [appId, chatHistoryProviderParams.outLinkUid, chatId, shareId]);
useMount(() => {
setIsLoaded(true);
setSource('share');
});
const systemLoaded = isLoaded && loaded && chatHistoryProviderParams.outLinkUid;
// Set outLinkAuthData
useEffect(() => {