feat: add model groups, verified registration and CNY credit grants
This commit is contained in:
1 parent
f5ba6cb255
commit
7a18db2123
40 files changed
+1980
-263
No files matched your search
@@ -10,7 +10,8 @@ server {
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header Forwarded "";
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Cookie $http_cookie;
|
||||
}
|
||||
@@ -20,7 +21,8 @@ server {
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header Forwarded "";
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
proxy_set_header Content-Type $http_content_type;
|
||||
|
||||
@@ -29,6 +29,7 @@ const authenticated = ref(false)
|
||||
const authUser = ref<AuthUser>()
|
||||
const accountMenuOpen = ref(false)
|
||||
const userName = ref('')
|
||||
const availableCredit = ref<number>()
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
@@ -80,6 +81,7 @@ function signIn(user: AuthUser) {
|
||||
}
|
||||
|
||||
function logout() {
|
||||
availableCredit.value = undefined
|
||||
accountMenuOpen.value = false
|
||||
portal.value = 'user'
|
||||
activeView.value = 'overview'
|
||||
@@ -130,9 +132,9 @@ function openAccountSettings() {
|
||||
|
||||
<div class="sidebar-footer">
|
||||
<div v-if="portal === 'user'" class="balance-card">
|
||||
<span>额度账本</span>
|
||||
<strong>尚未接入</strong>
|
||||
<small>额度由管理员配置后显示</small>
|
||||
<span>可用额度</span>
|
||||
<strong>{{ availableCredit === undefined ? '--' : `¥ ${availableCredit.toFixed(2)}` }}</strong>
|
||||
<small>人民币 CNY</small>
|
||||
</div>
|
||||
<div v-else class="security-card"><ShieldCheck :size="17" /><span>管理操作均写入审计日志</span></div>
|
||||
<button class="nav-link" @click="notify('帮助中心将在后续阶段开放')"><CircleHelp :size="18" /><span>帮助中心</span></button>
|
||||
@@ -164,7 +166,7 @@ function openAccountSettings() {
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<UserConsole v-if="portal === 'user'" :view="activeView" :display-name="userName" @navigate="navigate" @notify="notify" />
|
||||
<UserConsole v-if="portal === 'user'" :view="activeView" :display-name="userName" @navigate="navigate" @notify="notify" @balance="availableCredit = $event" />
|
||||
<AdminConsole v-else :view="activeView" :current-user="authUser" @navigate="navigate" @notify="notify" />
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { Plus, KeyRound, CircleDollarSign, RefreshCcw, Search, ShieldCheck, List } from 'lucide-vue-next'
|
||||
import { catalogClient, type AdminCatalogUser, type WalletEntry } from '../services/catalog'
|
||||
import type { AuthUser } from '../services/auth'
|
||||
import UiModal from './UiModal.vue'
|
||||
import SlidePanel from './SlidePanel.vue'
|
||||
const props = defineProps<{ currentUser?: AuthUser }>()
|
||||
const emit = defineEmits<{ notify: [message: string] }>()
|
||||
const users = ref<AdminCatalogUser[]>([])
|
||||
const balances = ref<Record<string, number>>({})
|
||||
const query = ref('')
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const error = ref('')
|
||||
const editor = ref<'account' | 'invite' | 'credit' | 'role' | ''>('')
|
||||
const target = ref<AdminCatalogUser>()
|
||||
const account = reactive({ account: '', displayName: '', password: '' })
|
||||
const role = ref<'user' | 'admin'>('user')
|
||||
const inviteLabel = ref('')
|
||||
const inviteCode = ref('')
|
||||
const amount = ref('')
|
||||
const reason = ref('')
|
||||
const requestId = ref('')
|
||||
const submittedGrant = ref<{ requestId: string; amount: string; reason: string }>()
|
||||
const ledgerUser = ref<AdminCatalogUser>()
|
||||
const entries = ref<WalletEntry[]>([])
|
||||
const ledgerLoading = ref(false)
|
||||
const filteredUsers = computed(() => users.value.filter(user => `${user.account} ${user.displayName}`.toLowerCase().includes(query.value.toLowerCase())))
|
||||
const totalBalance = computed(() => Object.values(balances.value).reduce((sum, balance) => sum + Number(balance), 0))
|
||||
const money = (value: number | undefined) => `¥ ${Number(value || 0).toFixed(2)}`
|
||||
const roleName = (value: string) => ({ user: '普通用户', admin: '管理员', super_admin: '超级管理员' })[value] || value
|
||||
async function refresh() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const [userResult, walletResult] = await Promise.all([catalogClient.listAdminUsers(), catalogClient.listWallets()])
|
||||
users.value = userResult.users
|
||||
balances.value = Object.fromEntries(walletResult.wallets.map(item => [item.userId, Number(item.balance)]))
|
||||
} catch (e) { error.value = e instanceof Error ? e.message : '加载失败' }
|
||||
finally { loading.value = false }
|
||||
}
|
||||
onMounted(refresh)
|
||||
function createAccount() { Object.assign(account, { account: '', displayName: '', password: '' }); editor.value = 'account' }
|
||||
function createInvite() { inviteCode.value = ''; inviteLabel.value = ''; editor.value = 'invite' }
|
||||
function credit(user: AdminCatalogUser) {
|
||||
target.value = user; amount.value = ''; reason.value = ''; requestId.value = crypto.randomUUID(); submittedGrant.value = undefined; editor.value = 'credit'
|
||||
}
|
||||
function editRole(user: AdminCatalogUser) { target.value = user; role.value = user.role === 'admin' ? 'admin' : 'user'; editor.value = 'role' }
|
||||
async function ledger(user: AdminCatalogUser) {
|
||||
ledgerUser.value = user; entries.value = []; ledgerLoading.value = true
|
||||
try { entries.value = (await catalogClient.walletEntries(user.id)).entries }
|
||||
catch (e) { emit('notify', e instanceof Error ? e.message : '加载流水失败') }
|
||||
finally { ledgerLoading.value = false }
|
||||
}
|
||||
async function save() {
|
||||
if (saving.value) return
|
||||
saving.value = true
|
||||
try {
|
||||
if (editor.value === 'account') {
|
||||
await catalogClient.createAdminUser(account)
|
||||
account.password = ''
|
||||
} else if (editor.value === 'invite') {
|
||||
inviteCode.value = (await catalogClient.createAdminInvitation({ label: inviteLabel.value, maxUses: 1 })).code
|
||||
emit('notify', '邀请码已创建')
|
||||
return
|
||||
} else if (editor.value === 'role' && target.value) {
|
||||
await catalogClient.changeUserRole(target.value.id, role.value)
|
||||
} else if (editor.value === 'credit' && target.value) {
|
||||
if (!reason.value.trim()) throw new Error('请填写发放原因')
|
||||
if (!submittedGrant.value) submittedGrant.value = { requestId: requestId.value, amount: amount.value, reason: reason.value.trim() }
|
||||
await catalogClient.grantCredit(target.value.id, submittedGrant.value)
|
||||
}
|
||||
editor.value = ''
|
||||
await refresh()
|
||||
emit('notify', '操作已完成')
|
||||
} catch (e) { emit('notify', e instanceof Error ? e.message : '操作失败') }
|
||||
finally { saving.value = false }
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page-heading"><h1>用户与额度</h1><div class="heading-actions"><button class="icon-button" title="刷新用户" :disabled="loading" @click="refresh"><RefreshCcw :size="18" /></button><button class="button secondary" @click="createInvite"><KeyRound :size="16" />创建邀请</button><button class="button primary" @click="createAccount"><Plus :size="16" />开通账号</button></div></section>
|
||||
<div class="account-summary"><span>用户 <strong>{{ users.length }}</strong></span><span>人民币余额合计 <strong>{{ money(totalBalance) }}</strong></span></div>
|
||||
<label class="search-input account-search"><Search :size="16" /><input v-model="query" placeholder="搜索账号或姓名" /></label>
|
||||
<p v-if="error" role="alert">{{ error }}</p><p v-if="loading">加载中…</p>
|
||||
<div class="responsive-table"><table><thead><tr><th>用户</th><th>角色</th><th>人民币余额</th><th>状态</th><th>操作</th></tr></thead><tbody><tr v-for="user in filteredUsers" :key="user.id"><td><strong>{{ user.displayName }}</strong><small class="account-secondary">{{ user.account }}</small></td><td>{{ roleName(user.role) }}</td><td>{{ money(balances[user.id]) }}</td><td>{{ user.status === 'active' ? '正常' : '已停用' }}</td><td><div class="heading-actions"><button class="button secondary small" :disabled="user.status !== 'active'" @click="credit(user)"><CircleDollarSign :size="15" />发放额度</button><button class="icon-button" :title="`${user.account} 额度流水`" @click="ledger(user)"><List :size="16" /></button><button v-if="props.currentUser?.role === 'super_admin' && user.role !== 'super_admin'" class="icon-button" :title="`${user.account} 修改角色`" @click="editRole(user)"><ShieldCheck :size="16" /></button></div></td></tr><tr v-if="!filteredUsers.length && !loading"><td colspan="5">暂无用户</td></tr></tbody></table></div>
|
||||
<UiModal v-if="editor" :title="editor === 'account' ? '开通账号' : editor === 'invite' ? '创建邀请' : editor === 'credit' ? '发放人民币额度' : '修改角色'" @close="!saving && (editor = '')">
|
||||
<form id="account-editor" @submit.prevent="save">
|
||||
<template v-if="editor === 'account'"><label class="form-label" for="new-account">账号</label><input id="new-account" v-model="account.account" class="text-input" required maxlength="254" autocomplete="off" placeholder="用户名、邮箱或手机号" /><label class="form-label" for="new-display">显示名称</label><input id="new-display" v-model="account.displayName" class="text-input" maxlength="80" /><label class="form-label" for="new-password">初始密码</label><input id="new-password" v-model="account.password" type="password" class="text-input" required minlength="8" maxlength="256" autocomplete="new-password" /></template>
|
||||
<template v-else-if="editor === 'invite'"><label class="form-label" for="invite-label">邀请备注</label><input id="invite-label" v-model="inviteLabel" class="text-input" :disabled="!!inviteCode" /><label v-if="inviteCode" class="form-label" for="invite-code">邀请码(仅显示一次)</label><input v-if="inviteCode" id="invite-code" :value="inviteCode" class="text-input" readonly /></template>
|
||||
<template v-else-if="editor === 'credit'"><p>{{ target?.displayName }} · {{ target?.account }}</p><p>当前余额:{{ money(balances[target?.id || '']) }}</p><label class="form-label" for="grant-amount">发放金额(人民币元)</label><input id="grant-amount" v-model="amount" class="text-input" required type="number" min="0.01" max="1000000" step="0.01" :disabled="!!submittedGrant" /><label class="form-label" for="grant-reason">发放原因</label><textarea id="grant-reason" v-model="reason" class="text-input" required maxlength="500" :disabled="!!submittedGrant" /><p>本次增加:{{ money(Number(amount)) }}</p></template>
|
||||
<template v-else><p>{{ target?.displayName }} · {{ target?.account }}</p><label class="form-label" for="account-role">角色</label><select id="account-role" v-model="role" class="text-input"><option value="user">普通用户</option><option value="admin">管理员</option></select></template>
|
||||
</form>
|
||||
<template #footer><button class="button secondary" :disabled="saving" @click="editor = ''">关闭</button><button v-if="!inviteCode || editor !== 'invite'" class="button primary" type="submit" form="account-editor" :disabled="saving">{{ saving ? '提交中…' : editor === 'credit' ? '确认发放' : '确认' }}</button></template>
|
||||
</UiModal>
|
||||
<SlidePanel v-if="ledgerUser" :title="`${ledgerUser.displayName} · 额度流水`" @close="ledgerUser = undefined"><p>币种:人民币 CNY</p><p v-if="ledgerLoading">加载中…</p><div v-for="entry in entries" :key="entry.id" class="wallet-entry"><strong>+ {{ money(entry.amount) }}</strong><p>{{ entry.reason }}</p><small>{{ entry.actor }} · {{ new Date(entry.createdAt).toLocaleString('zh-CN') }}</small><p>余额 {{ money(entry.balanceAfter) }}</p></div><p v-if="!entries.length && !ledgerLoading">暂无流水</p></SlidePanel>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.account-summary { display: flex; flex-wrap: wrap; gap: 28px; padding: 16px 0; border-bottom: 1px solid #dce3e5; }
|
||||
.account-search { max-width: 420px; }
|
||||
.account-secondary { display: block; margin-top: 5px; color: #687378; }
|
||||
.wallet-entry { border-bottom: 1px solid #dce3e5; padding: 16px 0; overflow-wrap: anywhere; }
|
||||
@media(max-width: 700px) { .heading-actions { flex-wrap: wrap; } }
|
||||
</style>
|
||||
@@ -0,0 +1,151 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { Plus, Pencil, RefreshCcw, Search } from 'lucide-vue-next'
|
||||
import { catalogClient, type CatalogProvider, type CatalogModel, type LogicalModel } from '../services/catalog'
|
||||
import UiModal from './UiModal.vue'
|
||||
|
||||
const props = defineProps<{ section: 'models' | 'channels' }>()
|
||||
const emit = defineEmits<{ notify: [message: string] }>()
|
||||
const channels = ref<CatalogProvider[]>([])
|
||||
const models = ref<LogicalModel[]>([])
|
||||
const groups = ref<CatalogModel[]>([])
|
||||
const query = ref('')
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const error = ref('')
|
||||
const editor = ref<'channel' | 'model' | 'group' | ''>('')
|
||||
const editingId = ref<string>()
|
||||
const channel = reactive({ code: '', name: '', protocol: 'openai-compatible' as CatalogProvider['protocol'], sourceType: 'relay' as CatalogProvider['sourceType'], baseUrl: '', credentialType: 'api-key' as NonNullable<CatalogProvider['credentialType']>, credentialSecret: '', description: '', status: 'active' as CatalogProvider['status'] })
|
||||
const model = reactive({ publicName: '', modelKey: '', type: 'text' as LogicalModel['type'], mode: 'sync' as LogicalModel['mode'], description: '', inputTypes: 'text', outputTypes: 'text', status: 'active' as LogicalModel['status'] })
|
||||
const group = reactive({ logicalModelId: '', providerId: '', sourceLabel: '', upstreamModel: '', input: '', output: '', unit: 'CNY / 1M tokens', priority: '100', maxConcurrency: '1', status: 'active' as CatalogModel['status'] })
|
||||
const shownModels = computed(() => models.value.filter(item => `${item.publicName} ${item.modelKey || ''}`.toLowerCase().includes(query.value.toLowerCase())))
|
||||
const shownChannels = computed(() => channels.value.filter(item => `${item.name} ${item.code}`.toLowerCase().includes(query.value.toLowerCase())))
|
||||
const channelName = (id: string) => channels.value.find(item => item.id === id)?.name || id
|
||||
const modelGroups = (id: string) => groups.value.filter(item => item.logicalModelId === id)
|
||||
|
||||
async function refresh() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const [providers, catalog] = await Promise.all([catalogClient.listAdminProviders(), catalogClient.listAdminModels()])
|
||||
channels.value = providers.providers
|
||||
models.value = catalog.logicalModels
|
||||
groups.value = catalog.models
|
||||
} catch (e) { error.value = e instanceof Error ? e.message : '加载失败' }
|
||||
finally { loading.value = false }
|
||||
}
|
||||
onMounted(refresh)
|
||||
watch(() => props.section, () => { query.value = '' })
|
||||
|
||||
function editChannel(item?: CatalogProvider) {
|
||||
editingId.value = item?.id
|
||||
Object.assign(channel, { code: '', name: '', protocol: 'openai-compatible', sourceType: 'relay', baseUrl: '', credentialType: 'api-key', description: '', status: 'active' }, item || {}, { credentialSecret: '' })
|
||||
editor.value = 'channel'
|
||||
}
|
||||
function editModel(item?: LogicalModel) {
|
||||
editingId.value = item?.id
|
||||
Object.assign(model, { publicName: '', modelKey: '', type: 'text', mode: 'sync', description: '', status: 'active' }, item || {}, { inputTypes: item?.inputTypes.join(', ') || 'text', outputTypes: item?.outputTypes.join(', ') || 'text' })
|
||||
editor.value = 'model'
|
||||
}
|
||||
function editGroup(parent: LogicalModel, item?: CatalogModel) {
|
||||
editingId.value = item?.id
|
||||
Object.assign(group, { logicalModelId: parent.id, providerId: item?.providerId || '', sourceLabel: item?.sourceLabel || '', upstreamModel: item?.upstreamModel || '', input: item?.pricing?.input?.toString() || '', output: item?.pricing?.output?.toString() || '', unit: item?.pricing?.unit || 'CNY / 1M tokens', priority: String(item?.priority ?? 100), maxConcurrency: String(item?.maxConcurrency ?? 1), status: item?.status || 'active' })
|
||||
editor.value = 'group'
|
||||
}
|
||||
async function save() {
|
||||
if (saving.value) return
|
||||
saving.value = true
|
||||
try {
|
||||
if (editor.value === 'channel') {
|
||||
if (!channel.code.trim() || !channel.name.trim()) throw new Error('请填写渠道 Code 和名称')
|
||||
if (editingId.value) await catalogClient.updateAdminProvider(editingId.value, { code: channel.code, name: channel.name, protocol: channel.protocol, sourceType: channel.sourceType, baseUrl: channel.baseUrl, credentialType: channel.credentialType, credentialSecret: channel.credentialSecret || undefined, description: channel.description, status: channel.status })
|
||||
else await catalogClient.createAdminProvider({ ...channel })
|
||||
channel.credentialSecret = ''
|
||||
} else if (editor.value === 'model') {
|
||||
if (!model.publicName.trim()) throw new Error('请填写模型名称')
|
||||
await catalogClient.saveDefinition(editingId.value, { ...model, inputTypes: model.inputTypes.split(',').map(s => s.trim()).filter(Boolean), outputTypes: model.outputTypes.split(',').map(s => s.trim()).filter(Boolean) })
|
||||
} else {
|
||||
if (!group.providerId || !group.sourceLabel.trim() || !group.upstreamModel.trim()) throw new Error('请选择渠道并填写分组名称、上游模型标识')
|
||||
await catalogClient.saveGroup(editingId.value, { logicalModelId: group.logicalModelId, providerId: group.providerId, sourceLabel: group.sourceLabel, upstreamModel: group.upstreamModel, status: group.status, priority: Number(group.priority), maxConcurrency: Number(group.maxConcurrency), pricing: { input: group.input === '' ? undefined : Number(group.input), output: group.output === '' ? undefined : Number(group.output), unit: group.unit } })
|
||||
}
|
||||
editor.value = ''
|
||||
await refresh()
|
||||
emit('notify', '已保存')
|
||||
} catch (e) { emit('notify', e instanceof Error ? e.message : '保存失败') }
|
||||
finally { saving.value = false }
|
||||
}
|
||||
async function toggle(kind: 'channel' | 'model' | 'group', item: CatalogProvider | LogicalModel | CatalogModel) {
|
||||
if (saving.value) return
|
||||
saving.value = true
|
||||
try {
|
||||
const status = item.status === 'active' ? 'disabled' : 'active'
|
||||
if (kind === 'channel') await catalogClient.updateAdminProvider(item.id, { status })
|
||||
else if (kind === 'model') await catalogClient.saveDefinition(item.id, { status })
|
||||
else await catalogClient.saveGroup(item.id, { status })
|
||||
await refresh()
|
||||
emit('notify', status === 'active' ? '已启用' : '已停用')
|
||||
} catch (e) { emit('notify', e instanceof Error ? e.message : '状态更新失败') }
|
||||
finally { saving.value = false }
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page-heading"><h1>{{ props.section === 'channels' ? '渠道管理' : '模型与分组' }}</h1><div class="heading-actions"><button class="icon-button" title="刷新" :disabled="loading" @click="refresh"><RefreshCcw :size="18" /></button><button class="button primary" @click="props.section === 'channels' ? editChannel() : editModel()"><Plus :size="16" />{{ props.section === 'channels' ? '添加渠道' : '添加模型' }}</button></div></section>
|
||||
<label class="search-input catalog-search"><Search :size="16" /><input v-model="query" :placeholder="props.section === 'channels' ? '搜索渠道名称或 Code' : '搜索模型名称或标识'" /></label>
|
||||
<p v-if="error" role="alert">{{ error }}</p>
|
||||
<p v-if="loading">加载中…</p>
|
||||
<div v-if="props.section === 'channels'" class="responsive-table"><table><thead><tr><th>渠道</th><th>来源 / 协议</th><th>Base URL</th><th>凭据</th><th>状态</th><th>操作</th></tr></thead><tbody><tr v-for="item in shownChannels" :key="item.id"><td><strong>{{ item.name }}</strong><small class="catalog-secondary">{{ item.code }}</small></td><td>{{ item.sourceType }}<small class="catalog-secondary">{{ item.protocol }}</small></td><td class="catalog-url">{{ item.baseUrl || '未配置' }}</td><td>{{ item.credentialMasked || '未配置' }}</td><td><label class="catalog-toggle"><input type="checkbox" :checked="item.status === 'active'" :disabled="saving" :aria-label="`${item.name} 启用`" @change="toggle('channel', item)" />{{ item.status === 'active' ? '已启用' : '已停用' }}</label></td><td><button class="icon-button" :title="`编辑渠道 ${item.name}`" @click="editChannel(item)"><Pencil :size="16" /></button></td></tr><tr v-if="!shownChannels.length && !loading"><td colspan="6">暂无渠道</td></tr></tbody></table></div>
|
||||
<template v-else>
|
||||
<section v-for="item in shownModels" :key="item.id" class="model-definition-section">
|
||||
<header class="panel-header"><div><h3>{{ item.publicName }}</h3><small>{{ item.modelKey || item.id }} · {{ item.type }} · {{ item.mode }}</small></div><div class="heading-actions"><label class="catalog-toggle"><input type="checkbox" :checked="item.status === 'active'" :disabled="saving" :aria-label="`${item.publicName} 启用`" @change="toggle('model', item)" />启用</label><button class="icon-button" :title="`编辑模型 ${item.publicName}`" @click="editModel(item)"><Pencil :size="16" /></button><button class="button secondary small" @click="editGroup(item)"><Plus :size="15" />添加分组</button></div></header>
|
||||
<p v-if="item.description" class="catalog-secondary">{{ item.description }}</p>
|
||||
<div class="responsive-table"><table><thead><tr><th>分组名称</th><th>渠道</th><th>上游模型</th><th>输入 / 输出价格</th><th>并发</th><th>状态</th><th>操作</th></tr></thead><tbody><tr v-for="route in modelGroups(item.id)" :key="route.id"><td>{{ route.sourceLabel }}</td><td>{{ channelName(route.providerId) }}</td><td><code>{{ route.upstreamModel }}</code></td><td>{{ route.pricing?.input ?? '—' }} / {{ route.pricing?.output ?? '—' }}<small class="catalog-secondary">{{ route.pricing?.unit }}</small></td><td>{{ route.maxConcurrency ?? '默认' }}</td><td><label class="catalog-toggle"><input type="checkbox" :checked="route.status === 'active'" :disabled="saving" :aria-label="`${route.sourceLabel} 启用`" @change="toggle('group', route)" />{{ route.status === 'active' ? '已启用' : '已停用' }}</label></td><td><button class="icon-button" :title="`编辑分组 ${route.sourceLabel}`" @click="editGroup(item, route)"><Pencil :size="16" /></button></td></tr><tr v-if="!modelGroups(item.id).length"><td colspan="7">暂无分组</td></tr></tbody></table></div>
|
||||
</section>
|
||||
<p v-if="!shownModels.length && !loading">暂无模型</p>
|
||||
</template>
|
||||
<UiModal v-if="editor" :title="`${editingId ? '编辑' : '添加'}${editor === 'channel' ? '渠道' : editor === 'model' ? '模型' : '分组'}`" @close="!saving && (editor = '')">
|
||||
<form id="catalog-editor" @submit.prevent="save">
|
||||
<template v-if="editor === 'channel'">
|
||||
<label class="form-label" for="channel-code">渠道 Code</label><input id="channel-code" v-model="channel.code" class="text-input" required maxlength="64" pattern="[a-z0-9][a-z0-9._\-]{1,63}" />
|
||||
<label class="form-label" for="channel-name">渠道名称</label><input id="channel-name" v-model="channel.name" class="text-input" required maxlength="120" />
|
||||
<label class="form-label" for="channel-source">来源类型</label><select id="channel-source" v-model="channel.sourceType" class="text-input"><option value="relay">中转站</option><option value="official">官方供应商</option><option value="self-hosted">自托管</option><option value="custom">其他</option></select>
|
||||
<label class="form-label" for="channel-protocol">接入协议</label><select id="channel-protocol" v-model="channel.protocol" class="text-input"><option value="openai-compatible">OpenAI 兼容</option><option value="http">HTTP</option><option value="sdk">SDK</option></select>
|
||||
<label class="form-label" for="channel-url">Base URL</label><input id="channel-url" v-model="channel.baseUrl" class="text-input" type="url" placeholder="https://api.example.com/v1" />
|
||||
<label class="form-label" for="channel-credential">凭据类型</label><select id="channel-credential" v-model="channel.credentialType" class="text-input"><option value="api-key">API Key</option><option value="bearer">Bearer Token</option><option value="access-token">Access Token</option><option value="none">不使用凭据</option></select>
|
||||
<label class="form-label" for="channel-secret">{{ editingId ? '新凭据(留空保留原值)' : '凭据' }}</label><input id="channel-secret" v-model="channel.credentialSecret" class="text-input" type="password" autocomplete="new-password" :disabled="channel.credentialType === 'none'" />
|
||||
<label class="form-label" for="channel-note">备注</label><textarea id="channel-note" v-model="channel.description" class="text-input" />
|
||||
</template>
|
||||
<template v-else-if="editor === 'model'">
|
||||
<label class="form-label" for="logical-name">模型名称</label><input id="logical-name" v-model="model.publicName" class="text-input" required maxlength="160" />
|
||||
<label class="form-label" for="logical-key">统一模型标识</label><input id="logical-key" v-model="model.modelKey" class="text-input" maxlength="160" />
|
||||
<label class="form-label" for="logical-type">模型类型</label><select id="logical-type" v-model="model.type" class="text-input"><option value="text">文本</option><option value="code">代码</option><option value="multimodal">多模态</option><option value="image">图像</option><option value="audio">音频</option><option value="video">视频</option><option value="embedding">向量</option><option value="3d">3D</option></select>
|
||||
<label class="form-label" for="logical-mode">调用模式</label><select id="logical-mode" v-model="model.mode" class="text-input"><option value="sync">同步</option><option value="stream">流式</option><option value="async">异步</option></select>
|
||||
<label class="form-label" for="logical-input">输入类型</label><input id="logical-input" v-model="model.inputTypes" class="text-input" />
|
||||
<label class="form-label" for="logical-output">输出类型</label><input id="logical-output" v-model="model.outputTypes" class="text-input" />
|
||||
<label class="form-label" for="logical-description">模型说明</label><textarea id="logical-description" v-model="model.description" class="text-input" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<label class="form-label" for="group-model">所属模型</label><select id="group-model" v-model="group.logicalModelId" class="text-input" required><option v-for="item in models" :key="item.id" :value="item.id">{{ item.publicName }}</option></select>
|
||||
<label class="form-label" for="group-name">分组名称</label><input id="group-name" v-model="group.sourceLabel" class="text-input" required maxlength="160" />
|
||||
<label class="form-label" for="group-channel">渠道</label><select id="group-channel" v-model="group.providerId" class="text-input" required><option value="" disabled>请选择渠道</option><option v-for="item in channels" :key="item.id" :value="item.id">{{ item.name }}{{ item.status === 'disabled' ? '(已停用)' : '' }}</option></select>
|
||||
<label class="form-label" for="group-upstream">上游模型标识</label><input id="group-upstream" v-model="group.upstreamModel" class="text-input" required maxlength="160" />
|
||||
<div class="modal-form-grid"><label><span class="form-label">输入价格</span><input v-model="group.input" class="text-input" type="number" min="0" step="any" /></label><label><span class="form-label">输出价格</span><input v-model="group.output" class="text-input" type="number" min="0" step="any" /></label></div>
|
||||
<label class="form-label" for="group-unit">价格单位</label><input id="group-unit" v-model="group.unit" class="text-input" required />
|
||||
<div class="modal-form-grid"><label><span class="form-label">优先级</span><input v-model="group.priority" class="text-input" type="number" min="0" step="1" required /></label><label><span class="form-label">并发上限</span><input v-model="group.maxConcurrency" class="text-input" type="number" min="1" step="1" required /></label></div>
|
||||
</template>
|
||||
</form>
|
||||
<template #footer><button class="button secondary" :disabled="saving" @click="editor = ''">取消</button><button class="button primary" form="catalog-editor" type="submit" :disabled="saving">{{ saving ? '保存中…' : '保存' }}</button></template>
|
||||
</UiModal>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.catalog-secondary { display: block; color: #687378; font-size: 12px; margin-top: 5px; overflow-wrap: anywhere; }
|
||||
.catalog-search { max-width: 420px; }
|
||||
.catalog-url { max-width: 320px; overflow-wrap: anywhere; }
|
||||
.catalog-toggle { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
|
||||
.model-definition-section { padding: 20px 0; border-bottom: 1px solid #dce3e5; }
|
||||
.model-definition-section h3 { margin: 0; font-size: 18px; }
|
||||
.model-definition-section .panel-header { padding: 0 0 16px; flex-wrap: wrap; gap: 12px; }
|
||||
.responsive-table code { overflow-wrap: anywhere; }
|
||||
@media(max-width: 700px) { .heading-actions { flex-wrap: wrap; } }
|
||||
</style>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import type { ModelItem } from '../types'
|
||||
|
||||
const props = defineProps<{ groups: ModelItem[]; modelValue: string[]; disabled?: boolean }>()
|
||||
const emit = defineEmits<{ 'update:modelValue': [ids: string[]] }>()
|
||||
const selectedModel = ref('')
|
||||
const models = computed(() => [...new Map(props.groups.map(group => [group.logicalModelId || group.id, group])).values()])
|
||||
const visibleGroups = computed(() => props.groups.filter(group => (group.logicalModelId || group.id) === selectedModel.value))
|
||||
const unavailable = computed(() => props.modelValue.filter(id => !props.groups.some(group => group.id === id)))
|
||||
function toggle(id: string, checked: boolean) {
|
||||
emit('update:modelValue', checked ? [...new Set([...props.modelValue, id])] : props.modelValue.filter(value => value !== id))
|
||||
}
|
||||
function count(id: string) { return props.groups.filter(group => (group.logicalModelId || group.id) === id && props.modelValue.includes(group.id)).length }
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="group-permissions">
|
||||
<label for="permission-model">模型</label>
|
||||
<select id="permission-model" v-model="selectedModel" class="text-input" :disabled="disabled">
|
||||
<option value="" disabled>请选择模型</option>
|
||||
<option v-for="model in models" :key="model.logicalModelId || model.id" :value="model.logicalModelId || model.id">{{ model.name }} (已选 {{ count(model.logicalModelId || model.id) }} 组)</option>
|
||||
</select>
|
||||
<fieldset :disabled="disabled"><legend>可调用分组</legend>
|
||||
<label v-for="group in visibleGroups" :key="group.id" class="group-option">
|
||||
<input type="checkbox" :checked="modelValue.includes(group.id)" @change="toggle(group.id, ($event.target as HTMLInputElement).checked)" />
|
||||
<span><strong>{{ group.sourceLabel || '默认分组' }}</strong><small>{{ group.provider }} · {{ group.mode }}</small><code>{{ group.id }}</code></span>
|
||||
</label>
|
||||
<p v-if="!selectedModel">尚未选择模型</p>
|
||||
<p v-else-if="!visibleGroups.length">该模型暂无可用分组</p>
|
||||
</fieldset>
|
||||
<fieldset v-if="unavailable.length" :disabled="disabled"><legend>暂不可用的既有授权</legend>
|
||||
<label v-for="id in unavailable" :key="id" class="group-option"><input type="checkbox" checked @change="toggle(id, false)" /><code>{{ id }}</code></label>
|
||||
</fieldset>
|
||||
<footer><span>已选 {{ modelValue.length }} 个分组</span><button class="text-link" :disabled="disabled || !modelValue.length" @click="emit('update:modelValue', [])">清空授权</button></footer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.group-permissions { display: grid; gap: 12px; min-width: 0; }
|
||||
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
|
||||
legend { margin-bottom: 8px; font-weight: 600; font-size: 13px; }
|
||||
.group-option { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid #e5e7eb; padding: 12px 0; cursor: pointer; }
|
||||
.group-option span { display: grid; gap: 5px; min-width: 0; }
|
||||
.group-option small, p { color: #6b7280; font-size: 12px; }
|
||||
code { font-size: 11px; overflow-wrap: anywhere; }
|
||||
footer { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
|
||||
</style>
|
||||
@@ -8,7 +8,7 @@ defineEmits<{ close: [] }>()
|
||||
<template>
|
||||
<div class="slide-overlay" @click="$emit('close')"></div>
|
||||
<aside class="slide-panel">
|
||||
<header><div><span>{{ eyebrow ?? 'DETAILS' }}</span><h2>{{ title }}</h2></div><button class="icon-button" @click="$emit('close')"><X :size="18" /></button></header>
|
||||
<header><div><span>{{ eyebrow ?? 'DETAILS' }}</span><h2>{{ title }}</h2></div><button class="icon-button" aria-label="关闭详情" title="关闭" @click="$emit('close')"><X :size="18" /></button></header>
|
||||
<div class="slide-content"><slot /></div>
|
||||
<footer><slot name="footer" /></footer>
|
||||
</aside>
|
||||
|
||||
@@ -7,8 +7,8 @@ defineEmits<{ close: [] }>()
|
||||
|
||||
<template>
|
||||
<div class="modal-overlay" @click.self="$emit('close')">
|
||||
<section class="modal">
|
||||
<header><div><span>{{ eyebrow ?? 'MOYI CONSOLE' }}</span><h2>{{ title }}</h2></div><button class="icon-button" @click="$emit('close')"><X :size="18" /></button></header>
|
||||
<section class="modal" role="dialog" aria-modal="true" :aria-label="title">
|
||||
<header><div><span>{{ eyebrow ?? 'MOYI CONSOLE' }}</span><h2>{{ title }}</h2></div><button class="icon-button" aria-label="关闭弹窗" title="关闭" @click="$emit('close')"><X :size="18" /></button></header>
|
||||
<div class="modal-body"><slot /></div>
|
||||
<footer><slot name="footer" /></footer>
|
||||
</section>
|
||||
|
||||
@@ -46,8 +46,8 @@ export const adminNavigation: NavGroup[] = [
|
||||
label: '资源运营',
|
||||
items: [
|
||||
{ id: 'admin-users', label: '用户与额度', icon: Users },
|
||||
{ id: 'admin-models', label: '模型与供应商', icon: Boxes },
|
||||
{ id: 'admin-routing', label: '渠道与路由', icon: Network },
|
||||
{ id: 'admin-models', label: '模型与分组', icon: Boxes },
|
||||
{ id: 'admin-routing', label: '渠道管理', icon: Network },
|
||||
{ id: 'admin-capacity', label: '并发与队列', icon: Gauge },
|
||||
{ id: 'admin-billing', label: '计费配置', icon: CircleDollarSign },
|
||||
{ id: 'admin-usage', label: '模型调用记录', icon: ScrollText },
|
||||
|
||||
@@ -13,6 +13,7 @@ export interface AuthUser {
|
||||
|
||||
export interface RegisterInput {
|
||||
invitationCode: string
|
||||
verificationCode: string
|
||||
account: string
|
||||
password: string
|
||||
displayName?: string
|
||||
@@ -24,6 +25,8 @@ export interface LoginInput {
|
||||
}
|
||||
|
||||
export interface AuthClient {
|
||||
verificationChannels(): Promise<{ email: boolean; phone: boolean }>
|
||||
sendVerificationCode(account: string, invitationCode: string): Promise<{ retryAfterSeconds: number }>
|
||||
health(): Promise<{ status: 'ok'; service: string; capabilities: { verificationCode: boolean; passwordReset: boolean } }>
|
||||
login(input: LoginInput): Promise<AuthUser>
|
||||
register(input: RegisterInput): Promise<AuthUser>
|
||||
@@ -34,6 +37,16 @@ export interface AuthClient {
|
||||
class HttpAuthClient implements AuthClient {
|
||||
constructor(private readonly baseUrl: string) {}
|
||||
|
||||
verificationChannels() {
|
||||
return this.request<{ email: boolean; phone: boolean }>('/api/auth/verification')
|
||||
}
|
||||
|
||||
sendVerificationCode(account: string, invitationCode: string) {
|
||||
return this.request<{ retryAfterSeconds: number }>('/api/auth/verification', {
|
||||
method: 'POST', body: JSON.stringify({ account, invitationCode }),
|
||||
})
|
||||
}
|
||||
|
||||
async health() {
|
||||
return this.request<{ status: 'ok'; service: string; capabilities: { verificationCode: boolean; passwordReset: boolean } }>('/health')
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ export interface CatalogProvider {
|
||||
|
||||
export interface CatalogModel {
|
||||
id: string
|
||||
logicalModelId: string
|
||||
providerId: string
|
||||
modelKey?: string
|
||||
sourceLabel?: string
|
||||
@@ -33,6 +34,28 @@ export interface CatalogModel {
|
||||
status: 'active' | 'disabled'
|
||||
}
|
||||
|
||||
export interface LogicalModel {
|
||||
id: string
|
||||
publicName: string
|
||||
modelKey?: string
|
||||
type: CatalogModelType
|
||||
mode: CatalogCallMode
|
||||
description: string
|
||||
inputTypes: string[]
|
||||
outputTypes: string[]
|
||||
status: 'active' | 'disabled'
|
||||
}
|
||||
|
||||
export interface WalletEntry {
|
||||
id: string
|
||||
amount: number
|
||||
balanceAfter: number
|
||||
currency: 'CNY'
|
||||
reason: string
|
||||
createdAt: string
|
||||
actor: string
|
||||
}
|
||||
|
||||
export interface CatalogProject {
|
||||
id: string
|
||||
ownerUserId: string
|
||||
@@ -180,7 +203,7 @@ class HttpCatalogClient {
|
||||
constructor(private readonly baseUrl: string) {}
|
||||
|
||||
async listModels() {
|
||||
return this.request<{ providers: CatalogProvider[]; models: CatalogModel[] }>('/api/models')
|
||||
return this.request<{ providers: CatalogProvider[]; models: CatalogModel[]; logicalModels: LogicalModel[] }>('/api/models')
|
||||
}
|
||||
|
||||
async listProjects() {
|
||||
@@ -251,7 +274,7 @@ class HttpCatalogClient {
|
||||
}
|
||||
|
||||
async listAdminModels() {
|
||||
return this.request<{ models: CatalogModel[] }>('/api/admin/models')
|
||||
return this.request<{ models: CatalogModel[]; logicalModels: LogicalModel[] }>('/api/admin/models')
|
||||
}
|
||||
|
||||
async listAdminUsage(filters: { q?: string; keyId?: string; modelId?: string; status?: string; eventKind?: string; page?: number; size?: number } = {}) {
|
||||
@@ -286,6 +309,22 @@ class HttpCatalogClient {
|
||||
return this.request<{ users: AdminCatalogUser[] }>('/api/admin/users')
|
||||
}
|
||||
|
||||
async createAdminUser(input: { account: string; displayName: string; password: string }) {
|
||||
return this.request<{ user: AdminCatalogUser }>('/api/admin/users', { method: 'POST', body: JSON.stringify(input) })
|
||||
}
|
||||
|
||||
async listWallets() {
|
||||
return this.request<{ wallets: Array<{ userId: string; balance: number }> }>('/api/admin/wallets')
|
||||
}
|
||||
|
||||
async walletEntries(userId: string) {
|
||||
return this.request<{ entries: WalletEntry[] }>(`/api/admin/users/${encodeURIComponent(userId)}/wallet`)
|
||||
}
|
||||
|
||||
async grantCredit(userId: string, input: { requestId: string; amount: string; reason: string }) {
|
||||
return this.request<{ id: string; balance: number; currency: 'CNY' }>(`/api/admin/users/${encodeURIComponent(userId)}/wallet/grants`, { method: 'POST', body: JSON.stringify(input) })
|
||||
}
|
||||
|
||||
async changeUserRole(id: string, role: 'user' | 'admin') {
|
||||
return this.request<{ user: AdminCatalogUser }>(`/api/admin/users/${encodeURIComponent(id)}/role`, {
|
||||
method: 'POST', body: JSON.stringify({ role }),
|
||||
@@ -312,6 +351,18 @@ class HttpCatalogClient {
|
||||
return this.request<{ provider: CatalogProvider }>('/api/admin/providers', { method: 'POST', body: JSON.stringify(input) })
|
||||
}
|
||||
|
||||
async updateAdminProvider(id: string, input: Partial<CatalogProvider> & { credentialSecret?: string }) {
|
||||
return this.request<{ provider: CatalogProvider }>(`/api/admin/providers/${encodeURIComponent(id)}`, { method: 'PATCH', body: JSON.stringify(input) })
|
||||
}
|
||||
|
||||
async saveDefinition(id: string | undefined, input: Partial<LogicalModel>) {
|
||||
return this.request<{ model: LogicalModel }>(`/api/admin/model-definitions${id ? `/${encodeURIComponent(id)}` : ''}`, { method: id ? 'PATCH' : 'POST', body: JSON.stringify(input) })
|
||||
}
|
||||
|
||||
async saveGroup(id: string | undefined, input: Partial<CatalogModel>) {
|
||||
return this.request<{ model: CatalogModel }>(`/api/admin/models${id ? `/${encodeURIComponent(id)}` : ''}`, { method: id ? 'PATCH' : 'POST', body: JSON.stringify(input) })
|
||||
}
|
||||
|
||||
async createAdminModel(input: { providerId: string; publicName: string; upstreamModel: string; modelKey?: string; sourceLabel?: string; type: CatalogModelType; mode: CatalogCallMode; description?: string; inputTypes?: string[]; outputTypes?: string[]; pricing?: { input?: number; output?: number; unit?: string }; priority?: number; maxConcurrency?: number }) {
|
||||
return this.request<{ model: CatalogModel }>('/api/admin/models', { method: 'POST', body: JSON.stringify(input) })
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ export interface NavGroup {
|
||||
}
|
||||
|
||||
export interface ModelItem {
|
||||
logicalModelId?: string
|
||||
id: string
|
||||
name: string
|
||||
provider: string
|
||||
|
||||
@@ -31,12 +31,13 @@ import {
|
||||
Users,
|
||||
WalletCards,
|
||||
} from 'lucide-vue-next'
|
||||
import type { AdminUser, ModelItem, ProviderItem, RouteItem } from '../types'
|
||||
import type { AdminUser, ModelItem, ProviderItem } from '../types'
|
||||
import { catalogClient, type AdminAuditEvent, type CatalogModel, type CatalogProvider, type UsageAuditRecord } from '../services/catalog'
|
||||
import { copyText } from '../services/clipboard'
|
||||
import type { AuthUser } from '../services/auth'
|
||||
import SlidePanel from '../components/SlidePanel.vue'
|
||||
import UiModal from '../components/UiModal.vue'
|
||||
import CatalogAdmin from '../components/CatalogAdmin.vue'
|
||||
import AccountAdmin from '../components/AccountAdmin.vue'
|
||||
|
||||
const props = defineProps<{ view: string; currentUser?: AuthUser }>()
|
||||
const emit = defineEmits<{ navigate: [view: string]; notify: [message: string] }>()
|
||||
@@ -44,43 +45,7 @@ const emit = defineEmits<{ navigate: [view: string]; notify: [message: string] }
|
||||
const users = ref<AdminUser[]>([])
|
||||
const providers = ref<ProviderItem[]>([])
|
||||
const models = ref<ModelItem[]>([])
|
||||
const routes = ref<RouteItem[]>([])
|
||||
const catalogConnected = ref(false)
|
||||
const userQuery = ref('')
|
||||
const userStatus = ref('全部')
|
||||
const selectedUser = ref<AdminUser | null>(null)
|
||||
const roleTarget = ref<AdminUser | null>(null)
|
||||
const roleChoice = ref<'user' | 'admin'>('user')
|
||||
const savingRole = ref(false)
|
||||
const canEditRole = computed(() => props.currentUser?.role === 'super_admin' && selectedUser.value?.roleCode !== 'super_admin' && selectedUser.value?.id !== props.currentUser.id)
|
||||
const invitationOpen = ref(false)
|
||||
const inviteLabel = ref('')
|
||||
const createdInviteCode = ref('')
|
||||
const providerOpen = ref(false)
|
||||
const providerCode = ref('')
|
||||
const providerName = ref('')
|
||||
const providerProtocol = ref<CatalogProvider['protocol']>('http')
|
||||
const providerSourceType = ref<CatalogProvider['sourceType']>('official')
|
||||
const providerBaseUrl = ref('')
|
||||
const providerCredentialType = ref<NonNullable<CatalogProvider['credentialType']>>('none')
|
||||
const providerCredentialSecret = ref('')
|
||||
const providerDescription = ref('')
|
||||
const modelOpen = ref(false)
|
||||
const modelProviderId = ref('')
|
||||
const modelPublicName = ref('')
|
||||
const modelUpstreamModel = ref('')
|
||||
const modelKey = ref('')
|
||||
const modelSourceLabel = ref('')
|
||||
const modelType = ref<CatalogModel['type']>('multimodal')
|
||||
const modelMode = ref<CatalogModel['mode']>('sync')
|
||||
const modelDescription = ref('')
|
||||
const modelInputTypes = ref('text')
|
||||
const modelOutputTypes = ref('text')
|
||||
const modelInputPrice = ref('')
|
||||
const modelOutputPrice = ref('')
|
||||
const modelPriceUnit = ref('1K tokens')
|
||||
const modelPriority = ref('100')
|
||||
const modelMaxConcurrency = ref('')
|
||||
const auditQuery = ref('')
|
||||
const usageRecords = ref<UsageAuditRecord[]>([])
|
||||
const usageQuery = ref('')
|
||||
@@ -181,11 +146,6 @@ function formatUsagePayload(value: unknown) {
|
||||
try { return JSON.stringify(value, null, 2) } catch { return String(value) }
|
||||
}
|
||||
|
||||
const filteredUsers = computed(() => {
|
||||
const query = userQuery.value.trim().toLowerCase()
|
||||
return users.value.filter((user) => (userStatus.value === '全部' || user.status === userStatus.value) && (!query || `${user.name} ${user.email} ${user.id}`.toLowerCase().includes(query)))
|
||||
})
|
||||
|
||||
const queueGroups: Array<{ name: string; type: string; running: number; limit: number; queued: number; wait: string; status: string }> = []
|
||||
const pricing: Array<{ model: string; unit: string; base: string; output: string; rule: string; status: string }> = []
|
||||
const auditEvents = ref<Array<{ time: string; actor: string; action: string; target: string; source: string; level: string }>>([])
|
||||
@@ -194,134 +154,14 @@ const filteredAudits = computed(() => {
|
||||
return query ? auditEvents.value.filter((event) => `${event.actor} ${event.action} ${event.target}`.toLowerCase().includes(query)) : auditEvents.value
|
||||
})
|
||||
|
||||
async function createInvitation() {
|
||||
if (!catalogConnected.value) return emit('notify', 'Control Plane 未连接,无法创建真实邀请码')
|
||||
try {
|
||||
const result = await catalogClient.createAdminInvitation({ label: inviteLabel.value.trim() || undefined, maxUses: 1 })
|
||||
createdInviteCode.value = result.code
|
||||
inviteLabel.value = ''
|
||||
invitationOpen.value = false
|
||||
emit('notify', '邀请码已创建,请在弹窗中安全保存完整代码')
|
||||
} catch (error) {
|
||||
emit('notify', error instanceof Error ? error.message : '创建邀请码失败')
|
||||
}
|
||||
}
|
||||
|
||||
function openCredit(user?: AdminUser) {
|
||||
if (user) selectedUser.value = user
|
||||
emit('notify', '额度账本接口尚未接入,当前不会伪造发放结果')
|
||||
}
|
||||
|
||||
async function copyUserId(id: string) {
|
||||
const result = await copyText(id)
|
||||
emit('notify', result === 'failed' ? '用户 ID 复制失败,请手动复制' : result === 'verified' ? '用户 ID 已复制并校验' : '用户 ID 已写入剪贴板')
|
||||
}
|
||||
|
||||
function mapUser(user: { id: string; account: string; displayName: string; role: 'user' | 'admin' | 'super_admin'; status: 'active' | 'disabled'; lastLoginAt?: string }): AdminUser {
|
||||
return { id: user.id, name: user.displayName, email: user.account, role: user.role === 'super_admin' ? '超级管理员' : user.role === 'admin' ? '平台管理员' : '普通用户', roleCode: user.role, status: user.status === 'active' ? '正常' : '已停用' }
|
||||
}
|
||||
|
||||
function openRoleEditor() {
|
||||
if (!selectedUser.value || !canEditRole.value) return
|
||||
roleTarget.value = selectedUser.value
|
||||
roleChoice.value = selectedUser.value.roleCode === 'admin' ? 'admin' : 'user'
|
||||
selectedUser.value = null
|
||||
}
|
||||
|
||||
async function saveRole() {
|
||||
if (!roleTarget.value || savingRole.value) return
|
||||
savingRole.value = true
|
||||
try {
|
||||
const result = await catalogClient.changeUserRole(roleTarget.value.id, roleChoice.value)
|
||||
const updated = mapUser(result.user)
|
||||
users.value = users.value.map((user) => user.id === updated.id ? updated : user)
|
||||
roleTarget.value = null
|
||||
selectedUser.value = updated
|
||||
emit('notify', '用户角色已更新')
|
||||
} catch (error) {
|
||||
emit('notify', error instanceof Error ? error.message : '角色更新失败')
|
||||
} finally {
|
||||
savingRole.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function mapAudit(event: AdminAuditEvent) {
|
||||
return { time: new Date(event.createdAt).toLocaleString('zh-CN'), actor: event.actorUserId || '系统', action: event.eventType, target: event.targetId || event.targetType || '--', source: event.ipAddress || '--', level: event.eventType.includes('failed') ? '风险' : '普通' }
|
||||
}
|
||||
|
||||
async function addProvider() {
|
||||
providerCode.value = ''
|
||||
providerName.value = ''
|
||||
providerProtocol.value = 'http'
|
||||
providerSourceType.value = 'official'
|
||||
providerBaseUrl.value = ''
|
||||
providerCredentialType.value = 'none'
|
||||
providerCredentialSecret.value = ''
|
||||
providerDescription.value = ''
|
||||
providerOpen.value = true
|
||||
}
|
||||
|
||||
async function createProvider() {
|
||||
const code = providerCode.value.trim()
|
||||
const name = providerName.value.trim()
|
||||
if (!code || !name) return emit('notify', '请填写供应商 code 和名称')
|
||||
if (!catalogConnected.value) return emit('notify', 'Control Plane 未连接,无法保存供应商')
|
||||
try {
|
||||
await catalogClient.createAdminProvider({ code, name, protocol: providerProtocol.value, sourceType: providerSourceType.value, baseUrl: providerBaseUrl.value.trim() || undefined, credentialType: providerCredentialType.value, credentialSecret: providerCredentialSecret.value.trim() || undefined, description: providerDescription.value.trim() || undefined })
|
||||
const result = await catalogClient.listAdminProviders()
|
||||
const modelsResult = await catalogClient.listAdminModels()
|
||||
providers.value = mapProviders(result.providers, modelsResult.models)
|
||||
providerOpen.value = false
|
||||
emit('notify', '供应商已登记')
|
||||
} catch (error) {
|
||||
emit('notify', error instanceof Error ? error.message : '登记供应商失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function addModel() {
|
||||
if (!catalogConnected.value) return emit('notify', 'Control Plane 未连接,无法保存模型')
|
||||
const provider = providers.value[0]
|
||||
if (!provider) return emit('notify', '请先登记供应商')
|
||||
modelProviderId.value = provider.id
|
||||
modelPublicName.value = ''
|
||||
modelUpstreamModel.value = ''
|
||||
modelKey.value = ''
|
||||
modelSourceLabel.value = ''
|
||||
modelType.value = 'multimodal'
|
||||
modelMode.value = 'sync'
|
||||
modelDescription.value = ''
|
||||
modelInputTypes.value = 'text'
|
||||
modelOutputTypes.value = 'text'
|
||||
modelInputPrice.value = ''
|
||||
modelOutputPrice.value = ''
|
||||
modelPriceUnit.value = '1K tokens'
|
||||
modelPriority.value = '100'
|
||||
modelMaxConcurrency.value = ''
|
||||
modelOpen.value = true
|
||||
}
|
||||
|
||||
async function createModel() {
|
||||
const publicName = modelPublicName.value.trim()
|
||||
const upstreamModel = modelUpstreamModel.value.trim()
|
||||
if (!publicName || !upstreamModel) return emit('notify', '请填写统一模型名称和上游模型标识')
|
||||
if (!catalogConnected.value) return emit('notify', 'Control Plane 未连接,无法保存模型')
|
||||
try {
|
||||
const inputPrice = modelInputPrice.value.trim() ? Number(modelInputPrice.value) : undefined
|
||||
const outputPrice = modelOutputPrice.value.trim() ? Number(modelOutputPrice.value) : undefined
|
||||
const priority = Number(modelPriority.value)
|
||||
const maxConcurrency = modelMaxConcurrency.value.trim() ? Number(modelMaxConcurrency.value) : undefined
|
||||
if ([inputPrice, outputPrice, priority, maxConcurrency].some((value) => value !== undefined && !Number.isFinite(value))) return emit('notify', '价格、优先级和并发数必须是有效数字')
|
||||
await catalogClient.createAdminModel({ providerId: modelProviderId.value, publicName, upstreamModel, modelKey: modelKey.value.trim() || undefined, sourceLabel: modelSourceLabel.value.trim() || undefined, type: modelType.value, mode: modelMode.value, inputTypes: modelInputTypes.value.split(',').map((value) => value.trim()).filter(Boolean), outputTypes: modelOutputTypes.value.split(',').map((value) => value.trim()).filter(Boolean), description: modelDescription.value.trim() || undefined, pricing: inputPrice !== undefined || outputPrice !== undefined ? { ...(inputPrice !== undefined ? { input: inputPrice } : {}), ...(outputPrice !== undefined ? { output: outputPrice } : {}), unit: modelPriceUnit.value } : undefined, priority, maxConcurrency })
|
||||
const [providerResult, modelResult] = await Promise.all([catalogClient.listAdminProviders(), catalogClient.listAdminModels()])
|
||||
providers.value = mapProviders(providerResult.providers, modelResult.models)
|
||||
models.value = mapModels(modelResult.models, providerResult.providers)
|
||||
modelOpen.value = false
|
||||
emit('notify', '模型已加入统一目录')
|
||||
} catch (error) {
|
||||
emit('notify', error instanceof Error ? error.message : '登记模型失败')
|
||||
}
|
||||
}
|
||||
|
||||
function mapProviders(items: CatalogProvider[], modelItems: CatalogModel[]): ProviderItem[] {
|
||||
return items.map((provider) => ({
|
||||
id: provider.id,
|
||||
@@ -372,29 +212,12 @@ function mapModels(items: CatalogModel[], providersList: CatalogProvider[]): Mod
|
||||
<template v-if="view === 'admin-overview'">
|
||||
<section class="page-heading compact"><div><span>ADMIN OVERVIEW</span><h1>管理总览</h1><p>掌握平台供给、用户、容量和风险状态。</p></div><div class="heading-actions"><span class="health-badge"><i></i>核心服务正常</span><button class="button secondary" @click="emit('notify', '数据已刷新')"><Activity :size="16" />刷新数据</button></div></section>
|
||||
<section class="metric-grid"><article class="metric-card"><span class="icon-tile violet"><Users :size="18" /></span><div><small>用户总数</small><strong>{{ users.length }}</strong><em>来自认证服务</em></div></article><article class="metric-card"><span class="icon-tile cyan"><Cloud :size="18" /></span><div><small>在线模型</small><strong>{{ models.length }}</strong><em>{{ providers.length }} 个供应商</em></div></article><article class="metric-card"><span class="icon-tile orange"><Gauge :size="18" /></span><div><small>等待任务</small><strong>--</strong><em>容量监控尚未接入</em></div></article><article class="metric-card"><span class="icon-tile green"><CircleDollarSign :size="18" /></span><div><small>今日额度消耗</small><strong>--</strong><em>计费账本尚未接入</em></div></article></section>
|
||||
<section class="two-column equal"><article class="panel chart-panel"><header class="panel-header"><div><span>PLATFORM TRAFFIC</span><h3>平台请求趋势</h3></div><span class="select-button static">最近 7 天</span></header><div class="empty-state compact"><BarChart3 :size="22" /><strong>暂无平台流量数据</strong><span>接入调用记录后会在这里形成趋势</span></div></article><article class="panel health-panel"><header class="panel-header"><div><span>GATEWAY HEALTH</span><h3>模型供给状态</h3></div><button class="text-link" @click="emit('navigate', 'admin-models')">管理供应商<ArrowRight :size="14" /></button></header><div v-if="providers.length" class="health-list"><div v-for="provider in providers.slice(0, 3)" :key="provider.id"><span class="provider-mark">{{ provider.name.slice(0, 1) }}</span><p><strong>{{ provider.name }}</strong><small>{{ provider.capability }} · {{ provider.latency }}</small></p><b>{{ provider.successRate }}</b><span class="status-chip" :class="provider.status === '健康' ? 'success' : 'warning'"><i></i>{{ provider.status }}</span></div></div><div v-else class="empty-state compact"><Cloud :size="22" /><strong>暂无供应商</strong><span>由管理员登记上游渠道后显示</span></div></article></section>
|
||||
<section class="two-column narrow-left"><article class="panel quick-credit"><header class="panel-header"><div><span>CREDIT OPERATIONS</span><h3>额度分配</h3></div><ShieldCheck :size="18" /></header><p>额度账本接口尚未接入,当前仅保留操作入口和审计位置。</p><button class="button primary full" @click="emit('navigate', 'admin-users')"><Users :size="16" />查看用户</button></article><article class="panel activity-panel"><header class="panel-header"><div><span>RECENT EVENTS</span><h3>最近运营事件</h3></div><button class="text-link" @click="emit('navigate', 'admin-audit')">审计日志<ArrowRight :size="14" /></button></header><div v-if="auditEvents.length" class="activity-list"><div v-for="event in auditEvents.slice(0, 3)" :key="`${event.time}-${event.action}`"><span class="activity-dot cyan"><ShieldCheck :size="14" /></span><p><strong>{{ event.action }}</strong><small>{{ event.actor }} · {{ event.target }}</small></p><time>{{ event.time }}</time></div></div><div v-else class="empty-state compact"><ShieldCheck :size="22" /><strong>暂无运营事件</strong><span>真实管理操作发生后会显示审计记录</span></div></article></section>
|
||||
<section class="two-column equal"><article class="panel chart-panel"><header class="panel-header"><div><span>PLATFORM TRAFFIC</span><h3>平台请求趋势</h3></div><span class="select-button static">最近 7 天</span></header><div class="empty-state compact"><BarChart3 :size="22" /><strong>暂无平台流量数据</strong><span>接入调用记录后会在这里形成趋势</span></div></article><article class="panel health-panel"><header class="panel-header"><div><span>GATEWAY HEALTH</span><h3>模型供给状态</h3></div><button class="text-link" @click="emit('navigate', 'admin-routing')">管理渠道<ArrowRight :size="14" /></button></header><div v-if="providers.length" class="health-list"><div v-for="provider in providers.slice(0, 3)" :key="provider.id"><span class="provider-mark">{{ provider.name.slice(0, 1) }}</span><p><strong>{{ provider.name }}</strong><small>{{ provider.capability }} · {{ provider.latency }}</small></p><b>{{ provider.successRate }}</b><span class="status-chip" :class="provider.status === '健康' ? 'success' : 'warning'"><i></i>{{ provider.status }}</span></div></div><div v-else class="empty-state compact"><Cloud :size="22" /><strong>暂无供应商</strong><span>由管理员登记上游渠道后显示</span></div></article></section>
|
||||
<section class="two-column narrow-left"><article class="panel quick-credit"><header class="panel-header"><div><span>CREDIT OPERATIONS</span><h3>额度分配</h3></div><ShieldCheck :size="18" /></header><p>人民币额度余额与发放流水</p><button class="button primary full" @click="emit('navigate', 'admin-users')"><Users :size="16" />查看用户</button></article><article class="panel activity-panel"><header class="panel-header"><div><span>RECENT EVENTS</span><h3>最近运营事件</h3></div><button class="text-link" @click="emit('navigate', 'admin-audit')">审计日志<ArrowRight :size="14" /></button></header><div v-if="auditEvents.length" class="activity-list"><div v-for="event in auditEvents.slice(0, 3)" :key="`${event.time}-${event.action}`"><span class="activity-dot cyan"><ShieldCheck :size="14" /></span><p><strong>{{ event.action }}</strong><small>{{ event.actor }} · {{ event.target }}</small></p><time>{{ event.time }}</time></div></div><div v-else class="empty-state compact"><ShieldCheck :size="22" /><strong>暂无运营事件</strong><span>真实管理操作发生后会显示审计记录</span></div></article></section>
|
||||
</template>
|
||||
|
||||
<template v-else-if="view === 'admin-users'">
|
||||
<section class="page-heading"><div><span>USERS & CREDITS</span><h1>用户与额度</h1><p>管理邀请、账号状态、角色和内测额度。</p></div><button class="button primary" @click="invitationOpen = true"><Plus :size="16" />创建邀请</button></section>
|
||||
<section class="metric-grid"><article class="metric-card"><span class="icon-tile violet"><Users :size="18" /></span><div><small>用户总数</small><strong>{{ users.length }}</strong><em>来自认证服务</em></div></article><article class="metric-card"><span class="icon-tile cyan"><CheckCircle2 :size="18" /></span><div><small>正常用户</small><strong>{{ users.filter((user) => user.status === '正常').length }}</strong><em>按账号状态统计</em></div></article><article class="metric-card"><span class="icon-tile orange"><CircleDollarSign :size="18" /></span><div><small>已发放额度</small><strong>--</strong><em>额度账本尚未接入</em></div></article><article class="metric-card"><span class="icon-tile green"><Activity :size="18" /></span><div><small>今日活跃</small><strong>--</strong><em>活跃统计尚未接入</em></div></article></section>
|
||||
<section class="panel table-card"><header class="panel-header table-toolbar"><div><span>USER DIRECTORY</span><h3>用户列表</h3></div><div class="toolbar-controls"><label class="search-input"><Search :size="16" /><input v-model="userQuery" placeholder="搜索姓名、邮箱或 ID" /></label><div class="tabs compact"><button v-for="status in ['全部','正常','待激活','已停用']" :key="status" :class="{ active: userStatus === status }" @click="userStatus = status">{{ status }}</button></div></div></header><div class="responsive-table"><table class="user-table"><thead><tr><th>用户</th><th>角色</th><th>额度余额</th><th>累计用量</th><th>最近活跃</th><th>状态</th></tr></thead><tbody><tr v-for="user in filteredUsers" :key="user.id" class="clickable" @click="selectedUser = user"><td><div class="entity-cell"><span class="avatar-small">{{ user.name.slice(0, 1) }}</span><div><strong>{{ user.name }}</strong><small>{{ user.email }} · {{ user.id }}</small></div></div></td><td><span class="role-tag">{{ user.role }}</span></td><td><strong class="mono">{{ user.balance === undefined ? '--' : `¥ ${user.balance.toFixed(2)}` }}</strong></td><td>{{ user.usage || '--' }}</td><td>{{ user.lastActive || '--' }}</td><td><span class="status-chip" :class="user.status === '正常' ? 'success' : user.status === '待激活' ? 'queued' : 'muted'"><i></i>{{ user.status }}</span></td></tr><tr v-if="!filteredUsers.length"><td colspan="6"><div class="empty-state compact"><Users :size="22" /><strong>暂无用户</strong><span>注册或邀请用户后会显示在这里</span></div></td></tr></tbody></table></div></section>
|
||||
</template>
|
||||
|
||||
<template v-else-if="view === 'admin-models'">
|
||||
<section class="page-heading"><div><span>MODELS & PROVIDERS</span><h1>模型与供应商</h1><p>配置统一模型目录、能力信息和上游渠道。</p></div><div class="heading-actions"><span class="admin-badge">{{ catalogConnected ? 'Control Plane 已连接' : 'Control Plane 未连接' }}</span><button class="button secondary" @click="addProvider"><Plus :size="16" />登记供应商</button><button class="button primary" @click="addModel"><Plus :size="16" />添加模型</button></div></section>
|
||||
<section class="notice"><Cloud :size="19" /><div><strong>模型目录与上游渠道解耦</strong><p>用户只看到统一模型名称,供应商密钥、实际渠道和故障转移策略仅在管理端可见。</p></div></section>
|
||||
<section class="panel table-card"><header class="panel-header"><div><span>PROVIDERS & CHANNELS</span><h3>供应商与渠道来源</h3></div><small>{{ providers.length }} 个来源 · 供应商密钥仅服务端保存</small></header><div class="responsive-table"><table><thead><tr><th>供应商 / 来源</th><th>类型</th><th>接入方式</th><th>服务地址</th><th>模型数</th><th>凭据</th><th>状态</th><th>启用</th></tr></thead><tbody><tr v-for="provider in providers" :key="provider.id"><td><div class="entity-cell"><span class="provider-mark">{{ provider.name.slice(0, 1) }}</span><div><strong>{{ provider.name }}</strong><div class="provider-meta"><span>{{ provider.code || provider.id }}</span><span v-if="provider.description">{{ provider.description }}</span></div></div></div></td><td><span class="provider-source-tag" :class="provider.sourceType">{{ provider.sourceType === 'official' ? '官方供应商' : provider.sourceType === 'relay' ? '中转站 / 渠道' : provider.sourceType === 'self-hosted' ? '自托管' : '自定义来源' }}</span></td><td>{{ provider.protocol === 'openai-compatible' ? 'OpenAI 兼容' : provider.protocol === 'sdk' ? 'SDK' : 'HTTP' }}</td><td><code class="provider-endpoint">{{ provider.baseUrl || '待配置' }}</code></td><td>{{ provider.models }}</td><td><span class="provider-credential">{{ provider.credentialType && provider.credentialType !== 'none' ? (provider.credentialMasked || '已配置') : '未配置' }}</span></td><td><span class="status-chip" :class="provider.status === '健康' ? 'success' : provider.status === '波动' ? 'warning' : 'muted'"><i></i>{{ provider.status }}</span></td><td><button class="switch" :class="{ active: provider.enabled }" @click="provider.enabled = !provider.enabled; emit('notify', `${provider.name} 已${provider.enabled ? '启用' : '停用'}`)"><span></span></button></td></tr></tbody></table></div></section>
|
||||
<section class="section-title"><div><span>MODEL DIRECTORY</span><h2>统一模型目录</h2></div><button class="text-link" @click="emit('notify', '能力 Schema 文档将在详细设计阶段开放')">能力 Schema<ArrowRight :size="14" /></button></section>
|
||||
<section class="admin-model-grid"><article v-for="model in models" :key="model.id"><div><span class="model-icon" :class="model.accent"><component :is="model.icon" :size="20" /></span><span class="status-chip success"><i></i>{{ model.availability }}</span></div><h3>{{ model.name }}</h3><p>{{ model.description || '暂无描述,建议补充能力与输入输出说明。' }}</p><div class="model-source-line"><span>来源:{{ model.provider }}</span><span v-if="model.sourceLabel">· {{ model.sourceLabel }}</span></div><div class="model-route-meta"><span>统一标识 <strong>{{ model.modelKey || model.id }}</strong></span><span>优先级 <strong>{{ model.priority ?? '—' }}</strong></span><span>并发 <strong>{{ model.maxConcurrency ?? '不限' }}</strong></span><span v-if="model.pricing">价格 <strong>{{ model.pricing.input ?? '—' }} / {{ model.pricing.output ?? '—' }}</strong> {{ model.pricing.unit || '' }}</span></div><footer><span>{{ model.type }}</span><span>{{ model.mode }}</span><span>{{ model.availability }}</span></footer></article><div v-if="!models.length" class="empty-state"><Boxes :size="24" /><strong>暂无模型</strong><span>添加模型目录项后会显示在这里</span></div></section>
|
||||
</template>
|
||||
|
||||
<template v-else-if="view === 'admin-routing'">
|
||||
<section class="page-heading"><div><span>CHANNEL ROUTING</span><h1>渠道与路由</h1><p>管理渠道优先级、故障转移和模型映射。</p></div><div class="heading-actions"><span class="health-badge offline"><i></i>路由监控未接入</span><button class="button secondary" @click="emit('notify', '路由模拟器将在真实策略接入后开放')"><SlidersHorizontal :size="16" />模拟路由</button></div></section>
|
||||
<section class="routing-hero"><span class="icon-tile light"><Network :size="22" /></span><div><small>SMART ROUTING</small><h2>按质量、速度、价格和可用性分配请求</h2><p>路由策略将在配置真实供应商后启用。</p></div><div><strong>--</strong><span>路由成功率</span></div></section>
|
||||
<section class="panel table-card"><header class="panel-header"><div><span>ROUTING POLICIES</span><h3>模型到渠道映射</h3></div><button class="text-link" @click="emit('notify', '批量编辑将在真实策略接入后开放')">批量编辑<ArrowRight :size="14" /></button></header><div class="responsive-table"><table class="routing-table"><thead><tr><th>模型</th><th>能力</th><th>主渠道</th><th>备用渠道</th><th>策略</th><th>健康</th><th>状态</th></tr></thead><tbody><tr v-for="route in routes" :key="route.id"><td><div class="stacked-cell"><strong>{{ route.model }}</strong><small>{{ route.id }}</small></div></td><td>{{ route.capability }}</td><td><strong>{{ route.primary }}</strong></td><td>{{ route.fallback }}</td><td><span class="role-tag">{{ route.policy }}</span></td><td><strong class="positive">{{ route.health }}</strong></td><td><button class="switch" disabled :class="{ active: route.enabled }" title="路由启停接口尚未接入"><span></span></button></td></tr><tr v-if="!routes.length"><td colspan="7"><div class="empty-state compact"><Network :size="22" /><strong>暂无路由策略</strong><span>配置模型与供应商后会显示映射关系</span></div></td></tr></tbody></table></div></section>
|
||||
</template>
|
||||
<AccountAdmin v-else-if="view === 'admin-users'" :current-user="props.currentUser" @notify="emit('notify', $event)" />
|
||||
<CatalogAdmin v-else-if="view === 'admin-models' || view === 'admin-routing'" :section="view === 'admin-routing' ? 'channels' : 'models'" @notify="emit('notify', $event)" />
|
||||
|
||||
<template v-else-if="view === 'admin-capacity'">
|
||||
<section class="page-heading"><div><span>CAPACITY CONTROL</span><h1>并发与队列</h1><p>查看实时并发、排队状态和容量保护。</p></div><div class="heading-actions"><span class="admin-badge"><ShieldCheck :size="15" />保护策略未配置</span><button class="button secondary" @click="emit('notify', '队列保护接口尚未接入')">配置保护策略</button></div></section>
|
||||
@@ -405,7 +228,7 @@ function mapModels(items: CatalogModel[], providersList: CatalogProvider[]): Mod
|
||||
<template v-else-if="view === 'admin-billing'">
|
||||
<section class="page-heading"><div><span>BILLING OPERATIONS</span><h1>计费配置</h1><p>维护模型计费单位、价格和扣费规则。</p></div><button class="button secondary" @click="emit('notify', '真实充值和订单流程将在商业规则确认后开放')"><WalletCards :size="16" />支付能力预留</button></section>
|
||||
<section class="notice warning-notice"><AlertTriangle :size="19" /><div><strong>当前仍采用管理员发放额度</strong><p>充值、订单和退款尚未启用。下面的价格目录只用于验证计费结构,不会产生真实支付。</p></div></section>
|
||||
<section class="metric-grid three"><article class="metric-card"><span class="icon-tile violet"><CircleDollarSign :size="18" /></span><div><small>本期额度发放</small><strong>--</strong><em>额度账本尚未接入</em></div></article><article class="metric-card"><span class="icon-tile cyan"><BarChart3 :size="18" /></span><div><small>本期实际消耗</small><strong>--</strong><em>计费规则尚未接入</em></div></article><article class="metric-card"><span class="icon-tile orange"><WalletCards :size="18" /></span><div><small>待对账流水</small><strong>--</strong><em>支付尚未开放</em></div></article></section>
|
||||
<section class="metric-grid three"><article class="metric-card"><span class="icon-tile violet"><CircleDollarSign :size="18" /></span><div><small>本期额度发放</small><strong>--</strong><em>见用户额度流水</em></div></article><article class="metric-card"><span class="icon-tile cyan"><BarChart3 :size="18" /></span><div><small>本期实际消耗</small><strong>--</strong><em>计费规则尚未接入</em></div></article><article class="metric-card"><span class="icon-tile orange"><WalletCards :size="18" /></span><div><small>待对账流水</small><strong>--</strong><em>支付尚未开放</em></div></article></section>
|
||||
<section class="panel table-card"><header class="panel-header"><div><span>PRICE CATALOG</span><h3>模型计费规则</h3></div><button class="button secondary small" @click="emit('notify', '计费规则接口尚未接入')"><Plus :size="15" />添加规则</button></header><div class="responsive-table"><table><thead><tr><th>模型</th><th>计费单位</th><th>输入 / 基础</th><th>输出 / 结果</th><th>扣费规则</th><th>状态</th></tr></thead><tbody><tr v-if="!pricing.length"><td colspan="6"><div class="empty-state compact"><CircleDollarSign :size="22" /><strong>暂无计费规则</strong><span>商业规则确认后由管理员配置</span></div></td></tr></tbody></table></div></section>
|
||||
</template>
|
||||
|
||||
@@ -423,30 +246,11 @@ function mapModels(items: CatalogModel[], providersList: CatalogProvider[]): Mod
|
||||
|
||||
<template v-else>
|
||||
<section class="page-heading"><div><span>PLATFORM SETTINGS</span><h1>平台设置</h1><p>管理注册策略、内测规则和平台级配置。</p></div><button class="button primary" @click="emit('notify', '平台设置接口尚未接入,当前仅展示规划项')"><Check :size="16" />保存设置</button></section>
|
||||
<section class="settings-grid"><article class="panel settings-card"><header class="panel-header"><div><span>ACCESS CONTROL</span><h3>用户注册策略</h3></div><KeyRound :size="18" /></header><p>第一版通过邀请码控制用户规模,手机号和邮箱公开注册保留开关。</p><div class="setting-list"><div><span><strong>邀请码注册</strong><small>策略接口尚未接入</small></span><button class="switch" disabled :class="{ active: settings.inviteOnly }"><span></span></button></div><div><span><strong>邮箱公开注册</strong><small>验证码服务尚未接入</small></span><button class="switch" disabled :class="{ active: settings.emailSignup }"><span></span></button></div><div><span><strong>手机号公开注册</strong><small>短信服务尚未接入</small></span><button class="switch" disabled :class="{ active: settings.phoneSignup }"><span></span></button></div></div></article><article class="panel settings-card"><header class="panel-header"><div><span>OPERATIONS</span><h3>内测运营策略</h3></div><Settings2 :size="18" /></header><p>配置新用户额度、维护公告和操作审计。</p><div class="setting-list"><div><span><strong>新用户自动发放额度</strong><small>额度账本接口尚未接入</small></span><button class="switch" disabled :class="{ active: settings.automaticCredit }"><span></span></button></div><div><span><strong>显示维护公告</strong><small>公告配置接口尚未接入</small></span><button class="switch" disabled :class="{ active: settings.maintenanceNotice }"><span></span></button></div><div><span><strong>保留操作审计</strong><small>当前仅展示认证服务审计</small></span><button class="switch" disabled :class="{ active: settings.auditRetention }"><span></span></button></div></div></article></section>
|
||||
<section class="settings-grid"><article class="panel settings-card"><header class="panel-header"><div><span>ACCESS CONTROL</span><h3>用户注册策略</h3></div><KeyRound :size="18" /></header><p>第一版通过邀请码控制用户规模,手机号和邮箱公开注册保留开关。</p><div class="setting-list"><div><span><strong>邀请码注册</strong><small>策略接口尚未接入</small></span><button class="switch" disabled :class="{ active: settings.inviteOnly }"><span></span></button></div><div><span><strong>邮箱公开注册</strong><small>邮箱验证码已支持,公开注册暂未开放</small></span><button class="switch" disabled :class="{ active: settings.emailSignup }"><span></span></button></div><div><span><strong>手机号公开注册</strong><small>短信验证码已支持,公开注册暂未开放</small></span><button class="switch" disabled :class="{ active: settings.phoneSignup }"><span></span></button></div></div></article><article class="panel settings-card"><header class="panel-header"><div><span>OPERATIONS</span><h3>内测运营策略</h3></div><Settings2 :size="18" /></header><p>配置新用户额度、维护公告和操作审计。</p><div class="setting-list"><div><span><strong>新用户自动发放额度</strong><small>自动赠送暂未开启,可在用户与额度手动发放</small></span><button class="switch" disabled :class="{ active: settings.automaticCredit }"><span></span></button></div><div><span><strong>显示维护公告</strong><small>公告配置接口尚未接入</small></span><button class="switch" disabled :class="{ active: settings.maintenanceNotice }"><span></span></button></div><div><span><strong>保留操作审计</strong><small>记录认证、渠道、账号及额度操作</small></span><button class="switch" disabled :class="{ active: settings.auditRetention }"><span></span></button></div></div></article></section>
|
||||
</template>
|
||||
|
||||
<SlidePanel v-if="selectedUser" :title="selectedUser.name" eyebrow="USER DETAILS" @close="selectedUser = null">
|
||||
<div class="user-profile"><span class="avatar-large">{{ selectedUser.name.slice(0, 1) }}</span><div><strong>{{ selectedUser.email }}</strong><small>{{ selectedUser.role }} · {{ selectedUser.status }}</small></div></div>
|
||||
<dl class="detail-list"><div><dt>用户 ID</dt><dd><code>{{ selectedUser.id }}</code><button class="icon-button" title="复制用户 ID" @click="copyUserId(selectedUser.id)"><Copy :size="14" /></button></dd></div><div><dt>额度余额</dt><dd>{{ selectedUser.balance === undefined ? '--(账本未接入)' : `¥ ${selectedUser.balance.toFixed(2)}` }}</dd></div><div><dt>累计用量</dt><dd>{{ selectedUser.usage || '--(用量统计未接入)' }}</dd></div><div><dt>最近活跃</dt><dd>{{ selectedUser.lastActive || '--' }}</dd></div></dl>
|
||||
<template #footer>
|
||||
<button v-if="canEditRole" class="button secondary full" @click="openRoleEditor"><ShieldCheck :size="16" />调整角色</button>
|
||||
<button v-if="selectedUser.roleCode !== 'super_admin'" class="button primary full" @click="openCredit(selectedUser)"><CircleDollarSign :size="16" />发放额度</button>
|
||||
<button v-if="selectedUser.roleCode === 'user'" class="button secondary full" @click="emit('notify', '用户状态接口尚未接入,当前不会修改状态')"><ShieldCheck :size="16" />{{ selectedUser.status === '已停用' ? '重新启用' : '停用用户' }}</button>
|
||||
</template>
|
||||
</SlidePanel>
|
||||
<UiModal v-if="roleTarget" title="调整用户角色" @close="!savingRole && (roleTarget = null)">
|
||||
<p>{{ roleTarget.email }}</p>
|
||||
<label class="form-label" for="user-role">角色</label>
|
||||
<select id="user-role" v-model="roleChoice" class="text-input" :disabled="savingRole"><option value="user">普通用户</option><option value="admin">平台管理员</option></select>
|
||||
<template #footer><button class="button secondary" :disabled="savingRole" @click="roleTarget = null">取消</button><button class="button primary" :disabled="savingRole || roleChoice === roleTarget.roleCode" @click="saveRole"><Check :size="16" />{{ savingRole ? '保存中…' : '保存角色' }}</button></template>
|
||||
</UiModal>
|
||||
<SlidePanel v-if="selectedUsage" :title="selectedUsage.modelName || selectedUsage.modelId || '调用记录详情'" eyebrow="REQUEST TRACE" @close="selectedUsage = null"><dl class="detail-list usage-detail-list"><div><dt>记录 ID</dt><dd><code>{{ selectedUsage.id }}</code></dd></div><div><dt>请求时间</dt><dd>{{ new Date(selectedUsage.createdAt).toLocaleString('zh-CN') }}</dd></div><div><dt>用户 / Key</dt><dd>{{ selectedUsage.userName || selectedUsage.userAccount || '--' }} / {{ selectedUsage.keyName || selectedUsage.keyPrefix || '--' }}</dd></div><div><dt>模型 / 供应商</dt><dd>{{ selectedUsage.modelName || selectedUsage.modelId }} / {{ selectedUsage.providerName || selectedUsage.providerId || '--' }}</dd></div><div><dt>状态与耗时</dt><dd>{{ selectedUsage.status }} · {{ selectedUsage.latencyMs ?? '--' }} ms</dd></div><div><dt>输入 / 输出单位</dt><dd>{{ selectedUsage.inputUnits ?? 0 }} / {{ selectedUsage.outputUnits ?? 0 }}</dd></div></dl><label class="form-label">输入数据(已脱敏)</label><pre class="usage-payload">{{ formatUsagePayload(selectedUsage.input) }}</pre><label class="form-label">输出数据(已脱敏)</label><pre class="usage-payload">{{ formatUsagePayload(selectedUsage.output) }}</pre><div v-if="selectedUsage.errorMessage" class="notice warning-notice"><AlertTriangle :size="16" /><span>{{ selectedUsage.errorCode }} · {{ selectedUsage.errorMessage }}</span></div><label class="form-label">管理员备注</label><textarea v-model="usageNote" class="text-input modal-textarea" placeholder="记录排查结论或运营备注"></textarea><template #footer><button class="button secondary" @click="saveUsageNote"><Check :size="16" />保存备注</button><button class="button danger" @click="deleteUsage(selectedUsage.id)"><Trash2 :size="16" />删除记录</button><button class="button primary" @click="selectedUsage = null">关闭</button></template></SlidePanel>
|
||||
<UiModal v-if="usageDeleteTarget" title="删除调用记录" eyebrow="DELETE REQUEST TRACE" @close="usageDeleteTarget = null"><p class="modal-description">删除后该记录不会再出现在查询和导出结果中,原始数据库记录会保留删除标记。</p><template #footer><button class="button secondary" @click="usageDeleteTarget = null">取消</button><button class="button danger" @click="deleteUsage(usageDeleteTarget); usageDeleteTarget = null">确认删除</button></template></UiModal>
|
||||
<UiModal v-if="usageBulkDeleteOpen" title="批量删除调用记录" eyebrow="BULK DELETE REQUESTS" @close="usageBulkDeleteOpen = false"><p class="modal-description">确认删除选中的 {{ usageSelectedIds.length }} 条记录?删除后不会再出现在查询和导出结果中。</p><template #footer><button class="button secondary" @click="usageBulkDeleteOpen = false">取消</button><button class="button danger" @click="usageBulkDeleteOpen = false; deleteSelectedUsage()">确认删除</button></template></UiModal>
|
||||
<UiModal v-if="invitationOpen" title="创建用户邀请" eyebrow="NEW INVITATION" @close="invitationOpen = false"><p class="modal-description">创建后生成一次性邀请码;账号和额度由用户激活后分别处理。</p><label class="form-label">邀请备注(可选)</label><input v-model="inviteLabel" class="text-input" placeholder="例如:内部测试成员" /><template #footer><button class="button secondary" @click="invitationOpen = false">取消</button><button class="button primary" @click="createInvitation"><Plus :size="16" />创建邀请码</button></template></UiModal>
|
||||
<UiModal v-if="createdInviteCode" title="请立即保存邀请码" eyebrow="INVITATION CREATED" @close="createdInviteCode = ''"><p class="modal-description centered">完整邀请码只展示一次,关闭后只能重新创建。</p><div class="secret-box"><code>{{ createdInviteCode }}</code><button title="复制邀请码" @click="copyUserId(createdInviteCode)"><Copy :size="16" /></button></div><template #footer><button class="button primary full" @click="createdInviteCode = ''">我已安全保存</button></template></UiModal>
|
||||
<UiModal v-if="providerOpen" title="登记供应商 / 渠道来源" eyebrow="NEW PROVIDER CHANNEL" @close="providerOpen = false"><p class="modal-description">供应商是渠道的身份,官方接口、中转站 Key、自托管服务都可以作为独立来源登记。保存后再关联该来源可提供的模型。</p><div class="modal-form-grid"><div><label class="form-label">供应商 Code</label><input v-model="providerCode" class="text-input" placeholder="例如:zhipu" @keyup.enter="createProvider" /></div><div><label class="form-label">显示名称</label><input v-model="providerName" class="text-input" placeholder="例如:智谱 AI / 内测中转 A" @keyup.enter="createProvider" /></div></div><div class="modal-form-grid"><div><label class="form-label">来源类型</label><select v-model="providerSourceType" class="text-input"><option value="official">官方供应商</option><option value="relay">中转站 / 渠道</option><option value="self-hosted">自托管模型</option><option value="custom">自定义来源</option></select></div><div><label class="form-label">接入协议</label><select v-model="providerProtocol" class="text-input"><option value="openai-compatible">OpenAI 兼容</option><option value="http">HTTP</option><option value="sdk">SDK</option></select></div></div><label class="form-label">服务 Base URL(可选)</label><input v-model="providerBaseUrl" class="text-input" placeholder="例如:https://api.example.com/v1" /><div class="modal-form-grid"><div><label class="form-label">凭据类型</label><select v-model="providerCredentialType" class="text-input"><option value="none">暂不配置</option><option value="api-key">API Key</option><option value="bearer">Bearer Token</option><option value="access-token">Access Token</option></select></div><div><label class="form-label">凭据值(可选)</label><input v-model="providerCredentialSecret" class="text-input" type="password" placeholder="仅保存服务端,不在用户端展示" /></div></div><label class="form-label">备注(可选)</label><textarea v-model="providerDescription" class="text-input modal-textarea" placeholder="记录区域、额度池、供应商文档或适配说明"></textarea><template #footer><button class="button secondary" @click="providerOpen = false">取消</button><button class="button primary" @click="createProvider"><Plus :size="16" />登记来源</button></template></UiModal>
|
||||
<UiModal v-if="modelOpen" title="添加模型目录项" eyebrow="NEW MODEL ROUTE" @close="modelOpen = false"><p class="modal-description">同一个用户可见模型可以通过多个来源提供。当前目录项代表“一个模型 + 一个渠道”,用于后续优先级、价格和并发路由。</p><div class="modal-form-grid"><div><label class="form-label">所属供应商 / 渠道</label><select v-model="modelProviderId" class="text-input"><option v-for="provider in providers" :key="provider.id" :value="provider.id">{{ provider.name }}{{ provider.sourceType === 'relay' ? ' · 中转' : '' }}</option></select></div><div><label class="form-label">渠道显示名(可选)</label><input v-model="modelSourceLabel" class="text-input" placeholder="例如:低价池 / 高质量池" /></div></div><div class="modal-form-grid"><div><label class="form-label">统一模型名称</label><input v-model="modelPublicName" class="text-input" placeholder="例如:GLM-4.5 Air" @keyup.enter="createModel" /></div><div><label class="form-label">统一模型标识(可选)</label><input v-model="modelKey" class="text-input" placeholder="留空则使用系统生成 ID" /></div></div><label class="form-label">上游模型标识</label><input v-model="modelUpstreamModel" class="text-input" placeholder="例如:glm-4.5-air" @keyup.enter="createModel" /><div class="modal-form-grid"><div><label class="form-label">模型类型</label><select v-model="modelType" class="text-input"><option value="text">文本</option><option value="code">代码</option><option value="multimodal">多模态</option><option value="image">图像</option><option value="audio">音频</option><option value="video">视频</option><option value="embedding">向量</option><option value="3d">3D</option></select></div><div><label class="form-label">调用模式</label><select v-model="modelMode" class="text-input"><option value="sync">同步</option><option value="stream">流式</option><option value="async">异步</option></select></div></div><div class="modal-form-grid"><div><label class="form-label">输入类型</label><input v-model="modelInputTypes" class="text-input" placeholder="text, image(逗号分隔)" /></div><div><label class="form-label">输出类型</label><input v-model="modelOutputTypes" class="text-input" placeholder="text / video / model" /></div></div><div class="modal-form-grid"><div><label class="form-label">输入价格(可选)</label><input v-model="modelInputPrice" class="text-input" type="number" min="0" step="0.000001" placeholder="例如:0.002" /></div><div><label class="form-label">输出价格(可选)</label><input v-model="modelOutputPrice" class="text-input" type="number" min="0" step="0.000001" placeholder="例如:0.008" /></div></div><div class="modal-form-grid"><div><label class="form-label">价格单位</label><input v-model="modelPriceUnit" class="text-input" placeholder="例如:1K tokens / 次 / 秒" /></div><div><label class="form-label">路由优先级</label><input v-model="modelPriority" class="text-input" type="number" min="0" step="1" placeholder="数字越小越优先" /></div></div><label class="form-label">单渠道并发上限(可选)</label><input v-model="modelMaxConcurrency" class="text-input" type="number" min="0" step="1" placeholder="留空表示由全局策略控制" /><label class="form-label">模型说明(可选)</label><textarea v-model="modelDescription" class="text-input modal-textarea" placeholder="描述能力、输入输出、限制或适用场景"></textarea><template #footer><button class="button secondary" @click="modelOpen = false">取消</button><button class="button primary" @click="createModel"><Plus :size="16" />添加模型来源</button></template></UiModal>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import {
|
||||
ArrowLeft,
|
||||
ArrowRight,
|
||||
@@ -30,6 +30,13 @@ const account = ref('')
|
||||
const password = ref('')
|
||||
const confirmPassword = ref('')
|
||||
const invitationCode = ref('')
|
||||
const verificationCode = ref('')
|
||||
const channels = ref({ email: false, phone: false })
|
||||
const sendingCode = ref(false)
|
||||
const cooldown = ref(0)
|
||||
let cooldownTimer: ReturnType<typeof setInterval> | undefined
|
||||
watch([account, registerChannel], () => { verificationCode.value = '' })
|
||||
onUnmounted(() => { clearInterval(cooldownTimer) })
|
||||
const agreeTerms = ref(false)
|
||||
const showPassword = ref(false)
|
||||
const showConfirmPassword = ref(false)
|
||||
@@ -43,8 +50,20 @@ function switchMode(nextMode: AuthMode) {
|
||||
mode.value = nextMode
|
||||
}
|
||||
|
||||
function sendCode() {
|
||||
emit('notify', '验证码服务尚未接入,当前请使用管理员邀请码注册')
|
||||
async function sendCode() {
|
||||
if (sendingCode.value || cooldown.value) return
|
||||
if (!invitationCode.value.trim()) return emit('notify', '请先填写邀请码')
|
||||
if (registerChannel.value === 'email' ? !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(account.value.trim()) : !/^(?:\+86)?1[3-9]\d{9}$/.test(account.value.trim())) return emit('notify', `请输入有效的${accountLabel.value}`)
|
||||
sendingCode.value = true
|
||||
try {
|
||||
const result = await authClient.sendVerificationCode(account.value, invitationCode.value)
|
||||
cooldown.value = result.retryAfterSeconds
|
||||
clearInterval(cooldownTimer)
|
||||
cooldownTimer = setInterval(() => { if (cooldown.value > 0) cooldown.value--; else clearInterval(cooldownTimer) }, 1000)
|
||||
emit('notify', '验证码已发送,5 分钟内有效')
|
||||
} catch (error) {
|
||||
emit('notify', error instanceof Error ? error.message : '验证码发送失败')
|
||||
} finally { sendingCode.value = false }
|
||||
}
|
||||
|
||||
async function submitLogin() {
|
||||
@@ -63,6 +82,7 @@ async function submitLogin() {
|
||||
async function submitRegister() {
|
||||
if (!invitationCode.value.trim()) return emit('notify', '第一版内测需要填写邀请码')
|
||||
if (!account.value.trim()) return emit('notify', `请输入${accountLabel.value}`)
|
||||
if (!/^\d{6}$/.test(verificationCode.value)) return emit('notify', '请输入 6 位验证码')
|
||||
if (password.value.length < 8) return emit('notify', '密码至少需要 8 位')
|
||||
if (password.value !== confirmPassword.value) return emit('notify', '两次输入的密码不一致')
|
||||
if (!agreeTerms.value) return emit('notify', '请先同意服务协议与隐私政策')
|
||||
@@ -70,6 +90,7 @@ async function submitRegister() {
|
||||
try {
|
||||
const user = await authClient.register({
|
||||
invitationCode: invitationCode.value,
|
||||
verificationCode: verificationCode.value,
|
||||
account: account.value,
|
||||
password: password.value,
|
||||
})
|
||||
@@ -86,6 +107,7 @@ function submitReset() {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
authClient.verificationChannels().then(value => { channels.value = value }).catch(() => {})
|
||||
try {
|
||||
await authClient.health()
|
||||
serviceStatus.value = 'online'
|
||||
@@ -152,7 +174,7 @@ onMounted(async () => {
|
||||
<label><span>邀请码</span><div class="auth-input"><KeyRound :size="17" /><input v-model="invitationCode" placeholder="请输入管理员提供的邀请码" /></div></label>
|
||||
<div class="register-channel"><button type="button" :class="{ active: registerChannel === 'email' }" @click="registerChannel = 'email'"><Mail :size="15" />邮箱注册</button><button type="button" :class="{ active: registerChannel === 'phone' }" @click="registerChannel = 'phone'"><Phone :size="15" />手机号注册</button></div>
|
||||
<label><span>{{ accountLabel }}</span><div class="auth-input"><component :is="registerChannel === 'email' ? Mail : Phone" :size="17" /><input v-model="account" :placeholder="accountPlaceholder" /></div></label>
|
||||
<label><span>验证码(公开注册开放后启用)</span><div class="auth-code-row"><div class="auth-input disabled"><ShieldCheck :size="17" /><input disabled placeholder="当前无需填写" /></div><button type="button" disabled @click="sendCode">暂未开放</button></div></label>
|
||||
<label><span>{{ registerChannel === 'email' ? '邮箱验证码' : '短信验证码' }}</span><div class="auth-code-row"><div class="auth-input"><ShieldCheck :size="17" /><input v-model="verificationCode" inputmode="numeric" autocomplete="one-time-code" maxlength="6" pattern="[0-9]{6}" required placeholder="6 位验证码" /></div><button type="button" :disabled="sendingCode || cooldown > 0 || !channels[registerChannel]" @click="sendCode">{{ sendingCode ? '发送中' : cooldown ? `${cooldown} 秒后重发` : '获取验证码' }}</button></div><small v-if="!channels[registerChannel]">{{ registerChannel === 'email' ? '邮箱' : '短信' }}发送服务暂不可用,请联系管理员。</small></label>
|
||||
<label><span>设置密码</span><div class="auth-input"><LockKeyhole :size="17" /><input v-model="password" :type="showPassword ? 'text' : 'password'" autocomplete="new-password" placeholder="至少 8 位字符" /><button type="button" @click="showPassword = !showPassword"><EyeOff v-if="showPassword" :size="17" /><Eye v-else :size="17" /></button></div></label>
|
||||
<label><span>确认密码</span><div class="auth-input"><LockKeyhole :size="17" /><input v-model="confirmPassword" :type="showConfirmPassword ? 'text' : 'password'" autocomplete="new-password" placeholder="再次输入密码" /><button type="button" @click="showConfirmPassword = !showConfirmPassword"><EyeOff v-if="showConfirmPassword" :size="17" /><Eye v-else :size="17" /></button></div></label>
|
||||
<label class="check-row terms-row"><input v-model="agreeTerms" type="checkbox" /><em>我已阅读并同意<a href="#" @click.prevent="emit('notify', '服务协议将在正式上线前补充')">《服务协议》</a>与<a href="#" @click.prevent="emit('notify', '隐私政策将在正式上线前补充')">《隐私政策》</a></em></label>
|
||||
|
||||
@@ -41,9 +41,10 @@ import { catalogClient, platformApiBaseUrl, type AsyncTaskResult, type CatalogAp
|
||||
import { copyText, type CopyResult } from '../services/clipboard'
|
||||
import SlidePanel from '../components/SlidePanel.vue'
|
||||
import UiModal from '../components/UiModal.vue'
|
||||
import ModelGroupPermissions from '../components/ModelGroupPermissions.vue'
|
||||
|
||||
defineProps<{ view: string; displayName?: string }>()
|
||||
const emit = defineEmits<{ navigate: [view: string]; notify: [message: string] }>()
|
||||
const emit = defineEmits<{ navigate: [view: string]; notify: [message: string]; balance: [value: number | undefined] }>()
|
||||
|
||||
const modelQuery = ref('')
|
||||
const modelType = ref<'全部' | ModelType>('全部')
|
||||
@@ -54,7 +55,17 @@ const selectedModel = ref<ModelItem | null>(null)
|
||||
const emptyModel: ModelItem = { id: '', name: '尚未选择模型', provider: '等待目录加载', type: '文本', mode: '同步', description: '', latency: '--', specification: '--', availability: '--', accent: 'violet', icon: MessageSquareText }
|
||||
const catalogModels = ref<ModelItem[]>([])
|
||||
const activeModel = ref<ModelItem>(emptyModel)
|
||||
const callMode = ref<CallMode>('流式')
|
||||
const callMode = ref<CallMode>('同步')
|
||||
const playgroundModels = computed(() => [...new Map(catalogModels.value.map(group => [group.logicalModelId || group.id, group])).values()])
|
||||
const playgroundGroups = computed(() => catalogModels.value.filter(group => (group.logicalModelId || group.id) === (activeModel.value.logicalModelId || activeModel.value.id)))
|
||||
function selectPlaygroundGroup(id: string) {
|
||||
const group = catalogModels.value.find(item => item.id === id)
|
||||
if (group) { activeModel.value = group; callMode.value = group.mode; response.value = ''; activeTaskId.value = '' }
|
||||
}
|
||||
function selectPlaygroundModel(id: string) {
|
||||
const group = catalogModels.value.find(item => (item.logicalModelId || item.id) === id)
|
||||
if (group) selectPlaygroundGroup(group.id)
|
||||
}
|
||||
const prompt = ref('')
|
||||
const running = ref(false)
|
||||
const response = ref('')
|
||||
@@ -91,10 +102,11 @@ onMounted(async () => {
|
||||
try {
|
||||
const [catalog, keyResult, projectResult, overviewResult] = await Promise.all([catalogClient.listModels(), catalogClient.listKeys(), catalogClient.listProjects(), catalogClient.getOverview()])
|
||||
catalogModels.value = mapCatalogModels(catalog.models, catalog.providers)
|
||||
if (catalogModels.value[0]) activeModel.value = catalogModels.value[0]
|
||||
if (catalogModels.value[0]) selectPlaygroundGroup(catalogModels.value[0].id)
|
||||
keys.value = keyResult.keys.map((key) => mapCatalogKey(key))
|
||||
projects.value = projectResult.projects
|
||||
overview.value = overviewResult
|
||||
emit('balance', overviewResult.availableCredit)
|
||||
overviewLoaded.value = true
|
||||
catalogConnected.value = true
|
||||
try {
|
||||
@@ -153,7 +165,6 @@ const usageSeries = computed(() => {
|
||||
const recentTasks = computed(() => tasks.value.slice(0, 3))
|
||||
const modelTypes: Array<'全部' | ModelType> = ['全部', '文本', '多模态', '图像', '3D', '视频', '音频']
|
||||
const callModes: Array<'全部' | CallMode> = ['全部', '同步', '流式', '异步']
|
||||
const allModelsSelected = computed(() => catalogModels.value.length > 0 && catalogModels.value.every((model) => selectedModelIds.value.includes(model.id)))
|
||||
|
||||
async function copy(value: string, label: string, target: string) {
|
||||
const result = await copyText(value)
|
||||
@@ -184,6 +195,7 @@ function resetModelFilters() {
|
||||
async function refreshOverview() {
|
||||
try {
|
||||
overview.value = await catalogClient.getOverview()
|
||||
emit('balance', overview.value.availableCredit)
|
||||
overviewLoaded.value = true
|
||||
} catch {}
|
||||
}
|
||||
@@ -326,6 +338,7 @@ function mapCatalogModels(items: CatalogModel[], providers: Array<{ id: string;
|
||||
const modeLabels: Record<string, CallMode> = { sync: '同步', stream: '流式', async: '异步' }
|
||||
return items.map((item) => ({
|
||||
id: item.id,
|
||||
logicalModelId: item.logicalModelId,
|
||||
name: item.publicName,
|
||||
provider: providerNames.get(item.providerId) || item.providerId,
|
||||
type: typeLabels[item.type] || '文本',
|
||||
@@ -379,20 +392,9 @@ function openCreatedKeyPermissions() {
|
||||
if (key) openModelPermissions(key)
|
||||
}
|
||||
|
||||
function toggleModelPermission(modelId: string) {
|
||||
selectedModelIds.value = selectedModelIds.value.includes(modelId)
|
||||
? selectedModelIds.value.filter((id) => id !== modelId)
|
||||
: [...selectedModelIds.value, modelId]
|
||||
}
|
||||
|
||||
function toggleAllModels() {
|
||||
selectedModelIds.value = allModelsSelected.value ? [] : catalogModels.value.map((model) => model.id)
|
||||
}
|
||||
|
||||
async function saveModelPermissions() {
|
||||
const key = permissionKey.value
|
||||
if (!key) return
|
||||
if (!selectedModelIds.value.length) return emit('notify', '请至少选择一个可调用模型')
|
||||
if (!catalogConnected.value) return emit('notify', 'Control Plane 未连接,无法保存模型权限')
|
||||
savingPermissions.value = true
|
||||
try {
|
||||
@@ -488,10 +490,12 @@ async function createProject() {
|
||||
<section class="playground-grid">
|
||||
<article class="panel request-panel">
|
||||
<header class="panel-header"><div><span>REQUEST</span><h3>请求配置</h3></div><button class="icon-button" @click="prompt = ''; response = ''; activeTaskId = ''"><RefreshCcw :size="16" /></button></header>
|
||||
<label class="form-label">模型</label>
|
||||
<button class="model-picker" @click="emit('navigate', 'models')"><span class="model-icon" :class="activeModel.accent"><component :is="activeModel.icon" :size="18" /></span><div><strong>{{ activeModel.name }}</strong><small>{{ activeModel.type }} · {{ activeModel.provider }}</small></div><ChevronDown :size="16" /></button>
|
||||
<div class="playground-selectors">
|
||||
<label>模型<select class="text-input" aria-label="调试模型" :value="activeModel.logicalModelId || activeModel.id" :disabled="running || !playgroundModels.length" @change="selectPlaygroundModel(($event.target as HTMLSelectElement).value)"><option v-for="model in playgroundModels" :key="model.logicalModelId || model.id" :value="model.logicalModelId || model.id">{{ model.name }}</option></select></label>
|
||||
<label>分组<select class="text-input" aria-label="调试分组" :value="activeModel.id" :disabled="running || !playgroundGroups.length" @change="selectPlaygroundGroup(($event.target as HTMLSelectElement).value)"><option v-for="group in playgroundGroups" :key="group.id" :value="group.id">{{ group.sourceLabel || '默认分组' }} · {{ group.provider }}</option></select></label>
|
||||
</div>
|
||||
<label class="form-label">调用模式</label>
|
||||
<div class="segment"><button v-for="mode in ['同步','流式','异步']" :key="mode" :class="{ active: callMode === mode }" @click="callMode = mode as CallMode">{{ mode }}</button></div>
|
||||
<div class="segment"><button v-for="mode in ['同步','流式','异步']" :key="mode" :disabled="running || mode !== activeModel.mode || mode === '流式'" :class="{ active: callMode === mode }" @click="callMode = mode as CallMode">{{ mode }}</button></div>
|
||||
<label class="form-label prompt-label"><span>输入内容</span><small>{{ prompt.length }}/4000</small></label>
|
||||
<textarea v-model="prompt" maxlength="4000" :placeholder="callMode === '异步' ? activeModel.type === '视频' ? '例如:电影感产品展示视频,柔和运镜与自然光影' : '例如:一个低面数的木质机械鸟,游戏资产风格' : '描述你希望模型完成的任务'"></textarea>
|
||||
<div class="request-footer"><span><ShieldCheck :size="14" />{{ catalogConnected ? '通过 MOYI Key 调用真实网关' : '连接服务后才能调用' }}</span><button class="button primary" :disabled="running || !catalogConnected || !activeModel.id" @click="runModel"><Play v-if="!running" :size="16" /><span v-else class="spinner"></span>{{ running ? '提交中…' : callMode === '异步' ? activeModel.type === '视频' ? '生成视频' : '生成 3D' : '开始调用' }}</button></div>
|
||||
@@ -516,7 +520,7 @@ async function createProject() {
|
||||
<template v-else-if="view === 'keys'">
|
||||
<section class="page-heading"><div><span>DEVELOPER ACCESS</span><h1>API Keys</h1><p>为不同应用和环境创建独立访问凭证。</p></div><button class="button primary" @click="createKeyOpen = true"><Plus :size="16" />创建 API Key</button></section>
|
||||
<section class="notice"><ShieldCheck :size="19" /><div><strong>妥善保管访问凭证</strong><p>完整 Key 只在创建时展示一次,请存放在安全的环境变量或密钥管理服务中。</p></div></section>
|
||||
<section class="panel table-card"><header class="panel-header"><div><span>CREDENTIALS</span><h3>个人与项目 Keys</h3></div><small>{{ keys.length }} 个凭证{{ catalogConnected ? ' · 已连接 Control Plane' : ' · 服务未连接' }}</small></header><div class="responsive-table"><table><thead><tr><th>名称</th><th>Key</th><th>归属范围</th><th>模型权限</th><th>最近使用</th><th>状态</th><th></th></tr></thead><tbody><tr v-for="key in keys" :key="key.id"><td><div class="entity-cell"><span class="icon-tile violet"><KeyRound :size="16" /></span><div><strong>{{ key.name }}</strong><small>创建于 {{ key.createdAt }}</small></div></div></td><td><span class="code-value readonly" title="完整 Key 仅在创建时展示"><code>{{ key.value }}</code><ShieldCheck :size="14" /></span></td><td>{{ key.scope }}</td><td><button class="model-permission-summary" :disabled="key.status !== '正常'" @click="openModelPermissions(key)"><span>{{ key.modelIds.length === catalogModels.length && catalogModels.length ? `全部 ${catalogModels.length} 个模型` : key.modelIds.length ? `${key.modelIds.length} 个模型` : '未配置' }}</span><SlidersHorizontal :size="14" /></button></td><td>{{ key.lastUsed }}</td><td><span class="status-chip" :class="key.status === '正常' ? 'success' : 'muted'"><i></i>{{ key.status }}</span></td><td><button class="icon-button" :title="key.status === '正常' ? '停用 Key' : '已停用'" @click="toggleKey(key)"><EyeOff v-if="key.status === '正常'" :size="16" /><Eye v-else :size="16" /></button></td></tr><tr v-if="!keys.length"><td colspan="7"><div class="empty-state compact"><KeyRound :size="22" /><strong>暂无 API Key</strong><span>创建后完整 Key 只会展示一次</span></div></td></tr></tbody></table></div></section>
|
||||
<section class="panel table-card"><header class="panel-header"><div><span>CREDENTIALS</span><h3>个人与项目 Keys</h3></div><small>{{ keys.length }} 个凭证{{ catalogConnected ? ' · 已连接 Control Plane' : ' · 服务未连接' }}</small></header><div class="responsive-table"><table><thead><tr><th>名称</th><th>Key</th><th>归属范围</th><th>模型权限</th><th>最近使用</th><th>状态</th><th></th></tr></thead><tbody><tr v-for="key in keys" :key="key.id"><td><div class="entity-cell"><span class="icon-tile violet"><KeyRound :size="16" /></span><div><strong>{{ key.name }}</strong><small>创建于 {{ key.createdAt }}</small></div></div></td><td><span class="code-value readonly" title="完整 Key 仅在创建时展示"><code>{{ key.value }}</code><ShieldCheck :size="14" /></span></td><td>{{ key.scope }}</td><td><button class="model-permission-summary" :disabled="key.status !== '正常'" @click="openModelPermissions(key)"><span>{{ key.modelIds.length ? `${key.modelIds.length} 个分组` : '未配置' }}</span><SlidersHorizontal :size="14" /></button></td><td>{{ key.lastUsed }}</td><td><span class="status-chip" :class="key.status === '正常' ? 'success' : 'muted'"><i></i>{{ key.status }}</span></td><td><button class="icon-button" :title="key.status === '正常' ? '停用 Key' : '已停用'" @click="toggleKey(key)"><EyeOff v-if="key.status === '正常'" :size="16" /><Eye v-else :size="16" /></button></td></tr><tr v-if="!keys.length"><td colspan="7"><div class="empty-state compact"><KeyRound :size="22" /><strong>暂无 API Key</strong><span>创建后完整 Key 只会展示一次</span></div></td></tr></tbody></table></div></section>
|
||||
</template>
|
||||
|
||||
<template v-else-if="view === 'tasks'">
|
||||
@@ -548,6 +552,19 @@ MOYI_MODEL=<model-id></code></pre></div></section><section><b>02</b><div><
|
||||
<UiModal v-if="createKeyOpen" title="创建 API Key" eyebrow="NEW CREDENTIAL" @close="createKeyOpen = false"><p class="modal-description">个人 Key 适合个人开发调试,项目 Key 适合服务端应用和团队协作。创建后再配置该 Key 可调用的具体模型。</p><label class="form-label">Key 名称</label><input v-model="keyName" class="text-input" placeholder="例如:生产环境" /><label class="form-label">Key 归属</label><div class="option-list"><button :class="{ active: keyScopeType === 'personal' }" @click="keyScopeType = 'personal'"><span><i></i><strong>个人 Key</strong><small>归属当前账号</small></span><Check v-if="keyScopeType === 'personal'" :size="16" /></button><button :class="{ active: keyScopeType === 'project' }" @click="keyScopeType = 'project'"><span><i></i><strong>项目 Key</strong><small>归属工作区/项目</small></span><Check v-if="keyScopeType === 'project'" :size="16" /></button></div><div v-if="keyScopeType === 'project'"><label class="form-label"><span>选择项目</span><button class="text-link" type="button" @click="openProjectModal">新建项目</button></label><select v-model="selectedProjectId" class="text-input"><option value="" disabled>请选择项目</option><option v-for="project in projects" :key="project.id" :value="project.id">{{ project.name }}</option></select></div><div class="permission-hint"><ShieldCheck :size="16" /><span>Key 创建后默认不开放模型权限,请在下一步选择具体可调用模型。</span></div><template #footer><button class="button secondary" @click="createKeyOpen = false">取消</button><button class="button primary" @click="createKey"><KeyRound :size="16" />生成 Key</button></template></UiModal>
|
||||
<UiModal v-if="secretOpen" title="请立即保存你的 Key" eyebrow="CREDENTIAL CREATED" @close="secretOpen = false"><div class="secret-success"><CheckCircle2 :size="25" /><strong>API Key 创建成功</strong></div><p class="modal-description centered">完整 Key 只展示一次,关闭后无法再次查看。保存后继续配置模型权限。</p><div class="secret-box"><code>{{ revealSecret ? createdSecret : `${createdSecret.slice(0, 10)}••••••••••••` }}</code><button title="显示或隐藏 Key" @click="revealSecret = !revealSecret"><EyeOff v-if="revealSecret" :size="16" /><Eye v-else :size="16" /></button><button title="复制完整 Key" @click="copy(createdSecret, 'API Key', 'secret-key')"><Check v-if="copySucceeded('secret-key')" :size="16" /><Copy v-else :size="16" /></button></div><template #footer><button class="button secondary" @click="secretOpen = false; revealSecret = false">稍后配置</button><button class="button primary" @click="openCreatedKeyPermissions"><SlidersHorizontal :size="16" />配置可调用模型</button></template></UiModal>
|
||||
<UiModal v-if="projectOpen" title="新建工作区 / 项目" eyebrow="NEW PROJECT" @close="projectOpen = false"><p class="modal-description">项目用于归属团队 Key,并为后续用量、额度和权限隔离预留空间。</p><label class="form-label">项目名称</label><input v-model="projectName" class="text-input" placeholder="例如:AI SoulMate 研发项目" @keyup.enter="createProject" /><label class="form-label">项目描述(可选)</label><textarea v-model="projectDescription" class="text-input modal-textarea" placeholder="描述项目用途或成员范围"></textarea><template #footer><button class="button secondary" @click="projectOpen = false">取消</button><button class="button primary" @click="createProject"><Plus :size="16" />创建项目</button></template></UiModal>
|
||||
<UiModal v-if="modelPermissionsOpen && permissionKey" title="配置模型权限" eyebrow="MODEL ACCESS" @close="modelPermissionsOpen = false; permissionKey = null"><p class="modal-description">为 <strong>{{ permissionKey.name }}</strong> 选择允许调用的模型。权限变更会立即应用到该 Key。</p><button class="permission-all-toggle" :class="{ active: allModelsSelected }" @click="toggleAllModels"><span><i></i><strong>全部模型</strong><small>{{ allModelsSelected ? '已选中当前目录全部模型' : '一键选择当前目录全部模型' }}</small></span><Check v-if="allModelsSelected" :size="17" /></button><div class="permission-model-list"><button v-for="model in catalogModels" :key="model.id" class="permission-model-button" :class="{ active: selectedModelIds.includes(model.id) }" @click="toggleModelPermission(model.id)"><span class="model-icon" :class="model.accent"><component :is="model.icon" :size="17" /></span><span><strong>{{ model.name }}</strong><small>{{ model.provider }} · {{ model.type }} · {{ model.mode }}</small></span><Check v-if="selectedModelIds.includes(model.id)" :size="17" /></button><div v-if="!catalogModels.length" class="empty-state compact"><Box :size="20" /><strong>暂无可选模型</strong><span>请先由管理员配置模型目录</span></div></div><template #footer><button class="button secondary" @click="modelPermissionsOpen = false; permissionKey = null">取消</button><button class="button primary" :disabled="savingPermissions || !selectedModelIds.length" @click="saveModelPermissions"><span v-if="savingPermissions" class="spinner"></span><Check v-else :size="16" />{{ savingPermissions ? '保存中…' : '保存模型权限' }}</button></template></UiModal>
|
||||
<UiModal v-if="modelPermissionsOpen && permissionKey" title="配置模型与分组权限" eyebrow="MODEL ACCESS" @close="modelPermissionsOpen = false; permissionKey = null">
|
||||
<p class="modal-description">{{ permissionKey.name }}</p>
|
||||
<ModelGroupPermissions v-model="selectedModelIds" :groups="catalogModels" :disabled="savingPermissions" />
|
||||
<template #footer><button class="button secondary" :disabled="savingPermissions" @click="modelPermissionsOpen = false; permissionKey = null">取消</button><button class="button primary" :disabled="savingPermissions" @click="saveModelPermissions"><span v-if="savingPermissions" class="spinner"></span><Check v-else :size="16" />{{ savingPermissions ? '保存中…' : '保存权限' }}</button></template>
|
||||
</UiModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.request-panel, .response-panel { min-width: 0; }
|
||||
.playground-selectors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
|
||||
.playground-selectors label { display: grid; gap: 8px; font-size: 13px; min-width: 0; }
|
||||
.playground-selectors select { width: 100%; min-width: 0; }
|
||||
@media(max-width: 1180px) { .playground-grid { grid-template-columns: minmax(0, 1fr); } }
|
||||
@media(max-width: 700px) { .playground-selectors { grid-template-columns: minmax(0, 1fr); } }
|
||||
</style>
|
||||
Reference in new issue
Block a user