plans.ts 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. import { UserNoticePipe } from '../../../components/feedback/user-notice.pipe';
  2. import { ChangeDetectionStrategy, Component, computed, inject, OnInit, signal } from '@angular/core';
  3. import { Router } from '@angular/router';
  4. import { PlanCode } from '../../../core/api/models';
  5. import { BILLING_OPTIONS, BillingPeriod, DEFAULT_BILLING, billingDays } from '../../../core/billing-period';
  6. import { PlanService } from '../../../core/plan.service';
  7. import { ProvisionService } from '../../../core/provision.service';
  8. import { LiveService } from '../../../core/live.service';
  9. import { LoadingOverlayComponent } from '../../../components/domain/loading-overlay/loading-overlay';
  10. import { ProvisionInstructionComponent } from '../../../components/domain/provision-instruction/provision-instruction';
  11. import { MAppBarComponent } from '../../components/m-app-bar/m-app-bar';
  12. import { MDrawerComponent } from '../../components/m-drawer/m-drawer';
  13. import { ProvisionConfirmComponent } from '../../../components/domain/provision-confirm/provision-confirm';
  14. import { suggestContainerName } from '../../../components/domain/provision-confirm/container-name';
  15. /**
  16. * 移动端套餐与开通(2026-11-25)
  17. *
  18. * ## 三档三条路径(用户裁决)
  19. *
  20. * 试用 / 入门 → 后端返回**接入提示词**,用户在自己容器里执行(平台不建容器)
  21. * 进阶 / 企业 → 后端**真实创建**(DM 主容器 → R730 docker run),前端轮询进度
  22. *
  23. * ## 🔴 状态真实性
  24. *
  25. * 点「开通」只代表**发起请求**。「已就绪」只认后端服务端核验结果
  26. * (容器记录 + Matrix joined + 心跳新鲜),不靠计时器、不靠主容器自述。
  27. *
  28. * ## 布局
  29. *
  30. * 移动端窄屏用**一行三列紧凑选择卡**,整组约 220px;
  31. * 桌面端用完整详情卡,两端独立设计。
  32. */
  33. @Component({
  34. selector: 'app-mb-plans-page',
  35. changeDetection: ChangeDetectionStrategy.OnPush,
  36. imports: [UserNoticePipe, MAppBarComponent, MDrawerComponent, ProvisionInstructionComponent, LoadingOverlayComponent, ProvisionConfirmComponent],
  37. template: `
  38. <div class="m-page--scroll">
  39. <!-- 返回(2026-12-03):套餐页多为门禁跳转进来的,必须能退回去 -->
  40. <app-m-app-bar title="套餐与开通" [back]="true" (backTap)="goBack()" [menu]="true" (menuTap)="drawerOpen.set(true)" />
  41. <!-- 名额已满提示(2026-12-03):页面顶部,用户点了开通马上能看到 -->
  42. @if (quotaFull(); as qf) {
  43. <div class="quota-full" role="alert">
  44. <p>「{{ qf.plan }}」的名额已满({{ existingNames().length }}/{{ qf.quota }})。</p>
  45. <p>可以删除不用的容器,或升级到名额更多的套餐。</p>
  46. <button type="button" (click)="quotaFull.set(null)">知道了</button>
  47. </div>
  48. }
  49. <!-- 试用到期提示(2026-12-03):被门禁送回本页的用户要知道为什么 -->
  50. @if (trialExpiredName(); as expired) {
  51. <div class="quota-full quota-full--expired" role="alert">
  52. <p>「{{ expired }}」的两天试用已到期。</p>
  53. <p>开通入门版(本地容器 + App)或进阶版(平台容器)后即可继续使用;到期后数据保留 7 天,7 天后容器与数据将被回收。</p>
  54. </div>
  55. }
  56. <div class="m-body">
  57. <!--
  58. 🔴 生成中提示条(2026-11-27)
  59. 试用/入门档要调云函数建 Matrix 身份 + 算密码,1-3 秒。
  60. 只转按钮在手机上根本看不出反馈,这里给一条明确的进度提示。
  61. -->
  62. @if (generating()) {
  63. <div class="plans-loading" role="status" aria-live="polite">
  64. <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
  65. <span>正在准备接入信息,首次生成可能需要 10 秒左右…</span>
  66. </div>
  67. }
  68. <!--
  69. 🔴 提示词区块独立渲染(2026-11-27 修)
  70. 原来它和「开通进度」是 @if / @else if 互斥分支:
  71. 点「进阶开通」的瞬间 hasJob() 变 true,提示词区块**立即消失**,
  72. 用户手上正在复制的参数就没了。两者本来就可以同时存在。
  73. -->
  74. @if (provision.instruction(); as ins) {
  75. <app-provision-instruction [text]="ins" (copiedOut)="afterCopy()" />
  76. }
  77. <!-- 开通进行中:显示真实状态 -->
  78. @if (provision.hasJob()) {
  79. <section class="plans-job" [class.plans-job--ready]="provision.isReady()" [class.plans-job--failed]="provision.isFailed()">
  80. <i class="fa-solid"
  81. [class]="provision.isReady() ? 'fa-circle-check' : provision.isFailed() ? 'fa-triangle-exclamation' : 'fa-spinner fa-spin'"
  82. aria-hidden="true"></i>
  83. <div class="plans-job-body">
  84. <strong>{{ provision.statusText() }}</strong>
  85. <p>{{ (provision.isFailed() ? provision.failureMessage() : '容器创建由平台自动完成,可以离开页面,完成后回来查看。') | userNotice:'暂时无法确认开通结果,请先查看已有申请。':'verify-result' }}</p>
  86. </div>
  87. </section>
  88. <div class="plans-job-actions">
  89. @if (provision.isFailed() && provision.canRetry()) {
  90. <button type="button" class="plans-job-btn" (click)="provision.retry()">重试</button>
  91. } @else if (provision.isFailed()) {
  92. <button type="button" class="plans-job-btn" (click)="go('/plans')">查看套餐升级</button>
  93. } @else if (!provision.isReady()) {
  94. <button type="button" class="plans-job-btn" (click)="go('/provision', provision.current()?.jobId)">查看开通进度</button>
  95. } @else {
  96. <button type="button" class="plans-job-btn plans-job-btn--primary" (click)="go('/mobile/contacts')">查看我的容器</button>
  97. }
  98. </div>
  99. }
  100. <!-- 什么都没有时:试用横幅 -->
  101. @if (!provision.hasJob() && !provision.instruction()) {
  102. <section class="plans-trial">
  103. <div class="plans-trial-icon"><i class="fa-solid fa-wand-magic-sparkles" aria-hidden="true"></i></div>
  104. <div class="plans-trial-body">
  105. <h2>先体验,再决定<span>两天试用</span></h2>
  106. <p>用你自己的 Hermes 接入 Fmode:<b>本机直接安装</b>或 <b>Docker 容器</b>均可</p>
  107. </div>
  108. <button type="button" class="plans-trial-btn" (click)="trialUsed() ? toggleTrialInstruction() : apply('trial')" [disabled]="provision.startBlocked()">
  109. @if (provision.isStarting('trial')) {
  110. <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
  111. 生成中…
  112. } @else {
  113. {{ trialUsed() ? (loadingInstruction() ? '加载中…' : (provision.instruction() ? '收起接入提示词' : '查看接入提示词')) : '开始试用' }}
  114. }
  115. </button>
  116. </section>
  117. }
  118. @if (provision.error(); as err) {
  119. <p class="plans-error"><i class="fa-solid fa-circle-exclamation" aria-hidden="true"></i> {{ (err) | userNotice:'暂时无法确认开通结果,请先查看已有申请。':'verify-result' }}</p>
  120. @if (provision.recoveryFailed()) {
  121. <button type="button" class="plans-job-btn" (click)="provision.restorePending()">重新检查开通任务</button>
  122. @if (provision.pendingStartRetryAvailable()) {
  123. <button type="button" class="plans-job-btn" [disabled]="provision.starting()" (click)="provision.retryPendingStart()">安全重试原申请</button>
  124. }
  125. }
  126. }
  127. <h2 class="plans-heading">为下一步,准备合适的空间</h2>
  128. <p class="plans-sub">个人专属 · 企业共享 · 按需增配</p>
  129. <!-- 一行三列紧凑卡 -->
  130. <div class="plans-grid">
  131. @for (plan of plans(); track plan.code) {
  132. <article class="plan-card" [class.plan-card--featured]="plan.recommended">
  133. @if (plan.recommended) {
  134. <span class="plan-badge">推荐</span>
  135. }
  136. <i class="plan-icon" [class]="iconOf(plan.code)" aria-hidden="true"></i>
  137. <h3>{{ plan.shortName }}</h3>
  138. <!-- 额度(2026-12-03 用户裁决 B):只显示上限;超额仍禁止开通;企业版不显示 -->
  139. @if (!plan.contactOnly && plan.quota > 0) {
  140. <p class="plan-quota"><strong>{{ plan.quota }}</strong><span>{{ plan.quotaLabel }}</span></p>
  141. }
  142. @if (plan.contactOnly) {
  143. <!-- 企业版(2026-12-03 用户裁决):不显示数量与价格,联系客服定制 -->
  144. <a class="plan-contact" href="tel:400-000-0000" target="_blank" rel="noopener">
  145. <i class="fa-solid fa-phone" aria-hidden="true"></i> 客服 400-000-0000
  146. </a>
  147. } @else {
  148. <!-- 付费时长三档(2026-12-03 用户裁决:月/季/年,默认月 30 天;价格仍待定不出现金额) -->
  149. <div class="plan-periods" role="radiogroup" [attr.aria-label]="plan.name + ' 计费周期'">
  150. @for (opt of billingOptions; track opt.value) {
  151. <button type="button" role="radio"
  152. [attr.aria-checked]="billingOf(plan.code) === opt.value"
  153. [class.on]="billingOf(plan.code) === opt.value"
  154. (click)="setBilling(plan.code, opt.value)">{{ opt.label }}</button>
  155. }
  156. </div>
  157. <p class="plan-price">价格待定</p>
  158. <p class="plan-unit">按{{ periodLabel(plan.code) }}开通 · {{ periodDays(plan.code) }} 天</p>
  159. }
  160. @if (plan.contactOnly) {
  161. <a class="plan-btn plan-btn--contact" href="mailto:contact@fmode.cn?subject=企业版定制咨询" target="_blank" rel="noopener">联系客服</a>
  162. } @else {
  163. <button
  164. type="button"
  165. class="plan-btn"
  166. [disabled]="provision.startBlocked()"
  167. (click)="apply(plan.code)"
  168. >
  169. <!-- 🔴 只在本档提交时转,不能所有卡片一起转(2026-11-27 修) -->
  170. @if (provision.isStarting(plan.code)) {
  171. <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
  172. 提交中…
  173. } @else {
  174. {{ ctaText(plan.code) }}
  175. }
  176. </button>
  177. }
  178. </article>
  179. }
  180. </div>
  181. <p class="plans-note">
  182. <i class="fa-solid fa-circle-info" aria-hidden="true"></i>
  183. <span>具体价格请咨询客服。试用与入门使用你自己的容器;进阶与企业由平台创建。</span>
  184. </p>
  185. <h2 class="plans-heading">权益说明</h2>
  186. <div class="plans-detail">
  187. @for (plan of plans(); track plan.code) {
  188. <section class="plans-detail-row">
  189. <h3>{{ plan.name }}</h3>
  190. <p class="plans-detail-quota">{{ plan.mobileQuota }}</p>
  191. <p class="plans-detail-benefit">{{ plan.mobileBenefit }}</p>
  192. </section>
  193. }
  194. </div>
  195. <div class="plans-links">
  196. <button type="button" class="plans-link" (click)="go('/mobile/contacts')">
  197. <i class="fa-solid fa-server" aria-hidden="true"></i>
  198. <span>我的容器</span>
  199. <i class="fa-solid fa-chevron-right" aria-hidden="true"></i>
  200. </button>
  201. </div>
  202. </div>
  203. </div>
  204. <app-m-drawer [open]="drawerOpen()" (close)="drawerOpen.set(false)" />
  205. <!--
  206. 开通命名确认弹窗(2026-12-03)。
  207. 🔴 不能复用 app-prompt-modal:/plans 是顶层路由、不在 shell 内,
  208. 全局弹窗在套餐页渲染不出来。本组件自带遮罩与对话框。
  209. -->
  210. @if (confirmOpen()) {
  211. <app-provision-confirm
  212. [planName]="pendingPlanName()"
  213. [isOnboarding]="pendingIsOnboarding()"
  214. [quota]="pendingQuota()"
  215. [quotaUsed]="existingNames().length"
  216. [existingNames]="existingNames()"
  217. [busy]="submitting()"
  218. (confirm)="onNameConfirmed($event)"
  219. (cancel)="cancelConfirm()"
  220. />
  221. }
  222. <!-- 全屏加载遮罩:明确告知正在进行 + 阻断误点(2026-11-27) -->
  223. @if (loadingHint(); as hint) {
  224. <app-loading-overlay [message]="hint.message" [hint]="hint.detail" />
  225. }
  226. `,
  227. styles: [`
  228. /* 名额已满提示(2026-12-03):内联在页面顶部,不遮挡操作 */
  229. .quota-full {
  230. display: flex;
  231. flex-direction: column;
  232. gap: var(--sp-1);
  233. margin: 0 0 var(--sp-4);
  234. padding: var(--sp-4);
  235. border: 1px solid var(--warning);
  236. border-radius: var(--r-md, 10px);
  237. background: var(--surface-2);
  238. color: var(--ink-2);
  239. font-size: var(--fs-13);
  240. }
  241. .quota-full--expired {
  242. /* 试用到期(2026-12-03):与「名额已满」同位置不同措辞,不用按钮(去开通就是点下方套餐) */
  243. background: var(--warning-subtle);
  244. }
  245. .quota-full p {
  246. margin: 0;
  247. line-height: 1.55;
  248. }
  249. .quota-full button {
  250. align-self: flex-start;
  251. min-height: 36px;
  252. margin-top: var(--sp-2);
  253. padding: 0 var(--sp-4);
  254. border: 1px solid var(--edge);
  255. border-radius: var(--r-sm, 6px);
  256. background: var(--surface);
  257. color: var(--ink);
  258. font: inherit;
  259. font-size: var(--fs-13);
  260. cursor: pointer;
  261. }
  262. :host {
  263. display: block;
  264. height: 100%;
  265. }
  266. /*
  267. * 固定外壳 + 内部滚动(2026-12-02 修,对齐 mine.ts 模式):
  268. * /plans 是顶层路由、不在 mobile-shell 内,全局 .m-page--scroll 不生效,
  269. * 必须本地补齐——否则顶栏跟着内容一起滚走。
  270. * 顶层页无 TabBar,底部只留安全区。
  271. */
  272. .m-page--scroll {
  273. display: flex;
  274. flex-direction: column;
  275. height: 100dvh;
  276. box-sizing: border-box;
  277. padding-bottom: var(--mob-safe-bottom);
  278. }
  279. .m-body {
  280. flex: 1;
  281. min-height: 0;
  282. overflow-y: auto;
  283. -webkit-overflow-scrolling: touch;
  284. overscroll-behavior: contain;
  285. padding: var(--sp-4);
  286. padding-bottom: var(--sp-6);
  287. }
  288. /* ---------- 生成中提示条(2026-11-27) ---------- */
  289. /* 试用档要调云函数 1-3 秒,只转按钮在手机上看不出反馈 */
  290. .plans-loading {
  291. display: flex;
  292. align-items: center;
  293. gap: var(--sp-2);
  294. margin-bottom: var(--sp-4);
  295. padding: var(--sp-3) var(--sp-4);
  296. border: 1px solid var(--edge);
  297. border-radius: var(--r-md);
  298. background: var(--primary-subtle, var(--surface-2));
  299. color: var(--ink-2);
  300. font-size: var(--fs-12);
  301. line-height: 1.6;
  302. }
  303. .plans-loading > i {
  304. flex: none;
  305. color: var(--primary);
  306. }
  307. /* ---------- 试用横幅 ---------- */
  308. .plans-trial {
  309. display: flex;
  310. align-items: center;
  311. gap: var(--sp-3);
  312. padding: var(--sp-4);
  313. margin-bottom: var(--sp-5);
  314. border: 1px solid var(--edge);
  315. border-radius: var(--r-lg);
  316. background: var(--surface);
  317. }
  318. .plans-trial-icon {
  319. display: grid;
  320. width: 36px;
  321. height: 36px;
  322. flex: none;
  323. place-items: center;
  324. border: 1px solid var(--edge);
  325. border-radius: var(--r-md);
  326. background: var(--surface-2);
  327. color: var(--primary);
  328. }
  329. .plans-trial-body {
  330. flex: 1;
  331. min-width: 0;
  332. }
  333. .plans-trial-body h2 {
  334. display: flex;
  335. align-items: center;
  336. gap: var(--sp-2);
  337. margin: 0;
  338. font-size: var(--fs-15);
  339. font-weight: 600;
  340. }
  341. .plans-trial-body h2 > span {
  342. padding: 1px 6px;
  343. border-radius: var(--r-sm);
  344. background: var(--success-subtle);
  345. color: var(--success);
  346. font-size: var(--fs-11);
  347. font-weight: 500;
  348. }
  349. .plans-trial-body p {
  350. margin: var(--sp-1) 0 0;
  351. color: var(--muted);
  352. font-size: var(--fs-12);
  353. }
  354. .plans-trial-btn {
  355. flex: none;
  356. min-height: 44px;
  357. padding: 0 var(--sp-3);
  358. border: 0;
  359. border-radius: var(--r-md);
  360. background: var(--primary);
  361. color: var(--primary-content);
  362. font: inherit;
  363. font-size: var(--fs-13);
  364. font-weight: 500;
  365. cursor: pointer;
  366. }
  367. /* ---------- 待确认横幅 ---------- */
  368. /* ---------- 开通进行中 / 提示词 ---------- */
  369. .plans-job {
  370. display: flex;
  371. align-items: flex-start;
  372. gap: var(--sp-3);
  373. padding: var(--sp-4);
  374. margin-bottom: var(--sp-3);
  375. border: 1px solid var(--edge);
  376. border-radius: var(--r-md);
  377. background: var(--surface);
  378. }
  379. .plans-job > i {
  380. margin-top: 2px;
  381. color: var(--primary);
  382. font-size: var(--fs-15);
  383. }
  384. .plans-job--ready > i {
  385. color: var(--success);
  386. }
  387. .plans-job--failed > i {
  388. color: var(--warning);
  389. }
  390. .plans-job-body {
  391. flex: 1;
  392. min-width: 0;
  393. }
  394. .plans-job-body strong {
  395. display: block;
  396. font-size: var(--fs-14);
  397. font-weight: 600;
  398. }
  399. .plans-job-body p {
  400. margin: var(--sp-1) 0 0;
  401. color: var(--muted);
  402. font-size: var(--fs-12);
  403. }
  404. .plans-job-actions {
  405. margin-bottom: var(--sp-4);
  406. }
  407. .plans-job-btn {
  408. width: 100%;
  409. min-height: 44px;
  410. border: 1px solid var(--edge);
  411. border-radius: var(--r-md);
  412. background: var(--surface);
  413. color: var(--ink);
  414. font: inherit;
  415. font-size: var(--fs-14);
  416. cursor: pointer;
  417. }
  418. .plans-job-btn--primary {
  419. border-color: transparent;
  420. background: var(--primary);
  421. color: var(--primary-content);
  422. font-weight: 500;
  423. }
  424. .plans-instruction {
  425. padding: var(--sp-4);
  426. margin-bottom: var(--sp-4);
  427. border: 1px solid var(--edge);
  428. border-radius: var(--r-md);
  429. background: var(--surface);
  430. }
  431. .plans-instruction h2 {
  432. display: flex;
  433. align-items: center;
  434. gap: var(--sp-2);
  435. margin: 0;
  436. font-size: var(--fs-15);
  437. font-weight: 600;
  438. }
  439. .plans-instruction h2 > i {
  440. color: var(--primary);
  441. }
  442. .plans-instruction > p {
  443. margin: var(--sp-2) 0 var(--sp-3);
  444. color: var(--muted);
  445. font-size: var(--fs-12);
  446. }
  447. .plans-instruction-code {
  448. max-height: 220px;
  449. overflow: auto;
  450. margin: 0 0 var(--sp-3);
  451. padding: var(--sp-3);
  452. border: 1px solid var(--edge);
  453. border-radius: var(--r-sm);
  454. background: var(--surface-2);
  455. color: var(--ink-2);
  456. font-family: ui-monospace, Consolas, monospace;
  457. font-size: var(--fs-11);
  458. line-height: 1.6;
  459. white-space: pre-wrap;
  460. overflow-wrap: anywhere;
  461. }
  462. .plans-error {
  463. display: flex;
  464. align-items: flex-start;
  465. gap: var(--sp-2);
  466. margin: 0 0 var(--sp-4);
  467. color: var(--danger);
  468. font-size: var(--fs-12);
  469. }
  470. .plans-error > i {
  471. margin-top: 2px;
  472. }
  473. .plans-pending {
  474. display: flex;
  475. align-items: flex-start;
  476. gap: var(--sp-3);
  477. padding: var(--sp-3) var(--sp-4);
  478. margin-bottom: var(--sp-5);
  479. border: 1px solid var(--edge);
  480. border-radius: var(--r-md);
  481. background: var(--warning-subtle);
  482. color: var(--ink);
  483. }
  484. .plans-pending > i {
  485. margin-top: 3px;
  486. color: var(--warning);
  487. }
  488. .plans-pending strong {
  489. display: block;
  490. font-size: var(--fs-14);
  491. font-weight: 600;
  492. }
  493. .plans-pending p {
  494. margin: 2px 0 0;
  495. color: var(--muted);
  496. font-size: var(--fs-12);
  497. }
  498. /* ---------- 标题 ---------- */
  499. .plans-heading {
  500. margin: 0;
  501. font-size: var(--fs-15);
  502. font-weight: 600;
  503. }
  504. .plans-sub {
  505. margin: var(--sp-1) 0 var(--sp-4);
  506. color: var(--muted);
  507. font-size: var(--fs-12);
  508. }
  509. /* ---------- 一行三列紧凑卡 ---------- */
  510. .plans-grid {
  511. display: grid;
  512. grid-template-columns: repeat(3, minmax(0, 1fr));
  513. gap: var(--sp-2);
  514. }
  515. .plan-card {
  516. position: relative;
  517. display: flex;
  518. flex-direction: column;
  519. align-items: center;
  520. padding: var(--sp-3) var(--sp-2);
  521. border: 1px solid var(--edge);
  522. border-radius: var(--r-md);
  523. background: var(--surface);
  524. text-align: center;
  525. }
  526. .plan-card--featured {
  527. border-color: var(--primary);
  528. box-shadow: inset 0 0 0 1px var(--primary);
  529. }
  530. .plan-card--applied {
  531. opacity: 0.62;
  532. }
  533. .plan-badge {
  534. position: absolute;
  535. top: -8px;
  536. left: 50%;
  537. padding: 1px 7px;
  538. border-radius: var(--r-sm);
  539. background: var(--primary);
  540. color: var(--primary-content);
  541. font-size: var(--fs-10, 11px);
  542. white-space: nowrap;
  543. transform: translateX(-50%);
  544. }
  545. .plan-icon {
  546. margin-bottom: var(--sp-2);
  547. color: var(--muted);
  548. font-size: var(--fs-17);
  549. }
  550. .plan-card h3 {
  551. margin: 0;
  552. font-size: var(--fs-14);
  553. font-weight: 600;
  554. line-height: 1.3;
  555. }
  556. .plan-quota {
  557. display: flex;
  558. align-items: baseline;
  559. gap: 2px;
  560. margin: var(--sp-2) 0 0;
  561. line-height: 1.2;
  562. }
  563. .plan-quota strong {
  564. font-size: var(--fs-20);
  565. font-weight: 600;
  566. letter-spacing: -0.03em;
  567. }
  568. .plan-quota span {
  569. color: var(--muted);
  570. font-size: var(--fs-10, 11px);
  571. }
  572. .plan-contact {
  573. display: flex; align-items: center; justify-content: center; gap: 4px;
  574. margin: var(--sp-2) 0; padding: var(--sp-2);
  575. border: 1px dashed var(--edge); border-radius: 8px;
  576. background: var(--surface-2); color: var(--primary);
  577. font-size: var(--fs-11, 11px); text-decoration: none;
  578. }
  579. .plan-btn--contact { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
  580. .plan-periods {
  581. display: flex;
  582. gap: 2px;
  583. margin: var(--sp-2) 0 0;
  584. padding: 2px;
  585. border-radius: 8px;
  586. background: var(--surface-2);
  587. }
  588. .plan-periods button {
  589. flex: 1;
  590. min-height: 28px;
  591. border: 0;
  592. border-radius: 6px;
  593. background: transparent;
  594. color: var(--muted);
  595. font-size: var(--fs-11, 11px);
  596. cursor: pointer;
  597. }
  598. .plan-periods button.on {
  599. background: var(--surface);
  600. color: var(--ink);
  601. font-weight: 600;
  602. }
  603. .plan-price {
  604. margin: var(--sp-1) 0 0;
  605. color: var(--ink-2);
  606. font-size: var(--fs-12);
  607. font-weight: 500;
  608. }
  609. .plan-unit {
  610. min-height: 15px;
  611. margin: 0;
  612. color: var(--muted);
  613. font-size: var(--fs-10, 11px);
  614. }
  615. .plan-btn {
  616. width: 100%;
  617. min-height: 44px;
  618. margin-top: var(--sp-2);
  619. padding: 0 var(--sp-1);
  620. border: 1px solid var(--edge);
  621. border-radius: var(--r-md);
  622. background: var(--surface);
  623. color: var(--ink);
  624. font: inherit;
  625. font-size: var(--fs-12);
  626. font-weight: 500;
  627. cursor: pointer;
  628. }
  629. .plan-card--featured .plan-btn {
  630. border-color: transparent;
  631. background: var(--primary);
  632. color: var(--primary-content);
  633. }
  634. .plan-btn:disabled {
  635. opacity: 0.5;
  636. cursor: not-allowed;
  637. }
  638. .plans-note {
  639. display: flex;
  640. align-items: flex-start;
  641. gap: var(--sp-2);
  642. margin: var(--sp-3) 0 var(--sp-5);
  643. color: var(--muted);
  644. font-size: var(--fs-12);
  645. }
  646. .plans-note > i {
  647. margin-top: 3px;
  648. }
  649. /* ---------- 权益明细 ---------- */
  650. .plans-detail {
  651. border: 1px solid var(--edge);
  652. border-radius: var(--r-md);
  653. background: var(--surface);
  654. overflow: hidden;
  655. }
  656. .plans-detail-row {
  657. padding: var(--sp-3) var(--sp-4);
  658. }
  659. .plans-detail-row + .plans-detail-row {
  660. border-top: 1px solid var(--edge);
  661. }
  662. .plans-detail-row h3 {
  663. margin: 0;
  664. font-size: var(--fs-14);
  665. font-weight: 600;
  666. }
  667. .plans-detail-quota {
  668. margin: 2px 0 0;
  669. color: var(--ink-2);
  670. font-size: var(--fs-12);
  671. }
  672. .plans-detail-benefit {
  673. margin: 2px 0 0;
  674. color: var(--muted);
  675. font-size: var(--fs-12);
  676. }
  677. /* ---------- 底部链接 ---------- */
  678. .plans-links {
  679. margin-top: var(--sp-4);
  680. border: 1px solid var(--edge);
  681. border-radius: var(--r-md);
  682. background: var(--surface);
  683. overflow: hidden;
  684. }
  685. .plans-link {
  686. display: flex;
  687. align-items: center;
  688. gap: var(--sp-3);
  689. width: 100%;
  690. min-height: 56px;
  691. padding: var(--sp-3) var(--sp-4);
  692. border: 0;
  693. background: transparent;
  694. color: var(--ink);
  695. font: inherit;
  696. font-size: var(--fs-14);
  697. text-align: left;
  698. cursor: pointer;
  699. }
  700. .plans-link > i:first-child {
  701. width: 20px;
  702. color: var(--primary);
  703. text-align: center;
  704. }
  705. .plans-link > span {
  706. flex: 1;
  707. }
  708. .plans-link > i:last-child {
  709. color: var(--faint);
  710. font-size: var(--fs-12);
  711. }
  712. `,
  713. ],
  714. })
  715. export class MbPlansPage implements OnInit {
  716. protected readonly plan = inject(PlanService);
  717. protected readonly provision = inject(ProvisionService);
  718. protected readonly live = inject(LiveService);
  719. private readonly router = inject(Router);
  720. /* 命名确认弹窗状态(2026-12-03) */
  721. protected readonly confirmOpen = signal(false);
  722. protected readonly pendingCode = signal<PlanCode | null>(null);
  723. protected readonly submitting = signal(false);
  724. /** 名额已满提示(2026-12-03)。null = 不显示 */
  725. protected readonly quotaFull = signal<{ plan: string; quota: number } | null>(null);
  726. ngOnInit(): void {
  727. void this.provision.restorePending();
  728. /*
  729. * 提示词**不再自动拉回**(2026-12-04 用户反馈「登录就直接显示提示词」)。
  730. * 已试用过的账号只显示「查看接入提示词」按钮,用户点了才展开。
  731. */
  732. /*
  733. * 配额预检与重名校验都依赖容器列表(2026-12-03):
  734. * /plans 是顶层路由不在 shell 内,没人替本页拉 live,
  735. * 不主动加载 existingNames() 永远是空 —— 配额预检形同虚设、
  736. * 默认名永远从「我的容器 1」开始。
  737. */
  738. void this.live.ensureLoaded();
  739. }
  740. protected readonly drawerOpen = signal(false);
  741. /** 付费三档(试用单独走横幅) */
  742. /** 是否已有付费套餐(2026-12-03):决定按钮文案「开通 / 续费」;试用不算 */
  743. /** 正在拉取接入提示词 */
  744. protected readonly loadingInstruction = signal(false);
  745. /** 已试用账号:展开 / 收起接入提示词(2026-12-04) */
  746. protected async toggleTrialInstruction(): Promise<void> {
  747. if (this.provision.instruction()) { this.provision.clearInstruction(); return; }
  748. this.loadingInstruction.set(true);
  749. try { await this.provision.loadInstruction(); }
  750. finally { this.loadingInstruction.set(false); }
  751. }
  752. /** 复制提示词后进入会话页(2026-12-04) */
  753. protected afterCopy(): void {
  754. const id = this.provision.instructionAgentId();
  755. if (!id) return;
  756. void this.router.navigateByUrl(`/mobile/chat/${encodeURIComponent(id)}/new`);
  757. }
  758. protected readonly hasPaidPlan = computed(() =>
  759. this.live.agents().some((a) => a.planCode === 'starter' || a.planCode === 'advanced' || a.planCode === 'enterprise'),
  760. );
  761. protected ctaText(_code: string): string { return this.hasPaidPlan() ? '续费' : '立即开通'; }
  762. /* 付费时长三档(2026-12-03):每张卡各自记住选择,默认月 */
  763. protected readonly billingOptions = BILLING_OPTIONS;
  764. private readonly billingSel = signal<Record<string, BillingPeriod>>({});
  765. protected billingOf(code: string): BillingPeriod { return this.billingSel()[code] ?? DEFAULT_BILLING; }
  766. protected setBilling(code: string, v: BillingPeriod): void {
  767. this.billingSel.update((m) => ({ ...m, [code]: v }));
  768. }
  769. protected periodLabel(code: string): string { return BILLING_OPTIONS.find((o) => o.value === this.billingOf(code))?.label ?? '月付'; }
  770. protected periodDays(code: string): number { return billingDays(this.billingOf(code)); }
  771. /**
  772. * 该账号是否已用过试用(2026-12-03 用户裁决:试用与容器数量无关,按账号只一次)。
  773. * 判据来自云函数派生的 trialUsedAt/trialExpired;用过就禁用试用入口,
  774. * 后端 `TRIAL_USED` 仍是最终防线。
  775. */
  776. protected readonly trialUsed = computed(() =>
  777. this.live.agents().some((a) => a.planCode === 'trial' || a.trialExpired === true),
  778. );
  779. protected readonly plans = computed(() => this.plan.catalog);
  780. /**
  781. * 是否正在生成接入提示词(试用/入门档)。
  782. *
  783. * 这两档要调云函数建 Matrix 身份 + 算密码,1-3 秒,
  784. * 期间给一条明确的进度提示(只转按钮在手机上看不出反馈)。
  785. */
  786. protected readonly generating = computed(() => {
  787. const p = this.provision.startingPlan();
  788. return p === 'trial' || p === 'starter';
  789. });
  790. /** 全屏加载遮罩文案(null = 不显示) */
  791. protected readonly loadingHint = computed<{ message: string; detail: string } | null>(() => {
  792. /*
  793. * 🔴 restoring 不再上全屏遮罩(2026-12-03 用户实测反馈):
  794. * 开通中离开再回 /plans,每次进页都重放一遍「正在检查开通任务…」过场动画。
  795. * restore 本来就是静默找回——完了有任务就显示 plans-job 区块,没有就无事发生。
  796. */
  797. const p = this.provision.startingPlan();
  798. if (!p) return null;
  799. if (p === 'trial' || p === 'starter') {
  800. return { message: '正在准备接入信息…', detail: '首次生成可能需要 10 秒左右,请稍候' };
  801. }
  802. return { message: '正在提交开通申请…', detail: '马上就好' };
  803. });
  804. protected iconOf(code: PlanCode): string {
  805. switch (code) {
  806. case 'starter':
  807. return 'fa-solid fa-server';
  808. case 'advanced':
  809. return 'fa-solid fa-wand-magic-sparkles';
  810. case 'enterprise':
  811. return 'fa-solid fa-building';
  812. default:
  813. return 'fa-solid fa-cube';
  814. }
  815. }
  816. /**
  817. * 发起开通。
  818. *
  819. * 🔴 这里只**发起请求**,不承诺结果:
  820. * · 试用/入门 → 后端返回接入提示词,页面上展示给用户复制
  821. * · 进阶/企业 → 后端受理并真实创建,成功后进入轮询态
  822. */
  823. /**
  824. * 发起开通(2026-11-27 改造)
  825. *
  826. * 🔴 两条路径分流:
  827. * · 试用 / 入门 → 后端返回**接入提示词**,留在本页展示(不建容器)
  828. * · 进阶 / 企业 → 后端**受理并真实创建** → **立刻跳转等待页**(全屏锁定)
  829. *
  830. * 跳转前必须 `await` 到 `jobId` 存在 —— 带着 undefined 跳过去,
  831. * 等待页会拉不到任务,用户看到的是空转。
  832. */
  833. /** 返回上一页;直接打开时回会话页(2026-12-03) */
  834. protected goBack(): void { if (history.length > 1) history.back(); else void this.router.navigateByUrl('/mobile/chat'); }
  835. protected async apply(code: PlanCode): Promise<void> {
  836. if (this.provision.isRunning()) return;
  837. /*
  838. * 配额判断依赖容器列表;首载还没落地时 existingNames() 是空数组,
  839. * 直接判会永远放行(2026-12-03 用户实测:已有 2 个容器仍没看到名额提示)。
  840. * 先等首载完成再校验;加载失败则由服务端配额校验兜底。
  841. */
  842. await this.live.ensureLoaded();
  843. /*
  844. * 名额已满就别让用户填名字了(2026-12-03)。
  845. * 在弹窗之前拦,而不是等提交后云函数返回 409 ——
  846. * 「认真填完名字才被告知名额已满」是很差的体验。
  847. */
  848. const quota = code === 'trial' ? 1 : (this.plan.planOf(code as never)?.quota ?? 0);
  849. /* 超额禁止(2026-12-03 裁决 B):只显示上限,但达到上限仍不允许再开 */
  850. if (code !== 'trial' && quota > 0 && this.existingNames().length >= quota) {
  851. this.quotaFull.set({ plan: this.plan.planOf(code as never)?.name || '该套餐', quota });
  852. return;
  853. }
  854. /*
  855. * 试用不弹命名框(2026-12-03 用户实测纠错):
  856. * 试用用的是**用户自己的 Hermes**,名字在接入完成后到容器设置里改即可;
  857. * 让用户「给试用起容器名」既不合理,也会和付费开通的命名弹窗混在一起。
  858. * 这里自动生成一个不重名的默认名直接提交。
  859. */
  860. if (code === 'trial') {
  861. const auto = suggestContainerName(this.existingNames());
  862. this.pendingCode.set(code);
  863. void this.onNameConfirmed(auto);
  864. return;
  865. }
  866. /* 付费档位:先弹命名确认(用户裁决 2026-12-03) */
  867. this.pendingCode.set(code);
  868. this.confirmOpen.set(true);
  869. }
  870. /**
  871. * 命名确认后真正提交(2026-12-03)。
  872. *
  873. * `name` 来自弹窗,已经过 `validateContainerName` 校验与 NFKC 归一化。
  874. */
  875. protected async onNameConfirmed(name: string): Promise<void> {
  876. const code = this.pendingCode();
  877. if (!code) return;
  878. this.submitting.set(true);
  879. try {
  880. const result = await this.provision.start(code, name, this.billingOf(code));
  881. this.confirmOpen.set(false);
  882. this.pendingCode.set(null);
  883. if (result?.mode === 'provision' && result.jobId) {
  884. await this.router.navigateByUrl(`/provision?jobId=${encodeURIComponent(result.jobId)}`, {
  885. replaceUrl: true,
  886. });
  887. }
  888. // onboarding 模式(试用/入门):留在本页,由模板渲染提示词
  889. } catch {
  890. /*
  891. * 提交抛错也要关弹窗(2026-12-03):否则弹窗永远盖在页面上,
  892. * 页面级的错误提示(plans-error)用户根本看不到。
  893. * 错误本身由 ProvisionService.error() 呈现在页面上。
  894. */
  895. this.confirmOpen.set(false);
  896. this.pendingCode.set(null);
  897. } finally {
  898. this.submitting.set(false);
  899. }
  900. }
  901. protected cancelConfirm(): void {
  902. this.confirmOpen.set(false);
  903. this.pendingCode.set(null);
  904. }
  905. /** 弹窗用:当前pending套餐的信息 */
  906. protected readonly pendingPlanName = computed(() => {
  907. const c = this.pendingCode();
  908. if (!c) return '';
  909. if (c === 'trial') return '试用';
  910. return this.plan.planOf(c)?.name ?? '套餐';
  911. });
  912. protected readonly pendingIsOnboarding = computed(() => {
  913. const c = this.pendingCode();
  914. return c === 'trial' || c === 'starter';
  915. });
  916. protected readonly pendingQuota = computed(() => {
  917. const c = this.pendingCode();
  918. if (!c || c === 'trial') return 1;
  919. return this.plan.planOf(c)?.quota ?? 0;
  920. });
  921. /** 已有容器名(重名校验 + 默认名生成) */
  922. protected readonly existingNames = computed(() =>
  923. this.live.agents().map((a) => a.name).filter((n): n is string => !!n),
  924. );
  925. /** 已到期的试用容器名(2026-12-03):顶部提示用 */
  926. protected readonly trialExpiredName = computed(
  927. () => this.live.agents().find((a) => a.trialExpired === true)?.name ?? '',
  928. );
  929. protected readonly suggestedName = computed(() => suggestContainerName(this.existingNames()));
  930. /** 导航;`jobId` 存在时拼进查询参数(如打开等待页) */
  931. protected go(path: string, jobId?: string): void {
  932. const url = jobId ? `${path}?jobId=${encodeURIComponent(jobId)}` : path;
  933. void this.router.navigateByUrl(url);
  934. }
  935. }