console.html 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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. background: rgba(0, 0, 0, 0.1);
  506. }
  507. .fg-children.open {
  508. display: block;
  509. }
  510. /* Load more */
  511. .load-more {
  512. display: flex;
  513. justify-content: center;
  514. padding: 16px;
  515. }
  516. .load-more-btn {
  517. padding: 9px 28px;
  518. border-radius: 6px;
  519. border: 1px solid var(--border);
  520. background: transparent;
  521. color: var(--text-secondary);
  522. font-family: inherit;
  523. font-size: 13px;
  524. cursor: pointer;
  525. transition: all 0.2s;
  526. }
  527. .load-more-btn:hover {
  528. background: var(--bg-hover);
  529. color: var(--text-primary);
  530. border-color: var(--border-active);
  531. }
  532. .load-more-btn:disabled {
  533. opacity: 0.4;
  534. cursor: default;
  535. }
  536. </style>
  537. </head>
  538. <body>
  539. <div class="app">
  540. <aside class="sidebar">
  541. <div class="sidebar-header">
  542. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  543. <path
  544. 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" />
  545. <polyline points="3.27 6.96 12 12.01 20.73 6.96" />
  546. <line x1="12" y1="22.08" x2="12" y2="12" />
  547. </svg>
  548. <span>Data Nexus</span>
  549. </div>
  550. <div class="sidebar-divider"></div>
  551. <div class="stage-tree-wrap" id="stageTreeWrap"></div>
  552. </aside>
  553. <main class="content">
  554. <div class="content-header">
  555. <div class="stage-path" id="stagePath"><span class="seg" style="color:var(--text-muted)">选择左侧数据阶段</span>
  556. </div>
  557. <div class="header-info" id="headerInfo"></div>
  558. </div>
  559. <div class="content-body" id="contentBody">
  560. <div class="state-box">
  561. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
  562. <path
  563. 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" />
  564. <polyline points="3.27 6.96 12 12.01 20.73 6.96" />
  565. <line x1="12" y1="22.08" x2="12" y2="12" />
  566. </svg>
  567. <h2>欢迎使用数据控制台</h2>
  568. <p>从左侧选择数据阶段,查看文件版本历史</p>
  569. </div>
  570. </div>
  571. </main>
  572. </div>
  573. <script>
  574. // ============ Icons ============
  575. const IC = {
  576. 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>',
  577. 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>',
  578. 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>',
  579. 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>',
  580. chevron: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="9 18 15 12 9 6"/></svg>',
  581. };
  582. // ============ State ============
  583. const PAGE_SIZE = 20;
  584. let S = {
  585. stages: [], // raw stage data from /stages/all
  586. stageProjectMap: {}, // stage name -> project_id
  587. stage: null,
  588. versions: [],
  589. skip: 0,
  590. hasMore: true,
  591. loading: false,
  592. };
  593. const $ = id => document.getElementById(id);
  594. // ============ Utils ============
  595. function esc(s) { if (!s) return ''; const d = document.createElement('div'); d.textContent = s; return d.innerHTML; }
  596. function fmtSize(b) {
  597. if (!b && b !== 0) return '-';
  598. const u = ['B', 'KB', 'MB', 'GB']; let i = 0, s = b;
  599. while (s >= 1024 && i < u.length - 1) { s /= 1024; i++; }
  600. return s.toFixed(i > 0 ? 1 : 0) + ' ' + u[i];
  601. }
  602. function fmtTime(iso) {
  603. if (!iso) return '';
  604. const d = new Date(iso), p = n => String(n).padStart(2, '0');
  605. return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
  606. }
  607. function relTime(iso) {
  608. if (!iso) return '';
  609. const m = Math.floor((Date.now() - new Date(iso).getTime()) / 60000);
  610. if (m < 1) return '刚刚'; if (m < 60) return m + ' 分钟前';
  611. const h = Math.floor(m / 60); if (h < 24) return h + ' 小时前';
  612. const d = Math.floor(h / 24); if (d < 30) return d + ' 天前';
  613. return fmtTime(iso);
  614. }
  615. async function api(url) { const r = await fetch(url); if (!r.ok) throw new Error(r.status); return r.json(); }
  616. // ============ Load All Stages ============
  617. async function loadAllStages() {
  618. $('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>';
  619. try {
  620. S.stages = await api('/stages/all');
  621. // Build stage -> project_id mapping
  622. S.stageProjectMap = {};
  623. S.stages.forEach(st => { S.stageProjectMap[st.name] = st.project_id; });
  624. renderStageTree();
  625. } catch (e) { $('stageTreeWrap').innerHTML = '<div style="padding:16px;color:#fc8181;font-size:13px;">加载失败</div>'; }
  626. }
  627. // ============ Stage Tree ============
  628. function buildTree(stages) {
  629. const root = [];
  630. for (const st of stages) {
  631. const parts = st.name.split('/');
  632. let cur = root;
  633. for (let i = 0; i < parts.length; i++) {
  634. let node = cur.find(n => n.label === parts[i]);
  635. if (!node) {
  636. node = { label: parts[i], children: [] };
  637. cur.push(node);
  638. }
  639. if (i === parts.length - 1) {
  640. node.stage = st.name;
  641. node.count = st.version_count;
  642. }
  643. cur = node.children;
  644. }
  645. }
  646. return root;
  647. }
  648. function renderStageTree() {
  649. const tree = buildTree(S.stages);
  650. $('stageTreeWrap').innerHTML = tree.length ? renderNodes(tree) : '<div style="padding:16px;font-size:13px;color:var(--text-muted)">暂无数据阶段</div>';
  651. }
  652. function renderNodes(nodes) {
  653. let h = '';
  654. for (const n of nodes) {
  655. if (n.stage && n.children.length === 0) {
  656. // Leaf
  657. h += `<div class="tree-leaf" data-stage="${esc(n.stage)}" onclick="selectStage(this, '${esc(n.stage)}')">
  658. <span class="tree-dot"></span>
  659. <span>${esc(n.label)}</span>
  660. <span class="tree-count">${n.count || ''}</span>
  661. </div>`;
  662. } else {
  663. // Branch (may also be a stage itself)
  664. const id = 'tb_' + Math.random().toString(36).substr(2, 6);
  665. h += `<div>
  666. <div class="tree-branch-header" onclick="toggleBranch('${id}', this)">
  667. <span class="tree-arrow" id="a_${id}">${IC.chevron}</span>
  668. <span>${esc(n.label)}</span>
  669. </div>
  670. <div class="tree-children" id="${id}">${renderNodes(n.children)}</div>
  671. </div>`;
  672. }
  673. }
  674. return h;
  675. }
  676. function toggleBranch(id, el) {
  677. const ch = $(id), ar = $('a_' + id);
  678. if (ch) ch.classList.toggle('open');
  679. if (ar) ar.classList.toggle('open');
  680. }
  681. function selectStage(el, stageName) {
  682. // Highlight
  683. document.querySelectorAll('.tree-leaf.active').forEach(e => e.classList.remove('active'));
  684. el.classList.add('active');
  685. S.stage = stageName;
  686. S.versions = []; S.skip = 0; S.hasMore = true;
  687. updateHeader();
  688. loadVersions();
  689. }
  690. // ============ Header ============
  691. function updateHeader() {
  692. if (!S.stage) {
  693. $('stagePath').innerHTML = '<span class="seg" style="color:var(--text-muted)">选择左侧数据阶段</span>';
  694. $('headerInfo').textContent = '';
  695. return;
  696. }
  697. const parts = S.stage.split('/');
  698. $('stagePath').innerHTML = parts.map((p, i) =>
  699. `${i > 0 ? '<span class="sep">/</span>' : ''}<span class="seg">${esc(p)}</span>`
  700. ).join('');
  701. }
  702. // ============ Versions ============
  703. async function loadVersions(append) {
  704. if (S.loading) return;
  705. S.loading = true;
  706. if (!append) {
  707. $('contentBody').innerHTML = '<div class="state-box"><div class="spinner"></div><p>加载中...</p></div>';
  708. }
  709. try {
  710. const pid = S.stageProjectMap[S.stage];
  711. const data = await api(`/projects/${pid}/stage-files?stage=${encodeURIComponent(S.stage)}&skip=${S.skip}&limit=${PAGE_SIZE}`);
  712. if (!append) S.versions = [];
  713. S.versions.push(...data);
  714. S.hasMore = data.length >= PAGE_SIZE;
  715. S.skip += data.length;
  716. renderVersions();
  717. const stageInfo = S.stages.find(s => s.name === S.stage);
  718. $('headerInfo').textContent = stageInfo ? `共 ${stageInfo.version_count} 次提交` : '';
  719. } catch (e) {
  720. if (!append) $('contentBody').innerHTML = '<div class="state-box"><p style="color:#fc8181;">加载失败: ' + esc(e.message) + '</p></div>';
  721. }
  722. S.loading = false;
  723. }
  724. function renderVersions() {
  725. if (!S.versions.length) {
  726. $('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>';
  727. return;
  728. }
  729. let h = '';
  730. S.versions.forEach((v, i) => {
  731. const groups = groupFiles(v.files);
  732. h += `<div class="version-card" style="animation-delay:${Math.min(i, 10) * 0.05}s">
  733. <div class="version-head">
  734. <span class="commit-tag">${IC.commit} ${esc(v.commit_id.substring(0, 8))}</span>
  735. <span class="v-author">${v.author ? esc(v.author) : ''}</span>
  736. <span class="v-time" title="${fmtTime(v.created_at)}">${relTime(v.created_at)}</span>
  737. </div>
  738. <div class="version-files">${renderGroups(groups, v)}</div>
  739. </div>`;
  740. });
  741. if (S.hasMore) {
  742. h += '<div class="load-more"><button class="load-more-btn" onclick="loadMore()">加载更多</button></div>';
  743. }
  744. $('contentBody').innerHTML = h;
  745. }
  746. function loadMore() {
  747. const btn = document.querySelector('.load-more-btn');
  748. if (btn) { btn.disabled = true; btn.textContent = '加载中...'; }
  749. loadVersions(true);
  750. }
  751. // ============ File Grouping ============
  752. function groupFiles(files) {
  753. if (!files || !files.length) return [];
  754. const topLevelGroups = {};
  755. const rootFiles = [];
  756. files.forEach(f => {
  757. const parts = f.relative_path.split('/');
  758. if (parts.length === 1) {
  759. rootFiles.push(f);
  760. } else {
  761. const topDir = parts[0];
  762. if (!topLevelGroups[topDir]) topLevelGroups[topDir] = [];
  763. topLevelGroups[topDir].push(f);
  764. }
  765. });
  766. const result = [];
  767. Object.entries(topLevelGroups).forEach(([topDir, fls]) => {
  768. let commonParts = fls[0].relative_path.split('/').slice(0, -1);
  769. for (let i = 1; i < fls.length; i++) {
  770. const parts = fls[i].relative_path.split('/').slice(0, -1);
  771. let j = 0;
  772. while (j < commonParts.length && j < parts.length && commonParts[j] === parts[j]) {
  773. j++;
  774. }
  775. commonParts.length = j;
  776. }
  777. const groupName = commonParts.join('/');
  778. result.push({ type: 'folder', name: groupName, path: groupName, files: fls });
  779. });
  780. rootFiles.forEach(f => {
  781. result.push({ type: 'file', file: f });
  782. });
  783. result.sort((a, b) => {
  784. if (a.type !== b.type) return a.type === 'folder' ? -1 : 1;
  785. return (a.name || a.file.name).localeCompare(b.name || b.file.name);
  786. });
  787. return result;
  788. }
  789. function renderGroups(groups, version) {
  790. if (!groups.length) return '';
  791. let h = '';
  792. groups.forEach(g => {
  793. if (g.type === 'folder') {
  794. const gid = 'fg_' + Math.random().toString(36).substr(2, 6);
  795. h += `
  796. <div class="fg-header" onclick="toggleFG('${gid}')">
  797. <div class="fg-name-wrap">
  798. <span class="fg-arrow" id="fa_${gid}">${IC.chevron}</span>
  799. <span class="fg-icon">${IC.folder}</span>
  800. <span class="fg-name">${esc(g.name)}/</span>
  801. <span class="fg-count">${g.files.length} 个文件</span>
  802. </div>
  803. <div></div>
  804. </div>
  805. <div class="fg-children" id="${gid}">
  806. ${g.files.map(f => fileRow(f, version, true, g.path)).join('')}
  807. </div>`;
  808. } else {
  809. h += fileRow(g.file, version, false, null);
  810. }
  811. });
  812. return h;
  813. }
  814. function fileRow(f, version, isChild, groupPath) {
  815. const padding = isChild ? 'padding-left: 44px;' : '';
  816. let displayName = f.name;
  817. if (groupPath && f.relative_path.startsWith(groupPath + '/')) {
  818. displayName = f.relative_path.substring(groupPath.length + 1);
  819. }
  820. return `
  821. <div class="file-row" style="${padding}">
  822. <div class="file-name-col" title="${esc(f.relative_path)}">
  823. <span class="f-icon">${IC.file}</span>
  824. <span class="f-name">${esc(displayName)}</span>
  825. <span class="f-size">${fmtSize(f.file_size)}</span>
  826. </div>
  827. <div class="btn-dl-wrap">
  828. <a class="btn-dl" href="/files/${f.id}/content" download="${esc(f.name)}" onclick="event.stopPropagation();">${IC.download}</a>
  829. </div>
  830. </div>`;
  831. }
  832. function toggleFG(id) {
  833. const ch = $(id), ar = $('fa_' + id);
  834. if (ch) ch.classList.toggle('open');
  835. if (ar) ar.classList.toggle('open');
  836. }
  837. // ============ UI Helpers ============
  838. function showWelcome() {
  839. $('stagePath').innerHTML = '<span class="seg" style="color:var(--text-muted)">选择左侧数据阶段</span>';
  840. $('headerInfo').textContent = '';
  841. $('contentBody').innerHTML = `<div class="state-box">
  842. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
  843. <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"/>
  844. <polyline points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/>
  845. </svg>
  846. <h2>欢迎使用数据控制台</h2>
  847. <p>从左侧选择数据阶段,查看文件版本历史</p>
  848. </div>`;
  849. }
  850. // ============ Init ============
  851. loadAllStages();
  852. </script>
  853. </body>
  854. </html>