mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 18:35:09 +00:00
Merge branch 'main' into um-5
This commit is contained in:
@@ -9,6 +9,7 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
const bedrockAccounts = ref([])
|
||||
const geminiAccounts = ref([])
|
||||
const openaiAccounts = ref([])
|
||||
const azureOpenaiAccounts = ref([])
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
const sortBy = ref('')
|
||||
@@ -111,6 +112,25 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取Azure OpenAI账户列表
|
||||
const fetchAzureOpenAIAccounts = async () => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const response = await apiClient.get('/admin/azure-openai-accounts')
|
||||
if (response.success) {
|
||||
azureOpenaiAccounts.value = response.data || []
|
||||
} else {
|
||||
throw new Error(response.message || '获取Azure OpenAI账户失败')
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.message
|
||||
throw err
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 获取所有账户
|
||||
const fetchAllAccounts = async () => {
|
||||
loading.value = true
|
||||
@@ -121,7 +141,8 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
fetchClaudeConsoleAccounts(),
|
||||
fetchBedrockAccounts(),
|
||||
fetchGeminiAccounts(),
|
||||
fetchOpenAIAccounts()
|
||||
fetchOpenAIAccounts(),
|
||||
fetchAzureOpenAIAccounts()
|
||||
])
|
||||
} catch (err) {
|
||||
error.value = err.message
|
||||
@@ -231,6 +252,26 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 创建Azure OpenAI账户
|
||||
const createAzureOpenAIAccount = async (data) => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const response = await apiClient.post('/admin/azure-openai-accounts', data)
|
||||
if (response.success) {
|
||||
await fetchAzureOpenAIAccounts()
|
||||
return response.data
|
||||
} else {
|
||||
throw new Error(response.message || '创建Azure OpenAI账户失败')
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.message
|
||||
throw err
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 更新Claude账户
|
||||
const updateClaudeAccount = async (id, data) => {
|
||||
loading.value = true
|
||||
@@ -331,6 +372,26 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新Azure OpenAI账户
|
||||
const updateAzureOpenAIAccount = async (id, data) => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const response = await apiClient.put(`/admin/azure-openai-accounts/${id}`, data)
|
||||
if (response.success) {
|
||||
await fetchAzureOpenAIAccounts()
|
||||
return response
|
||||
} else {
|
||||
throw new Error(response.message || '更新Azure OpenAI账户失败')
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.message
|
||||
throw err
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 切换账户状态
|
||||
const toggleAccount = async (platform, id) => {
|
||||
loading.value = true
|
||||
@@ -345,6 +406,10 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
endpoint = `/admin/bedrock-accounts/${id}/toggle`
|
||||
} else if (platform === 'gemini') {
|
||||
endpoint = `/admin/gemini-accounts/${id}/toggle`
|
||||
} else if (platform === 'openai') {
|
||||
endpoint = `/admin/openai-accounts/${id}/toggle`
|
||||
} else if (platform === 'azure_openai') {
|
||||
endpoint = `/admin/azure-openai-accounts/${id}/toggle`
|
||||
} else {
|
||||
endpoint = `/admin/openai-accounts/${id}/toggle`
|
||||
}
|
||||
@@ -359,6 +424,10 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
await fetchBedrockAccounts()
|
||||
} else if (platform === 'gemini') {
|
||||
await fetchGeminiAccounts()
|
||||
} else if (platform === 'openai') {
|
||||
await fetchOpenAIAccounts()
|
||||
} else if (platform === 'azure_openai') {
|
||||
await fetchAzureOpenAIAccounts()
|
||||
} else {
|
||||
await fetchOpenAIAccounts()
|
||||
}
|
||||
@@ -388,6 +457,10 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
endpoint = `/admin/bedrock-accounts/${id}`
|
||||
} else if (platform === 'gemini') {
|
||||
endpoint = `/admin/gemini-accounts/${id}`
|
||||
} else if (platform === 'openai') {
|
||||
endpoint = `/admin/openai-accounts/${id}`
|
||||
} else if (platform === 'azure_openai') {
|
||||
endpoint = `/admin/azure-openai-accounts/${id}`
|
||||
} else {
|
||||
endpoint = `/admin/openai-accounts/${id}`
|
||||
}
|
||||
@@ -402,6 +475,10 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
await fetchBedrockAccounts()
|
||||
} else if (platform === 'gemini') {
|
||||
await fetchGeminiAccounts()
|
||||
} else if (platform === 'openai') {
|
||||
await fetchOpenAIAccounts()
|
||||
} else if (platform === 'azure_openai') {
|
||||
await fetchAzureOpenAIAccounts()
|
||||
} else {
|
||||
await fetchOpenAIAccounts()
|
||||
}
|
||||
@@ -580,6 +657,7 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
bedrockAccounts.value = []
|
||||
geminiAccounts.value = []
|
||||
openaiAccounts.value = []
|
||||
azureOpenaiAccounts.value = []
|
||||
loading.value = false
|
||||
error.value = null
|
||||
sortBy.value = ''
|
||||
@@ -593,6 +671,7 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
bedrockAccounts,
|
||||
geminiAccounts,
|
||||
openaiAccounts,
|
||||
azureOpenaiAccounts,
|
||||
loading,
|
||||
error,
|
||||
sortBy,
|
||||
@@ -604,17 +683,20 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
fetchBedrockAccounts,
|
||||
fetchGeminiAccounts,
|
||||
fetchOpenAIAccounts,
|
||||
fetchAzureOpenAIAccounts,
|
||||
fetchAllAccounts,
|
||||
createClaudeAccount,
|
||||
createClaudeConsoleAccount,
|
||||
createBedrockAccount,
|
||||
createGeminiAccount,
|
||||
createOpenAIAccount,
|
||||
createAzureOpenAIAccount,
|
||||
updateClaudeAccount,
|
||||
updateClaudeConsoleAccount,
|
||||
updateBedrockAccount,
|
||||
updateGeminiAccount,
|
||||
updateOpenAIAccount,
|
||||
updateAzureOpenAIAccount,
|
||||
toggleAccount,
|
||||
deleteAccount,
|
||||
refreshClaudeToken,
|
||||
|
||||
@@ -19,6 +19,8 @@ export const useDashboardStore = defineStore('dashboard', () => {
|
||||
claude: { total: 0, normal: 0, abnormal: 0, paused: 0, rateLimited: 0 },
|
||||
'claude-console': { total: 0, normal: 0, abnormal: 0, paused: 0, rateLimited: 0 },
|
||||
gemini: { total: 0, normal: 0, abnormal: 0, paused: 0, rateLimited: 0 },
|
||||
openai: { total: 0, normal: 0, abnormal: 0, paused: 0, rateLimited: 0 },
|
||||
azure_openai: { total: 0, normal: 0, abnormal: 0, paused: 0, rateLimited: 0 },
|
||||
bedrock: { total: 0, normal: 0, abnormal: 0, paused: 0, rateLimited: 0 }
|
||||
},
|
||||
todayRequests: 0,
|
||||
@@ -174,6 +176,8 @@ export const useDashboardStore = defineStore('dashboard', () => {
|
||||
claude: { total: 0, normal: 0, abnormal: 0, paused: 0, rateLimited: 0 },
|
||||
'claude-console': { total: 0, normal: 0, abnormal: 0, paused: 0, rateLimited: 0 },
|
||||
gemini: { total: 0, normal: 0, abnormal: 0, paused: 0, rateLimited: 0 },
|
||||
openai: { total: 0, normal: 0, abnormal: 0, paused: 0, rateLimited: 0 },
|
||||
azure_openai: { total: 0, normal: 0, abnormal: 0, paused: 0, rateLimited: 0 },
|
||||
bedrock: { total: 0, normal: 0, abnormal: 0, paused: 0, rateLimited: 0 }
|
||||
},
|
||||
todayRequests: recentActivity.requestsToday || 0,
|
||||
|
||||
149
web/admin-spa/src/stores/theme.js
Normal file
149
web/admin-spa/src/stores/theme.js
Normal file
@@ -0,0 +1,149 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed, watch } from 'vue'
|
||||
|
||||
// 主题模式枚举
|
||||
export const ThemeMode = {
|
||||
LIGHT: 'light',
|
||||
DARK: 'dark',
|
||||
AUTO: 'auto'
|
||||
}
|
||||
|
||||
export const useThemeStore = defineStore('theme', () => {
|
||||
// 状态 - 支持三种模式:light, dark, auto
|
||||
const themeMode = ref(ThemeMode.AUTO)
|
||||
const systemPrefersDark = ref(false)
|
||||
|
||||
// 计算属性 - 实际的暗黑模式状态
|
||||
const isDarkMode = computed(() => {
|
||||
if (themeMode.value === ThemeMode.DARK) {
|
||||
return true
|
||||
} else if (themeMode.value === ThemeMode.LIGHT) {
|
||||
return false
|
||||
} else {
|
||||
// auto 模式,跟随系统
|
||||
return systemPrefersDark.value
|
||||
}
|
||||
})
|
||||
|
||||
// 计算属性 - 当前实际使用的主题
|
||||
const currentTheme = computed(() => {
|
||||
return isDarkMode.value ? ThemeMode.DARK : ThemeMode.LIGHT
|
||||
})
|
||||
|
||||
// 初始化主题
|
||||
const initTheme = () => {
|
||||
// 检测系统主题偏好
|
||||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
||||
systemPrefersDark.value = mediaQuery.matches
|
||||
|
||||
// 从 localStorage 读取保存的主题模式
|
||||
const savedMode = localStorage.getItem('themeMode')
|
||||
|
||||
if (savedMode && Object.values(ThemeMode).includes(savedMode)) {
|
||||
themeMode.value = savedMode
|
||||
} else {
|
||||
// 默认使用 auto 模式
|
||||
themeMode.value = ThemeMode.AUTO
|
||||
}
|
||||
|
||||
// 应用主题
|
||||
applyTheme()
|
||||
|
||||
// 开始监听系统主题变化
|
||||
watchSystemTheme()
|
||||
}
|
||||
|
||||
// 应用主题到 DOM
|
||||
const applyTheme = () => {
|
||||
const root = document.documentElement
|
||||
|
||||
if (isDarkMode.value) {
|
||||
root.classList.add('dark')
|
||||
} else {
|
||||
root.classList.remove('dark')
|
||||
}
|
||||
}
|
||||
|
||||
// 设置主题模式
|
||||
const setThemeMode = (mode) => {
|
||||
if (Object.values(ThemeMode).includes(mode)) {
|
||||
themeMode.value = mode
|
||||
}
|
||||
}
|
||||
|
||||
// 循环切换主题模式
|
||||
const cycleThemeMode = () => {
|
||||
const modes = [ThemeMode.LIGHT, ThemeMode.DARK, ThemeMode.AUTO]
|
||||
const currentIndex = modes.indexOf(themeMode.value)
|
||||
const nextIndex = (currentIndex + 1) % modes.length
|
||||
themeMode.value = modes[nextIndex]
|
||||
}
|
||||
|
||||
// 监听主题模式变化,自动保存到 localStorage 并应用
|
||||
watch(themeMode, (newMode) => {
|
||||
localStorage.setItem('themeMode', newMode)
|
||||
applyTheme()
|
||||
})
|
||||
|
||||
// 监听系统主题偏好变化
|
||||
watch(systemPrefersDark, () => {
|
||||
// 只有在 auto 模式下才需要重新应用主题
|
||||
if (themeMode.value === ThemeMode.AUTO) {
|
||||
applyTheme()
|
||||
}
|
||||
})
|
||||
|
||||
// 监听系统主题变化
|
||||
const watchSystemTheme = () => {
|
||||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
||||
|
||||
const handleChange = (e) => {
|
||||
systemPrefersDark.value = e.matches
|
||||
}
|
||||
|
||||
// 初始检测
|
||||
systemPrefersDark.value = mediaQuery.matches
|
||||
|
||||
// 添加监听器
|
||||
mediaQuery.addEventListener('change', handleChange)
|
||||
|
||||
// 返回清理函数
|
||||
return () => {
|
||||
mediaQuery.removeEventListener('change', handleChange)
|
||||
}
|
||||
}
|
||||
|
||||
// 兼容旧版 API
|
||||
const toggleTheme = () => {
|
||||
cycleThemeMode()
|
||||
}
|
||||
|
||||
const setTheme = (theme) => {
|
||||
if (theme === 'dark') {
|
||||
setThemeMode(ThemeMode.DARK)
|
||||
} else if (theme === 'light') {
|
||||
setThemeMode(ThemeMode.LIGHT)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
// State
|
||||
themeMode,
|
||||
isDarkMode,
|
||||
currentTheme,
|
||||
systemPrefersDark,
|
||||
|
||||
// Constants
|
||||
ThemeMode,
|
||||
|
||||
// Actions
|
||||
initTheme,
|
||||
setThemeMode,
|
||||
cycleThemeMode,
|
||||
watchSystemTheme,
|
||||
|
||||
// 兼容旧版 API
|
||||
toggleTheme,
|
||||
setTheme
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user