SystemOverviewPanel.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <script setup lang="ts">
  2. import { computed, ref, watch } from 'vue'
  3. import AppIcon from '@/components/common/AppIcon.vue'
  4. import { listUsers, type ManagedUser } from '@/api/admin'
  5. import { getDuplexVoiceSettings, type DuplexVoiceSettings } from '@/api/agentManagement'
  6. import { getPushSystemStatus, type PushSystemStatus } from '@/api/push'
  7. import { systemUpdateStatus, type SystemUpdateStatus } from '@/api/systemUpdate'
  8. type Destination = 'system-models' | 'system-users' | 'system-connection' | 'system-push' | 'system-voice' | 'system-update'
  9. const props = withDefaults(defineProps<{
  10. active?: boolean
  11. upstreamReady?: boolean
  12. upstreamError?: string
  13. }>(), {
  14. active: true,
  15. upstreamReady: false,
  16. upstreamError: '',
  17. })
  18. const emit = defineEmits<{ navigate: [destination: Destination] }>()
  19. const users = ref<ManagedUser[]>()
  20. const push = ref<PushSystemStatus>()
  21. const voice = ref<DuplexVoiceSettings>()
  22. const update = ref<SystemUpdateStatus>()
  23. const checking = ref(false)
  24. const error = ref('')
  25. const userStatus = computed(() => users.value
  26. ? `${users.value.filter(user => user.role === 'admin').length} 位管理员 · ${users.value.length} 位用户`
  27. : '尚未读取用户状态')
  28. const pushStatus = computed(() => {
  29. if (!push.value) return '尚未读取推送状态'
  30. const apns = push.value.configured && push.value.healthy ? 'APNs 已启用' : 'APNs 未就绪'
  31. const fcm = push.value.providers?.fcm
  32. return `${apns} · ${fcm?.configured && fcm.healthy ? 'FCM 已启用' : 'FCM 未配置'}`
  33. })
  34. const voiceStatus = computed(() => voice.value ? `已配置 ${voice.value.voices.length} 个音色` : '尚未读取语音状态')
  35. const updateStatus = computed(() => {
  36. if (!update.value) return '尚未读取版本状态'
  37. return `Web ${update.value.current.webVersion} · 可独立升级与回滚`
  38. })
  39. async function refresh() {
  40. checking.value = true
  41. error.value = ''
  42. const results = await Promise.allSettled([
  43. listUsers(),
  44. getPushSystemStatus(),
  45. getDuplexVoiceSettings(),
  46. // Publish local update status immediately, without waiting for 9119 panels.
  47. systemUpdateStatus().then(value => { update.value = value; return value }),
  48. ])
  49. if (results[0]?.status === 'fulfilled') users.value = results[0].value
  50. if (results[1]?.status === 'fulfilled') push.value = results[1].value
  51. if (results[2]?.status === 'fulfilled') voice.value = results[2].value
  52. if (results[3]?.status === 'fulfilled') update.value = results[3].value
  53. const failed = results.filter(result => result.status === 'rejected').length
  54. if (failed) error.value = failed === results.length ? '无法读取系统状态' : `${failed} 项状态暂时无法读取,可进入对应页面重试。`
  55. checking.value = false
  56. }
  57. watch(() => props.active, active => { if (active) void refresh() }, { immediate: true })
  58. </script>
  59. <template>
  60. <section class="system-overview-panel" aria-label="系统概览">
  61. <div class="overview-toolbar">
  62. <p>影响整个夭夭安装及所有机器人,仅管理员可见。</p>
  63. <button type="button" :disabled="checking" @click="refresh"><AppIcon name="refresh" :size="16" />{{ checking ? '检查中…' : '检查系统状态' }}</button>
  64. </div>
  65. <p v-if="error" class="overview-warning" role="status">{{ error }}</p>
  66. <div class="overview-list">
  67. <button type="button" @click="emit('navigate', 'system-models')">
  68. <AppIcon name="model" :size="22" />
  69. <span><strong>模型服务</strong><small>供应商、账号登录、API Key 与辅助模型</small></span>
  70. <AppIcon class="chevron" name="chevron-left" :size="18" />
  71. </button>
  72. <button type="button" @click="emit('navigate', 'system-users')">
  73. <AppIcon name="users" :size="22" />
  74. <span><strong>用户与权限</strong><small>{{ userStatus }}</small></span>
  75. <AppIcon class="chevron" name="chevron-left" :size="18" />
  76. </button>
  77. <button type="button" @click="emit('navigate', 'system-connection')">
  78. <AppIcon name="link" :size="22" />
  79. <span><strong>Hermes 连接</strong><small :class="{ success: upstreamReady }">{{ upstreamReady ? '内置 Hermes 已就绪' : upstreamError || '尚未检查内置 Hermes' }}</small></span>
  80. <AppIcon class="chevron" name="chevron-left" :size="18" />
  81. </button>
  82. <button type="button" @click="emit('navigate', 'system-push')">
  83. <AppIcon name="bell" :size="22" />
  84. <span><strong>消息推送</strong><small>{{ pushStatus }}</small></span>
  85. <AppIcon class="chevron" name="chevron-left" :size="18" />
  86. </button>
  87. <button type="button" @click="emit('navigate', 'system-voice')">
  88. <AppIcon name="audio" :size="22" />
  89. <span><strong>双流语音 <em>全局</em></strong><small>{{ voiceStatus }}</small></span>
  90. <AppIcon class="chevron" name="chevron-left" :size="18" />
  91. </button>
  92. <button type="button" @click="emit('navigate', 'system-update')">
  93. <AppIcon name="refresh" :size="22" />
  94. <span><strong>更新与回滚</strong><small>{{ updateStatus }} <b v-if="update?.latest && !update.updateAvailable">已是最新版本</b></small></span>
  95. <AppIcon class="chevron" name="chevron-left" :size="18" />
  96. </button>
  97. </div>
  98. <p class="ownership-note">Hermes 已内置在夭夭服务中运行,无需单独启动 9119;外部文件与进程不在此处控制。</p>
  99. </section>
  100. </template>
  101. <style scoped>
  102. .system-overview-panel { display: grid; gap: 16px; }
  103. .overview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
  104. .overview-toolbar p { margin: 0; color: var(--text-secondary); font-size: 14px; }
  105. .overview-toolbar button { display: inline-flex; min-height: 40px; flex: 0 0 auto; align-items: center; gap: 7px; padding: 0 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-raised); color: var(--text-primary); cursor: pointer; font: 600 13px var(--font-ui); }
  106. .overview-toolbar button:disabled { cursor: wait; opacity: .55; }
  107. .overview-warning { margin: 0; padding: 10px 12px; border-radius: 9px; background: color-mix(in srgb, var(--warning, #bd7611) 10%, transparent); color: var(--text-secondary); font-size: 12px; }
  108. .overview-list { border-top: 1px solid var(--line); }
  109. .overview-list > button { display: grid; width: 100%; min-height: 76px; grid-template-columns: 28px minmax(0, 1fr) 22px; align-items: center; gap: 15px; padding: 12px 8px; border: 0; border-bottom: 1px solid var(--line); border-radius: 9px; background: transparent; color: var(--text-primary); cursor: pointer; text-align: left; }
  110. .overview-list > button:hover { background: var(--surface-soft); }
  111. .overview-list > button:focus-visible { outline: 0; box-shadow: inset 0 0 0 2px color-mix(in srgb, #7c4dff 72%, var(--line-strong)); }
  112. .overview-list > button > span { display: grid; min-width: 0; gap: 6px; }
  113. .overview-list strong { display: flex; align-items: center; gap: 8px; font-size: 15px; }
  114. .overview-list small { color: var(--text-muted); font-size: 13px; }
  115. .overview-list small.success,.overview-list small b { color: var(--success, #21845b); font-weight: 600; }
  116. .overview-list em { padding: 2px 7px; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--text-muted); font: normal 11px var(--font-ui); }
  117. .chevron { transform: rotate(180deg); color: var(--text-muted); }
  118. .ownership-note { margin: 2px 0 0; color: var(--text-muted); font-size: 12px; line-height: 1.6; }
  119. @media (max-width: 700px) {
  120. .overview-toolbar { align-items: stretch; flex-direction: column; }
  121. .overview-toolbar button { justify-content: center; }
  122. .overview-list > button { min-height: 72px; padding-inline: 4px; }
  123. }
  124. </style>