mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-04-27 11:43:25 +08:00
feat: 项目加载优化
This commit is contained in:
@@ -20,12 +20,29 @@ const isCollapsed = computed(() => designStore.isCollapseConversationList);
|
||||
|
||||
// 判断是否为新建对话状态(没有选中任何会话)
|
||||
const isNewChatState = computed(() => !sessionStore.currentSession);
|
||||
const isLoading = ref(false);
|
||||
|
||||
onMounted(async () => {
|
||||
await sessionStore.requestSessionList();
|
||||
if (conversationsList.value.length > 0 && sessionId.value) {
|
||||
const currentSessionRes = await get_session(`${sessionId.value}`);
|
||||
sessionStore.setCurrentSession(currentSessionRes.data);
|
||||
onMounted(() => {
|
||||
// 使用 requestIdleCallback 或 setTimeout 延迟加载数据
|
||||
// 避免阻塞首屏渲染
|
||||
const loadData = async () => {
|
||||
isLoading.value = true;
|
||||
try {
|
||||
await sessionStore.requestSessionList();
|
||||
if (conversationsList.value.length > 0 && sessionId.value) {
|
||||
const currentSessionRes = await get_session(`${sessionId.value}`);
|
||||
sessionStore.setCurrentSession(currentSessionRes.data);
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 优先使用 requestIdleCallback,如果不支持则使用 setTimeout
|
||||
if (typeof requestIdleCallback !== 'undefined') {
|
||||
requestIdleCallback(() => loadData(), { timeout: 1000 });
|
||||
} else {
|
||||
setTimeout(loadData, 100);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -35,30 +35,6 @@ const layout = computed((): LayoutType | 'mobile' => {
|
||||
// 否则使用全局设置的 layout
|
||||
return designStore.layout;
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
// 更好的做法是等待所有资源加载
|
||||
window.addEventListener('load', () => {
|
||||
const loader = document.getElementById('yixinai-loader');
|
||||
if (loader) {
|
||||
loader.style.opacity = '0';
|
||||
setTimeout(() => {
|
||||
loader.style.display = 'none';
|
||||
}, 500); // 匹配过渡时间
|
||||
}
|
||||
});
|
||||
|
||||
// 设置超时作为兜底
|
||||
setTimeout(() => {
|
||||
const loader = document.getElementById('yixinai-loader');
|
||||
if (loader) {
|
||||
loader.style.opacity = '0';
|
||||
setTimeout(() => {
|
||||
loader.style.display = 'none';
|
||||
}, 500);
|
||||
}
|
||||
}, 500); // 最多显示0.5秒
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user