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
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user