| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964 |
- import { UserNoticePipe } from '../../../components/feedback/user-notice.pipe';
- import { ChangeDetectionStrategy, Component, computed, inject, OnInit, signal } from '@angular/core';
- import { Router } from '@angular/router';
- import { PlanCode } from '../../../core/api/models';
- import { BILLING_OPTIONS, BillingPeriod, DEFAULT_BILLING, billingDays } from '../../../core/billing-period';
- import { PlanService } from '../../../core/plan.service';
- import { ProvisionService } from '../../../core/provision.service';
- import { LiveService } from '../../../core/live.service';
- import { LoadingOverlayComponent } from '../../../components/domain/loading-overlay/loading-overlay';
- import { ProvisionInstructionComponent } from '../../../components/domain/provision-instruction/provision-instruction';
- import { MAppBarComponent } from '../../components/m-app-bar/m-app-bar';
- import { MDrawerComponent } from '../../components/m-drawer/m-drawer';
- import { ProvisionConfirmComponent } from '../../../components/domain/provision-confirm/provision-confirm';
- import { suggestContainerName } from '../../../components/domain/provision-confirm/container-name';
- /**
- * 移动端套餐与开通(2026-11-25)
- *
- * ## 三档三条路径(用户裁决)
- *
- * 试用 / 入门 → 后端返回**接入提示词**,用户在自己容器里执行(平台不建容器)
- * 进阶 / 企业 → 后端**真实创建**(DM 主容器 → R730 docker run),前端轮询进度
- *
- * ## 🔴 状态真实性
- *
- * 点「开通」只代表**发起请求**。「已就绪」只认后端服务端核验结果
- * (容器记录 + Matrix joined + 心跳新鲜),不靠计时器、不靠主容器自述。
- *
- * ## 布局
- *
- * 移动端窄屏用**一行三列紧凑选择卡**,整组约 220px;
- * 桌面端用完整详情卡,两端独立设计。
- */
- @Component({
- selector: 'app-mb-plans-page',
- changeDetection: ChangeDetectionStrategy.OnPush,
- imports: [UserNoticePipe, MAppBarComponent, MDrawerComponent, ProvisionInstructionComponent, LoadingOverlayComponent, ProvisionConfirmComponent],
- template: `
- <div class="m-page--scroll">
- <!-- 返回(2026-12-03):套餐页多为门禁跳转进来的,必须能退回去 -->
- <app-m-app-bar title="套餐与开通" [back]="true" (backTap)="goBack()" [menu]="true" (menuTap)="drawerOpen.set(true)" />
- <!-- 名额已满提示(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>
- }
- <!-- 试用到期提示(2026-12-03):被门禁送回本页的用户要知道为什么 -->
- @if (trialExpiredName(); as expired) {
- <div class="quota-full quota-full--expired" role="alert">
- <p>「{{ expired }}」的两天试用已到期。</p>
- <p>开通入门版(本地容器 + App)或进阶版(平台容器)后即可继续使用;到期后数据保留 7 天,7 天后容器与数据将被回收。</p>
- </div>
- }
- <div class="m-body">
- <!--
- 🔴 生成中提示条(2026-11-27)
- 试用/入门档要调云函数建 Matrix 身份 + 算密码,1-3 秒。
- 只转按钮在手机上根本看不出反馈,这里给一条明确的进度提示。
- -->
- @if (generating()) {
- <div class="plans-loading" role="status" aria-live="polite">
- <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
- <span>正在准备接入信息,首次生成可能需要 10 秒左右…</span>
- </div>
- }
- <!--
- 🔴 提示词区块独立渲染(2026-11-27 修)
- 原来它和「开通进度」是 @if / @else if 互斥分支:
- 点「进阶开通」的瞬间 hasJob() 变 true,提示词区块**立即消失**,
- 用户手上正在复制的参数就没了。两者本来就可以同时存在。
- -->
- @if (provision.instruction(); as ins) {
- <app-provision-instruction [text]="ins" />
- }
- <!-- 开通进行中:显示真实状态 -->
- @if (provision.hasJob()) {
- <section class="plans-job" [class.plans-job--ready]="provision.isReady()" [class.plans-job--failed]="provision.isFailed()">
- <i class="fa-solid"
- [class]="provision.isReady() ? 'fa-circle-check' : provision.isFailed() ? 'fa-triangle-exclamation' : 'fa-spinner fa-spin'"
- aria-hidden="true"></i>
- <div class="plans-job-body">
- <strong>{{ provision.statusText() }}</strong>
- <p>{{ (provision.isFailed() ? provision.failureMessage() : '容器创建由平台自动完成,可以离开页面,完成后回来查看。') | userNotice:'暂时无法确认开通结果,请先查看已有申请。':'verify-result' }}</p>
- </div>
- </section>
- <div class="plans-job-actions">
- @if (provision.isFailed() && provision.canRetry()) {
- <button type="button" class="plans-job-btn" (click)="provision.retry()">重试</button>
- } @else if (provision.isFailed()) {
- <button type="button" class="plans-job-btn" (click)="go('/plans')">查看套餐升级</button>
- } @else if (!provision.isReady()) {
- <button type="button" class="plans-job-btn" (click)="go('/provision', provision.current()?.jobId)">查看开通进度</button>
- } @else {
- <button type="button" class="plans-job-btn plans-job-btn--primary" (click)="go('/mobile/contacts')">查看我的容器</button>
- }
- </div>
- }
- <!-- 什么都没有时:试用横幅 -->
- @if (!provision.hasJob() && !provision.instruction()) {
- <section class="plans-trial">
- <div class="plans-trial-icon"><i class="fa-solid fa-wand-magic-sparkles" aria-hidden="true"></i></div>
- <div class="plans-trial-body">
- <h2>先体验,再决定<span>两天试用</span></h2>
- <p>用你自己的 Hermes 接入 Fmode:<b>本机直接安装</b>或 <b>Docker 容器</b>均可</p>
- </div>
- <button type="button" class="plans-trial-btn" (click)="apply('trial')" [disabled]="provision.startBlocked() || trialUsed()">
- @if (provision.isStarting('trial')) {
- <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
- 生成中…
- } @else {
- {{ trialUsed() ? '已使用过试用' : '开始试用' }}
- }
- </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-job-btn" (click)="provision.restorePending()">重新检查开通任务</button>
- @if (provision.pendingStartRetryAvailable()) {
- <button type="button" class="plans-job-btn" [disabled]="provision.starting()" (click)="provision.retryPendingStart()">安全重试原申请</button>
- }
- }
- }
- <h2 class="plans-heading">为下一步,准备合适的空间</h2>
- <p class="plans-sub">个人专属 · 企业共享 · 按需增配</p>
- <!-- 一行三列紧凑卡 -->
- <div class="plans-grid">
- @for (plan of plans(); track plan.code) {
- <article class="plan-card" [class.plan-card--featured]="plan.recommended">
- @if (plan.recommended) {
- <span class="plan-badge">推荐</span>
- }
- <i class="plan-icon" [class]="iconOf(plan.code)" aria-hidden="true"></i>
- <h3>{{ plan.shortName }}</h3>
- <!-- 额度(2026-12-03 用户裁决 B):只显示上限;超额仍禁止开通;企业版不显示 -->
- @if (!plan.contactOnly && plan.quota > 0) {
- <p class="plan-quota"><strong>{{ plan.quota }}</strong><span>{{ plan.quotaLabel }}</span></p>
- }
- @if (plan.contactOnly) {
- <!-- 企业版(2026-12-03 用户裁决):不显示数量与价格,联系客服定制 -->
- <a class="plan-contact" href="tel:400-000-0000" target="_blank" rel="noopener">
- <i class="fa-solid fa-phone" aria-hidden="true"></i> 客服 400-000-0000
- </a>
- } @else {
- <!-- 付费时长三档(2026-12-03 用户裁决:月/季/年,默认月 30 天;价格仍待定不出现金额) -->
- <div class="plan-periods" role="radiogroup" [attr.aria-label]="plan.name + ' 计费周期'">
- @for (opt of billingOptions; track opt.value) {
- <button type="button" role="radio"
- [attr.aria-checked]="billingOf(plan.code) === opt.value"
- [class.on]="billingOf(plan.code) === opt.value"
- (click)="setBilling(plan.code, opt.value)">{{ opt.label }}</button>
- }
- </div>
- <p class="plan-price">价格待定</p>
- <p class="plan-unit">按{{ periodLabel(plan.code) }}开通 · {{ periodDays(plan.code) }} 天</p>
- }
- @if (plan.contactOnly) {
- <a class="plan-btn plan-btn--contact" href="mailto:contact@fmode.cn?subject=企业版定制咨询" target="_blank" rel="noopener">联系客服</a>
- } @else {
- <button
- type="button"
- class="plan-btn"
- [disabled]="provision.startBlocked()"
- (click)="apply(plan.code)"
- >
- <!-- 🔴 只在本档提交时转,不能所有卡片一起转(2026-11-27 修) -->
- @if (provision.isStarting(plan.code)) {
- <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
- 提交中…
- } @else {
- {{ ctaText(plan.code) }}
- }
- </button>
- }
- </article>
- }
- </div>
- <p class="plans-note">
- <i class="fa-solid fa-circle-info" aria-hidden="true"></i>
- <span>具体价格请咨询客服。试用与入门使用你自己的容器;进阶与企业由平台创建。</span>
- </p>
- <h2 class="plans-heading">权益说明</h2>
- <div class="plans-detail">
- @for (plan of plans(); track plan.code) {
- <section class="plans-detail-row">
- <h3>{{ plan.name }}</h3>
- <p class="plans-detail-quota">{{ plan.mobileQuota }}</p>
- <p class="plans-detail-benefit">{{ plan.mobileBenefit }}</p>
- </section>
- }
- </div>
- <div class="plans-links">
- <button type="button" class="plans-link" (click)="go('/mobile/contacts')">
- <i class="fa-solid fa-server" aria-hidden="true"></i>
- <span>我的容器</span>
- <i class="fa-solid fa-chevron-right" aria-hidden="true"></i>
- </button>
- </div>
- </div>
- </div>
- <app-m-drawer [open]="drawerOpen()" (close)="drawerOpen.set(false)" />
- <!--
- 开通命名确认弹窗(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()"
- />
- }
- <!-- 全屏加载遮罩:明确告知正在进行 + 阻断误点(2026-11-27) -->
- @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--expired {
- /* 试用到期(2026-12-03):与「名额已满」同位置不同措辞,不用按钮(去开通就是点下方套餐) */
- background: var(--warning-subtle);
- }
- .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%;
- }
- /*
- * 固定外壳 + 内部滚动(2026-12-02 修,对齐 mine.ts 模式):
- * /plans 是顶层路由、不在 mobile-shell 内,全局 .m-page--scroll 不生效,
- * 必须本地补齐——否则顶栏跟着内容一起滚走。
- * 顶层页无 TabBar,底部只留安全区。
- */
- .m-page--scroll {
- display: flex;
- flex-direction: column;
- height: 100dvh;
- box-sizing: border-box;
- padding-bottom: var(--mob-safe-bottom);
- }
- .m-body {
- flex: 1;
- min-height: 0;
- overflow-y: auto;
- -webkit-overflow-scrolling: touch;
- overscroll-behavior: contain;
- padding: var(--sp-4);
- padding-bottom: var(--sp-6);
- }
- /* ---------- 生成中提示条(2026-11-27) ---------- */
- /* 试用档要调云函数 1-3 秒,只转按钮在手机上看不出反馈 */
- .plans-loading {
- display: flex;
- align-items: center;
- gap: var(--sp-2);
- margin-bottom: var(--sp-4);
- padding: var(--sp-3) var(--sp-4);
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--primary-subtle, var(--surface-2));
- color: var(--ink-2);
- font-size: var(--fs-12);
- line-height: 1.6;
- }
- .plans-loading > i {
- flex: none;
- color: var(--primary);
- }
- /* ---------- 试用横幅 ---------- */
- .plans-trial {
- display: flex;
- align-items: center;
- gap: var(--sp-3);
- padding: var(--sp-4);
- margin-bottom: var(--sp-5);
- border: 1px solid var(--edge);
- border-radius: var(--r-lg);
- background: var(--surface);
- }
- .plans-trial-icon {
- display: grid;
- width: 36px;
- height: 36px;
- flex: none;
- place-items: center;
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface-2);
- color: var(--primary);
- }
- .plans-trial-body {
- flex: 1;
- min-width: 0;
- }
- .plans-trial-body h2 {
- display: flex;
- align-items: center;
- gap: var(--sp-2);
- margin: 0;
- font-size: var(--fs-15);
- font-weight: 600;
- }
- .plans-trial-body h2 > span {
- padding: 1px 6px;
- border-radius: var(--r-sm);
- background: var(--success-subtle);
- color: var(--success);
- font-size: var(--fs-11);
- font-weight: 500;
- }
- .plans-trial-body p {
- margin: var(--sp-1) 0 0;
- color: var(--muted);
- font-size: var(--fs-12);
- }
- .plans-trial-btn {
- flex: none;
- min-height: 44px;
- padding: 0 var(--sp-3);
- border: 0;
- border-radius: var(--r-md);
- background: var(--primary);
- color: var(--primary-content);
- font: inherit;
- font-size: var(--fs-13);
- font-weight: 500;
- cursor: pointer;
- }
- /* ---------- 待确认横幅 ---------- */
- /* ---------- 开通进行中 / 提示词 ---------- */
- .plans-job {
- display: flex;
- align-items: flex-start;
- gap: var(--sp-3);
- padding: var(--sp-4);
- margin-bottom: var(--sp-3);
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface);
- }
- .plans-job > i {
- margin-top: 2px;
- color: var(--primary);
- font-size: var(--fs-15);
- }
- .plans-job--ready > i {
- color: var(--success);
- }
- .plans-job--failed > i {
- color: var(--warning);
- }
- .plans-job-body {
- flex: 1;
- min-width: 0;
- }
- .plans-job-body strong {
- display: block;
- font-size: var(--fs-14);
- font-weight: 600;
- }
- .plans-job-body p {
- margin: var(--sp-1) 0 0;
- color: var(--muted);
- font-size: var(--fs-12);
- }
- .plans-job-actions {
- margin-bottom: var(--sp-4);
- }
- .plans-job-btn {
- width: 100%;
- min-height: 44px;
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface);
- color: var(--ink);
- font: inherit;
- font-size: var(--fs-14);
- cursor: pointer;
- }
- .plans-job-btn--primary {
- border-color: transparent;
- background: var(--primary);
- color: var(--primary-content);
- font-weight: 500;
- }
- .plans-instruction {
- padding: var(--sp-4);
- margin-bottom: var(--sp-4);
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface);
- }
- .plans-instruction h2 {
- display: flex;
- align-items: center;
- gap: var(--sp-2);
- margin: 0;
- font-size: var(--fs-15);
- font-weight: 600;
- }
- .plans-instruction h2 > i {
- color: var(--primary);
- }
- .plans-instruction > p {
- margin: var(--sp-2) 0 var(--sp-3);
- color: var(--muted);
- font-size: var(--fs-12);
- }
- .plans-instruction-code {
- max-height: 220px;
- overflow: auto;
- margin: 0 0 var(--sp-3);
- 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-11);
- 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-12);
- }
- .plans-error > i {
- margin-top: 2px;
- }
- .plans-pending {
- display: flex;
- align-items: flex-start;
- gap: var(--sp-3);
- padding: var(--sp-3) var(--sp-4);
- margin-bottom: var(--sp-5);
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--warning-subtle);
- color: var(--ink);
- }
- .plans-pending > i {
- margin-top: 3px;
- color: var(--warning);
- }
- .plans-pending strong {
- display: block;
- font-size: var(--fs-14);
- font-weight: 600;
- }
- .plans-pending p {
- margin: 2px 0 0;
- color: var(--muted);
- font-size: var(--fs-12);
- }
- /* ---------- 标题 ---------- */
- .plans-heading {
- margin: 0;
- font-size: var(--fs-15);
- font-weight: 600;
- }
- .plans-sub {
- margin: var(--sp-1) 0 var(--sp-4);
- color: var(--muted);
- font-size: var(--fs-12);
- }
- /* ---------- 一行三列紧凑卡 ---------- */
- .plans-grid {
- display: grid;
- grid-template-columns: repeat(3, minmax(0, 1fr));
- gap: var(--sp-2);
- }
- .plan-card {
- position: relative;
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: var(--sp-3) var(--sp-2);
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface);
- text-align: center;
- }
- .plan-card--featured {
- border-color: var(--primary);
- box-shadow: inset 0 0 0 1px var(--primary);
- }
- .plan-card--applied {
- opacity: 0.62;
- }
- .plan-badge {
- position: absolute;
- top: -8px;
- left: 50%;
- padding: 1px 7px;
- border-radius: var(--r-sm);
- background: var(--primary);
- color: var(--primary-content);
- font-size: var(--fs-10, 11px);
- white-space: nowrap;
- transform: translateX(-50%);
- }
- .plan-icon {
- margin-bottom: var(--sp-2);
- color: var(--muted);
- font-size: var(--fs-17);
- }
- .plan-card h3 {
- margin: 0;
- font-size: var(--fs-14);
- font-weight: 600;
- line-height: 1.3;
- }
- .plan-quota {
- display: flex;
- align-items: baseline;
- gap: 2px;
- margin: var(--sp-2) 0 0;
- line-height: 1.2;
- }
- .plan-quota strong {
- font-size: var(--fs-20);
- font-weight: 600;
- letter-spacing: -0.03em;
- }
- .plan-quota span {
- color: var(--muted);
- font-size: var(--fs-10, 11px);
- }
- .plan-contact {
- display: flex; align-items: center; justify-content: center; gap: 4px;
- margin: var(--sp-2) 0; padding: var(--sp-2);
- border: 1px dashed var(--edge); border-radius: 8px;
- background: var(--surface-2); color: var(--primary);
- font-size: var(--fs-11, 11px); text-decoration: none;
- }
- .plan-btn--contact { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
- .plan-periods {
- display: flex;
- gap: 2px;
- margin: var(--sp-2) 0 0;
- padding: 2px;
- border-radius: 8px;
- background: var(--surface-2);
- }
- .plan-periods button {
- flex: 1;
- min-height: 28px;
- border: 0;
- border-radius: 6px;
- background: transparent;
- color: var(--muted);
- font-size: var(--fs-11, 11px);
- cursor: pointer;
- }
- .plan-periods button.on {
- background: var(--surface);
- color: var(--ink);
- font-weight: 600;
- }
- .plan-price {
- margin: var(--sp-1) 0 0;
- color: var(--ink-2);
- font-size: var(--fs-12);
- font-weight: 500;
- }
- .plan-unit {
- min-height: 15px;
- margin: 0;
- color: var(--muted);
- font-size: var(--fs-10, 11px);
- }
- .plan-btn {
- width: 100%;
- min-height: 44px;
- margin-top: var(--sp-2);
- padding: 0 var(--sp-1);
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface);
- color: var(--ink);
- font: inherit;
- font-size: var(--fs-12);
- font-weight: 500;
- cursor: pointer;
- }
- .plan-card--featured .plan-btn {
- border-color: transparent;
- background: var(--primary);
- color: var(--primary-content);
- }
- .plan-btn:disabled {
- opacity: 0.5;
- cursor: not-allowed;
- }
- .plans-note {
- display: flex;
- align-items: flex-start;
- gap: var(--sp-2);
- margin: var(--sp-3) 0 var(--sp-5);
- color: var(--muted);
- font-size: var(--fs-12);
- }
- .plans-note > i {
- margin-top: 3px;
- }
- /* ---------- 权益明细 ---------- */
- .plans-detail {
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface);
- overflow: hidden;
- }
- .plans-detail-row {
- padding: var(--sp-3) var(--sp-4);
- }
- .plans-detail-row + .plans-detail-row {
- border-top: 1px solid var(--edge);
- }
- .plans-detail-row h3 {
- margin: 0;
- font-size: var(--fs-14);
- font-weight: 600;
- }
- .plans-detail-quota {
- margin: 2px 0 0;
- color: var(--ink-2);
- font-size: var(--fs-12);
- }
- .plans-detail-benefit {
- margin: 2px 0 0;
- color: var(--muted);
- font-size: var(--fs-12);
- }
- /* ---------- 底部链接 ---------- */
- .plans-links {
- margin-top: var(--sp-4);
- border: 1px solid var(--edge);
- border-radius: var(--r-md);
- background: var(--surface);
- overflow: hidden;
- }
- .plans-link {
- display: flex;
- align-items: center;
- gap: var(--sp-3);
- width: 100%;
- min-height: 56px;
- padding: var(--sp-3) var(--sp-4);
- border: 0;
- background: transparent;
- color: var(--ink);
- font: inherit;
- font-size: var(--fs-14);
- text-align: left;
- cursor: pointer;
- }
- .plans-link > i:first-child {
- width: 20px;
- color: var(--primary);
- text-align: center;
- }
- .plans-link > span {
- flex: 1;
- }
- .plans-link > i:last-child {
- color: var(--faint);
- font-size: var(--fs-12);
- }
- `,
- ],
- })
- export class MbPlansPage implements OnInit {
- protected readonly plan = inject(PlanService);
- protected readonly provision = inject(ProvisionService);
- protected readonly live = inject(LiveService);
- private readonly router = inject(Router);
- /* 命名确认弹窗状态(2026-12-03) */
- protected readonly confirmOpen = signal(false);
- protected readonly pendingCode = signal<PlanCode | null>(null);
- protected readonly submitting = signal(false);
- /** 名额已满提示(2026-12-03)。null = 不显示 */
- protected readonly quotaFull = signal<{ plan: string; quota: number } | null>(null);
- ngOnInit(): void {
- void this.provision.restorePending();
- /*
- * 配额预检与重名校验都依赖容器列表(2026-12-03):
- * /plans 是顶层路由不在 shell 内,没人替本页拉 live,
- * 不主动加载 existingNames() 永远是空 —— 配额预检形同虚设、
- * 默认名永远从「我的容器 1」开始。
- */
- void this.live.ensureLoaded();
- }
- protected readonly drawerOpen = signal(false);
- /** 付费三档(试用单独走横幅) */
- /** 是否已有付费套餐(2026-12-03):决定按钮文案「开通 / 续费」;试用不算 */
- protected readonly hasPaidPlan = computed(() =>
- this.live.agents().some((a) => a.planCode === 'starter' || a.planCode === 'advanced' || a.planCode === 'enterprise'),
- );
- protected ctaText(_code: string): string { return this.hasPaidPlan() ? '续费' : '立即开通'; }
- /* 付费时长三档(2026-12-03):每张卡各自记住选择,默认月 */
- protected readonly billingOptions = BILLING_OPTIONS;
- private readonly billingSel = signal<Record<string, BillingPeriod>>({});
- protected billingOf(code: string): BillingPeriod { return this.billingSel()[code] ?? DEFAULT_BILLING; }
- protected setBilling(code: string, v: BillingPeriod): void {
- this.billingSel.update((m) => ({ ...m, [code]: v }));
- }
- protected periodLabel(code: string): string { return BILLING_OPTIONS.find((o) => o.value === this.billingOf(code))?.label ?? '月付'; }
- protected periodDays(code: string): number { return billingDays(this.billingOf(code)); }
- /**
- * 该账号是否已用过试用(2026-12-03 用户裁决:试用与容器数量无关,按账号只一次)。
- * 判据来自云函数派生的 trialUsedAt/trialExpired;用过就禁用试用入口,
- * 后端 `TRIAL_USED` 仍是最终防线。
- */
- protected readonly trialUsed = computed(() =>
- this.live.agents().some((a) => a.planCode === 'trial' || a.trialExpired === true),
- );
- protected readonly plans = computed(() => this.plan.catalog);
- /**
- * 是否正在生成接入提示词(试用/入门档)。
- *
- * 这两档要调云函数建 Matrix 身份 + 算密码,1-3 秒,
- * 期间给一条明确的进度提示(只转按钮在手机上看不出反馈)。
- */
- protected readonly generating = computed(() => {
- const p = this.provision.startingPlan();
- return p === 'trial' || p === 'starter';
- });
- /** 全屏加载遮罩文案(null = 不显示) */
- protected readonly loadingHint = computed<{ message: string; detail: string } | null>(() => {
- /*
- * 🔴 restoring 不再上全屏遮罩(2026-12-03 用户实测反馈):
- * 开通中离开再回 /plans,每次进页都重放一遍「正在检查开通任务…」过场动画。
- * restore 本来就是静默找回——完了有任务就显示 plans-job 区块,没有就无事发生。
- */
- const p = this.provision.startingPlan();
- if (!p) return null;
- if (p === 'trial' || p === 'starter') {
- return { message: '正在准备接入信息…', detail: '首次生成可能需要 10 秒左右,请稍候' };
- }
- return { message: '正在提交开通申请…', detail: '马上就好' };
- });
- protected iconOf(code: PlanCode): 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 改造)
- *
- * 🔴 两条路径分流:
- * · 试用 / 入门 → 后端返回**接入提示词**,留在本页展示(不建容器)
- * · 进阶 / 企业 → 后端**受理并真实创建** → **立刻跳转等待页**(全屏锁定)
- *
- * 跳转前必须 `await` 到 `jobId` 存在 —— 带着 undefined 跳过去,
- * 等待页会拉不到任务,用户看到的是空转。
- */
- /** 返回上一页;直接打开时回会话页(2026-12-03) */
- protected goBack(): void { if (history.length > 1) history.back(); else void this.router.navigateByUrl('/mobile/chat'); }
- protected async apply(code: PlanCode): Promise<void> {
- if (this.provision.isRunning()) return;
- /*
- * 配额判断依赖容器列表;首载还没落地时 existingNames() 是空数组,
- * 直接判会永远放行(2026-12-03 用户实测:已有 2 个容器仍没看到名额提示)。
- * 先等首载完成再校验;加载失败则由服务端配额校验兜底。
- */
- await this.live.ensureLoaded();
- /*
- * 名额已满就别让用户填名字了(2026-12-03)。
- * 在弹窗之前拦,而不是等提交后云函数返回 409 ——
- * 「认真填完名字才被告知名额已满」是很差的体验。
- */
- const quota = code === 'trial' ? 1 : (this.plan.planOf(code as never)?.quota ?? 0);
- /* 超额禁止(2026-12-03 裁决 B):只显示上限,但达到上限仍不允许再开 */
- if (code !== 'trial' && quota > 0 && this.existingNames().length >= quota) {
- this.quotaFull.set({ plan: this.plan.planOf(code as never)?.name || '该套餐', quota });
- return;
- }
- /*
- * 试用不弹命名框(2026-12-03 用户实测纠错):
- * 试用用的是**用户自己的 Hermes**,名字在接入完成后到容器设置里改即可;
- * 让用户「给试用起容器名」既不合理,也会和付费开通的命名弹窗混在一起。
- * 这里自动生成一个不重名的默认名直接提交。
- */
- if (code === 'trial') {
- const auto = suggestContainerName(this.existingNames());
- this.pendingCode.set(code);
- void this.onNameConfirmed(auto);
- return;
- }
- /* 付费档位:先弹命名确认(用户裁决 2026-12-03) */
- this.pendingCode.set(code);
- this.confirmOpen.set(true);
- }
- /**
- * 命名确认后真正提交(2026-12-03)。
- *
- * `name` 来自弹窗,已经过 `validateContainerName` 校验与 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.billingOf(code));
- 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,
- });
- }
- // onboarding 模式(试用/入门):留在本页,由模板渲染提示词
- } catch {
- /*
- * 提交抛错也要关弹窗(2026-12-03):否则弹窗永远盖在页面上,
- * 页面级的错误提示(plans-error)用户根本看不到。
- * 错误本身由 ProvisionService.error() 呈现在页面上。
- */
- this.confirmOpen.set(false);
- this.pendingCode.set(null);
- } finally {
- this.submitting.set(false);
- }
- }
- protected cancelConfirm(): void {
- this.confirmOpen.set(false);
- this.pendingCode.set(null);
- }
- /** 弹窗用:当前pending套餐的信息 */
- protected readonly pendingPlanName = computed(() => {
- const c = this.pendingCode();
- if (!c) return '';
- if (c === 'trial') return '试用';
- return this.plan.planOf(c)?.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)?.quota ?? 0;
- });
- /** 已有容器名(重名校验 + 默认名生成) */
- protected readonly existingNames = computed(() =>
- this.live.agents().map((a) => a.name).filter((n): n is string => !!n),
- );
- /** 已到期的试用容器名(2026-12-03):顶部提示用 */
- protected readonly trialExpiredName = computed(
- () => this.live.agents().find((a) => a.trialExpired === true)?.name ?? '',
- );
- protected readonly suggestedName = computed(() => suggestContainerName(this.existingNames()));
- /** 导航;`jobId` 存在时拼进查询参数(如打开等待页) */
- protected go(path: string, jobId?: string): void {
- const url = jobId ? `${path}?jobId=${encodeURIComponent(jobId)}` : path;
- void this.router.navigateByUrl(url);
- }
- }
|