| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844 |
- import { UserNoticePipe } from '../../../components/feedback/user-notice.pipe';
- import { ChangeDetectionStrategy, Component, computed, inject, OnInit, signal } from '@angular/core';
- import { Router } from '@angular/router';
- import { PaidPlanCode } from '../../../core/api/models';
- import { LoadingOverlayComponent } from '../../../components/domain/loading-overlay/loading-overlay';
- import { ProvisionInstructionComponent } from '../../../components/domain/provision-instruction/provision-instruction';
- import { PlanService } from '../../../core/plan.service';
- import { ProvisionService } from '../../../core/provision.service';
- import { RenewalGuideComponent } from '../../../components/domain/renewal-guide/renewal-guide';
- import { LiveService } from '../../../core/live.service';
- import { ProvisionConfirmComponent } from '../../../components/domain/provision-confirm/provision-confirm';
- import { suggestContainerName } from '../../../components/domain/provision-confirm/container-name';
- /**
- * 桌面端套餐与开通(2026-11-25 第一期)
- *
- * ## 与移动端的差异(两端独立设计)
- *
- * 桌面横向空间充足,用**三列详情卡**:图标 / 名称 / 副标题 / 价格 /
- * 开通按钮 / 权益清单全部展示,一屏看完三档对比。
- * 移动端受窄屏所限用紧凑选择卡,见 `mobile/pages/plans`。
- *
- * ## 本期边界
- *
- * 只做展示 + 申请意向。**不显示金额、不显示「已开通」、不显示开通进度**。
- */
- @Component({
- selector: 'app-dk-plans-page',
- changeDetection: ChangeDetectionStrategy.OnPush,
- imports: [UserNoticePipe, ProvisionInstructionComponent, LoadingOverlayComponent, RenewalGuideComponent, ProvisionConfirmComponent],
- template: `
- <div class="plans-page">
- <!-- 名额已满提示(2026-12-03):页面顶部,用户点了开通马上能看到 -->
- @if (quotaFull(); as qf) {
- <div class="quota-full" role="alert">
- <p>「{{ qf.plan }}」的名额已满({{ existingNames().length }}/{{ qf.quota }})。</p>
- <p>可以删除不用的容器,或升级到名额更多的套餐。</p>
- <button type="button" (click)="quotaFull.set(null)">知道了</button>
- </div>
- }
- <header class="plans-head">
- <div>
- <p class="plans-eyebrow"><i class="fa-solid fa-crown" aria-hidden="true"></i> 套餐与开通</p>
- <h1>选择适合你的协作方式。</h1>
- <p class="plans-lead">按需选择,随时升级。</p>
- </div>
- </header>
- <!--
- 当前资产概览(2026-12-02 PC 优化)。
- 桌面端宽屏下先回答「我现在有什么」,再让用户选「要不要再开一个」——
- 原来一进页面只能看到三张价格卡,对自己已有的容器与名额没有概念。
- -->
- <section class="plans-status" aria-label="当前容器与名额">
- <div class="plans-status-item">
- <span class="plans-status-label">我的容器</span>
- @if (live.hasData()) {
- <strong class="plans-status-value">{{ live.agents().length }} 个</strong>
- <span class="plans-status-hint">{{ runningCount() }} 个运行中</span>
- } @else {
- <strong class="plans-status-value">—</strong>
- <span class="plans-status-hint">正在读取…</span>
- }
- </div>
- <div class="plans-status-item">
- <span class="plans-status-label">当前套餐</span>
- <strong class="plans-status-value">{{ currentPlanName() }}</strong>
- <span class="plans-status-hint">{{ provision.hasJob() ? provision.statusText() : '按需升级,随时生效' }}</span>
- </div>
- <div class="plans-status-actions">
- <button type="button" class="plans-status-btn" (click)="go('/desktop/my-containers')">
- <i class="fa-solid fa-server" aria-hidden="true"></i> 管理容器
- </button>
- <button type="button" class="plans-status-btn plans-status-btn--primary" [disabled]="provision.startBlocked()" (click)="apply('advanced')">
- <i class="fa-solid fa-plus" aria-hidden="true"></i> 新增容器
- </button>
- </div>
- </section>
- <!-- 开通进行中 / 提示词 / 试用引导 -->
- @if (provision.hasJob()) {
- <section class="plans-banner plans-banner--pending">
- <i class="fa-solid"
- [class]="provision.isReady() ? 'fa-circle-check' : provision.isFailed() ? 'fa-triangle-exclamation' : 'fa-spinner fa-spin'"
- aria-hidden="true"></i>
- <div style="flex:1;min-width:0">
- <h2>{{ provision.statusText() }}</h2>
- <p>{{ (provision.isFailed() ? provision.failureMessage() : '容器创建由平台自动完成,请稍候。') | userNotice:'暂时无法确认开通结果,请先查看已有申请。':'verify-result' }}</p>
- @if (provision.isRunning() && provision.completedStages() > 0) {
- <div class="plans-progress" role="progressbar"
- [attr.aria-valuenow]="provision.completedStages()"
- [attr.aria-valuemin]="0" [attr.aria-valuemax]="5">
- <span class="plans-progress-bar"
- [style.width.%]="(provision.completedStages() / 5) * 100"></span>
- </div>
- }
- </div>
- @if (provision.isFailed() && provision.canRetry()) {
- <button type="button" class="plans-banner-btn" (click)="provision.retry()">重试</button>
- } @else if (provision.isFailed()) {
- <button type="button" class="plans-banner-btn" (click)="go('/plans')">查看套餐升级</button>
- } @else if (!provision.isReady()) {
- <button type="button" class="plans-banner-btn" (click)="go('/provision?jobId=' + provision.current()?.jobId)">查看开通进度</button>
- } @else {
- <button type="button" class="plans-banner-btn" (click)="go('/desktop/my-containers')">查看我的容器</button>
- }
- </section>
- } @else if (provision.instruction(); as ins) {
- <!-- 试用/入门:接入提示词(组件内含复制 + 失败兜底) -->
- <app-provision-instruction [text]="ins" />
- } @else {
- <section class="plans-banner">
- <div class="plans-banner-icon">
- <i class="fa-solid fa-wand-magic-sparkles" aria-hidden="true"></i>
- </div>
- <div class="plans-banner-body">
- <h2>先体验,再决定。<span>两天试用</span></h2>
- <p>使用你自己的容器接入 Fmode</p>
- </div>
- <button type="button" class="plans-banner-btn" [disabled]="provision.startBlocked()" (click)="apply('trial')">
- @if (provision.isStarting('trial')) {
- <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
- 生成中…
- } @else {
- 开始两天试用
- }
- </button>
- </section>
- }
- @if (provision.error(); as err) {
- <p class="plans-error"><i class="fa-solid fa-circle-exclamation" aria-hidden="true"></i> {{ (err) | userNotice:'暂时无法确认开通结果,请先查看已有申请。':'verify-result' }}</p>
- @if (provision.recoveryFailed()) {
- <button type="button" class="plans-banner-btn" (click)="provision.restorePending()">重新检查开通任务</button>
- @if (provision.pendingStartRetryAvailable()) {
- <button type="button" class="plans-banner-btn" [disabled]="provision.starting()" (click)="provision.retryPendingStart()">安全重试原申请</button>
- }
- }
- }
- <div class="plans-section-head">
- <h2>为下一步,准备合适的空间</h2>
- <p>个人专属 · 企业共享 · 按需增配</p>
- </div>
- <div class="plans-grid">
- @for (item of plans(); track item.code) {
- <article class="plan-card" [class.plan-card--featured]="item.recommended">
- @if (item.recommended) {
- <span class="plan-ribbon">推荐</span>
- }
- <div class="plan-icon">
- <i [class]="iconOf(item.code)" aria-hidden="true"></i>
- </div>
- <h3>{{ item.name }}</h3>
- <p class="plan-tagline">{{ item.tagline }}</p>
- <div class="plan-price">
- <strong>价格待定</strong>
- @if (item.billingUnit) {
- <span>{{ item.billingUnit }}</span>
- }
- </div>
- <p class="plan-billing">{{ item.billingNote }}</p>
- <button
- type="button"
- class="plan-cta"
- [class.plan-cta--primary]="item.recommended"
- [disabled]="provision.startBlocked()"
- (click)="apply(item.code)"
- >
- <!-- 🔴 只在本档提交时转,不是所有卡片一起转 -->
- @if (provision.isStarting(item.code)) {
- <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
- 提交中…
- } @else {
- 立即开通
- }
- </button>
- <ul class="plan-features">
- @for (f of item.features; track f) {
- <li><i class="fa-solid fa-check" aria-hidden="true"></i><span>{{ f }}</span></li>
- }
- </ul>
- </article>
- }
- </div>
- <p class="plans-note">
- <i class="fa-solid fa-circle-info" aria-hidden="true"></i>
- <span>具体价格请咨询客服。提交申请后由工作人员联系确认,确认前不会产生费用。</span>
- </p>
- <app-renewal-guide />
- <div class="plans-links">
- <section class="plans-link-card">
- <i class="fa-solid fa-server" aria-hidden="true"></i>
- <div>
- <h3>我的容器</h3>
- <p>查看已有的容器与名额使用情况</p>
- </div>
- <button type="button" class="plans-link-btn" (click)="go('/desktop/my-containers')">查看</button>
- </section>
- <section class="plans-link-card">
- <i class="fa-solid fa-shield-halved" aria-hidden="true"></i>
- <div>
- <h3>数据为你保留</h3>
- <p>试用结束后,开通套餐即可继续使用原有容器</p>
- </div>
- </section>
- </div>
- </div>
- <!--
- 🔴 全屏加载遮罩(2026-11-27)
- 用户反馈「点开通感觉像卡死」—— 请求要 1-3 秒,只有按钮变字在大屏上看不出来。
- 遮罩同时起两个作用:① 明确告知正在进行 ② 阻断误点
- -->
- <!--
- 开通命名确认弹窗(2026-12-03)。
- 🔴 不能复用 app-prompt-modal:/plans 是顶层路由、不在 shell 内。
- -->
- @if (confirmOpen()) {
- <app-provision-confirm
- [planName]="pendingPlanName()"
- [isOnboarding]="pendingIsOnboarding()"
- [quota]="pendingQuota()"
- [quotaUsed]="existingNames().length"
- [existingNames]="existingNames()"
- [busy]="submitting()"
- (confirm)="onNameConfirmed($event)"
- (cancel)="cancelConfirm()"
- />
- }
- @if (loadingHint(); as hint) {
- <app-loading-overlay [message]="hint.message" [hint]="hint.detail" />
- }
- `,
- styles: [`
- /* 名额已满提示(2026-12-03):内联在页面顶部,不遮挡操作 */
- .quota-full {
- display: flex;
- flex-direction: column;
- gap: var(--sp-1);
- margin: 0 0 var(--sp-4);
- padding: var(--sp-4);
- border: 1px solid var(--warning);
- border-radius: var(--r-md, 10px);
- background: var(--surface-2);
- color: var(--ink-2);
- font-size: var(--fs-13);
- }
- .quota-full p {
- margin: 0;
- line-height: 1.55;
- }
- .quota-full button {
- align-self: flex-start;
- min-height: 36px;
- margin-top: var(--sp-2);
- padding: 0 var(--sp-4);
- border: 1px solid var(--edge);
- border-radius: var(--r-sm, 6px);
- background: var(--surface);
- color: var(--ink);
- font: inherit;
- font-size: var(--fs-13);
- cursor: pointer;
- }
- :host {
- display: block;
- height: 100%;
- overflow-y: auto;
- }
- .plans-page {
- max-width: 1120px;
- margin: 0 auto;
- padding: var(--sp-8);
- }
- .plans-eyebrow {
- display: flex;
- align-items: center;
- gap: var(--sp-2);
- margin: 0 0 var(--sp-2);
- color: var(--muted);
- font-size: var(--fs-12);
- }
- .plans-head h1 {
- margin: 0;
- font-size: var(--fs-26);
- font-weight: 600;
- letter-spacing: -0.04em;
- }
- .plans-lead {
- margin: var(--sp-2) 0 0;
- color: var(--muted);
- font-size: var(--fs-14);
- }
- /* ---------- 横幅 ---------- */
- .plans-banner {
- display: flex;
- align-items: center;
- gap: var(--sp-5);
- margin: var(--sp-6) 0;
- padding: var(--sp-6);
- border: 1px solid var(--edge-strong);
- border-radius: var(--r-lg);
- background: var(--surface);
- }
- .plans-banner--pending {
- align-items: flex-start;
- border-color: var(--edge);
- background: var(--warning-subtle);
- }
- .plans-banner--pending > i {
- margin-top: 3px;
- color: var(--warning);
- }
- /* 真实阶段进度条:源自 Agent 写库的 step 记录,不是估算 */
- .plans-progress {
- width: 100%;
- max-width: 320px;
- height: 4px;
- margin-top: var(--sp-3);
- border-radius: 999px;
- background: var(--surface-2);
- overflow: hidden;
- }
- .plans-progress-bar {
- display: block;
- height: 100%;
- border-radius: inherit;
- background: var(--primary);
- transition: width 200ms cubic-bezier(0.2, 0, 0, 1);
- }
- @media (prefers-reduced-motion: reduce) {
- .plans-progress-bar {
- transition: none;
- }
- }
- .plans-banner-icon {
- display: grid;
- width: 48px;
- height: 48px;
- flex: none;
- place-items: center;
- border: 1px solid var(--edge);
- border-radius: var(--r-lg);
- background: var(--surface-2);
- color: var(--primary);
- font-size: var(--fs-20);
- }
- .plans-banner-body {
- flex: 1;
- min-width: 0;
- }
- .plans-banner h2 {
- display: flex;
- align-items: center;
- gap: var(--sp-3);
- margin: 0;
- font-size: var(--fs-20);
- font-weight: 600;
- letter-spacing: -0.02em;
- }
- .plans-banner h2 > span {
- padding: 1px 7px;
- border-radius: var(--r-sm);
- background: var(--success-subtle);
- color: var(--success);
- font-size: var(--fs-11);
- font-weight: 500;
- }
- .plans-banner p {
- margin: var(--sp-2) 0 0;
- color: var(--muted);
- font-size: var(--fs-13);
- }
- .plans-banner-btn {
- flex: none;
- min-height: 44px;
- padding: 0 var(--sp-5);
- border: 0;
- border-radius: var(--r-md);
- background: var(--primary);
- color: var(--primary-content);
- font: inherit;
- font-size: var(--fs-14);
- font-weight: 500;
- cursor: pointer;
- }
- /* ---------- 三列卡 ---------- */
- .plans-section-head {
- display: flex;
- align-items: baseline;
- justify-content: space-between;
- gap: var(--sp-4);
- margin-bottom: var(--sp-4);
- }
- .plans-section-head h2 {
- margin: 0;
- font-size: var(--fs-17);
- font-weight: 600;
- }
- .plans-section-head p {
- margin: 0;
- color: var(--muted);
- font-size: var(--fs-12);
- }
- .plans-grid {
- display: grid;
- grid-template-columns: repeat(3, minmax(0, 1fr));
- gap: var(--sp-4);
- }
- .plan-card {
- position: relative;
- display: flex;
- flex-direction: column;
- padding: var(--sp-6);
- border: 1px solid var(--edge);
- border-radius: var(--r-lg);
- background: var(--surface);
- }
- .plan-card--featured {
- border-color: var(--primary);
- box-shadow: inset 0 0 0 1px var(--primary);
- }
- .plan-ribbon {
- position: absolute;
- top: -11px;
- left: var(--sp-5);
- padding: 2px 9px;
- border-radius: var(--r-sm);
- background: var(--primary);
- color: var(--primary-content);
- font-size: var(--fs-11);
- white-space: nowrap;
- }
- .plan-icon {
- display: grid;
- width: 36px;
- height: 36px;
- margin-bottom: var(--sp-4);
- place-items: center;
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface-2);
- color: var(--ink-2);
- }
- .plan-card h3 {
- margin: 0;
- font-size: var(--fs-20);
- font-weight: 600;
- }
- .plan-tagline {
- margin: 5px 0 0;
- color: var(--muted);
- font-size: var(--fs-13);
- }
- .plan-price {
- display: flex;
- align-items: baseline;
- gap: 7px;
- margin: var(--sp-6) 0 var(--sp-1);
- }
- .plan-price strong {
- font-size: var(--fs-26);
- font-weight: 600;
- letter-spacing: -0.04em;
- }
- .plan-price span {
- color: var(--muted);
- font-size: var(--fs-12);
- }
- .plan-billing {
- min-height: 24px;
- margin: 0;
- color: var(--muted);
- font-size: var(--fs-12);
- }
- .plan-cta {
- width: 100%;
- min-height: 44px;
- margin-top: var(--sp-4);
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface);
- color: var(--ink);
- font: inherit;
- font-size: var(--fs-14);
- font-weight: 500;
- cursor: pointer;
- }
- .plan-cta--primary {
- border-color: transparent;
- background: var(--primary);
- color: var(--primary-content);
- }
- .plan-cta:disabled {
- opacity: 0.5;
- cursor: not-allowed;
- }
- .plan-features {
- display: flex;
- flex-direction: column;
- gap: var(--sp-3);
- margin: var(--sp-6) 0 0;
- padding: var(--sp-5) 0 0;
- border-top: 1px solid var(--edge);
- list-style: none;
- }
- .plan-features li {
- display: flex;
- align-items: flex-start;
- gap: var(--sp-2);
- color: var(--ink-2);
- font-size: var(--fs-13);
- line-height: 1.6;
- }
- .plan-features i {
- margin-top: 4px;
- color: var(--muted);
- font-size: var(--fs-11);
- }
- .plans-code {
- max-height: 200px;
- overflow: auto;
- margin: var(--sp-3) 0 0;
- padding: var(--sp-3);
- border: 1px solid var(--edge);
- border-radius: var(--r-sm);
- background: var(--surface-2);
- color: var(--ink-2);
- font-family: ui-monospace, Consolas, monospace;
- font-size: var(--fs-12);
- line-height: 1.6;
- white-space: pre-wrap;
- overflow-wrap: anywhere;
- }
- .plans-error {
- display: flex;
- align-items: flex-start;
- gap: var(--sp-2);
- margin: 0 0 var(--sp-4);
- color: var(--danger);
- font-size: var(--fs-13);
- }
- .plans-note {
- display: flex;
- align-items: flex-start;
- gap: var(--sp-2);
- margin: var(--sp-5) 0 var(--sp-8);
- color: var(--muted);
- font-size: var(--fs-12);
- }
- .plans-note > i {
- margin-top: 3px;
- }
- /* ---------- 当前资产概览(2026-12-02) ---------- */
- .plans-status {
- display: grid;
- grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
- gap: var(--sp-5);
- align-items: center;
- margin: 0 0 var(--sp-5);
- padding: var(--sp-4) var(--sp-5);
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface);
- }
- .plans-status-item {
- display: flex;
- flex-direction: column;
- gap: 2px;
- min-width: 0;
- }
- .plans-status-label {
- font-size: var(--fs-12);
- color: var(--muted);
- }
- .plans-status-value {
- font-size: var(--fs-20);
- font-weight: 600;
- color: var(--ink);
- font-variant-numeric: tabular-nums;
- }
- .plans-status-hint {
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- font-size: var(--fs-12);
- color: var(--faint);
- }
- .plans-status-actions {
- display: flex;
- gap: var(--sp-2);
- }
- .plans-status-btn {
- display: inline-flex;
- align-items: center;
- gap: var(--sp-1);
- min-height: 40px;
- padding: 0 var(--sp-4);
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface);
- color: var(--ink);
- font: inherit;
- font-size: var(--fs-13);
- cursor: pointer;
- }
- .plans-status-btn:hover {
- background: var(--surface-hover);
- }
- .plans-status-btn--primary {
- border-color: var(--primary);
- background: var(--primary);
- color: var(--inverse);
- }
- .plans-status-btn--primary:hover {
- background: var(--primary);
- opacity: 0.92;
- }
- .plans-status-btn:disabled {
- opacity: 0.5;
- cursor: not-allowed;
- }
- @media (max-width: 1100px) {
- .plans-status {
- grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
- }
- .plans-status-actions {
- grid-column: 1 / -1;
- }
- }
- /* ---------- 底部链接 ---------- */
- .plans-links {
- display: grid;
- grid-template-columns: 1fr 1fr;
- gap: var(--sp-4);
- }
- .plans-link-card {
- display: flex;
- align-items: center;
- gap: var(--sp-3);
- padding: var(--sp-4) var(--sp-5);
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface);
- }
- .plans-link-card > i {
- color: var(--muted);
- font-size: var(--fs-17);
- }
- .plans-link-card > div {
- flex: 1;
- min-width: 0;
- }
- .plans-link-card h3 {
- margin: 0;
- font-size: var(--fs-14);
- font-weight: 500;
- }
- .plans-link-card p {
- margin: 3px 0 0;
- color: var(--muted);
- font-size: var(--fs-12);
- }
- .plans-link-btn {
- flex: none;
- min-height: 44px;
- padding: 0 var(--sp-4);
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface);
- color: var(--ink);
- font: inherit;
- font-size: var(--fs-13);
- cursor: pointer;
- }
- `,
- ],
- })
- export class DkPlansPage implements OnInit {
- protected readonly plan = inject(PlanService);
- protected readonly live = inject(LiveService);
- /* 命名确认弹窗状态(2026-12-03) */
- protected readonly confirmOpen = signal(false);
- protected readonly pendingCode = signal<PaidPlanCode | 'trial' | null>(null);
- protected readonly submitting = signal(false);
- /** 名额已满提示(2026-12-03)。null = 不显示 */
- protected readonly quotaFull = signal<{ plan: string; quota: number } | null>(null);
- protected readonly provision = inject(ProvisionService);
- private readonly router = inject(Router);
- ngOnInit(): void {
- void this.provision.restorePending();
- }
- protected readonly plans = computed(() => this.plan.catalog);
- /** 运行中的容器数(资产概览用;状态口径与通讯录一致) */
- protected readonly runningCount = computed(
- () => this.live.agents().filter((a) => a.status === 'running' || a.status === 'idle').length,
- );
- /**
- * 当前套餐名。
- *
- * 🔴 不从容器数量反推档位(2026-12-02 自查):2 个容器可能是「入门版 + 加购」,
- * 也可能是进阶版送的名额,数量推不出套餐 —— 猜错比不说更糟。
- * PlanService 暂无「当前订阅」字段,这里如实显示「已开通」;
- * 接入订阅接口后替换为真实套餐名。
- */
- protected readonly currentPlanName = computed(() =>
- this.live.agents().length > 0 ? '已开通' : '尚未开通',
- );
- /**
- * 全屏加载遮罩的文案(null = 不显示)。
- *
- * 🔴 区分两种慢操作,因为用户等待时的心理预期完全不同:
- * · 试用档生成提示词 → 要建 Matrix 身份,首次可能需要十秒左右
- * · 进阶/企业开通 → 只受理,很快,之后跳等待页
- */
- protected readonly loadingHint = computed<{ message: string; detail: string } | null>(() => {
- if (this.provision.restoring()) return { message: '正在检查开通任务…', detail: '正在找回已有进度,请稍候' };
- const p = this.provision.startingPlan();
- if (!p) return null;
- if (p === 'trial' || p === 'starter') {
- return { message: '正在准备接入信息…', detail: '首次生成可能需要 10 秒左右,请稍候' };
- }
- return { message: '正在提交开通申请…', detail: '马上就好' };
- });
- protected iconOf(code: PaidPlanCode): string {
- switch (code) {
- case 'starter':
- return 'fa-solid fa-server';
- case 'advanced':
- return 'fa-solid fa-wand-magic-sparkles';
- case 'enterprise':
- return 'fa-solid fa-building';
- default:
- return 'fa-solid fa-cube';
- }
- }
- /**
- * 发起开通。
- *
- * 🔴 只发起请求,不承诺结果:
- * · 试用/入门 → 后端返回接入提示词(用户自己的容器)
- * · 进阶/企业 → 后端真实创建,进入轮询态
- */
- /**
- * 发起开通(2026-11-27 改造)
- *
- * 与移动端同源逻辑:试用/入门留在本页给提示词,进阶/企业跳全屏等待页。
- */
- protected apply(code: PaidPlanCode | 'trial'): void {
- if (this.provision.isRunning()) return;
- /*
- * 名额已满就别让用户填名字了(2026-12-03)。
- * 在弹窗之前拦,而不是等提交后云函数返回 409 ——
- * 「认真填完名字才被告知名额已满」是很差的体验。
- */
- const quota = code === 'trial' ? 1 : (this.plan.planOf(code as never)?.quota ?? 0);
- if (quota > 0 && this.existingNames().length >= quota) {
- this.quotaFull.set({ plan: this.plan.planOf(code as never)?.name || '该套餐', quota });
- return;
- }
- /* 先弹命名确认(用户裁决 2026-12-03),不再直接提交 */
- this.pendingCode.set(code);
- this.confirmOpen.set(true);
- }
- /** 命名确认后真正提交;`name` 已由弹窗校验并 NFKC 归一化 */
- protected async onNameConfirmed(name: string): Promise<void> {
- const code = this.pendingCode();
- if (!code) return;
- this.submitting.set(true);
- try {
- const result = await this.provision.start(code, name);
- this.confirmOpen.set(false);
- this.pendingCode.set(null);
- if (result?.mode === 'provision' && result.jobId) {
- await this.router.navigateByUrl(`/provision?jobId=${encodeURIComponent(result.jobId)}`, {
- replaceUrl: true,
- });
- }
- } finally {
- this.submitting.set(false);
- }
- }
- protected cancelConfirm(): void {
- this.confirmOpen.set(false);
- this.pendingCode.set(null);
- }
- protected readonly pendingPlanName = computed(() => {
- const c = this.pendingCode();
- if (!c) return '';
- if (c === 'trial') return '试用';
- return this.plan.planOf(c as PaidPlanCode)?.name ?? '套餐';
- });
- protected readonly pendingIsOnboarding = computed(() => {
- const c = this.pendingCode();
- return c === 'trial' || c === 'starter';
- });
- protected readonly pendingQuota = computed(() => {
- const c = this.pendingCode();
- if (!c || c === 'trial') return 1;
- return this.plan.planOf(c as PaidPlanCode)?.quota ?? 0;
- });
- protected readonly existingNames = computed(() =>
- this.live.agents().map((a) => a.name).filter((n): n is string => !!n),
- );
- protected readonly suggestedName = computed(() => suggestContainerName(this.existingNames()));
- protected go(path: string): void {
- void this.router.navigateByUrl(path);
- }
- }
|