File size: 10,732 Bytes
8059bf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<template>
  <div class="sora-root">
    <!-- Sora 页面内容 -->
    <div class="sora-page">
      <!-- 功能未启用提示 -->
      <div v-if="!soraEnabled" class="sora-not-enabled">
        <svg class="sora-not-enabled-icon" fill="none" viewBox="0 0 24 24" stroke="currentColor">
          <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9.813 15.904L9 18.75l-.813-2.846a4.5 4.5 0 00-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 003.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 003.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 00-3.09 3.09zM18.259 8.715L18 9.75l-.259-1.035a3.375 3.375 0 00-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 002.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 002.455 2.456L21.75 6l-1.036.259a3.375 3.375 0 00-2.455 2.456z" />
        </svg>
        <h2 class="sora-not-enabled-title">{{ t('sora.notEnabled') }}</h2>
        <p class="sora-not-enabled-desc">{{ t('sora.notEnabledDesc') }}</p>
      </div>

      <!-- Sora 主界面 -->
      <template v-else>
        <!-- 自定义 Sora 头部 -->
        <header class="sora-header">
          <div class="sora-header-left">
            <!-- 返回主页按钮 -->
            <router-link :to="dashboardPath" class="sora-back-btn" :title="t('common.back')">
              <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M15 19l-7-7 7-7" />
              </svg>
            </router-link>
            <nav class="sora-nav-tabs">
              <button
                v-for="tab in tabs"
                :key="tab.key"
                :class="['sora-nav-tab', activeTab === tab.key && 'active']"
                @click="activeTab = tab.key"
              >
                {{ tab.label }}
              </button>
            </nav>
          </div>
          <div class="sora-header-right">
            <SoraQuotaBar v-if="quota" :quota="quota" />
            <div v-if="activeTaskCount > 0" class="sora-queue-indicator">
              <span class="sora-queue-dot" :class="{ busy: hasGeneratingTask }"></span>
              <span>{{ activeTaskCount }} {{ t('sora.queueTasks') }}</span>
            </div>
          </div>
        </header>

        <!-- 内容区域 -->
        <main class="sora-main">
          <SoraGeneratePage
            v-show="activeTab === 'generate'"
            @task-count-change="onTaskCountChange"
          />
          <SoraLibraryPage
            v-show="activeTab === 'library'"
            @switch-to-generate="activeTab = 'generate'"
          />
        </main>
      </template>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { useAppStore, useAuthStore } from '@/stores'
import SoraQuotaBar from '@/components/sora/SoraQuotaBar.vue'
import SoraGeneratePage from '@/components/sora/SoraGeneratePage.vue'
import SoraLibraryPage from '@/components/sora/SoraLibraryPage.vue'
import soraAPI, { type QuotaInfo } from '@/api/sora'

const { t } = useI18n()
const authStore = useAuthStore()
const appStore = useAppStore()

const soraEnabled = computed(() => appStore.cachedPublicSettings?.sora_client_enabled ?? false)

const activeTab = ref<'generate' | 'library'>('generate')
const quota = ref<QuotaInfo | null>(null)
const activeTaskCount = ref(0)
const hasGeneratingTask = ref(false)
const dashboardPath = computed(() => (authStore.isAdmin ? '/admin/dashboard' : '/dashboard'))

const tabs = computed(() => [
  { key: 'generate' as const, label: t('sora.tabGenerate') },
  { key: 'library' as const, label: t('sora.tabLibrary') }
])

function onTaskCountChange(counts: { active: number; generating: boolean }) {
  activeTaskCount.value = counts.active
  hasGeneratingTask.value = counts.generating
}

onMounted(async () => {
  if (!soraEnabled.value) return
  try {
    quota.value = await soraAPI.getQuota()
  } catch {
    // 配额查询失败不阻塞页面
  }
})
</script>

<style scoped>
/* ============================================================
   Sora 主题 CSS 变量 — 亮色模式(跟随应用主题)
   ============================================================ */
.sora-root {
  --sora-bg-primary: #F9FAFB;
  --sora-bg-secondary: #FFFFFF;
  --sora-bg-tertiary: #F3F4F6;
  --sora-bg-elevated: #FFFFFF;
  --sora-bg-hover: #E5E7EB;
  --sora-bg-input: #FFFFFF;
  --sora-text-primary: #111827;
  --sora-text-secondary: #6B7280;
  --sora-text-tertiary: #9CA3AF;
  --sora-text-muted: #D1D5DB;
  --sora-accent-primary: #14b8a6;
  --sora-accent-secondary: #0d9488;
  --sora-accent-gradient: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);
  --sora-accent-gradient-hover: linear-gradient(135deg, #2dd4bf 0%, #14b8a6 100%);
  --sora-success: #10B981;
  --sora-warning: #F59E0B;
  --sora-error: #EF4444;
  --sora-info: #3B82F6;
  --sora-border-color: #E5E7EB;
  --sora-border-subtle: #F3F4F6;
  --sora-radius-sm: 8px;
  --sora-radius-md: 12px;
  --sora-radius-lg: 16px;
  --sora-radius-xl: 20px;
  --sora-radius-full: 9999px;
  --sora-shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --sora-shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --sora-shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --sora-shadow-glow: 0 0 20px rgba(20,184,166,0.25);
  --sora-transition-fast: 150ms ease;
  --sora-transition-normal: 250ms ease;
  --sora-header-height: 56px;
  --sora-header-bg: rgba(249, 250, 251, 0.85);
  --sora-placeholder-gradient: linear-gradient(135deg, #e0e7ff 0%, #dbeafe 50%, #cffafe 100%);
  --sora-modal-backdrop: rgba(0, 0, 0, 0.4);

  min-height: 100vh;
  background: var(--sora-bg-primary);
  color: var(--sora-text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   页面布局
   ============================================================ */
.sora-page {
  width: 100%;
}

/* ============================================================
   头部导航栏
   ============================================================ */
.sora-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--sora-header-height);
  background: var(--sora-header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--sora-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.sora-header-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.sora-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* 返回按钮 */
.sora-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--sora-radius-sm);
  color: var(--sora-text-secondary);
  text-decoration: none;
  transition: all var(--sora-transition-fast);
}

.sora-back-btn:hover {
  background: var(--sora-bg-tertiary);
  color: var(--sora-text-primary);
}

/* Tab 导航 */
.sora-nav-tabs {
  display: flex;
  gap: 4px;
  background: var(--sora-bg-secondary);
  border-radius: var(--sora-radius-full);
  padding: 3px;
}

.sora-nav-tab {
  padding: 6px 20px;
  border-radius: var(--sora-radius-full);
  font-size: 13px;
  font-weight: 500;
  color: var(--sora-text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  transition: all var(--sora-transition-fast);
  user-select: none;
}

.sora-nav-tab:hover {
  color: var(--sora-text-primary);
}

.sora-nav-tab.active {
  background: var(--sora-bg-tertiary);
  color: var(--sora-text-primary);
}

/* 队列指示器 */
.sora-queue-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--sora-bg-secondary);
  border-radius: var(--sora-radius-full);
  font-size: 12px;
  color: var(--sora-text-secondary);
}

.sora-queue-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sora-success);
  animation: sora-pulse-dot 2s ease-in-out infinite;
}

.sora-queue-dot.busy {
  background: var(--sora-warning);
}

@keyframes sora-pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================================================
   主内容区
   ============================================================ */
.sora-main {
  min-height: calc(100vh - var(--sora-header-height));
}

/* ============================================================
   功能未启用
   ============================================================ */
.sora-not-enabled {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: 40px;
}

.sora-not-enabled-icon {
  width: 64px;
  height: 64px;
  color: var(--sora-text-tertiary);
  margin-bottom: 16px;
}

.sora-not-enabled-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--sora-text-secondary);
  margin-bottom: 8px;
}

.sora-not-enabled-desc {
  font-size: 14px;
  color: var(--sora-text-tertiary);
  max-width: 400px;
}

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 900px) {
  .sora-header {
    padding: 0 16px;
  }

  .sora-header-left {
    gap: 12px;
  }
}

@media (max-width: 600px) {
  .sora-nav-tab {
    padding: 5px 14px;
    font-size: 12px;
  }
}

/* 滚动条 */
.sora-root ::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.sora-root ::-webkit-scrollbar-track {
  background: transparent;
}

.sora-root ::-webkit-scrollbar-thumb {
  background: var(--sora-bg-hover);
  border-radius: 3px;
}

.sora-root ::-webkit-scrollbar-thumb:hover {
  background: var(--sora-text-tertiary);
}
</style>

<style>
/* 暗色模式:必须明确命中 .sora-root,避免被 scoped 编译后的变量覆盖问题 */
html.dark .sora-root {
  --sora-bg-primary: #020617;
  --sora-bg-secondary: #0f172a;
  --sora-bg-tertiary: #1e293b;
  --sora-bg-elevated: #1e293b;
  --sora-bg-hover: #334155;
  --sora-bg-input: #0f172a;
  --sora-text-primary: #f1f5f9;
  --sora-text-secondary: #94a3b8;
  --sora-text-tertiary: #64748b;
  --sora-text-muted: #475569;
  --sora-border-color: #334155;
  --sora-border-subtle: #1e293b;
  --sora-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --sora-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --sora-shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --sora-shadow-glow: 0 0 20px rgba(20, 184, 166, 0.3);
  --sora-header-bg: rgba(2, 6, 23, 0.85);
  --sora-placeholder-gradient: linear-gradient(135deg, #1e293b 0%, #0f172a 50%, #020617 100%);
  --sora-modal-backdrop: rgba(0, 0, 0, 0.7);
}
</style>