重构: tool_registry拆分及多批改进

This commit is contained in:
lxy
2026-06-19 00:10:14 +08:00
parent a2871a66e0
commit 60b01d03ee
33 changed files with 703 additions and 247 deletions
+44 -11
View File
@@ -7,7 +7,7 @@
<span class="dash-subtitle">{{ $t('dashboard.subtitle') }}</span>
</div>
<div class="dash-header-right">
<button class="df-btn df-btn--ghost" @click="refresh">
<button class="df-btn df-btn--ghost" @click="refresh" :disabled="loading" :title="$t('dashboard.refresh')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 11-2.12-9.36L23 10"/></svg>
</button>
<button class="df-btn df-btn--primary" @click="quickCapture">
@@ -17,6 +17,12 @@
</div>
</header>
<!-- 错误条:refresh/onMounted 加载失败对用户可见(对齐 Knowledge error-banner) -->
<div v-if="errorMsg" class="error-banner">
<span class="error-text">{{ errorMsg }}</span>
<button class="error-dismiss" @click="errorMsg = ''"></button>
</div>
<!-- Stat Cards -->
<div class="stat-row">
<div
@@ -104,7 +110,7 @@
</template>
<script setup lang="ts">
import { computed, onMounted } from 'vue'
import { computed, onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { useProjectStore } from '@/stores/project'
@@ -114,6 +120,10 @@ const router = useRouter()
const store = useProjectStore()
const { t } = useI18n()
// 加载态(refresh/load 期间 true,驱动刷新按钮禁用) + 错误态(加载失败对用户可见)
const loading = ref(false)
const errorMsg = ref('')
const stats = computed(() => [
{ key: 'ideas', icon: '\u{1F4A1}', label: t('dashboard.stats.ideas'), value: store.stats.ideas, trend: 0,
iconBg: 'rgba(123,111,240,0.12)' },
@@ -179,24 +189,32 @@ function ideaStatusLabel(status: string): string {
return t('dashboard.ideaStatus.' + status)
}
async function refresh() {
// 统一加载入口(projects/tasks/ideas 并行),管理 loading + errorMsg
// refresh 与 onMounted 共用,避免两处 catch 逻辑重复
async function loadAll() {
if (loading.value) return // 防重复触发
loading.value = true
errorMsg.value = ''
try {
await Promise.all([store.loadProjects(), store.loadTasks(), store.loadIdeas()])
} catch (e) {
console.error('Dashboard refresh failed:', e)
} catch (e: any) {
console.error('Dashboard load failed:', e)
errorMsg.value = e?.toString() ?? t('dashboard.err.loadFailed')
} finally {
loading.value = false
}
}
async function refresh() {
await loadAll()
}
function quickCapture() {
router.push('/ideas')
}
onMounted(async () => {
try {
await Promise.all([store.loadProjects(), store.loadTasks(), store.loadIdeas()])
} catch (e) {
console.error('Dashboard load failed:', e)
}
onMounted(() => {
loadAll()
})
</script>
@@ -271,6 +289,21 @@ onMounted(async () => {
border-color: var(--df-border-strong);
}
.df-btn--xs { padding: 4px 10px; font-size: 11px; }
.df-btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* ═══ 错误条(对齐 Knowledge error-banner) ═══ */
.error-banner {
display: flex; align-items: center; justify-content: space-between; gap: 12px;
padding: 8px 12px; margin-bottom: 14px;
background: rgba(255,107,107,0.12); border: 0.5px solid var(--df-danger);
border-radius: var(--df-radius-sm); color: var(--df-danger); font-size: 12px;
}
.error-text { word-break: break-word; }
.error-dismiss {
flex-shrink: 0; background: transparent; border: none; color: var(--df-danger);
font-size: 14px; cursor: pointer; line-height: 1; padding: 0 2px;
}
.error-dismiss:hover { opacity: 0.7; }
/* ═══ Stat Cards ═══ */
.stat-row {