对接OME Office APP数据

This commit is contained in:
Ted 2025-02-19 10:27:52 +08:00
parent e65a33d801
commit 4f3410f4f1
2 changed files with 27 additions and 2 deletions

View File

@ -30,7 +30,7 @@ import { type ClientApi, getClientApi } from "../client/api";
import { useAccessStore } from "../store"; import { useAccessStore } from "../store";
import clsx from "clsx"; import clsx from "clsx";
import { initializeMcpSystem, isMcpEnabled } from "../mcp/actions"; import { initializeMcpSystem, isMcpEnabled } from "../mcp/actions";
import { isEmpty } from "lodash-es"; import { isEmpty, isString } from "lodash-es";
export function Loading(props: { noLogo?: boolean }) { export function Loading(props: { noLogo?: boolean }) {
return ( return (
@ -264,7 +264,32 @@ export function Home() {
useEffect(() => { useEffect(() => {
window.parent.postMessage("omemetis is ready", "*"); window.parent.postMessage("omemetis is ready", "*");
try {
const message = {
data: "omemetis is ready",
url: location.origin,
};
window.ReactNativeWebView.postMessage(JSON.stringify(message));
} catch {
console.log("window.ReactNativeWebView Err");
}
const handleMessage = (event: any) => { const handleMessage = (event: any) => {
const data = event.data;
if (isString(data)) {
try {
const params = JSON.parse(data);
if (!isEmpty(params?.omeToken) && params?.from === "OmeOfficeApp")
appConfig.setOmeToken(params?.omeToken ?? "");
} catch {}
return;
}
// 逻辑判断 是对象还是字符串
if (!event.origin.includes("omeoffice")) { if (!event.origin.includes("omeoffice")) {
return; // 如果不是信任的源,忽略消息 return; // 如果不是信任的源,忽略消息
} }

View File

@ -1775,7 +1775,7 @@ export function Settings() {
</List> </List>
<List id={SlotID.CustomModel}> <List id={SlotID.CustomModel}>
{saasStartComponent} {/* {saasStartComponent} */}
{accessCodeComponent} {accessCodeComponent}
{!accessStore.hideUserApiKey && ( {!accessStore.hideUserApiKey && (