增强场景模型导入请求反馈
This commit is contained in:
@@ -35,6 +35,7 @@ type SceneModelMessagePayload = {
|
|||||||
|
|
||||||
type SceneModelMessage = {
|
type SceneModelMessage = {
|
||||||
type?: string;
|
type?: string;
|
||||||
|
requestId?: string;
|
||||||
payload?: SceneModelMessagePayload;
|
payload?: SceneModelMessagePayload;
|
||||||
message?: string;
|
message?: string;
|
||||||
};
|
};
|
||||||
@@ -42,6 +43,8 @@ type SceneModelMessage = {
|
|||||||
let dictionariesLoaded = false;
|
let dictionariesLoaded = false;
|
||||||
let dictionariesLoading: Promise<void> | null = null;
|
let dictionariesLoading: Promise<void> | null = null;
|
||||||
let sceneModelBridgeBound = false;
|
let sceneModelBridgeBound = false;
|
||||||
|
let pendingSceneModelRequestId = "";
|
||||||
|
let pendingSceneModelRequestTimer: number | null = null;
|
||||||
|
|
||||||
export function bindModelActions() {
|
export function bindModelActions() {
|
||||||
const isAdmin = getCurrentUser()?.role === "admin";
|
const isAdmin = getCurrentUser()?.role === "admin";
|
||||||
@@ -305,13 +308,26 @@ function requestSceneModelImport() {
|
|||||||
notify("请在 DMT 主程序中使用导入场景模型");
|
notify("请在 DMT 主程序中使用导入场景模型");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const requestId = createSceneModelRequestId();
|
||||||
|
pendingSceneModelRequestId = requestId;
|
||||||
|
clearSceneModelRequestTimer();
|
||||||
|
pendingSceneModelRequestTimer = window.setTimeout(() => {
|
||||||
|
if (pendingSceneModelRequestId !== requestId) return;
|
||||||
|
pendingSceneModelRequestId = "";
|
||||||
|
pendingSceneModelRequestTimer = null;
|
||||||
|
notifyError("主程序未响应导入场景模型请求,请确认模型库是在主程序面板中打开");
|
||||||
|
}, 15000);
|
||||||
window.parent.postMessage({
|
window.parent.postMessage({
|
||||||
type: requestSceneModelMessageType
|
type: requestSceneModelMessageType,
|
||||||
|
requestId
|
||||||
}, resolveParentOrigin());
|
}, resolveParentOrigin());
|
||||||
notify("已请求主程序导出当前选中模型");
|
notify("已请求主程序导出当前选中模型");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSceneModelMessage(data: SceneModelMessage) {
|
async function handleSceneModelMessage(data: SceneModelMessage) {
|
||||||
|
if (pendingSceneModelRequestId && data.requestId && data.requestId !== pendingSceneModelRequestId) return;
|
||||||
|
pendingSceneModelRequestId = "";
|
||||||
|
clearSceneModelRequestTimer();
|
||||||
if (data.type === sceneModelErrorMessageType) {
|
if (data.type === sceneModelErrorMessageType) {
|
||||||
notifyError(data.message || "主程序导出模型失败");
|
notifyError(data.message || "主程序导出模型失败");
|
||||||
return;
|
return;
|
||||||
@@ -332,6 +348,16 @@ async function handleSceneModelMessage(data: SceneModelMessage) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearSceneModelRequestTimer() {
|
||||||
|
if (pendingSceneModelRequestTimer === null) return;
|
||||||
|
window.clearTimeout(pendingSceneModelRequestTimer);
|
||||||
|
pendingSceneModelRequestTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createSceneModelRequestId() {
|
||||||
|
return `scene-model-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
||||||
|
}
|
||||||
|
|
||||||
function isAllowedParentOrigin(origin: string) {
|
function isAllowedParentOrigin(origin: string) {
|
||||||
const expectedOrigin = resolveParentOrigin();
|
const expectedOrigin = resolveParentOrigin();
|
||||||
return expectedOrigin === "*" || origin === expectedOrigin;
|
return expectedOrigin === "*" || origin === expectedOrigin;
|
||||||
|
|||||||
Reference in New Issue
Block a user