refactor: export panelWindowManager

chore/devcontainer
moonrailgun 1 year ago
parent 087713afbf
commit e0f9f5dab9

@ -34,6 +34,7 @@ export {
} from '@/utils/url-helper';
export { getServiceWorkerRegistration } from '@/utils/sw-helper';
export { postMessageEvent } from '@/utils/event-helper';
export { panelWindowManager } from '@/utils/window-helper';
import {
/**
* : Tailchat requestimport axios()

@ -16,15 +16,25 @@ export function buildWindowFeatures(
.join(',');
}
interface OpenInNewWindowOptions {
width?: number;
height?: number;
top?: number;
left?: number;
}
/**
*
* @param url
*/
export function openInNewWindow(url: string) {
const width = 414;
const height = 736;
const top = (window.screen.height - height) / 2;
const left = (window.screen.width - width) / 2;
export function openInNewWindow(
url: string,
options: OpenInNewWindowOptions = {}
) {
const width = options.width ?? 414;
const height = options.height ?? 736;
const top = options.top ?? (window.screen.height - height) / 2;
const left = options.left ?? (window.screen.width - width) / 2;
// 打开窗口
const win = window.open(
@ -53,15 +63,18 @@ class PanelWindowManager {
*
* @param url Url
*/
open(url: string, options?: { onClose: () => void }): void {
open(
url: string,
options: { onClose?: () => void } & OpenInNewWindowOptions = {}
): Window {
if (this.openedPanelWindows[url]) {
this.openedPanelWindows[url].focus();
return;
return this.openedPanelWindows[url];
}
const win = openInNewWindow(url);
if (!win) {
return;
throw new Error('Create window failed');
}
const timer = setInterval(() => {
@ -74,12 +87,14 @@ class PanelWindowManager {
if (typeof options?.onClose === 'function') {
// 触发回调
options?.onClose();
options.onClose?.();
}
}
}, 1000);
this.openedPanelWindows[url] = win;
return win;
}
/**

Loading…
Cancel
Save