/* AI 账号视图 */ const AIAccountsView = { template: `
共 {{ totalAccounts }} 个账号 · 总余额 {{ totalBalance }}
{{ g.provider }} {{ g.accounts.length }} 个账号
余额合计 {{ g.totalBalance }}
{{ a.name }} {{ a.ai_detail.plan }}
余额 {{ fmtBal(a.ai_detail && a.ai_detail.balance) }}{{ a.ai_detail && a.ai_detail.balance !== null && a.ai_detail.balance !== undefined ? ' ' + a.ai_detail.currency : '' }} 用量 {{ a.ai_detail.monthly_usage }}/{{ a.ai_detail.monthly_limit ?? '∞' }}
暂无 AI 账号,点右上角「新增账号」添加(同一平台可添加多个)
`, setup() { const aiList = () => store.assets.filter(a => a.asset_type === 'ai_agent'); const groups = Vue.computed(() => { const map = {}; for (const a of aiList()) { const prov = (a.ai_detail && a.ai_detail.provider) || a.provider || '其他'; if (!map[prov]) map[prov] = { provider: prov, accounts: [], totalBalance: 0 }; map[prov].accounts.push(a); const bal = a.ai_detail && a.ai_detail.balance; if (bal) map[prov].totalBalance += Number(bal); } return Object.values(map).map(g => ({ ...g, totalBalance: Math.round(g.totalBalance * 100) / 100 })).sort((x, y) => y.totalBalance - x.totalBalance); }); const totalAccounts = Vue.computed(() => aiList().length); const totalBalance = Vue.computed(() => Math.round(aiList().reduce((s, a) => s + (a.ai_detail && a.ai_detail.balance ? Number(a.ai_detail.balance) : 0), 0) * 100) / 100); function balanceClass(b) { if (b === null || b === undefined) return 'text-slate-400'; if (Number(b) < 10) return 'text-red-600 dark:text-red-400 font-semibold'; if (Number(b) < 50) return 'text-amber-600 dark:text-amber-400'; return 'text-emerald-600 dark:text-emerald-400'; } function fmtBal(b) { return (b === null || b === undefined) ? '—' : b; } return { store, groups, totalAccounts, totalBalance, balanceClass, fmtBal, add: openAICreate, addAny: () => openAICreate(''), edit: openAssetEdit }; }, };