desktop.html 42.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light">
<meta name="theme-color" content="#f1ede3">
<title>坐标补齐</title>
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23f1ede3'/%3E%3Cpath d='M16 5v22M5 16h22' stroke='%23b23a2c' stroke-width='1.4'/%3E%3Ccircle cx='16' cy='16' r='5' fill='none' stroke='%23171a15' stroke-width='2'/%3E%3C/svg%3E">
<style>
  :root {
    color-scheme: light;
    --paper: #f1ede3; --paper-2: #fbf8f0; --paper-3: #f6f2e8;
    --line: #d9d1c0; --line-soft: #e8e1d2; --line-strong: #bcb29d;
    --ink: #171a15; --ink-2: #41463d; --muted: #6a6a5e;
    --mark: #b23a2c; --mark-soft: #f6e6df; --mark-line: #e2c1b6;
    --warn: #8a5410; --warn-soft: #f8edd9; --bad: #9e2b1f; --good: #1f6347;
    --rail: #161a15; --rail-2: #1c211b; --rail-line: #333a30;
    --rail-ink: #ece8da; --rail-muted: #a4ac9d;
    --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
    --radius: 3px;
    --sans: "Segoe UI Variable Text", "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
    --display: "Bahnschrift", "Segoe UI Variable Display", "Segoe UI", "Microsoft YaHei UI", sans-serif;
    --mono: "Cascadia Mono", "Cascadia Code", Consolas, "Courier New", monospace;
    --shadow-card: 0 1px 0 rgba(255, 255, 255, .75) inset, 0 10px 26px rgba(23, 26, 21, .04);
  }
  * { box-sizing: border-box; }
  [hidden] { display: none !important; }
  html { -webkit-text-size-adjust: 100%; }
  body {
    margin: 0; min-height: 100vh; color: var(--ink);
    font: 400 14px/1.7 var(--sans);
    background:
      radial-gradient(900px 420px at 88% -8%, rgba(178, 58, 44, .07), transparent 62%),
      repeating-linear-gradient(0deg, rgba(23, 26, 21, .028) 0 1px, transparent 1px 88px),
      repeating-linear-gradient(90deg, rgba(23, 26, 21, .028) 0 1px, transparent 1px 88px),
      var(--paper);
  }
  /* 纸面颗粒:一层极淡的噪声,让大片留白不像屏幕底色 */
  body::before {
    content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .045;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  }
  .wrap { position: relative; z-index: 1; max-width: 1280px; margin: 0 auto; padding: 26px 28px 56px; }

  /* 页眉:制图刻度 + 台账标题 */
  .ruler {
    height: 9px; margin-bottom: 20px; border-top: 1px solid var(--line);
    background: repeating-linear-gradient(90deg, var(--line-strong) 0 1px, transparent 1px 20px);
    -webkit-mask-image: linear-gradient(90deg, #000 0 62%, transparent 100%);
    mask-image: linear-gradient(90deg, #000 0 62%, transparent 100%);
  }
  .masthead {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end;
    gap: 20px 48px; padding: 0 0 22px; margin-bottom: 24px; border-bottom: 1px solid var(--line);
    animation: rise .5s cubic-bezier(.2, .7, .2, 1) both;
  }
  .eyebrow {
    display: flex; align-items: center; gap: 9px; margin: 0 0 12px;
    font: 600 11px/1 var(--display); letter-spacing: .13em; text-transform: uppercase; color: var(--mark);
  }
  .eyebrow::before { content: ""; width: 18px; height: 1px; background: currentColor; }
  h1 { margin: 0; font: 600 40px/1.12 var(--sans); letter-spacing: .015em; }
  .lede { margin: 12px 0 0; max-width: 56ch; color: var(--ink-2); font-size: 14.5px; }
  .mast-side { display: grid; gap: 12px; justify-items: end; text-align: right; }
  .meta { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin: 0; }
  .meta span {
    padding: 5px 8px; border: 1px solid var(--line-strong); border-radius: 2px;
    background: rgba(255, 255, 255, .35); color: var(--ink-2);
    font: 600 10.5px/1 var(--display); letter-spacing: .13em; text-transform: uppercase;
  }
  .where { margin: 0; color: var(--muted); font-size: 11.5px; letter-spacing: .01em; }

  /* 两栏:左台账,右运行台 */
  .layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px 26px; align-items: start; }
  @media (min-width: 1100px) {
    .layout { grid-template-columns: minmax(0, 1fr) 404px; }
    .side {
      position: sticky; top: 18px; align-self: start; max-height: calc(100vh - 36px);
      overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
      scrollbar-color: #59624f transparent;
    }
    .side::-webkit-scrollbar { width: 8px; }
    .side::-webkit-scrollbar-thumb { background: #59624f; border: 2px solid var(--paper); border-radius: 99px; }
  }
  .col { display: grid; gap: 14px; align-content: start; min-width: 0; }
  .col > * { animation: rise .45s cubic-bezier(.2, .7, .2, 1) both; }
  .col > *:nth-child(1) { animation-delay: .04s; }
  .col > *:nth-child(2) { animation-delay: .08s; }
  .col > *:nth-child(3) { animation-delay: .12s; }
  .col > *:nth-child(4) { animation-delay: .16s; }
  .col > *:nth-child(5) { animation-delay: .2s; }
  .col > *:nth-child(6) { animation-delay: .24s; }
  .col > *:nth-child(7) { animation-delay: .28s; }
  .col > *:nth-child(8) { animation-delay: .32s; }
  .side { animation: rise .5s cubic-bezier(.2, .7, .2, 1) .1s both; }
  @keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

  .card {
    position: relative; padding: 18px 20px 20px;
    background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-card);
  }
  /* 右上角的套准角标:像一张排好的制图板 */
  .card::after {
    content: ""; position: absolute; top: 9px; right: 9px; width: 7px; height: 7px;
    border-top: 1px solid var(--line-strong); border-right: 1px solid var(--line-strong);
    pointer-events: none; opacity: .75;
  }
  .sec-head {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding-bottom: 11px; margin-bottom: 13px; border-bottom: 1px solid var(--line-soft);
  }
  .num {
    flex: none; padding: 4px 5px; border: 1px solid var(--mark-line); border-radius: 2px;
    background: #fffdf8; color: var(--mark);
    font: 600 11px/1 var(--display); letter-spacing: .1em; font-variant-numeric: tabular-nums;
  }
  h2 {
    display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin: 0;
    font: 600 15.5px/1.35 var(--sans); letter-spacing: .01em;
  }
  .hint { font-size: 11.5px; font-weight: 500; color: var(--muted); letter-spacing: .01em; }
  .desc { margin: 0 0 14px; max-width: 66ch; color: var(--muted); font-size: 12.5px; line-height: 1.68; }
  .group-label {
    display: flex; align-items: center; gap: 12px; margin: 8px 2px 0;
    color: var(--muted); font-size: 11px; letter-spacing: .09em;
  }
  .group-label::before, .group-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }

  /* 表单 */
  .field { min-width: 0; }
  .fields { display: grid; gap: 14px; }
  label { display: block; margin-bottom: 6px; color: var(--ink-2); font-size: 12px; font-weight: 600; letter-spacing: .02em; }
  .control { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  input[type=text], input[type=number], input[type=password] {
    flex: 1 1 220px; width: 100%; min-width: 0; padding: 9px 11px;
    font: 400 13.5px/1.5 var(--sans); color: var(--ink); font-variant-numeric: tabular-nums;
    background: #fffdfa; border: 1px solid var(--line-strong); border-radius: 2px;
    transition: border-color .12s, box-shadow .12s;
  }
  input.path { font: 400 12.5px/1.55 var(--mono); }
  input.short { flex: 1 1 140px; }
  input::placeholder { color: #9a9588; }
  input, textarea { caret-color: var(--mark); }
  ::selection { background: rgba(178, 58, 44, .2); }
  input:hover:not(:disabled) { border-color: #8d8574; }
  input:focus-visible { outline: 0; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(178, 58, 44, .16); }
  input:disabled, button:disabled { opacity: .4; cursor: not-allowed; }
  .unit { flex: none; color: var(--muted); font-size: 12px; }

  button {
    padding: 10px 15px; border: 1px solid var(--ink); border-radius: 2px;
    background: var(--ink); color: var(--paper-2); cursor: pointer;
    font: 600 13.5px/1.2 var(--sans); letter-spacing: .02em;
    transition: background .14s, border-color .14s, color .14s, transform .1s;
  }
  button:hover:not(:disabled) { background: var(--mark); border-color: var(--mark); }
  button:active:not(:disabled) { transform: translateY(1px); }
  button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
  button.ghost { background: #fffdfa; border-color: var(--line-strong); color: var(--ink); }
  button.ghost:hover:not(:disabled) { background: var(--mark-soft); border-color: var(--mark); color: var(--bad); }
  button.quiet { padding: 4px 2px; border: 0; background: none; color: var(--mark); font-weight: 600; }
  button.quiet:hover:not(:disabled) { background: none; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
  button.chip {
    flex: none; padding: 8px 11px; background: #fffdfa; border-color: var(--line-strong);
    color: var(--ink-2); font-size: 12px; font-weight: 600;
  }
  button.chip:hover:not(:disabled) { background: var(--mark-soft); border-color: var(--mark); color: var(--bad); }
  button.big { padding: 12px 16px; font-size: 14.5px; }
  button.stop { border-color: #c9b5a6; background: transparent; color: var(--bad); }
  button.stop:hover:not(:disabled) { background: var(--mark-soft); border-color: var(--bad); color: var(--bad); }

  /* 开关:方形滑钮,像仪表上的拨子 */
  .switch { display: flex; gap: 12px; align-items: flex-start; }
  .switch + .switch { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--line-soft); }
  .switch input {
    appearance: none; -webkit-appearance: none; flex: none; width: 40px; height: 24px;
    margin: 1px 0 0; border: 1px solid #c7bfae; border-radius: 3px; background: #ddd6c7;
    position: relative; cursor: pointer; transition: background .16s, border-color .16s;
  }
  .switch input::after {
    content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
    border-radius: 2px; background: #fffdfa; box-shadow: 0 1px 2px rgba(23, 26, 21, .25);
    transition: transform .16s cubic-bezier(.3, .8, .3, 1);
  }
  .switch input:checked { background: var(--mark); border-color: var(--mark); }
  .switch input:checked::after { transform: translateX(16px); }
  .switch input:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
  .switch > div { min-width: 0; }
  .switch label { margin: 0; font-size: 13.5px; font-weight: 600; color: var(--ink); }
  .switch .desc { margin: 3px 0 0; }

  .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 14px; }
  .grid .field + .field { margin-top: 0; }
  .grid.tight { margin-top: 15px; }
  .fade { opacity: .4; transition: opacity .2s; }
  .note { margin-top: 10px; color: var(--muted); font-size: 12px; line-height: 1.62; overflow-wrap: anywhere; }
  .note:empty { display: none; }
  .note.warn, .note.bad, .note.ok { padding-left: 9px; border-left: 2px solid currentColor; }
  .note.warn { color: var(--warn); }
  .note.bad { color: var(--bad); }
  .note.ok { color: var(--good); }

  /* 运行台:深墨底、纸色字,和左侧台账形成一明一暗 */
  .deck {
    overflow: hidden; color: var(--rail-ink); background: var(--rail);
    border: 1px solid #0d110d; border-radius: 4px;
    box-shadow: 0 20px 44px rgba(16, 20, 16, .2);
  }
  .deck-top {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 11px 18px; background: #121612; border-bottom: 1px solid var(--rail-line);
  }
  .deck-title { font: 600 10.5px/1 var(--sans); letter-spacing: .22em; color: var(--rail-muted); }
  .status { display: inline-flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--rail-muted); }
  .status i {
    width: 7px; height: 7px; border-radius: 50%; background: #6d7a68;
    box-shadow: 0 0 0 3px rgba(109, 122, 104, .14);
  }
  .deck[data-state=running] .status i { background: var(--mark); animation: pulse 1.6s ease-in-out infinite; }
  .deck[data-state=done] .status i { background: #57a879; box-shadow: 0 0 0 3px rgba(87, 168, 121, .16); }
  .deck[data-state=error] .status i { background: #d46a58; box-shadow: 0 0 0 3px rgba(212, 106, 88, .16); }
  @keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(178, 58, 44, .14); }
    50% { box-shadow: 0 0 0 6px rgba(178, 58, 44, .02); }
  }
  .deck-sec { padding: 18px; }
  .deck-sec + .deck-sec { border-top: 1px solid var(--rail-line); }
  .deck .sec-head { border-bottom: 1px dashed var(--rail-line); }
  .deck h2 { color: var(--rail-ink); font-size: 14.5px; }
  .deck .num { background: #221a17; border-color: #4a3b35; color: #e0a093; }
  .deck .desc { color: var(--rail-muted); }
  .deck label { color: var(--rail-ink); }
  .deck .note { color: var(--rail-muted); }
  .deck .note.warn { color: #e8b46e; }
  .deck .note.bad { color: #f0a596; }
  .deck .note.ok { color: #8fcaa8; }
  .deck input[type=text], .deck input[type=password] {
    background: #0e120e; border-color: #3b4338; color: #f1ede1; font-family: var(--mono);
  }
  .deck input::placeholder { color: #78826f; }
  .deck input:hover:not(:disabled) { border-color: #5b6655; }
  .deck input:focus-visible { border-color: #e9e4d7; box-shadow: 0 0 0 3px rgba(178, 58, 44, .35); }
  .deck button.ghost { background: #1d241d; border-color: #3d463b; color: #e9e4d6; }
  .deck button.ghost:hover:not(:disabled) { background: #2a1c18; border-color: #8a4a3c; color: #f0b3a7; }
  .deck button.quiet { color: #cfd6c8; }
  .deck button.quiet:hover:not(:disabled) { background: none; color: #fff; }
  .deck button:focus-visible { outline-color: var(--rail-ink); }
  .deck .big { flex: 1; background: var(--paper-2); border-color: var(--paper-2); color: var(--ink); }
  .deck .big:hover:not(:disabled) { background: var(--mark); border-color: var(--mark); color: var(--paper-2); }
  .deck button.stop { border-color: #4a3b36; color: #d9a196; }
  .deck button.stop:hover:not(:disabled) { background: #2a1b18; border-color: #7a4438; color: #f0b3a7; }
  .actions { display: flex; gap: 8px; margin-top: 15px; }

  .stage {
    position: relative; min-height: 46px; margin-top: 12px; padding-left: 15px;
    color: var(--rail-ink); font-size: 15px; font-weight: 600; line-height: 1.5;
    font-variant-numeric: tabular-nums;
  }
  .stage::before {
    content: ""; position: absolute; left: 0; top: 9px; width: 6px; height: 6px;
    background: var(--mark); transition: background .2s;
  }
  .stage.ok::before { background: #57a879; }
  .stage.bad::before { background: #d46a58; }
  .bar {
    position: relative; height: 8px; margin: 12px 0 0; border-radius: 2px;
    background: #2a302a; overflow: hidden;
  }
  .bar i { display: block; height: 100%; width: 0; background: var(--mark); transition: width .25s ease-out; }
  .bar::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), rgba(236, 232, 218, .16) calc(10% - 1px) 10%);
  }
  .bar.busy i { width: 32%; animation: slide 1.5s cubic-bezier(.4, 0, .6, 1) infinite; }
  @keyframes slide { from { margin-left: -32%; } to { margin-left: 100%; } }

  .log { margin-top: 14px; border: 1px solid var(--rail-line); border-radius: 3px; background: #0d110d; }
  .log summary {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer;
    list-style: none; color: var(--rail-muted); font-size: 11.5px; font-weight: 600; letter-spacing: .04em;
  }
  .log summary::-webkit-details-marker { display: none; }
  .log summary::before { content: "▸"; color: var(--mark); font-family: var(--mono); transition: transform .15s; }
  .log[open] summary::before { transform: rotate(90deg); }
  .console {
    max-height: 190px; overflow: auto; padding: 10px 12px; border-top: 1px solid var(--rail-line);
    color: #aeb7a6; font: 11.5px/1.75 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
    scrollbar-width: thin; scrollbar-color: #3d463b transparent;
  }
  .console::-webkit-scrollbar { width: 7px; }
  .console::-webkit-scrollbar-thumb { background: #3d463b; border-radius: 99px; }

  .headline {
    margin: 12px 0 14px; padding-bottom: 14px; border-bottom: 1px dashed var(--rail-line);
    color: var(--rail-ink); font-size: 18.5px; font-weight: 600; line-height: 1.5;
    letter-spacing: .01em; font-variant-numeric: tabular-nums;
  }
  #summary { width: 100%; border-collapse: collapse; }
  #summary th, #summary td {
    padding: 7px 0; border-bottom: 1px dashed var(--rail-line);
    text-align: left; vertical-align: top; font-size: 12.5px; line-height: 1.6;
  }
  #summary tr:last-child th, #summary tr:last-child td { border-bottom: 0; }
  #summary th {
    width: 40%; padding-right: 12px; color: var(--rail-muted);
    font-size: 11.5px; font-weight: 500;
  }
  #summary td { color: #e9e4d6; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
  .caption {
    margin: 18px 0 8px; color: var(--rail-muted);
    font-size: 10.5px; font-weight: 600; letter-spacing: .16em;
  }
  .files { display: grid; gap: 8px; }
  .out { padding: 10px 12px; background: #1a201a; border: 1px solid var(--rail-line); border-radius: 3px; }
  .out .line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
  .out .name { flex: 1 1 auto; color: var(--rail-ink); font-size: 12.5px; font-weight: 600; }
  .out .path {
    display: block; margin-top: 4px; color: #98a291;
    font: 11px/1.6 var(--mono); overflow-wrap: anywhere;
  }

  /* 本机目录选择 */
  dialog {
    width: min(760px, 94vw); max-height: 88vh; padding: 0;
    color: var(--ink); background: var(--paper-2);
    border: 1px solid #2a2e28; border-radius: 4px;
    box-shadow: 0 30px 80px rgba(15, 18, 15, .32);
  }
  dialog[open] { display: flex; flex-direction: column; }
  dialog::backdrop { background: rgba(20, 24, 20, .42); backdrop-filter: blur(2px) saturate(.9); }
  .dhead {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
    padding: 15px 18px 12px; background: var(--paper-3); border-bottom: 1px solid var(--line);
  }
  .dhead .eyebrow { margin: 0 0 7px; }
  .dhead h2 { font-size: 17px; }
  .esc { color: var(--muted); font-size: 11px; letter-spacing: .06em; }
  .dpath { display: flex; gap: 8px; padding: 12px 18px 0; }
  .dpath input { flex: 1 1 auto; }
  .pick-hint { margin: 8px 18px 0; color: var(--muted); font-size: 11.5px; }
  .roots { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 18px 0; }
  .roots button {
    padding: 6px 10px; background: #fffdfa; border-color: var(--line-strong);
    color: var(--ink-2); font-size: 12px; font-weight: 600;
  }
  .roots button:hover:not(:disabled) { background: var(--mark-soft); border-color: var(--mark); color: var(--bad); }
  #pickNote { margin: 8px 18px 0; }
  .dlist {
    flex: 1; min-height: 0; max-height: 52vh; overflow: auto; margin-top: 8px;
    padding: 8px 10px 12px; border-top: 1px solid var(--line-soft);
    scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
  }
  .dlist button {
    display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px;
    border: 0; border-radius: 2px; background: none; color: var(--ink); text-align: left;
    font: 400 13px/1.5 var(--sans); font-weight: 400; white-space: nowrap; overflow: hidden;
  }
  .dlist button:hover:not(:disabled) { background: var(--mark-soft); color: var(--ink); }
  .dlist .dir::before { content: "▸"; flex: none; color: var(--mark); font-family: var(--mono); }
  .dlist .file::before { content: "·"; flex: none; color: var(--line-strong); font-family: var(--mono); }
  .dlist .name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }
  .dlist .size { flex: none; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
  .dlist .empty { padding: 18px 10px; color: var(--muted); font-size: 12.5px; }
  .foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--paper-3); }
  .foot #closePick { margin-right: auto; }

  @media (max-width: 720px) {
    .wrap { padding: 20px 16px 40px; }
    .masthead { grid-template-columns: minmax(0, 1fr); }
    .mast-side { justify-items: start; text-align: left; }
    .meta { justify-content: flex-start; }
    h1 { font-size: 32px; }
    .card { padding: 16px; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
  }
</style>
</head>
<body>
<div class="wrap">
  <div class="ruler" aria-hidden="true"></div>
  <header class="masthead">
    <div>
      <p class="eyebrow">GCJ-02 · 高德坐标补全</p>
      <h1>坐标补齐</h1>
      <p class="lede">先读地址文本,读不出或读得可疑的那些行才用坐标问地图接口。</p>
    </div>
    <div class="mast-side">
      <p class="meta"><span>CSV / EXCEL</span><span>GCJ-02</span><span>只写新文件</span></p>
      <p class="where">关掉启动它的终端窗口,或按 Ctrl+C 即停止。</p>
    </div>
  </header>

  <div class="layout">
    <div class="col">
      <section class="card">
        <div class="sec-head"><span class="num">01</span><h2>源文件</h2></div>
        <p class="desc">第三方导出的那张表,CSV 或 Excel 都行。表里只要有经纬度;缺的三列会自动追加。</p>
        <div class="field">
          <label for="input">表格文件 <span class="hint">.csv / .xlsx / .xlsm / .xlsb / .xls</span></label>
          <div class="control">
            <input type="text" id="input" class="path" placeholder="完整路径,或点右边「浏览」" spellcheck="false">
            <button type="button" class="ghost" id="pickInput">浏览</button>
          </div>
          <div class="note" id="inputNote"></div>
        </div>
      </section>

      <section class="card">
        <div class="sec-head"><span class="num">02</span><h2>输出</h2></div>
        <p class="desc">永远写新文件,不碰源表。正式表格进源文件旁的 out/,处理日志与清单进源文件旁的 .temp/,工具目录不落运行产物。</p>
        <div class="fields">
          <div class="field">
            <label for="outputDir">输出目录 <span class="hint">留空 = 源文件旁/out</span></label>
            <div class="control">
              <input type="text" id="outputDir" class="path" placeholder="留空即放在源文件旁的 out 文件夹" spellcheck="false">
              <button type="button" class="ghost" id="pickDir">浏览</button>
            </div>
          </div>
          <div class="field">
            <label for="outputName">文件名 <span class="hint">留空 = 原名.已补全</span></label>
            <input type="text" id="outputName" class="path" placeholder="留空自动生成" spellcheck="false">
          </div>
        </div>
        <div class="note" id="outputNote"></div>
      </section>

      <div class="group-label"><span>以下四段通常保持默认,需要时再改</span></div>

      <section class="card">
        <div class="sec-head"><span class="num">03</span><h2>已查坐标缓存</h2></div>
        <p class="desc">问过的坐标记在这里,续跑要用同一个文件;拷走它,换电脑也不重复花钱。</p>
        <div class="field">
          <label for="cache">缓存文件 <span class="hint">留空 = 源文件旁/cache</span></label>
          <div class="control">
            <input type="text" id="cache" class="path" placeholder="留空即放在源文件旁的 cache 文件夹" spellcheck="false">
            <button type="button" class="ghost" id="pickCache">浏览</button>
          </div>
          <div class="note" id="cacheNote"></div>
        </div>
      </section>

      <section class="card">
        <div class="sec-head"><span class="num">04</span><h2>接口节奏</h2></div>
        <p class="desc">只有地址补不齐的行才会走到这里。并发越高越快,也越容易被限流。</p>
        <div class="grid">
          <div class="field">
            <label for="workers">同时在途请求</label>
            <input type="number" id="workers" min="1" step="1">
          </div>
          <div class="field">
            <label for="qps">每秒请求上限 <span class="hint">0 为不限</span></label>
            <input type="number" id="qps" min="0" step="1">
          </div>
          <div class="field">
            <label for="limit">只处理前几行 <span class="hint">留空为全量</span></label>
            <div class="control">
              <input type="number" id="limit" class="short" min="1" step="1" placeholder="留空">
              <button type="button" class="chip" id="trial20" title="把「只处理前几行」填成 20">填 20 行</button>
            </div>
          </div>
        </div>
        <div class="note">先用「只处理前几行」填 20 跑一遍,看取值对不对,再回来跑全量。</div>
      </section>

      <section class="card">
        <div class="sec-head"><span class="num">05</span><h2>续跑清单 <span class="hint">可留空</span></h2></div>
        <p class="desc">上一次运行生成的「限流待重试」清单。填了它,本次只有清单里的行允许问接口;表格与日志仍按整张表写,其余行照旧用表内原值、地址和缓存补齐。</p>
        <div class="field">
          <label for="onlyList">清单文件 <span class="hint">补齐工具写的 .csv,与生成它的那张输入表配对使用</span></label>
          <div class="control">
            <input type="text" id="onlyList" class="path" placeholder="留空 = 整张表都可以问接口" spellcheck="false">
            <button type="button" class="ghost" id="pickList">浏览</button>
          </div>
          <div class="note" id="listNote"></div>
        </div>
      </section>

      <section class="card">
        <div class="sec-head"><span class="num">06</span><h2>推断与排序</h2></div>
        <div class="switch">
          <input type="checkbox" id="sortIncompleteLast">
          <div>
            <label for="sortIncompleteLast">把仍有空白的记录排到表格末尾</label>
            <p class="desc">完整记录在前,导入时先拿稳的,空白的留在末尾等人工补。</p>
          </div>
        </div>
        <div class="switch">
          <input type="checkbox" id="inferNearby">
          <div>
            <label for="inferNearby">允许用附近已知地点的归属补空白</label>
            <p class="desc">这类值是「附近大概是这里」,不是这一条的实测结果,日志里单独标来源,所以默认关着。打开后能少问很多接口。</p>
          </div>
        </div>
        <div class="grid tight fade" id="radii">
          <div class="field">
            <label for="streetMeters">街道半径</label>
            <div class="control"><input type="number" id="streetMeters" min="1" step="1"><span class="unit">米</span></div>
          </div>
          <div class="field">
            <label for="roadMeters">道路半径</label>
            <div class="control"><input type="number" id="roadMeters" min="1" step="1"><span class="unit">米</span></div>
          </div>
        </div>
        <div class="note">行政区不用邻近补:两个区之间隔着几公里,附近点容易把案子记到隔壁区。</div>
      </section>
    </div>

    <div class="side">
      <aside class="deck" id="deck" data-state="idle" aria-label="运行台">
        <div class="deck-top">
          <span class="deck-title">运行台</span>
          <span class="status"><i aria-hidden="true"></i><span id="deckState">待命</span></span>
        </div>

        <section class="deck-sec">
          <div class="sec-head"><span class="num">07</span><h2>高德 Key</h2></div>
          <p class="desc">只有本次真有待查坐标时才用到。填一次、只用这一次,不写进配置、日志、缓存。</p>
          <div class="control">
            <input type="password" id="key" placeholder="需要问接口时再填" autocomplete="off" spellcheck="false">
            <button type="button" class="quiet" id="keyEye">显示</button>
            <button type="button" class="ghost" id="sendKey" hidden>继续</button>
          </div>
          <div class="note" id="keyNote">整张表都能靠地址和缓存补齐时不会用到 Key。</div>
        </section>

        <section class="deck-sec">
          <h2>运行</h2>
          <div class="actions">
            <button id="start" class="big">开始补齐</button>
            <button class="stop" id="stop" disabled>停止</button>
          </div>
          <div class="note bad" id="blocked" aria-live="polite"></div>
        </section>

        <section class="deck-sec" id="runSection" hidden>
          <h2>正在做</h2>
          <div class="stage" id="stage" role="status" aria-live="polite">准备中…</div>
          <div class="bar" id="bar"><i></i></div>
          <details class="log" id="logBox" open>
            <summary>运行日志</summary>
            <div class="console" id="console"></div>
          </details>
        </section>

        <section class="deck-sec" id="doneSection" hidden>
          <h2>本次结果</h2>
          <div class="headline" id="headline"></div>
          <table id="summary"></table>
          <div class="note warn" id="caution"></div>
          <div class="caption">产物文件</div>
          <div class="files" id="files"></div>
        </section>
      </aside>
    </div>
  </div>
</div>

<dialog id="picker" aria-labelledby="pickTitle">
  <div class="dhead">
    <div>
      <p class="eyebrow">本机目录</p>
      <h2 id="pickTitle">选择文件</h2>
    </div>
    <span class="esc">Esc 关闭</span>
  </div>
  <div class="dpath">
    <input type="text" id="browsePath" class="path" spellcheck="false">
    <button type="button" class="ghost" id="browseGo">前往</button>
  </div>
  <p class="pick-hint" id="pickHint"></p>
  <div class="roots" id="roots"></div>
  <div class="note" id="pickNote"></div>
  <div class="dlist" id="dlist"></div>
  <div class="foot">
    <button type="button" class="ghost" id="closePick">取消</button>
    <button type="button" id="useDir">选这个目录</button>
  </div>
</dialog>

<script type="module">
const TOKEN = '%%TOKEN%%';
const $ = (id) => document.getElementById(id);
const fields = ['input', 'outputDir', 'outputName', 'cache', 'onlyList', 'workers', 'qps', 'limit',
  'inferNearby', 'streetMeters', 'roadMeters', 'sortIncompleteLast'];

async function api(path, data) {
  const response = await fetch('/api/' + path, {
    method: 'POST',
    headers: { 'content-type': 'application/json', 'x-token': TOKEN },
    body: JSON.stringify(data || {}),
  });
  const value = await response.json();
  if (!response.ok || value.error) throw new Error(value.error || ('HTTP ' + response.status));
  return value;
}

function form() {
  const values = {};
  for (const name of fields) {
    const el = $(name);
    values[name] = el.type === 'checkbox' ? el.checked
      : el.type === 'number' ? (el.value === '' ? '' : Number(el.value)) : el.value.trim();
  }
  return values;
}

function setSize(bytes) {
  if (!bytes) return '';
  const mb = bytes / 1048576;
  return mb >= 1 ? mb.toFixed(1) + ' MB' : Math.round(bytes / 1024) + ' KB';
}

/** 缓存大小跟着当前缓存路径走:改了路径就要重算,否则提示的是另一个文件。 */
function setCacheNote(bytes) {
  const size = setSize(bytes);
  $('cacheNote').textContent = size
    ? `缓存文件现有 ${size},里面查过的坐标这次不会重复问。` : '';
}

let checkTimer = 0;
async function check() {
  clearTimeout(checkTimer);
  checkTimer = setTimeout(async () => {
    try {
      const value = await api('check', form());
      $('inputNote').textContent = value.issue || '';
      $('inputNote').className = 'note ' + (value.issue ? 'bad' : '');
      $('outputNote').textContent = value.notice;
      $('outputNote').className = 'note ' + (/会覆盖|拒绝/.test(value.notice) ? 'warn' : '');
      setCacheNote(value.cacheSize);
      $('listNote').textContent = value.listNotice || '';
      $('listNote').className = 'note ' + (/找不到|不是|不认|读不出来/.test(value.listNotice) ? 'bad' : '');
      $('blocked').textContent = value.issue || '';
      $('start').disabled = !!value.issue || $('start').dataset.running === '1';
    } catch (error) {
      $('inputNote').textContent = error.message;
    }
  }, 250);
}

function setField(name, value) {
  const el = $(name);
  if (el.type === 'checkbox') el.checked = !!value;
  else el.value = value === null || value === undefined ? '' : String(value);
}

function setDeck(state, label) {
  $('deck').dataset.state = state;
  $('deckState').textContent = label;
}

// 浏览目录:浏览器给不出本机绝对路径,所以列目录由本机做
let pickTarget = 'input';
const join = (dir, name) => `${dir}${dir.includes('\\') ? '\\' : '/'}${name}`;
const pickTitles = { input: '选择表格文件', outputDir: '选择输出目录', cache: '选择缓存文件', onlyList: '选择续跑清单' };
const pickHints = {
  input: '点文件名直接选中;这里只列出能读的表格格式。',
  outputDir: '点进目标文件夹,再点右下角「选这个目录」。',
  cache: '点进目标文件夹,再点右下角按钮;文件名保持不变。',
  onlyList: '点文件名直接选中;这里只列出 .csv。',
};

async function show(dir) {
  const kind = pickTarget === 'cache' ? 'cache' : pickTarget === 'onlyList' ? 'list' : '';
  const value = await api('browse', { dir, kind });
  $('browsePath').value = value.dir;
  const list = $('dlist');
  list.textContent = '';
  if (value.parent) {
    const up = document.createElement('button');
    up.type = 'button';
    up.className = 'dir';
    up.textContent = '.. 上一级';
    up.onclick = () => show(value.parent);
    list.append(up);
  }
  for (const entry of value.entries) {
    const item = document.createElement('button');
    item.type = 'button';
    item.className = entry.directory ? 'dir' : 'file';
    const name = document.createElement('span');
    name.className = 'name';
    name.textContent = entry.name;
    item.append(name);
    if (!entry.directory) {
      const size = document.createElement('span');
      size.className = 'size';
      size.textContent = setSize(entry.size);
      item.append(size);
    }
    item.onclick = () => {
      if (entry.directory) show(entry.path);
      else { $(pickTarget).value = entry.path; $('picker').close(); check(); }
    };
    list.append(item);
  }
  if (value.entries.length === 0) {
    const empty = document.createElement('div');
    empty.className = 'empty';
    empty.textContent = '这个目录里没有可选项。';
    list.append(empty);
  }
  $('pickNote').textContent = value.note || '';
  $('browsePath').title = value.note || '';
  $('useDir').onclick = () => {
    if (pickTarget === 'cache') {
      const current = $('cache').value.split(/[\\/]/).pop() || 'amap_regeo_cache.sqlite3';
      $('cache').value = join(value.dir, current);
    } else {
      $('outputDir').value = value.dir;
    }
    $('picker').close();
    check();
  };
}

function openPicker(target, start) {
  pickTarget = target;
  $('pickTitle').textContent = pickTitles[target] || '选择位置';
  $('pickHint').textContent = pickHints[target] || '';
  // 源文件与清单都是文件:选目录对它们没有意义
  $('useDir').hidden = target === 'input' || target === 'onlyList';
  $('useDir').textContent = target === 'cache' ? '用这个目录存缓存' : '选这个目录';
  $('pickNote').textContent = '';
  $('picker').showModal();
  show(start || '').catch((error) => { $('dlist').textContent = error.message; });
}

function renderSummary(summary) {
  $('doneSection').hidden = false;
  $('headline').textContent = summary.headline;

  const table = $('summary');
  table.textContent = '';
  for (const line of summary.rows) {
    const row = table.insertRow();
    const label = document.createElement('th');
    label.scope = 'row';
    label.textContent = line.label;
    const value = document.createElement('td');
    value.textContent = line.value;
    row.append(label, value);
  }
  $('caution').textContent = summary.caution;
  $('caution').className = summary.caution ? 'note warn' : 'note';
  $('caution').hidden = !summary.caution;

  const links = $('files');
  links.textContent = '';
  for (const file of summary.files) {
    const box = document.createElement('div');
    box.className = 'out';
    const line = document.createElement('div');
    line.className = 'line';
    const name = document.createElement('span');
    name.className = 'name';
    name.textContent = file.label;
    const open = document.createElement('button');
    open.type = 'button';
    open.className = 'quiet';
    open.textContent = '打开';
    open.onclick = () => api('open', { path: file.value }).catch(() => undefined);
    line.append(name, open);
    // 限流那份是唯一值得再跑一次的清单:把「填回去」做成一次点击
    if (file.label === '限流待重试') {
      const again = document.createElement('button');
      again.type = 'button';
      again.className = 'quiet';
      again.textContent = '用它续跑';
      again.onclick = () => {
        $('onlyList').value = file.value;
        $('onlyList').focus();
        check();
      };
      line.append(again);
    }
    const path = document.createElement('span');
    path.className = 'path';
    path.textContent = file.value;
    box.append(line, path);
    links.append(box);
  }
}

const source = new EventSource('/api/events?t=' + TOKEN);
source.onmessage = (event) => {
  const data = JSON.parse(event.data);
  if (data.type === 'stage') {
    $('runSection').hidden = false;
    $('stage').className = 'stage';
    $('stage').textContent = data.text || ('正在' + data.label);
    const bar = $('bar');
    if (data.total && data.done !== undefined) {
      bar.className = 'bar';
      bar.firstElementChild.style.width = Math.min(100, data.done / data.total * 100) + '%';
    } else {
      bar.className = 'bar busy';
      bar.firstElementChild.style.width = '32%';
    }
    setDeck('running', '运行中');
  } else if (data.type === 'log') {
    append(data.message);
  } else if (data.type === 'key-needed') {
    $('sendKey').hidden = false;
    $('keyNote').textContent = '这次运行要问地图接口,请在上面填 Key 后点「继续」。';
    $('keyNote').className = 'note warn';
    $('key').focus();
    $('logBox').open = true;
    append('等待高德 Key…');
    setDeck('running', '等待 Key');
  } else if (data.type === 'done') {
    $('stage').className = 'stage ok';
    $('stage').textContent = '已完成';
    $('bar').className = 'bar';
    $('bar').firstElementChild.style.width = '100%';
    $('logBox').open = false;
    renderSummary(data.summary);
    setDeck('done', '已完成');
    // 跑完缓存文件长了(或中途停下来也写了一批),提示语要跟着新大小
    check();
  } else if (data.type === 'error') {
    $('stage').className = 'stage bad';
    $('stage').textContent = '停下来:' + data.message;
    const hint = data.detail ? `(内部提示:${data.detail.split('\n')[0]};完整提示在启动界面的那个终端窗口里)` : '';
    $('logBox').open = true;
    append('失败:' + data.message + hint);
    $('bar').className = 'bar';
    setDeck('error', '已停止');
    check();
  } else if (data.type === 'running') {
    running(data.running);
  }
};

function append(message) {
  const box = $('console');
  box.textContent += message + '\n';
  box.scrollTop = box.scrollHeight;
}

function running(on) {
  $('start').dataset.running = on ? '1' : '';
  $('start').disabled = on || !!$('blocked').textContent;
  $('stop').disabled = !on;
  for (const name of fields) $(name).disabled = on;
  $('key').disabled = false;
  if (on) setDeck('running', '运行中');
  else if ($('deck').dataset.state === 'running') setDeck('idle', '待命');
}

$('start').onclick = async () => {
  $('runSection').hidden = false;
  $('doneSection').hidden = true;
  $('console').textContent = '';
  $('logBox').open = true;
  $('stage').className = 'stage';
  $('stage').textContent = '正在开始…';
  $('bar').className = 'bar busy';
  $('bar').firstElementChild.style.width = '32%';
  setDeck('running', '启动中');
  try {
    await api('start', { ...form(), key: $('key').value.trim() });
    running(true);
  } catch (error) {
    $('stage').className = 'stage bad';
    $('stage').textContent = error.message;
    setDeck('idle', '待命');
  }
};
$('stop').onclick = () => api('stop', {}).catch(() => undefined);
$('sendKey').onclick = async () => {
  await api('key', { value: $('key').value.trim() });
  $('sendKey').hidden = true;
  $('keyNote').textContent = '已收到,继续跑。';
  $('keyNote').className = 'note';
  setDeck('running', '运行中');
};
$('keyEye').onclick = () => {
  const key = $('key');
  const shown = key.type === 'text';
  key.type = shown ? 'password' : 'text';
  $('keyEye').textContent = shown ? '显示' : '隐藏';
  key.focus();
};
$('trial20').onclick = () => {
  $('limit').value = '20';
  $('limit').focus();
  check();
};
for (const name of fields) $(name).addEventListener('input', () => {
  if (name === 'inferNearby') $('radii').classList.toggle('fade', !$(name).checked);
  check();
});
$('pickInput').onclick = () => openPicker('input', $('input').value);
$('pickCache').onclick = () => openPicker('cache', $('cache').value);
$('pickDir').onclick = () => openPicker('outputDir', $('outputDir').value);
$('pickList').onclick = () => openPicker('onlyList', $('onlyList').value);
$('browseGo').onclick = () => show($('browsePath').value);
$('browsePath').addEventListener('keydown', (event) => {
  if (event.key !== 'Enter') return;
  event.preventDefault();
  show($('browsePath').value);
});
$('closePick').onclick = () => $('picker').close();

const boot = await api('boot', {});
for (const name of fields) setField(name, boot.state[name]);
$('radii').classList.toggle('fade', !$('inferNearby').checked);
setCacheNote(boot.cacheSize);
const roots = $('roots');
for (const spot of boot.quickRoots) {
  const button = document.createElement('button');
  button.type = 'button';
  button.textContent = spot.name;
  button.onclick = () => show(spot.path);
  roots.append(button);
}
running(boot.running);
if (boot.running) {
  $('runSection').hidden = false;
  $('stage').textContent = '运行中…';
  $('bar').className = 'bar busy';
}
if (boot.savedExists && boot.state.input) append('已载入上次的路径与参数。');
check();
</script>
</body>
</html>