/* 平台管理视图 */ const ProvidersView = { template: `
🏢 平台 = 资产的服务商(Vultr / 新网 / OpenAI…)。凭证(登录信息/API Key)配在账号上:点平台卡片「👤 账号」新增账号并填写凭证,即可在账号上「测试/同步」拉取真实数据。
{{ p.name }}
{{ p.slug }}
{{ Fmt.SERVICES_LABELS[s] || s }}
{{ Fmt.CATEGORY_LABELS[p.category] }}
API 对接: {{ p.sdk_type }}
管理面板 ↗
{{ p.enabled ? '启用' : '停用' }}
最后同步:{{ fmtTime(p.last_synced_at) }}
`, setup() { // 凭证已下沉到账号层:平台卡片不再提供测试/同步(见账号弹窗) // 平台关联资产数:优先按 provider_id 归并,其次按资产里填的平台名/slug const assetCounts = Vue.computed(() => { const m = {}; for (const a of store.assets) { if (a.provider_id) m['id:' + a.provider_id] = (m['id:' + a.provider_id] || 0) + 1; else if (a.provider) m['p:' + a.provider] = (m['p:' + a.provider] || 0) + 1; } return m; }); function countOf(p) { return (assetCounts.value['id:' + p.id] || 0) + (assetCounts.value['p:' + p.slug] || 0) + (assetCounts.value['p:' + p.name] || 0); } // 平台名下账号数(账号按 platform slug 归属平台) function accountsCountOf(p) { return store.accounts.filter(a => a.platform === p.slug).length; } // 在用判定:有资产/有账号/已配置 API 任一即算在用 function isUsed(p) { return countOf(p) > 0 || accountsCountOf(p) > 0 || p.has_api_config; } // 默认隐藏未使用平台,避免预设平台撑满屏幕;偏好持久化到 localStorage const showAll = Vue.ref(localStorage.getItem('vps_show_all_providers') === '1'); function toggleShowAll() { showAll.value = !showAll.value; localStorage.setItem('vps_show_all_providers', showAll.value ? '1' : '0'); } const visibleProviders = Vue.computed(() => showAll.value ? store.providers : store.providers.filter(isUsed)); const hiddenCount = Vue.computed(() => store.providers.length - visibleProviders.value.length); function serviceList(p) { return (p.services || '').split(',').map(s => s.trim()).filter(Boolean); } function fmtTime(iso) { if (!iso) return ''; return new Date(iso).toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }); } return { store, Fmt, countOf, accountsCountOf, serviceList, showAll, toggleShowAll, visibleProviders, hiddenCount, fmtTime, seed: seedProviders, create: openProviderCreate, edit: openProviderEdit, del: deleteProvider, openAccounts: (p) => openAccountsView(p.slug), manageAccounts: () => openAccountsView(null), goAssets: openAssetsByProvider }; }, };