plans.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  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 { PaidPlanCode } from '../../../core/api/models';
  5. import { LoadingOverlayComponent } from '../../../components/domain/loading-overlay/loading-overlay';
  6. import { ProvisionInstructionComponent } from '../../../components/domain/provision-instruction/provision-instruction';
  7. import { PlanService } from '../../../core/plan.service';
  8. import { ProvisionService } from '../../../core/provision.service';
  9. import { RenewalGuideComponent } from '../../../components/domain/renewal-guide/renewal-guide';
  10. import { LiveService } from '../../../core/live.service';
  11. import { ProvisionConfirmComponent } from '../../../components/domain/provision-confirm/provision-confirm';
  12. import { suggestContainerName } from '../../../components/domain/provision-confirm/container-name';
  13. /**
  14. * 桌面端套餐与开通(2026-11-25 第一期)
  15. *
  16. * ## 与移动端的差异(两端独立设计)
  17. *
  18. * 桌面横向空间充足,用**三列详情卡**:图标 / 名称 / 副标题 / 价格 /
  19. * 开通按钮 / 权益清单全部展示,一屏看完三档对比。
  20. * 移动端受窄屏所限用紧凑选择卡,见 `mobile/pages/plans`。
  21. *
  22. * ## 本期边界
  23. *
  24. * 只做展示 + 申请意向。**不显示金额、不显示「已开通」、不显示开通进度**。
  25. */
  26. @Component({
  27. selector: 'app-dk-plans-page',
  28. changeDetection: ChangeDetectionStrategy.OnPush,
  29. imports: [UserNoticePipe, ProvisionInstructionComponent, LoadingOverlayComponent, RenewalGuideComponent, ProvisionConfirmComponent],
  30. template: `
  31. <div class="plans-page">
  32. <!-- 名额已满提示(2026-12-03):页面顶部,用户点了开通马上能看到 -->
  33. @if (quotaFull(); as qf) {
  34. <div class="quota-full" role="alert">
  35. <p>「{{ qf.plan }}」的名额已满({{ existingNames().length }}/{{ qf.quota }})。</p>
  36. <p>可以删除不用的容器,或升级到名额更多的套餐。</p>
  37. <button type="button" (click)="quotaFull.set(null)">知道了</button>
  38. </div>
  39. }
  40. <header class="plans-head">
  41. <div>
  42. <p class="plans-eyebrow"><i class="fa-solid fa-crown" aria-hidden="true"></i> 套餐与开通</p>
  43. <h1>选择适合你的协作方式。</h1>
  44. <p class="plans-lead">按需选择,随时升级。</p>
  45. </div>
  46. </header>
  47. <!--
  48. 当前资产概览(2026-12-02 PC 优化)。
  49. 桌面端宽屏下先回答「我现在有什么」,再让用户选「要不要再开一个」——
  50. 原来一进页面只能看到三张价格卡,对自己已有的容器与名额没有概念。
  51. -->
  52. <section class="plans-status" aria-label="当前容器与名额">
  53. <div class="plans-status-item">
  54. <span class="plans-status-label">我的容器</span>
  55. @if (live.hasData()) {
  56. <strong class="plans-status-value">{{ live.agents().length }} 个</strong>
  57. <span class="plans-status-hint">{{ runningCount() }} 个运行中</span>
  58. } @else {
  59. <strong class="plans-status-value">—</strong>
  60. <span class="plans-status-hint">正在读取…</span>
  61. }
  62. </div>
  63. <div class="plans-status-item">
  64. <span class="plans-status-label">当前套餐</span>
  65. <strong class="plans-status-value">{{ currentPlanName() }}</strong>
  66. <span class="plans-status-hint">{{ provision.hasJob() ? provision.statusText() : '按需升级,随时生效' }}</span>
  67. </div>
  68. <div class="plans-status-actions">
  69. <button type="button" class="plans-status-btn" (click)="go('/desktop/my-containers')">
  70. <i class="fa-solid fa-server" aria-hidden="true"></i> 管理容器
  71. </button>
  72. <button type="button" class="plans-status-btn plans-status-btn--primary" [disabled]="provision.startBlocked()" (click)="apply('advanced')">
  73. <i class="fa-solid fa-plus" aria-hidden="true"></i> 新增容器
  74. </button>
  75. </div>
  76. </section>
  77. <!-- 开通进行中 / 提示词 / 试用引导 -->
  78. @if (provision.hasJob()) {
  79. <section class="plans-banner plans-banner--pending">
  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 style="flex:1;min-width:0">
  84. <h2>{{ provision.statusText() }}</h2>
  85. <p>{{ (provision.isFailed() ? provision.failureMessage() : '容器创建由平台自动完成,请稍候。') | userNotice:'暂时无法确认开通结果,请先查看已有申请。':'verify-result' }}</p>
  86. @if (provision.isRunning() && provision.completedStages() > 0) {
  87. <div class="plans-progress" role="progressbar"
  88. [attr.aria-valuenow]="provision.completedStages()"
  89. [attr.aria-valuemin]="0" [attr.aria-valuemax]="5">
  90. <span class="plans-progress-bar"
  91. [style.width.%]="(provision.completedStages() / 5) * 100"></span>
  92. </div>
  93. }
  94. </div>
  95. @if (provision.isFailed() && provision.canRetry()) {
  96. <button type="button" class="plans-banner-btn" (click)="provision.retry()">重试</button>
  97. } @else if (provision.isFailed()) {
  98. <button type="button" class="plans-banner-btn" (click)="go('/plans')">查看套餐升级</button>
  99. } @else if (!provision.isReady()) {
  100. <button type="button" class="plans-banner-btn" (click)="go('/provision?jobId=' + provision.current()?.jobId)">查看开通进度</button>
  101. } @else {
  102. <button type="button" class="plans-banner-btn" (click)="go('/desktop/my-containers')">查看我的容器</button>
  103. }
  104. </section>
  105. } @else if (provision.instruction(); as ins) {
  106. <!-- 试用/入门:接入提示词(组件内含复制 + 失败兜底) -->
  107. <app-provision-instruction [text]="ins" />
  108. } @else {
  109. <section class="plans-banner">
  110. <div class="plans-banner-icon">
  111. <i class="fa-solid fa-wand-magic-sparkles" aria-hidden="true"></i>
  112. </div>
  113. <div class="plans-banner-body">
  114. <h2>先体验,再决定。<span>两天试用</span></h2>
  115. <p>使用你自己的容器接入 Fmode</p>
  116. </div>
  117. <button type="button" class="plans-banner-btn" [disabled]="provision.startBlocked()" (click)="apply('trial')">
  118. @if (provision.isStarting('trial')) {
  119. <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
  120. 生成中…
  121. } @else {
  122. 开始两天试用
  123. }
  124. </button>
  125. </section>
  126. }
  127. @if (provision.error(); as err) {
  128. <p class="plans-error"><i class="fa-solid fa-circle-exclamation" aria-hidden="true"></i> {{ (err) | userNotice:'暂时无法确认开通结果,请先查看已有申请。':'verify-result' }}</p>
  129. @if (provision.recoveryFailed()) {
  130. <button type="button" class="plans-banner-btn" (click)="provision.restorePending()">重新检查开通任务</button>
  131. @if (provision.pendingStartRetryAvailable()) {
  132. <button type="button" class="plans-banner-btn" [disabled]="provision.starting()" (click)="provision.retryPendingStart()">安全重试原申请</button>
  133. }
  134. }
  135. }
  136. <div class="plans-section-head">
  137. <h2>为下一步,准备合适的空间</h2>
  138. <p>个人专属 · 企业共享 · 按需增配</p>
  139. </div>
  140. <div class="plans-grid">
  141. @for (item of plans(); track item.code) {
  142. <article class="plan-card" [class.plan-card--featured]="item.recommended">
  143. @if (item.recommended) {
  144. <span class="plan-ribbon">推荐</span>
  145. }
  146. <div class="plan-icon">
  147. <i [class]="iconOf(item.code)" aria-hidden="true"></i>
  148. </div>
  149. <h3>{{ item.name }}</h3>
  150. <p class="plan-tagline">{{ item.tagline }}</p>
  151. <div class="plan-price">
  152. <strong>价格待定</strong>
  153. @if (item.billingUnit) {
  154. <span>{{ item.billingUnit }}</span>
  155. }
  156. </div>
  157. <p class="plan-billing">{{ item.billingNote }}</p>
  158. <button
  159. type="button"
  160. class="plan-cta"
  161. [class.plan-cta--primary]="item.recommended"
  162. [disabled]="provision.startBlocked()"
  163. (click)="apply(item.code)"
  164. >
  165. <!-- 🔴 只在本档提交时转,不是所有卡片一起转 -->
  166. @if (provision.isStarting(item.code)) {
  167. <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
  168. 提交中…
  169. } @else {
  170. 立即开通
  171. }
  172. </button>
  173. <ul class="plan-features">
  174. @for (f of item.features; track f) {
  175. <li><i class="fa-solid fa-check" aria-hidden="true"></i><span>{{ f }}</span></li>
  176. }
  177. </ul>
  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. <app-renewal-guide />
  186. <div class="plans-links">
  187. <section class="plans-link-card">
  188. <i class="fa-solid fa-server" aria-hidden="true"></i>
  189. <div>
  190. <h3>我的容器</h3>
  191. <p>查看已有的容器与名额使用情况</p>
  192. </div>
  193. <button type="button" class="plans-link-btn" (click)="go('/desktop/my-containers')">查看</button>
  194. </section>
  195. <section class="plans-link-card">
  196. <i class="fa-solid fa-shield-halved" aria-hidden="true"></i>
  197. <div>
  198. <h3>数据为你保留</h3>
  199. <p>试用结束后,开通套餐即可继续使用原有容器</p>
  200. </div>
  201. </section>
  202. </div>
  203. </div>
  204. <!--
  205. 🔴 全屏加载遮罩(2026-11-27)
  206. 用户反馈「点开通感觉像卡死」—— 请求要 1-3 秒,只有按钮变字在大屏上看不出来。
  207. 遮罩同时起两个作用:① 明确告知正在进行 ② 阻断误点
  208. -->
  209. <!--
  210. 开通命名确认弹窗(2026-12-03)。
  211. 🔴 不能复用 app-prompt-modal:/plans 是顶层路由、不在 shell 内。
  212. -->
  213. @if (confirmOpen()) {
  214. <app-provision-confirm
  215. [planName]="pendingPlanName()"
  216. [isOnboarding]="pendingIsOnboarding()"
  217. [quota]="pendingQuota()"
  218. [quotaUsed]="existingNames().length"
  219. [existingNames]="existingNames()"
  220. [busy]="submitting()"
  221. (confirm)="onNameConfirmed($event)"
  222. (cancel)="cancelConfirm()"
  223. />
  224. }
  225. @if (loadingHint(); as hint) {
  226. <app-loading-overlay [message]="hint.message" [hint]="hint.detail" />
  227. }
  228. `,
  229. styles: [`
  230. /* 名额已满提示(2026-12-03):内联在页面顶部,不遮挡操作 */
  231. .quota-full {
  232. display: flex;
  233. flex-direction: column;
  234. gap: var(--sp-1);
  235. margin: 0 0 var(--sp-4);
  236. padding: var(--sp-4);
  237. border: 1px solid var(--warning);
  238. border-radius: var(--r-md, 10px);
  239. background: var(--surface-2);
  240. color: var(--ink-2);
  241. font-size: var(--fs-13);
  242. }
  243. .quota-full p {
  244. margin: 0;
  245. line-height: 1.55;
  246. }
  247. .quota-full button {
  248. align-self: flex-start;
  249. min-height: 36px;
  250. margin-top: var(--sp-2);
  251. padding: 0 var(--sp-4);
  252. border: 1px solid var(--edge);
  253. border-radius: var(--r-sm, 6px);
  254. background: var(--surface);
  255. color: var(--ink);
  256. font: inherit;
  257. font-size: var(--fs-13);
  258. cursor: pointer;
  259. }
  260. :host {
  261. display: block;
  262. height: 100%;
  263. overflow-y: auto;
  264. }
  265. .plans-page {
  266. max-width: 1120px;
  267. margin: 0 auto;
  268. padding: var(--sp-8);
  269. }
  270. .plans-eyebrow {
  271. display: flex;
  272. align-items: center;
  273. gap: var(--sp-2);
  274. margin: 0 0 var(--sp-2);
  275. color: var(--muted);
  276. font-size: var(--fs-12);
  277. }
  278. .plans-head h1 {
  279. margin: 0;
  280. font-size: var(--fs-26);
  281. font-weight: 600;
  282. letter-spacing: -0.04em;
  283. }
  284. .plans-lead {
  285. margin: var(--sp-2) 0 0;
  286. color: var(--muted);
  287. font-size: var(--fs-14);
  288. }
  289. /* ---------- 横幅 ---------- */
  290. .plans-banner {
  291. display: flex;
  292. align-items: center;
  293. gap: var(--sp-5);
  294. margin: var(--sp-6) 0;
  295. padding: var(--sp-6);
  296. border: 1px solid var(--edge-strong);
  297. border-radius: var(--r-lg);
  298. background: var(--surface);
  299. }
  300. .plans-banner--pending {
  301. align-items: flex-start;
  302. border-color: var(--edge);
  303. background: var(--warning-subtle);
  304. }
  305. .plans-banner--pending > i {
  306. margin-top: 3px;
  307. color: var(--warning);
  308. }
  309. /* 真实阶段进度条:源自 Agent 写库的 step 记录,不是估算 */
  310. .plans-progress {
  311. width: 100%;
  312. max-width: 320px;
  313. height: 4px;
  314. margin-top: var(--sp-3);
  315. border-radius: 999px;
  316. background: var(--surface-2);
  317. overflow: hidden;
  318. }
  319. .plans-progress-bar {
  320. display: block;
  321. height: 100%;
  322. border-radius: inherit;
  323. background: var(--primary);
  324. transition: width 200ms cubic-bezier(0.2, 0, 0, 1);
  325. }
  326. @media (prefers-reduced-motion: reduce) {
  327. .plans-progress-bar {
  328. transition: none;
  329. }
  330. }
  331. .plans-banner-icon {
  332. display: grid;
  333. width: 48px;
  334. height: 48px;
  335. flex: none;
  336. place-items: center;
  337. border: 1px solid var(--edge);
  338. border-radius: var(--r-lg);
  339. background: var(--surface-2);
  340. color: var(--primary);
  341. font-size: var(--fs-20);
  342. }
  343. .plans-banner-body {
  344. flex: 1;
  345. min-width: 0;
  346. }
  347. .plans-banner h2 {
  348. display: flex;
  349. align-items: center;
  350. gap: var(--sp-3);
  351. margin: 0;
  352. font-size: var(--fs-20);
  353. font-weight: 600;
  354. letter-spacing: -0.02em;
  355. }
  356. .plans-banner h2 > span {
  357. padding: 1px 7px;
  358. border-radius: var(--r-sm);
  359. background: var(--success-subtle);
  360. color: var(--success);
  361. font-size: var(--fs-11);
  362. font-weight: 500;
  363. }
  364. .plans-banner p {
  365. margin: var(--sp-2) 0 0;
  366. color: var(--muted);
  367. font-size: var(--fs-13);
  368. }
  369. .plans-banner-btn {
  370. flex: none;
  371. min-height: 44px;
  372. padding: 0 var(--sp-5);
  373. border: 0;
  374. border-radius: var(--r-md);
  375. background: var(--primary);
  376. color: var(--primary-content);
  377. font: inherit;
  378. font-size: var(--fs-14);
  379. font-weight: 500;
  380. cursor: pointer;
  381. }
  382. /* ---------- 三列卡 ---------- */
  383. .plans-section-head {
  384. display: flex;
  385. align-items: baseline;
  386. justify-content: space-between;
  387. gap: var(--sp-4);
  388. margin-bottom: var(--sp-4);
  389. }
  390. .plans-section-head h2 {
  391. margin: 0;
  392. font-size: var(--fs-17);
  393. font-weight: 600;
  394. }
  395. .plans-section-head p {
  396. margin: 0;
  397. color: var(--muted);
  398. font-size: var(--fs-12);
  399. }
  400. .plans-grid {
  401. display: grid;
  402. grid-template-columns: repeat(3, minmax(0, 1fr));
  403. gap: var(--sp-4);
  404. }
  405. .plan-card {
  406. position: relative;
  407. display: flex;
  408. flex-direction: column;
  409. padding: var(--sp-6);
  410. border: 1px solid var(--edge);
  411. border-radius: var(--r-lg);
  412. background: var(--surface);
  413. }
  414. .plan-card--featured {
  415. border-color: var(--primary);
  416. box-shadow: inset 0 0 0 1px var(--primary);
  417. }
  418. .plan-ribbon {
  419. position: absolute;
  420. top: -11px;
  421. left: var(--sp-5);
  422. padding: 2px 9px;
  423. border-radius: var(--r-sm);
  424. background: var(--primary);
  425. color: var(--primary-content);
  426. font-size: var(--fs-11);
  427. white-space: nowrap;
  428. }
  429. .plan-icon {
  430. display: grid;
  431. width: 36px;
  432. height: 36px;
  433. margin-bottom: var(--sp-4);
  434. place-items: center;
  435. border: 1px solid var(--edge);
  436. border-radius: var(--r-md);
  437. background: var(--surface-2);
  438. color: var(--ink-2);
  439. }
  440. .plan-card h3 {
  441. margin: 0;
  442. font-size: var(--fs-20);
  443. font-weight: 600;
  444. }
  445. .plan-tagline {
  446. margin: 5px 0 0;
  447. color: var(--muted);
  448. font-size: var(--fs-13);
  449. }
  450. .plan-price {
  451. display: flex;
  452. align-items: baseline;
  453. gap: 7px;
  454. margin: var(--sp-6) 0 var(--sp-1);
  455. }
  456. .plan-price strong {
  457. font-size: var(--fs-26);
  458. font-weight: 600;
  459. letter-spacing: -0.04em;
  460. }
  461. .plan-price span {
  462. color: var(--muted);
  463. font-size: var(--fs-12);
  464. }
  465. .plan-billing {
  466. min-height: 24px;
  467. margin: 0;
  468. color: var(--muted);
  469. font-size: var(--fs-12);
  470. }
  471. .plan-cta {
  472. width: 100%;
  473. min-height: 44px;
  474. margin-top: var(--sp-4);
  475. border: 1px solid var(--edge);
  476. border-radius: var(--r-md);
  477. background: var(--surface);
  478. color: var(--ink);
  479. font: inherit;
  480. font-size: var(--fs-14);
  481. font-weight: 500;
  482. cursor: pointer;
  483. }
  484. .plan-cta--primary {
  485. border-color: transparent;
  486. background: var(--primary);
  487. color: var(--primary-content);
  488. }
  489. .plan-cta:disabled {
  490. opacity: 0.5;
  491. cursor: not-allowed;
  492. }
  493. .plan-features {
  494. display: flex;
  495. flex-direction: column;
  496. gap: var(--sp-3);
  497. margin: var(--sp-6) 0 0;
  498. padding: var(--sp-5) 0 0;
  499. border-top: 1px solid var(--edge);
  500. list-style: none;
  501. }
  502. .plan-features li {
  503. display: flex;
  504. align-items: flex-start;
  505. gap: var(--sp-2);
  506. color: var(--ink-2);
  507. font-size: var(--fs-13);
  508. line-height: 1.6;
  509. }
  510. .plan-features i {
  511. margin-top: 4px;
  512. color: var(--muted);
  513. font-size: var(--fs-11);
  514. }
  515. .plans-code {
  516. max-height: 200px;
  517. overflow: auto;
  518. margin: var(--sp-3) 0 0;
  519. padding: var(--sp-3);
  520. border: 1px solid var(--edge);
  521. border-radius: var(--r-sm);
  522. background: var(--surface-2);
  523. color: var(--ink-2);
  524. font-family: ui-monospace, Consolas, monospace;
  525. font-size: var(--fs-12);
  526. line-height: 1.6;
  527. white-space: pre-wrap;
  528. overflow-wrap: anywhere;
  529. }
  530. .plans-error {
  531. display: flex;
  532. align-items: flex-start;
  533. gap: var(--sp-2);
  534. margin: 0 0 var(--sp-4);
  535. color: var(--danger);
  536. font-size: var(--fs-13);
  537. }
  538. .plans-note {
  539. display: flex;
  540. align-items: flex-start;
  541. gap: var(--sp-2);
  542. margin: var(--sp-5) 0 var(--sp-8);
  543. color: var(--muted);
  544. font-size: var(--fs-12);
  545. }
  546. .plans-note > i {
  547. margin-top: 3px;
  548. }
  549. /* ---------- 当前资产概览(2026-12-02) ---------- */
  550. .plans-status {
  551. display: grid;
  552. grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  553. gap: var(--sp-5);
  554. align-items: center;
  555. margin: 0 0 var(--sp-5);
  556. padding: var(--sp-4) var(--sp-5);
  557. border: 1px solid var(--edge);
  558. border-radius: var(--r-md);
  559. background: var(--surface);
  560. }
  561. .plans-status-item {
  562. display: flex;
  563. flex-direction: column;
  564. gap: 2px;
  565. min-width: 0;
  566. }
  567. .plans-status-label {
  568. font-size: var(--fs-12);
  569. color: var(--muted);
  570. }
  571. .plans-status-value {
  572. font-size: var(--fs-20);
  573. font-weight: 600;
  574. color: var(--ink);
  575. font-variant-numeric: tabular-nums;
  576. }
  577. .plans-status-hint {
  578. overflow: hidden;
  579. text-overflow: ellipsis;
  580. white-space: nowrap;
  581. font-size: var(--fs-12);
  582. color: var(--faint);
  583. }
  584. .plans-status-actions {
  585. display: flex;
  586. gap: var(--sp-2);
  587. }
  588. .plans-status-btn {
  589. display: inline-flex;
  590. align-items: center;
  591. gap: var(--sp-1);
  592. min-height: 40px;
  593. padding: 0 var(--sp-4);
  594. border: 1px solid var(--edge);
  595. border-radius: var(--r-md);
  596. background: var(--surface);
  597. color: var(--ink);
  598. font: inherit;
  599. font-size: var(--fs-13);
  600. cursor: pointer;
  601. }
  602. .plans-status-btn:hover {
  603. background: var(--surface-hover);
  604. }
  605. .plans-status-btn--primary {
  606. border-color: var(--primary);
  607. background: var(--primary);
  608. color: var(--inverse);
  609. }
  610. .plans-status-btn--primary:hover {
  611. background: var(--primary);
  612. opacity: 0.92;
  613. }
  614. .plans-status-btn:disabled {
  615. opacity: 0.5;
  616. cursor: not-allowed;
  617. }
  618. @media (max-width: 1100px) {
  619. .plans-status {
  620. grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  621. }
  622. .plans-status-actions {
  623. grid-column: 1 / -1;
  624. }
  625. }
  626. /* ---------- 底部链接 ---------- */
  627. .plans-links {
  628. display: grid;
  629. grid-template-columns: 1fr 1fr;
  630. gap: var(--sp-4);
  631. }
  632. .plans-link-card {
  633. display: flex;
  634. align-items: center;
  635. gap: var(--sp-3);
  636. padding: var(--sp-4) var(--sp-5);
  637. border: 1px solid var(--edge);
  638. border-radius: var(--r-md);
  639. background: var(--surface);
  640. }
  641. .plans-link-card > i {
  642. color: var(--muted);
  643. font-size: var(--fs-17);
  644. }
  645. .plans-link-card > div {
  646. flex: 1;
  647. min-width: 0;
  648. }
  649. .plans-link-card h3 {
  650. margin: 0;
  651. font-size: var(--fs-14);
  652. font-weight: 500;
  653. }
  654. .plans-link-card p {
  655. margin: 3px 0 0;
  656. color: var(--muted);
  657. font-size: var(--fs-12);
  658. }
  659. .plans-link-btn {
  660. flex: none;
  661. min-height: 44px;
  662. padding: 0 var(--sp-4);
  663. border: 1px solid var(--edge);
  664. border-radius: var(--r-md);
  665. background: var(--surface);
  666. color: var(--ink);
  667. font: inherit;
  668. font-size: var(--fs-13);
  669. cursor: pointer;
  670. }
  671. `,
  672. ],
  673. })
  674. export class DkPlansPage implements OnInit {
  675. protected readonly plan = inject(PlanService);
  676. protected readonly live = inject(LiveService);
  677. /* 命名确认弹窗状态(2026-12-03) */
  678. protected readonly confirmOpen = signal(false);
  679. protected readonly pendingCode = signal<PaidPlanCode | 'trial' | null>(null);
  680. protected readonly submitting = signal(false);
  681. /** 名额已满提示(2026-12-03)。null = 不显示 */
  682. protected readonly quotaFull = signal<{ plan: string; quota: number } | null>(null);
  683. protected readonly provision = inject(ProvisionService);
  684. private readonly router = inject(Router);
  685. ngOnInit(): void {
  686. void this.provision.restorePending();
  687. }
  688. protected readonly plans = computed(() => this.plan.catalog);
  689. /** 运行中的容器数(资产概览用;状态口径与通讯录一致) */
  690. protected readonly runningCount = computed(
  691. () => this.live.agents().filter((a) => a.status === 'running' || a.status === 'idle').length,
  692. );
  693. /**
  694. * 当前套餐名。
  695. *
  696. * 🔴 不从容器数量反推档位(2026-12-02 自查):2 个容器可能是「入门版 + 加购」,
  697. * 也可能是进阶版送的名额,数量推不出套餐 —— 猜错比不说更糟。
  698. * PlanService 暂无「当前订阅」字段,这里如实显示「已开通」;
  699. * 接入订阅接口后替换为真实套餐名。
  700. */
  701. protected readonly currentPlanName = computed(() =>
  702. this.live.agents().length > 0 ? '已开通' : '尚未开通',
  703. );
  704. /**
  705. * 全屏加载遮罩的文案(null = 不显示)。
  706. *
  707. * 🔴 区分两种慢操作,因为用户等待时的心理预期完全不同:
  708. * · 试用档生成提示词 → 要建 Matrix 身份,首次可能需要十秒左右
  709. * · 进阶/企业开通 → 只受理,很快,之后跳等待页
  710. */
  711. protected readonly loadingHint = computed<{ message: string; detail: string } | null>(() => {
  712. if (this.provision.restoring()) return { message: '正在检查开通任务…', detail: '正在找回已有进度,请稍候' };
  713. const p = this.provision.startingPlan();
  714. if (!p) return null;
  715. if (p === 'trial' || p === 'starter') {
  716. return { message: '正在准备接入信息…', detail: '首次生成可能需要 10 秒左右,请稍候' };
  717. }
  718. return { message: '正在提交开通申请…', detail: '马上就好' };
  719. });
  720. protected iconOf(code: PaidPlanCode): string {
  721. switch (code) {
  722. case 'starter':
  723. return 'fa-solid fa-server';
  724. case 'advanced':
  725. return 'fa-solid fa-wand-magic-sparkles';
  726. case 'enterprise':
  727. return 'fa-solid fa-building';
  728. default:
  729. return 'fa-solid fa-cube';
  730. }
  731. }
  732. /**
  733. * 发起开通。
  734. *
  735. * 🔴 只发起请求,不承诺结果:
  736. * · 试用/入门 → 后端返回接入提示词(用户自己的容器)
  737. * · 进阶/企业 → 后端真实创建,进入轮询态
  738. */
  739. /**
  740. * 发起开通(2026-11-27 改造)
  741. *
  742. * 与移动端同源逻辑:试用/入门留在本页给提示词,进阶/企业跳全屏等待页。
  743. */
  744. protected apply(code: PaidPlanCode | 'trial'): void {
  745. if (this.provision.isRunning()) return;
  746. /*
  747. * 名额已满就别让用户填名字了(2026-12-03)。
  748. * 在弹窗之前拦,而不是等提交后云函数返回 409 ——
  749. * 「认真填完名字才被告知名额已满」是很差的体验。
  750. */
  751. const quota = code === 'trial' ? 1 : (this.plan.planOf(code as never)?.quota ?? 0);
  752. if (quota > 0 && this.existingNames().length >= quota) {
  753. this.quotaFull.set({ plan: this.plan.planOf(code as never)?.name || '该套餐', quota });
  754. return;
  755. }
  756. /* 先弹命名确认(用户裁决 2026-12-03),不再直接提交 */
  757. this.pendingCode.set(code);
  758. this.confirmOpen.set(true);
  759. }
  760. /** 命名确认后真正提交;`name` 已由弹窗校验并 NFKC 归一化 */
  761. protected async onNameConfirmed(name: string): Promise<void> {
  762. const code = this.pendingCode();
  763. if (!code) return;
  764. this.submitting.set(true);
  765. try {
  766. const result = await this.provision.start(code, name);
  767. this.confirmOpen.set(false);
  768. this.pendingCode.set(null);
  769. if (result?.mode === 'provision' && result.jobId) {
  770. await this.router.navigateByUrl(`/provision?jobId=${encodeURIComponent(result.jobId)}`, {
  771. replaceUrl: true,
  772. });
  773. }
  774. } finally {
  775. this.submitting.set(false);
  776. }
  777. }
  778. protected cancelConfirm(): void {
  779. this.confirmOpen.set(false);
  780. this.pendingCode.set(null);
  781. }
  782. protected readonly pendingPlanName = computed(() => {
  783. const c = this.pendingCode();
  784. if (!c) return '';
  785. if (c === 'trial') return '试用';
  786. return this.plan.planOf(c as PaidPlanCode)?.name ?? '套餐';
  787. });
  788. protected readonly pendingIsOnboarding = computed(() => {
  789. const c = this.pendingCode();
  790. return c === 'trial' || c === 'starter';
  791. });
  792. protected readonly pendingQuota = computed(() => {
  793. const c = this.pendingCode();
  794. if (!c || c === 'trial') return 1;
  795. return this.plan.planOf(c as PaidPlanCode)?.quota ?? 0;
  796. });
  797. protected readonly existingNames = computed(() =>
  798. this.live.agents().map((a) => a.name).filter((n): n is string => !!n),
  799. );
  800. protected readonly suggestedName = computed(() => suggestContainerName(this.existingNames()));
  801. protected go(path: string): void {
  802. void this.router.navigateByUrl(path);
  803. }
  804. }