mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 07:09:20 +08:00
feat: 优化缩小化
This commit is contained in:
@@ -27,6 +27,13 @@ function ensureShadow(host: HTMLElement): ShadowRoot {
|
||||
return host.shadowRoot ?? host.attachShadow({ mode: 'open' });
|
||||
}
|
||||
|
||||
function setHostHidden(hidden: boolean) {
|
||||
const host = document.getElementById(HOST_ID);
|
||||
if (host) {
|
||||
host.style.display = hidden ? 'none' : '';
|
||||
}
|
||||
}
|
||||
|
||||
function removeLauncher() {
|
||||
document.getElementById(LAUNCHER_ID)?.remove();
|
||||
}
|
||||
@@ -70,12 +77,16 @@ function unmountApp() {
|
||||
if (host?.shadowRoot) {
|
||||
host.shadowRoot.innerHTML = '';
|
||||
}
|
||||
if (host) {
|
||||
host.style.display = '';
|
||||
}
|
||||
}
|
||||
|
||||
function mountApp() {
|
||||
const host = ensureHost();
|
||||
const shadow = ensureShadow(host);
|
||||
shadow.innerHTML = '';
|
||||
host.style.display = '';
|
||||
|
||||
const styleEl = document.createElement('style');
|
||||
styleEl.textContent = styles;
|
||||
@@ -87,8 +98,9 @@ function mountApp() {
|
||||
app = createApp(FloatingPanel, {
|
||||
onClose: () => setFloatingVisible(false),
|
||||
onMinimize: () => {
|
||||
// 只隐藏,不销毁 Vue,保留已累计的多日数据
|
||||
minimized = true;
|
||||
unmountApp();
|
||||
setHostHidden(true);
|
||||
showLauncher();
|
||||
visible = true;
|
||||
emitFeatureEvent(FEATURE_ID, 'minimized');
|
||||
@@ -115,10 +127,9 @@ export function setFloatingVisible(next: boolean): boolean {
|
||||
}
|
||||
|
||||
visible = true;
|
||||
minimized = false;
|
||||
removeLauncher();
|
||||
if (minimized) {
|
||||
minimized = false;
|
||||
}
|
||||
setHostHidden(false);
|
||||
if (!app) {
|
||||
mountApp();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user