feat: implement theme synchronization and loading skeletons across various components, enhancing user experience during content loading

This commit is contained in:
wizardchen
2026-04-11 15:03:20 +08:00
committed by lyingbug
parent 1a4b7b390d
commit 6d8b47e57c
15 changed files with 441 additions and 19 deletions
+30
View File
@@ -39,6 +39,23 @@
</div>
</div>
<div class="agent-list-main">
<!-- 骨架屏占位 -->
<div v-if="loading && agents.length === 0" class="agent-card-wrap">
<div v-for="n in 6" :key="'skel-'+n" class="agent-card agent-card-skeleton">
<div class="card-header">
<div class="card-header-left">
<t-skeleton animation="gradient" :row-col="[[{ width: '32px', height: '32px', type: 'circle' }, { width: '40%', height: '18px' }]]" />
</div>
</div>
<div class="card-content">
<t-skeleton animation="gradient" :row-col="[{ width: '100%', height: '14px' }, { width: '70%', height: '14px' }]" />
</div>
<div class="card-bottom">
<t-skeleton animation="gradient" :row-col="[[{ width: '60px', height: '22px', type: 'rect' }, { width: '60px', height: '22px', type: 'rect' }]]" />
</div>
</div>
</div>
<!-- 全部:我的 + 共享 -->
<div v-if="spaceSelection === 'all' && filteredAgents.length > 0" class="agent-card-wrap">
<div
@@ -1184,10 +1201,23 @@ defineExpose({
}
@keyframes contentFadeIn {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: translateY(0); }
}
.agent-card-wrap {
display: grid;
gap: 20px;
grid-template-columns: 1fr;
animation: contentFadeIn 0.32s ease-out;
}
.agent-card-skeleton {
cursor: default;
.card-header { margin-bottom: 16px; }
.card-content { flex: 1; }
.card-bottom { margin-top: auto; }
}
/* 与知识库列表卡片统一尺寸:160px 高、18px 20px 内边距、12px 圆角 */
+57 -3
View File
@@ -2,9 +2,33 @@
<div class="chat">
<div ref="scrollContainer" class="chat_scroll_box" @scroll="handleScroll">
<div class="msg_list">
<!-- 消息列表骨架屏 -->
<div v-if="historyLoading && messagesList.length === 0" class="msg-skeleton-list">
<div class="msg-skeleton msg-skeleton-user">
<t-skeleton animation="gradient" :row-col="[{ width: '45%', height: '36px', type: 'rect' }]" />
</div>
<div class="msg-skeleton msg-skeleton-bot">
<t-skeleton animation="gradient" :row-col="[{ width: '80%', height: '16px' }, { width: '100%', height: '16px' }, { width: '60%', height: '16px' }]" />
</div>
<div class="msg-skeleton msg-skeleton-user">
<t-skeleton animation="gradient" :row-col="[{ width: '35%', height: '36px', type: 'rect' }]" />
</div>
<div class="msg-skeleton msg-skeleton-bot">
<t-skeleton animation="gradient" :row-col="[{ width: '70%', height: '16px' }, { width: '90%', height: '16px' }]" />
</div>
</div>
<!-- 推荐问题卡片 - 仅在新会话(无消息)时展示 -->
<div v-if="messagesList.length === 0 && !loading" class="suggested-questions-container" :class="{ 'has-questions': suggestedQuestions.length > 0 }">
<transition name="sq-fade">
<div v-if="messagesList.length === 0 && !loading" class="suggested-questions-container" :class="{ 'has-questions': suggestedQuestions.length > 0 || suggestedQuestionsLoading }">
<!-- 骨架屏占位 -->
<div v-if="suggestedQuestionsLoading && suggestedQuestions.length === 0" class="suggested-questions-inner">
<div class="suggested-questions-title"><t-skeleton animation="gradient" :row-col="[{ width: '120px', height: '18px' }]" /></div>
<div class="suggested-questions-grid">
<div v-for="n in 6" :key="'sq-skel-'+n" class="suggested-question-card sq-card-skeleton">
<t-skeleton animation="gradient" :row-col="[{ width: '90%', height: '14px' }, { width: '60%', height: '14px' }]" />
</div>
</div>
</div>
<transition v-else appear name="sq-fade">
<div v-if="suggestedQuestions.length > 0" class="suggested-questions-inner">
<div class="suggested-questions-title">{{ t('chat.suggestedQuestions') }}</div>
<div class="suggested-questions-grid">
@@ -103,6 +127,7 @@ const scrollLock = ref(false);
const isNeedTitle = ref(false);
const isFirstEnter = ref(true);
const loading = ref(false);
const historyLoading = ref(true);
let fullContent = ref('')
let userquery = ref('')
const scrollContainer = ref(null)
@@ -212,7 +237,8 @@ watch([() => route.params], (newvalue) => {
messagesList.splice(0);
session_id.value = newvalue[0].chatid;
// 切换会话时,重置状态(加载历史消息不应显示loading)
// 切换会话时,重置状态
historyLoading.value = true;
loading.value = false;
isReplying.value = false;
currentAssistantMessageId.value = '';
@@ -271,6 +297,8 @@ const getmsgList = (data, isScrollType = false, scrollHeight) => {
created_at.value = res.data[0].created_at;
handleMsgList(res.data, isScrollType, scrollHeight);
}
}).finally(() => {
historyLoading.value = false;
})
}
@@ -1103,6 +1131,7 @@ onMounted(async () => {
checkmenuTitle(session_id.value)
if (firstQuery.value) {
scrollLock.value = true;
historyLoading.value = false;
sendMsg(firstQuery.value, firstModelId.value || '', firstMentionedItems.value || [], firstImageFiles.value || []);
usemenuStore.changeFirstQuery('', [], '', []);
} else {
@@ -1236,6 +1265,30 @@ onBeforeRouteUpdate((to, from, next) => {
}
}
@keyframes contentFadeIn {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: translateY(0); }
}
.msg-skeleton-list {
display: flex;
flex-direction: column;
gap: 20px;
max-width: 800px;
padding: 16px 0;
animation: contentFadeIn 0.3s ease-out;
}
.msg-skeleton-user {
display: flex;
justify-content: flex-end;
}
.msg-skeleton-bot {
display: flex;
flex-direction: column;
gap: 8px;
padding-left: 4px;
}
.msg_list {
display: flex;
flex-direction: column;
@@ -1308,6 +1361,7 @@ onBeforeRouteUpdate((to, from, next) => {
flex-direction: column;
align-items: center;
width: 100%;
animation: contentFadeIn 0.3s ease-out;
}
.sq-fade-enter-active,
+28 -2
View File
@@ -6,7 +6,16 @@
</div>
<!-- 推荐问题 -->
<div ref="sqContainerRef" class="suggested-questions-container">
<transition name="sq-slide-fade" mode="out-in"
<!-- 骨架屏占位 -->
<div v-if="sqLoading && suggestedQuestions.length === 0" class="suggested-questions-inner">
<div class="suggested-questions-title"><t-skeleton animation="gradient" :row-col="[{ width: '120px', height: '18px' }]" /></div>
<div class="suggested-questions-grid">
<div v-for="n in 6" :key="'sq-skel-'+n" class="suggested-question-card sq-card-skeleton">
<t-skeleton animation="gradient" :row-col="[{ width: '90%', height: '14px' }, { width: '60%', height: '14px' }]" />
</div>
</div>
</div>
<transition v-else appear name="sq-slide-fade" mode="out-in"
@before-leave="onBeforeLeave"
@after-leave="onAfterLeave"
@enter="onEnter"
@@ -69,6 +78,7 @@ const { navigateToKnowledgeBaseList } = useKnowledgeBaseCreationNavigation();
// ===== 推荐问题 =====
const suggestedQuestions = ref<SuggestedQuestion[]>([]);
const sqLoading = ref(true);
const sqCardsRevealed = ref(false);
const sqRenderKey = ref(0);
const sqContainerRef = ref<HTMLElement | null>(null);
@@ -119,7 +129,7 @@ const onQuestionsEntered = () => {
const fetchSuggestedQuestions = async () => {
const fetchId = ++suggestedQuestionsFetchId;
// 加载期间保留旧数据,不清空,避免布局抖动
if (suggestedQuestions.value.length === 0) sqLoading.value = true;
try {
const agentId = settingsStore.selectedAgentId;
if (!agentId) return;
@@ -140,6 +150,10 @@ const fetchSuggestedQuestions = async () => {
if (fetchId === suggestedQuestionsFetchId) {
suggestedQuestions.value = [];
}
} finally {
if (fetchId === suggestedQuestionsFetchId) {
sqLoading.value = false;
}
}
};
@@ -277,11 +291,17 @@ const handleKBEditorSuccess = (kbId: string) => {
transition: height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes skeletonFadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.suggested-questions-inner {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
animation: skeletonFadeIn 0.3s ease-out;
}
// 容器整体过渡:淡入 + 轻微上滑
@@ -335,6 +355,12 @@ const handleKBEditorSuccess = (kbId: string) => {
background 0.2s ease,
box-shadow 0.2s ease;
&.sq-card-skeleton {
opacity: 1;
transform: none;
cursor: default;
}
&.sq-card-visible {
opacity: 1;
transform: translateY(0) scale(1);
+48 -3
View File
@@ -42,6 +42,7 @@ const uploadInputRef = ref<HTMLInputElement | null>(null);
const folderUploadInputRef = ref<HTMLInputElement | null>(null);
const uploading = ref(false);
const kbLoading = ref(false);
const docListLoading = ref(true);
const isFAQ = computed(() => (kbInfo.value?.type || '') === 'faq');
const missingStorageEngine = computed(() => {
if (!kbInfo.value || isFAQ.value) return false
@@ -566,6 +567,7 @@ const loadKnowledgeBaseInfo = async (targetKbId: string) => {
// 重置store中的标签选择状态,避免上传文档时自动带上之前选择的标签
uiStore.setSelectedTagId('');
if (!isFAQ.value) {
docListLoading.value = true;
loadKnowledgeFiles(targetKbId);
} else {
cardList.value = [];
@@ -723,6 +725,7 @@ onUnmounted(() => {
});
watch(() => cardList.value, (newValue) => {
if (isFAQ.value) return;
docListLoading.value = false;
// Auto-open document if navigated with ?knowledge_id=xxx
if (pendingKnowledgeId.value && newValue?.length) {
@@ -1758,8 +1761,22 @@ async function createNewSession(value: string): Promise<void> {
ref="knowledgeScroll"
@scroll="handleScroll"
>
<template v-if="cardList.length">
<div class="doc-card-list">
<!-- 文档骨架屏 -->
<div v-if="docListLoading && cardList.length === 0" class="doc-card-list doc-card-list-animated">
<div v-for="n in 8" :key="'doc-skel-'+n" class="knowledge-card knowledge-card-skeleton">
<div class="card-content">
<div class="card-content-nav">
<t-skeleton animation="gradient" :row-col="[{ width: '70%', height: '18px' }]" />
</div>
<t-skeleton animation="gradient" :row-col="[{ width: '100%', height: '14px' }, { width: '60%', height: '14px' }]" />
</div>
<div class="card-bottom">
<t-skeleton animation="gradient" :row-col="[[{ width: '80px', height: '14px' }, { width: '40px', height: '18px', type: 'rect' }]]" />
</div>
</div>
</div>
<template v-else-if="cardList.length">
<div class="doc-card-list doc-card-list-animated">
<!-- 现有文档卡片 -->
<div
class="knowledge-card"
@@ -1978,7 +1995,7 @@ async function createNewSession(value: string): Promise<void> {
</div>
</Teleport>
</template>
<template v-else>
<template v-else-if="!docListLoading">
<div class="doc-empty-state">
<EmptyKnowledge />
</div>
@@ -2898,6 +2915,11 @@ async function createNewSession(value: string): Promise<void> {
}
}
@keyframes contentFadeIn {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: translateY(0); }
}
.doc-card-list {
box-sizing: border-box;
display: grid;
@@ -2905,6 +2927,29 @@ async function createNewSession(value: string): Promise<void> {
gap: 14px;
align-content: flex-start;
width: 100%;
&.doc-card-list-animated {
animation: contentFadeIn 0.32s ease-out;
}
}
.knowledge-card-skeleton {
cursor: default;
.card-content { padding: 15px 17px 13px; }
.card-content-nav { margin-bottom: 14px; }
.card-bottom {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
padding: 0 17px;
box-sizing: border-box;
height: 34px;
display: flex;
align-items: center;
justify-content: space-between;
border-top: 1px solid var(--td-component-stroke);
}
}
.doc-empty-state {
@@ -78,6 +78,21 @@
</div>
</div>
<!-- 骨架屏占位 -->
<div v-if="loading && kbs.length === 0" class="kb-card-wrap">
<div v-for="n in 6" :key="'skel-'+n" class="kb-card kb-card-skeleton">
<div class="card-header">
<t-skeleton animation="gradient" :row-col="[{ width: '60%', height: '20px' }]" />
</div>
<div class="card-content">
<t-skeleton animation="gradient" :row-col="[{ width: '100%', height: '14px' }, { width: '80%', height: '14px' }]" />
</div>
<div class="card-bottom">
<t-skeleton animation="gradient" :row-col="[[{ width: '28px', height: '28px', type: 'rect' }, { width: '28px', height: '28px', type: 'rect' }]]" />
</div>
</div>
</div>
<!-- 卡片网格:全部 -->
<div v-if="spaceSelection === 'all' && filteredKnowledgeBases.length > 0" class="kb-card-wrap">
<!-- 全部:我的知识库 + 共享给我的知识库 -->
@@ -1583,10 +1598,16 @@ const handleUploadFinishedEvent = (event: Event) => {
transition: width 0.2s ease;
}
@keyframes contentFadeIn {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: translateY(0); }
}
.kb-card-wrap {
display: grid;
gap: 20px;
grid-template-columns: 1fr;
animation: contentFadeIn 0.32s ease-out;
}
.kb-card {
@@ -1605,6 +1626,13 @@ const handleUploadFinishedEvent = (event: Event) => {
height: 160px;
min-height: 160px;
&.kb-card-skeleton {
cursor: default;
.card-header { margin-bottom: 16px; }
.card-content { flex: 1; }
.card-bottom { margin-top: auto; }
}
&:hover {
border-color: var(--td-brand-color);
box-shadow: 0 4px 12px rgba(7, 192, 95, 0.12);
@@ -394,9 +394,22 @@
</div>
<!-- Card List Container with Scroll -->
<div ref="scrollContainer" class="faq-scroll-container" @scroll="handleScroll">
<t-loading :loading="loading && entries.length === 0" size="medium">
<!-- FAQ 骨架屏 -->
<div v-if="loading && entries.length === 0" class="faq-skeleton-grid">
<div v-for="n in 6" :key="'faq-skel-'+n" class="faq-card faq-card-skeleton">
<div class="faq-card-header">
<t-skeleton animation="gradient" :row-col="[{ width: '80%', height: '16px' }]" />
</div>
<div class="faq-card-body">
<t-skeleton animation="gradient" :row-col="[{ width: '100%', height: '13px' }, { width: '90%', height: '13px' }, { width: '60%', height: '13px' }]" />
</div>
<div class="faq-skel-footer">
<t-skeleton animation="gradient" :row-col="[[{ width: '50px', height: '18px', type: 'rect' }, { width: '60px', height: '18px', type: 'rect' }]]" />
</div>
</div>
</div>
<!-- Card List -->
<template v-if="entries.length > 0">
<template v-else-if="entries.length > 0">
<div ref="cardListRef" class="faq-card-list">
<div
v-for="entry in entries"
@@ -614,8 +627,8 @@
</div>
</div>
</template>
<template v-else>
<div v-if="!loading" class="faq-empty-state">
<template v-else-if="!loading">
<div class="faq-empty-state">
<div class="empty-content">
<t-icon name="file-add" size="48px" class="empty-icon" />
<div class="empty-text">{{ $t('knowledgeEditor.faq.emptyTitle') }}</div>
@@ -623,7 +636,6 @@
</div>
</div>
</template>
</t-loading>
<div v-if="loadingMore" class="faq-load-more">
<t-loading size="small" :text="$t('common.loading')" />
</div>
@@ -1363,7 +1375,7 @@ const handleFaqAction = (data: { value: string }) => {
}
}
const loading = ref(false)
const loading = ref(true)
const loadingMore = ref(false)
const entries = ref<FAQEntry[]>([])
const entryStatusLoading = reactive<Record<number, boolean>>({})
@@ -4171,10 +4183,40 @@ watch(() => entries.value.map(e => ({
padding-right: 4px;
}
@keyframes contentFadeIn {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: translateY(0); }
}
.faq-skeleton-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 12px;
width: 100%;
animation: contentFadeIn 0.32s ease-out;
}
.faq-card-skeleton {
cursor: default;
height: auto;
.faq-card-header {
padding-bottom: 10px;
border-bottom: 1px solid var(--td-component-stroke);
}
.faq-card-body {
padding: 8px 0;
}
.faq-skel-footer {
padding-top: 8px;
border-top: 1px solid var(--td-component-stroke);
}
}
// 卡片列表样式 - 使用绝对定位实现瀑布流,下一行补齐上一行空缺
.faq-card-list {
position: relative;
width: 100%;
animation: contentFadeIn 0.32s ease-out;
min-width: 0;
}
@@ -43,6 +43,21 @@
</div>
</div>
<div class="org-list-main">
<!-- 骨架屏占位 -->
<div v-if="loading && filteredOrganizations.length === 0" class="org-card-wrap">
<div v-for="n in 4" :key="'skel-'+n" class="org-card org-card-skeleton">
<div class="card-header">
<t-skeleton animation="gradient" :row-col="[[{ width: '36px', height: '36px', type: 'circle' }, { width: '50%', height: '20px' }]]" />
</div>
<div style="flex:1;margin-top:12px">
<t-skeleton animation="gradient" :row-col="[{ width: '100%', height: '14px' }, { width: '70%', height: '14px' }]" />
</div>
<div style="margin-top:auto">
<t-skeleton animation="gradient" :row-col="[[{ width: '60px', height: '22px', type: 'rect' }, { width: '60px', height: '22px', type: 'rect' }]]" />
</div>
</div>
</div>
<!-- 卡片网格 -->
<div v-if="filteredOrganizations.length > 0" class="org-card-wrap">
<div
@@ -1406,10 +1421,24 @@ onUnmounted(() => {
}
}
@keyframes contentFadeIn {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: translateY(0); }
}
.org-card-wrap {
display: grid;
gap: 20px;
grid-template-columns: 1fr;
animation: contentFadeIn 0.32s ease-out;
}
.org-card-skeleton {
cursor: default;
display: flex;
flex-direction: column;
height: 160px;
min-height: 160px;
}
/* 与知识库列表卡片统一尺寸:160px 高、18px 20px 内边距、12px 圆角 */