This commit is contained in:
parent
58894838f0
commit
fe04bc6fb1
|
@ -70,7 +70,7 @@ import * as os from '@/os';
|
||||||
import { i18n } from '@/i18n';
|
import { i18n } from '@/i18n';
|
||||||
import { isTouchUsing } from '@/scripts/touch';
|
import { isTouchUsing } from '@/scripts/touch';
|
||||||
|
|
||||||
const childrenCache = new WeakMap<MenuParent, Ref<(MenuItem | MenuPending)[]>>();
|
const childrenCache = new WeakMap<MenuParent, MenuItem[]>();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
@ -154,36 +154,32 @@ function onItemMouseLeave(item) {
|
||||||
if (childCloseTimer) window.clearTimeout(childCloseTimer);
|
if (childCloseTimer) window.clearTimeout(childCloseTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showChildren(item: MenuParent, ev: MouseEvent) {
|
async function showChildren(item: MenuParent, ev: MouseEvent) {
|
||||||
if (props.asDrawer && childrenCache.has(item)) return;
|
const children = await (async () => {
|
||||||
|
if (childrenCache.has(item)) {
|
||||||
const children = (() => {
|
|
||||||
if (!item.noCache && childrenCache.has(item)) {
|
|
||||||
return childrenCache.get(item)!;
|
return childrenCache.get(item)!;
|
||||||
} else {
|
} else {
|
||||||
if (typeof item.children === 'function') {
|
if (typeof item.children === 'function') {
|
||||||
const result: Ref<(MenuItem | MenuPending)[]> = ref([{ type: 'pending' }]);
|
return Promise.resolve(item.children());
|
||||||
childrenCache.set(item, result);
|
|
||||||
Promise.resolve(item.children()).then(x => {
|
|
||||||
result.value = x;
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
} else {
|
} else {
|
||||||
return ref(item.children) as Ref<(MenuItem | MenuPending)[]>;
|
return item.children;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
if (!item.noCache) {
|
||||||
|
childrenCache.set(item, children);
|
||||||
|
}
|
||||||
|
|
||||||
if (props.asDrawer) {
|
if (props.asDrawer) {
|
||||||
os.popupMenu(children as Ref<MenuItem[]>, ev.currentTarget ?? ev.target).finally(() => {
|
os.popupMenu(children, ev.currentTarget ?? ev.target).finally(() => {
|
||||||
childrenCache.delete(item);
|
|
||||||
emit('close');
|
emit('close');
|
||||||
});
|
});
|
||||||
emit('hide');
|
emit('hide');
|
||||||
} else {
|
} else {
|
||||||
childTarget = ev.currentTarget ?? ev.target;
|
childTarget = ev.currentTarget ?? ev.target;
|
||||||
// これでもリアクティビティは保たれる
|
// これでもリアクティビティは保たれる
|
||||||
childMenu.value = children.value as MenuItem[];
|
childMenu.value = children;
|
||||||
childShowingItem = item;
|
childShowingItem = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue