console.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Data Nexus - 数据控制台</title>
  7. <meta name="description" content="Data Nexus 数据中台管理控制台">
  8. <link rel="preconnect" href="https://fonts.googleapis.com">
  9. <link
  10. href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
  11. rel="stylesheet">
  12. <style>
  13. *,
  14. *::before,
  15. *::after {
  16. margin: 0;
  17. padding: 0;
  18. box-sizing: border-box;
  19. }
  20. :root {
  21. --bg-base: #080c18;
  22. --bg-sidebar: #0c1222;
  23. --bg-surface: #111827;
  24. --bg-card: #151f32;
  25. --bg-card-head: rgba(0, 0, 0, 0.2);
  26. --bg-hover: rgba(255, 255, 255, 0.04);
  27. --bg-active: rgba(99, 179, 237, 0.08);
  28. --border: rgba(255, 255, 255, 0.06);
  29. --border-card: rgba(255, 255, 255, 0.08);
  30. --border-active: rgba(99, 179, 237, 0.35);
  31. --text-primary: #e2e8f0;
  32. --text-secondary: #8b9ab5;
  33. --text-muted: #556477;
  34. --accent: #63b3ed;
  35. --accent-light: #90cdf4;
  36. --accent-dim: rgba(99, 179, 237, 0.12);
  37. --green: #68d391;
  38. --green-dim: rgba(104, 211, 145, 0.12);
  39. --orange: #f6ad55;
  40. --orange-dim: rgba(246, 173, 85, 0.12);
  41. --purple: #b794f4;
  42. --radius: 8px;
  43. --sidebar-w: 280px;
  44. }
  45. body {
  46. font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  47. background: var(--bg-base);
  48. color: var(--text-primary);
  49. height: 100vh;
  50. overflow: hidden;
  51. line-height: 1.5;
  52. }
  53. ::-webkit-scrollbar {
  54. width: 5px;
  55. }
  56. ::-webkit-scrollbar-track {
  57. background: transparent;
  58. }
  59. ::-webkit-scrollbar-thumb {
  60. background: rgba(255, 255, 255, 0.08);
  61. border-radius: 3px;
  62. }
  63. ::-webkit-scrollbar-thumb:hover {
  64. background: rgba(255, 255, 255, 0.14);
  65. }
  66. /* Layout */
  67. .app {
  68. display: grid;
  69. grid-template-columns: var(--sidebar-w) 1fr;
  70. height: 100vh;
  71. }
  72. /* Sidebar */
  73. .sidebar {
  74. background: var(--bg-sidebar);
  75. border-right: 1px solid var(--border);
  76. display: flex;
  77. flex-direction: column;
  78. overflow: hidden;
  79. }
  80. .sidebar-header {
  81. display: flex;
  82. align-items: center;
  83. gap: 10px;
  84. padding: 20px 20px 16px;
  85. flex-shrink: 0;
  86. }
  87. .sidebar-header svg {
  88. width: 26px;
  89. height: 26px;
  90. color: var(--accent);
  91. flex-shrink: 0;
  92. }
  93. .sidebar-header span {
  94. font-size: 16px;
  95. font-weight: 700;
  96. background: linear-gradient(135deg, var(--accent-light), var(--purple));
  97. -webkit-background-clip: text;
  98. background-clip: text;
  99. -webkit-text-fill-color: transparent;
  100. }
  101. .sidebar-section {
  102. padding: 0 16px;
  103. flex-shrink: 0;
  104. }
  105. .sidebar-label {
  106. display: block;
  107. font-size: 11px;
  108. font-weight: 600;
  109. color: var(--text-muted);
  110. text-transform: uppercase;
  111. letter-spacing: 0.8px;
  112. padding: 12px 4px 8px;
  113. }
  114. .sidebar-divider {
  115. height: 1px;
  116. background: var(--border);
  117. margin: 8px 16px;
  118. flex-shrink: 0;
  119. }
  120. /* Project select */
  121. .select-wrap {
  122. position: relative;
  123. }
  124. .select-wrap::after {
  125. content: '';
  126. position: absolute;
  127. right: 12px;
  128. top: 50%;
  129. transform: translateY(-50%);
  130. border: 4px solid transparent;
  131. border-top: 5px solid var(--text-muted);
  132. pointer-events: none;
  133. }
  134. .project-select {
  135. width: 100%;
  136. padding: 9px 32px 9px 12px;
  137. background: var(--bg-surface);
  138. border: 1px solid var(--border);
  139. border-radius: 6px;
  140. color: var(--text-primary);
  141. font-family: inherit;
  142. font-size: 13px;
  143. cursor: pointer;
  144. appearance: none;
  145. outline: none;
  146. transition: border-color 0.2s;
  147. }
  148. .project-select:focus {
  149. border-color: var(--accent);
  150. }
  151. .project-select option {
  152. background: var(--bg-surface);
  153. color: var(--text-primary);
  154. }
  155. /* Stage tree */
  156. .stage-tree-wrap {
  157. flex: 1;
  158. overflow-y: auto;
  159. padding: 0 8px 16px;
  160. }
  161. .tree-branch-header {
  162. display: flex;
  163. align-items: center;
  164. gap: 4px;
  165. padding: 7px 10px;
  166. cursor: pointer;
  167. border-radius: 6px;
  168. transition: background 0.12s;
  169. user-select: none;
  170. font-size: 13px;
  171. color: var(--text-secondary);
  172. }
  173. .tree-branch-header:hover {
  174. background: var(--bg-hover);
  175. }
  176. .tree-arrow {
  177. width: 16px;
  178. height: 16px;
  179. color: var(--text-muted);
  180. transition: transform 0.2s;
  181. flex-shrink: 0;
  182. }
  183. .tree-arrow.open {
  184. transform: rotate(90deg);
  185. }
  186. .tree-children {
  187. display: none;
  188. padding-left: 8px;
  189. margin-left: 12px;
  190. border-left: 1px solid var(--border);
  191. }
  192. .tree-children.open {
  193. display: block;
  194. }
  195. .tree-leaf {
  196. display: flex;
  197. align-items: center;
  198. gap: 8px;
  199. padding: 7px 10px 7px 12px;
  200. cursor: pointer;
  201. border-radius: 6px;
  202. transition: all 0.12s;
  203. font-size: 13px;
  204. color: var(--text-secondary);
  205. }
  206. .tree-leaf:hover {
  207. background: var(--bg-hover);
  208. color: var(--text-primary);
  209. }
  210. .tree-leaf.active {
  211. background: var(--bg-active);
  212. color: var(--accent);
  213. font-weight: 500;
  214. }
  215. .tree-dot {
  216. width: 5px;
  217. height: 5px;
  218. border-radius: 50%;
  219. background: var(--text-muted);
  220. flex-shrink: 0;
  221. }
  222. .tree-leaf.active .tree-dot {
  223. background: var(--accent);
  224. }
  225. .tree-count {
  226. margin-left: auto;
  227. font-size: 11px;
  228. color: var(--text-muted);
  229. background: rgba(255, 255, 255, 0.04);
  230. padding: 1px 6px;
  231. border-radius: 4px;
  232. }
  233. /* Content */
  234. .content {
  235. display: flex;
  236. flex-direction: column;
  237. height: 100vh;
  238. overflow: hidden;
  239. }
  240. .content-header {
  241. flex-shrink: 0;
  242. padding: 18px 28px;
  243. border-bottom: 1px solid var(--border);
  244. background: rgba(12, 18, 34, 0.6);
  245. backdrop-filter: blur(12px);
  246. display: flex;
  247. align-items: center;
  248. justify-content: space-between;
  249. min-height: 60px;
  250. }
  251. .stage-path {
  252. display: flex;
  253. align-items: center;
  254. gap: 6px;
  255. font-size: 14px;
  256. }
  257. .stage-path .sep {
  258. color: var(--text-muted);
  259. font-size: 11px;
  260. }
  261. .stage-path .seg {
  262. color: var(--text-secondary);
  263. }
  264. .stage-path .seg:last-child {
  265. color: var(--text-primary);
  266. font-weight: 600;
  267. }
  268. .header-info {
  269. font-size: 12px;
  270. color: var(--text-muted);
  271. }
  272. .content-body {
  273. flex: 1;
  274. overflow-y: auto;
  275. padding: 24px 28px;
  276. }
  277. /* Welcome state */
  278. .state-box {
  279. display: flex;
  280. flex-direction: column;
  281. align-items: center;
  282. justify-content: center;
  283. height: 100%;
  284. text-align: center;
  285. color: var(--text-muted);
  286. padding: 40px;
  287. }
  288. .state-box svg {
  289. width: 56px;
  290. height: 56px;
  291. margin-bottom: 20px;
  292. opacity: 0.25;
  293. }
  294. .state-box h2 {
  295. font-size: 17px;
  296. font-weight: 600;
  297. color: var(--text-secondary);
  298. margin-bottom: 6px;
  299. }
  300. .state-box p {
  301. font-size: 13px;
  302. }
  303. /* Spinner */
  304. .spinner {
  305. width: 28px;
  306. height: 28px;
  307. border: 3px solid var(--border);
  308. border-top-color: var(--accent);
  309. border-radius: 50%;
  310. animation: spin 0.7s linear infinite;
  311. margin-bottom: 16px;
  312. }
  313. @keyframes spin {
  314. to {
  315. transform: rotate(360deg);
  316. }
  317. }
  318. /* Version card */
  319. .version-card {
  320. background: var(--bg-card);
  321. border: 1px solid var(--border-card);
  322. border-radius: var(--radius);
  323. overflow: hidden;
  324. margin-bottom: 16px;
  325. animation: fadeUp 0.35s ease forwards;
  326. opacity: 0;
  327. }
  328. .version-card:hover {
  329. border-color: rgba(255, 255, 255, 0.1);
  330. }
  331. .version-head {
  332. display: flex;
  333. align-items: center;
  334. gap: 14px;
  335. padding: 14px 20px;
  336. border-bottom: 1px solid var(--border);
  337. background: var(--bg-card-head);
  338. flex-wrap: wrap;
  339. }
  340. .v-author {
  341. font-size: 13px;
  342. color: var(--text-secondary);
  343. }
  344. .v-time {
  345. margin-left: auto;
  346. font-size: 12px;
  347. color: var(--text-muted);
  348. }
  349. /* File row grid */
  350. .file-row {
  351. display: grid;
  352. grid-template-columns: 1fr 100px;
  353. gap: 16px;
  354. align-items: center;
  355. padding: 12px 20px;
  356. border-bottom: 1px solid var(--border);
  357. transition: background 0.1s;
  358. }
  359. .file-row:last-child {
  360. border-bottom: none;
  361. }
  362. .file-row:hover {
  363. background: var(--bg-hover);
  364. }
  365. .file-name-col {
  366. display: flex;
  367. align-items: center;
  368. gap: 10px;
  369. min-width: 0;
  370. /* allows text truncation */
  371. }
  372. @keyframes fadeUp {
  373. from {
  374. opacity: 0;
  375. transform: translateY(10px);
  376. }
  377. to {
  378. opacity: 1;
  379. transform: translateY(0);
  380. }
  381. }
  382. .f-icon {
  383. width: 18px;
  384. height: 18px;
  385. flex-shrink: 0;
  386. color: var(--text-muted);
  387. }
  388. .f-name {
  389. font-size: 13px;
  390. color: var(--text-primary);
  391. white-space: nowrap;
  392. overflow: hidden;
  393. text-overflow: ellipsis;
  394. }
  395. .f-size {
  396. font-size: 11px;
  397. color: var(--text-muted);
  398. margin-left: 6px;
  399. }
  400. .col-text {
  401. font-size: 13px;
  402. color: var(--text-secondary);
  403. white-space: nowrap;
  404. overflow: hidden;
  405. text-overflow: ellipsis;
  406. }
  407. .commit-tag {
  408. display: inline-flex;
  409. align-items: center;
  410. gap: 5px;
  411. font-family: 'JetBrains Mono', monospace;
  412. font-size: 13px;
  413. font-weight: 500;
  414. color: var(--accent);
  415. background: var(--accent-dim);
  416. padding: 3px 10px;
  417. border-radius: 5px;
  418. }
  419. .commit-tag svg {
  420. width: 14px;
  421. height: 14px;
  422. }
  423. .btn-dl-wrap {
  424. display: flex;
  425. justify-content: flex-end;
  426. }
  427. .btn-dl {
  428. display: inline-flex;
  429. align-items: center;
  430. gap: 4px;
  431. padding: 4px 10px;
  432. border-radius: 5px;
  433. border: none;
  434. background: var(--accent-dim);
  435. color: var(--accent);
  436. font-size: 12px;
  437. font-family: inherit;
  438. cursor: pointer;
  439. transition: all 0.15s;
  440. text-decoration: none;
  441. flex-shrink: 0;
  442. }
  443. .btn-dl:hover {
  444. background: rgba(99, 179, 237, 0.2);
  445. }
  446. .btn-dl svg {
  447. width: 13px;
  448. height: 13px;
  449. }
  450. /* File group (folder) */
  451. .fg-header {
  452. display: grid;
  453. grid-template-columns: 1fr 100px;
  454. gap: 16px;
  455. align-items: center;
  456. padding: 12px 20px;
  457. border-bottom: 1px solid var(--border);
  458. cursor: pointer;
  459. transition: background 0.1s;
  460. user-select: none;
  461. }
  462. .fg-header:hover {
  463. background: var(--bg-hover);
  464. }
  465. .fg-name-wrap {
  466. display: flex;
  467. align-items: center;
  468. gap: 8px;
  469. min-width: 0;
  470. }
  471. .fg-header:hover {
  472. background: var(--bg-hover);
  473. }
  474. .fg-arrow {
  475. width: 14px;
  476. height: 14px;
  477. color: var(--text-muted);
  478. transition: transform 0.2s;
  479. flex-shrink: 0;
  480. }
  481. .fg-arrow.open {
  482. transform: rotate(90deg);
  483. }
  484. .fg-icon {
  485. width: 18px;
  486. height: 18px;
  487. flex-shrink: 0;
  488. color: var(--orange);
  489. }
  490. .fg-name {
  491. font-size: 13px;
  492. color: var(--text-primary);
  493. font-weight: 500;
  494. }
  495. .fg-count {
  496. font-size: 11px;
  497. color: var(--text-muted);
  498. background: rgba(255, 255, 255, 0.04);
  499. padding: 1px 7px;
  500. border-radius: 4px;
  501. margin-left: 4px;
  502. }
  503. .fg-children {
  504. display: none;
  505. }
  506. .fg-children.open {
  507. display: block;
  508. }
  509. /* Load more */
  510. .load-more {
  511. display: flex;
  512. justify-content: center;
  513. padding: 16px;
  514. }
  515. .load-more-btn {
  516. padding: 9px 28px;
  517. border-radius: 6px;
  518. border: 1px solid var(--border);
  519. background: transparent;
  520. color: var(--text-secondary);
  521. font-family: inherit;
  522. font-size: 13px;
  523. cursor: pointer;
  524. transition: all 0.2s;
  525. }
  526. .load-more-btn:hover {
  527. background: var(--bg-hover);
  528. color: var(--text-primary);
  529. border-color: var(--border-active);
  530. }
  531. .load-more-btn:disabled {
  532. opacity: 0.4;
  533. cursor: default;
  534. }
  535. </style>
  536. </head>
  537. <body>
  538. <div class="app">
  539. <aside class="sidebar">
  540. <div class="sidebar-header">
  541. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  542. <path
  543. d="M21 16V8a2 2 0 00-1-1.73l-7-4a2 2 0 00-2 0l-7 4A2 2 0 003 8v8a2 2 0 001 1.73l7 4a2 2 0 002 0l7-4A2 2 0 0021 16z" />
  544. <polyline points="3.27 6.96 12 12.01 20.73 6.96" />
  545. <line x1="12" y1="22.08" x2="12" y2="12" />
  546. </svg>
  547. <span>Data Nexus</span>
  548. </div>
  549. <div class="sidebar-divider"></div>
  550. <div class="stage-tree-wrap" id="stageTreeWrap"></div>
  551. </aside>
  552. <main class="content">
  553. <div class="content-header">
  554. <div class="stage-path" id="stagePath"><span class="seg" style="color:var(--text-muted)">选择左侧数据阶段</span>
  555. </div>
  556. <div class="header-info" id="headerInfo"></div>
  557. </div>
  558. <div class="content-body" id="contentBody">
  559. <div class="state-box">
  560. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
  561. <path
  562. d="M21 16V8a2 2 0 00-1-1.73l-7-4a2 2 0 00-2 0l-7 4A2 2 0 003 8v8a2 2 0 001 1.73l7 4a2 2 0 002 0l7-4A2 2 0 0021 16z" />
  563. <polyline points="3.27 6.96 12 12.01 20.73 6.96" />
  564. <line x1="12" y1="22.08" x2="12" y2="12" />
  565. </svg>
  566. <h2>欢迎使用数据控制台</h2>
  567. <p>从左侧选择数据阶段,查看文件版本历史</p>
  568. </div>
  569. </div>
  570. </main>
  571. </div>
  572. <script>
  573. // ============ Icons ============
  574. const IC = {
  575. commit: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="4"/><line x1="1.05" y1="12" x2="7" y2="12"/><line x1="17.01" y1="12" x2="22.96" y2="12"/></svg>',
  576. file: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>',
  577. folder: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 19a2 2 0 01-2 2H4a2 2 0 01-2-2V5a2 2 0 012-2h5l2 3h9a2 2 0 012 2z"/></svg>',
  578. download: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>',
  579. chevron: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="9 18 15 12 9 6"/></svg>',
  580. };
  581. // ============ State ============
  582. const PAGE_SIZE = 20;
  583. let S = {
  584. stages: [], // raw stage data from /stages/all
  585. stageProjectMap: {}, // stage name -> project_id
  586. stage: null,
  587. versions: [],
  588. skip: 0,
  589. hasMore: true,
  590. loading: false,
  591. };
  592. const $ = id => document.getElementById(id);
  593. // ============ Utils ============
  594. function esc(s) { if (!s) return ''; const d = document.createElement('div'); d.textContent = s; return d.innerHTML; }
  595. function fmtSize(b) {
  596. if (!b && b !== 0) return '-';
  597. const u = ['B', 'KB', 'MB', 'GB']; let i = 0, s = b;
  598. while (s >= 1024 && i < u.length - 1) { s /= 1024; i++; }
  599. return s.toFixed(i > 0 ? 1 : 0) + ' ' + u[i];
  600. }
  601. function fmtTime(iso) {
  602. if (!iso) return '';
  603. const d = new Date(iso), p = n => String(n).padStart(2, '0');
  604. return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
  605. }
  606. function relTime(iso) {
  607. if (!iso) return '';
  608. const m = Math.floor((Date.now() - new Date(iso).getTime()) / 60000);
  609. if (m < 1) return '刚刚'; if (m < 60) return m + ' 分钟前';
  610. const h = Math.floor(m / 60); if (h < 24) return h + ' 小时前';
  611. const d = Math.floor(h / 24); if (d < 30) return d + ' 天前';
  612. return fmtTime(iso);
  613. }
  614. async function api(url) { const r = await fetch(url); if (!r.ok) throw new Error(r.status); return r.json(); }
  615. // ============ Load All Stages ============
  616. async function loadAllStages() {
  617. $('stageTreeWrap').innerHTML = '<div style="padding:16px;text-align:center;"><div class="spinner" style="margin:0 auto 8px;"></div><span style="font-size:12px;color:var(--text-muted)">加载中...</span></div>';
  618. try {
  619. S.stages = await api('/stages/all');
  620. // Build stage -> project_id mapping
  621. S.stageProjectMap = {};
  622. S.stages.forEach(st => { S.stageProjectMap[st.name] = st.project_id; });
  623. renderStageTree();
  624. } catch (e) { $('stageTreeWrap').innerHTML = '<div style="padding:16px;color:#fc8181;font-size:13px;">加载失败</div>'; }
  625. }
  626. // ============ Stage Tree ============
  627. function buildTree(stages) {
  628. const root = [];
  629. for (const st of stages) {
  630. const parts = st.name.split('/');
  631. let cur = root;
  632. for (let i = 0; i < parts.length; i++) {
  633. let node = cur.find(n => n.label === parts[i]);
  634. if (!node) {
  635. node = { label: parts[i], children: [] };
  636. cur.push(node);
  637. }
  638. if (i === parts.length - 1) {
  639. node.stage = st.name;
  640. node.count = st.version_count;
  641. }
  642. cur = node.children;
  643. }
  644. }
  645. return root;
  646. }
  647. function renderStageTree() {
  648. const tree = buildTree(S.stages);
  649. $('stageTreeWrap').innerHTML = tree.length ? renderNodes(tree) : '<div style="padding:16px;font-size:13px;color:var(--text-muted)">暂无数据阶段</div>';
  650. }
  651. function renderNodes(nodes) {
  652. let h = '';
  653. for (const n of nodes) {
  654. if (n.stage && n.children.length === 0) {
  655. // Leaf
  656. h += `<div class="tree-leaf" data-stage="${esc(n.stage)}" onclick="selectStage(this, '${esc(n.stage)}')">
  657. <span class="tree-dot"></span>
  658. <span>${esc(n.label)}</span>
  659. <span class="tree-count">${n.count || ''}</span>
  660. </div>`;
  661. } else {
  662. // Branch (may also be a stage itself)
  663. const id = 'tb_' + Math.random().toString(36).substr(2, 6);
  664. h += `<div>
  665. <div class="tree-branch-header" onclick="toggleBranch('${id}', this)">
  666. <span class="tree-arrow" id="a_${id}">${IC.chevron}</span>
  667. <span>${esc(n.label)}</span>
  668. </div>
  669. <div class="tree-children" id="${id}">${renderNodes(n.children)}</div>
  670. </div>`;
  671. }
  672. }
  673. return h;
  674. }
  675. function toggleBranch(id, el) {
  676. const ch = $(id), ar = $('a_' + id);
  677. if (ch) ch.classList.toggle('open');
  678. if (ar) ar.classList.toggle('open');
  679. }
  680. function selectStage(el, stageName) {
  681. // Highlight
  682. document.querySelectorAll('.tree-leaf.active').forEach(e => e.classList.remove('active'));
  683. el.classList.add('active');
  684. S.stage = stageName;
  685. S.versions = []; S.skip = 0; S.hasMore = true;
  686. updateHeader();
  687. loadVersions();
  688. }
  689. // ============ Header ============
  690. function updateHeader() {
  691. if (!S.stage) {
  692. $('stagePath').innerHTML = '<span class="seg" style="color:var(--text-muted)">选择左侧数据阶段</span>';
  693. $('headerInfo').textContent = '';
  694. return;
  695. }
  696. const parts = S.stage.split('/');
  697. $('stagePath').innerHTML = parts.map((p, i) =>
  698. `${i > 0 ? '<span class="sep">/</span>' : ''}<span class="seg">${esc(p)}</span>`
  699. ).join('');
  700. }
  701. // ============ Versions ============
  702. async function loadVersions(append) {
  703. if (S.loading) return;
  704. S.loading = true;
  705. if (!append) {
  706. $('contentBody').innerHTML = '<div class="state-box"><div class="spinner"></div><p>加载中...</p></div>';
  707. }
  708. try {
  709. const pid = S.stageProjectMap[S.stage];
  710. const data = await api(`/projects/${pid}/stage-files?stage=${encodeURIComponent(S.stage)}&skip=${S.skip}&limit=${PAGE_SIZE}`);
  711. if (!append) S.versions = [];
  712. S.versions.push(...data);
  713. S.hasMore = data.length >= PAGE_SIZE;
  714. S.skip += data.length;
  715. renderVersions();
  716. const stageInfo = S.stages.find(s => s.name === S.stage);
  717. $('headerInfo').textContent = stageInfo ? `共 ${stageInfo.version_count} 次提交` : '';
  718. } catch (e) {
  719. if (!append) $('contentBody').innerHTML = '<div class="state-box"><p style="color:#fc8181;">加载失败: ' + esc(e.message) + '</p></div>';
  720. }
  721. S.loading = false;
  722. }
  723. function renderVersions() {
  724. if (!S.versions.length) {
  725. $('contentBody').innerHTML = '<div class="state-box"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/></svg><h2>暂无数据</h2><p>该阶段还没有提交记录</p></div>';
  726. return;
  727. }
  728. let h = '';
  729. S.versions.forEach((v, i) => {
  730. const tree = buildFileTree(v.files);
  731. h += `<div class="version-card" style="animation-delay:${Math.min(i, 10) * 0.05}s">
  732. <div class="version-head">
  733. <span class="commit-tag">${IC.commit} ${esc(v.commit_id.substring(0, 8))}</span>
  734. <span class="v-author">${v.author ? esc(v.author) : ''}</span>
  735. <span class="v-time" title="${fmtTime(v.created_at)}">${relTime(v.created_at)}</span>
  736. </div>
  737. <div class="version-files">${renderTree(tree, v, 0)}</div>
  738. </div>`;
  739. });
  740. if (S.hasMore) {
  741. h += '<div class="load-more"><button class="load-more-btn" onclick="loadMore()">加载更多</button></div>';
  742. }
  743. $('contentBody').innerHTML = h;
  744. }
  745. function loadMore() {
  746. const btn = document.querySelector('.load-more-btn');
  747. if (btn) { btn.disabled = true; btn.textContent = '加载中...'; }
  748. loadVersions(true);
  749. }
  750. // ============ File Grouping ============
  751. function countFiles(node) {
  752. let cnt = node.files.length;
  753. Object.values(node.dirs).forEach(d => { cnt += countFiles(d); });
  754. return cnt;
  755. }
  756. function buildFileTree(files) {
  757. const root = { dirs: {}, files: [], path: '' };
  758. if (!files || !files.length) return root;
  759. files.forEach(f => {
  760. const parts = f.relative_path.split('/');
  761. let cur = root;
  762. for (let i = 0; i < parts.length - 1; i++) {
  763. const p = parts[i];
  764. if (!cur.dirs[p]) {
  765. const curPath = cur.path ? cur.path + '/' + p : p;
  766. cur.dirs[p] = { name: p, path: curPath, dirs: {}, files: [] };
  767. }
  768. cur = cur.dirs[p];
  769. }
  770. cur.files.push(f);
  771. });
  772. function compact(node) {
  773. const dirKeys = Object.keys(node.dirs);
  774. dirKeys.forEach(k => {
  775. compact(node.dirs[k]);
  776. });
  777. Object.keys(node.dirs).forEach(k => {
  778. let child = node.dirs[k];
  779. if (!child) return;
  780. let changed = true;
  781. while (changed) {
  782. changed = false;
  783. if (Object.keys(child.dirs).length === 1 && child.files.length === 0) {
  784. const onlyChildKey = Object.keys(child.dirs)[0];
  785. const onlyChild = child.dirs[onlyChildKey];
  786. child.name = child.name + '/' + onlyChild.name;
  787. child.path = onlyChild.path;
  788. child.dirs = onlyChild.dirs;
  789. child.files = onlyChild.files;
  790. changed = true;
  791. }
  792. if (Object.keys(child.dirs).length === 0 && child.files.length === 1) {
  793. node.files.push(child.files[0]);
  794. delete node.dirs[k];
  795. // since child is deleted, break inner loops
  796. changed = false;
  797. }
  798. }
  799. });
  800. }
  801. compact(root);
  802. return root;
  803. }
  804. function renderTree(node, version, depth) {
  805. let h = '';
  806. const dirKeys = Object.keys(node.dirs).sort((a, b) => a.localeCompare(b));
  807. dirKeys.forEach(k => {
  808. const d = node.dirs[k];
  809. const gid = 'fg_' + Math.random().toString(36).substr(2, 6);
  810. const fileCount = countFiles(d);
  811. const padding = `padding-left: ${20 + depth * 24}px;`;
  812. h += `
  813. <div class="fg-header" style="${padding}" onclick="toggleFG('${gid}')">
  814. <div class="fg-name-wrap">
  815. <span class="fg-arrow" id="fa_${gid}">${IC.chevron}</span>
  816. <span class="fg-icon">${IC.folder}</span>
  817. <span class="fg-name" title="${esc(d.path)}">${esc(d.name)}/</span>
  818. <span class="fg-count">${fileCount} 个文件</span>
  819. </div>
  820. <div></div>
  821. </div>
  822. <div class="fg-children" id="${gid}">
  823. ${renderTree(d, version, depth + 1)}
  824. </div>`;
  825. });
  826. node.files.sort((a, b) => a.relative_path.localeCompare(b.relative_path)).forEach(f => {
  827. let displayName = f.relative_path || f.name;
  828. if (node.path && f.relative_path.startsWith(node.path + '/')) {
  829. displayName = f.relative_path.substring(node.path.length + 1);
  830. }
  831. const padding = `padding-left: ${depth === 0 ? 20 : 44 + (depth - 1) * 24}px;`;
  832. h += `
  833. <div class="file-row" style="${padding}">
  834. <div class="file-name-col" title="${esc(f.relative_path)}">
  835. <span class="f-icon">${IC.file}</span>
  836. <span class="f-name">${esc(displayName)}</span>
  837. <span class="f-size">${fmtSize(f.file_size)}</span>
  838. </div>
  839. <div class="btn-dl-wrap">
  840. <a class="btn-dl" href="/files/${f.id}/content" download="${esc(f.name)}" onclick="event.stopPropagation();">${IC.download}</a>
  841. </div>
  842. </div>`;
  843. });
  844. if (depth === 0 && h === '') {
  845. return '<div style="padding:14px 20px;font-size:13px;color:var(--text-muted)">暂无文件</div>';
  846. }
  847. return h;
  848. }
  849. function toggleFG(id) {
  850. const ch = $(id), ar = $('fa_' + id);
  851. if (ch) ch.classList.toggle('open');
  852. if (ar) ar.classList.toggle('open');
  853. }
  854. // ============ UI Helpers ============
  855. function showWelcome() {
  856. $('stagePath').innerHTML = '<span class="seg" style="color:var(--text-muted)">选择左侧数据阶段</span>';
  857. $('headerInfo').textContent = '';
  858. $('contentBody').innerHTML = `<div class="state-box">
  859. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
  860. <path d="M21 16V8a2 2 0 00-1-1.73l-7-4a2 2 0 00-2 0l-7 4A2 2 0 003 8v8a2 2 0 001 1.73l7 4a2 2 0 002 0l7-4A2 2 0 0021 16z"/>
  861. <polyline points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/>
  862. </svg>
  863. <h2>欢迎使用数据控制台</h2>
  864. <p>从左侧选择数据阶段,查看文件版本历史</p>
  865. </div>`;
  866. }
  867. // ============ Init ============
  868. loadAllStages();
  869. </script>
  870. </body>
  871. </html>