2026-10-16-oa-done-bank-receipt-upload-demo.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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" />
  6. <title>已办中心 · 银行回执单上传 Demo</title>
  7. <style>
  8. :root {
  9. --primary: #10b981;
  10. --primary-dark: #059669;
  11. --primary-bg: #ecfdf5;
  12. --primary-border: #a7f3d0;
  13. --text: #0f172a;
  14. --text-2: #334155;
  15. --muted: #94a3b8;
  16. --border: #e2e8f0;
  17. --bg: #f8fafc;
  18. --panel: #ffffff;
  19. --danger: #ef4444;
  20. --shadow: 0 12px 40px rgba(15, 23, 42, 0.12);
  21. font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  22. }
  23. * { box-sizing: border-box; }
  24. body {
  25. margin: 0;
  26. background: linear-gradient(180deg, #f0fdf4 0%, #f8fafc 40%, #f1f5f9 100%);
  27. color: var(--text);
  28. min-height: 100vh;
  29. padding: 24px;
  30. }
  31. .page-title {
  32. display: flex;
  33. align-items: baseline;
  34. gap: 12px;
  35. margin: 0 0 16px;
  36. }
  37. .page-title h1 {
  38. margin: 0;
  39. font-size: 20px;
  40. font-weight: 700;
  41. display: flex;
  42. align-items: center;
  43. gap: 10px;
  44. }
  45. .page-title h1::before {
  46. content: "";
  47. width: 4px;
  48. height: 18px;
  49. border-radius: 2px;
  50. background: var(--primary);
  51. }
  52. .page-title .hint {
  53. font-size: 13px;
  54. color: var(--muted);
  55. }
  56. .panel {
  57. background: var(--panel);
  58. border: 1px solid var(--border);
  59. border-radius: 10px;
  60. overflow: hidden;
  61. box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  62. }
  63. table {
  64. width: 100%;
  65. border-collapse: collapse;
  66. font-size: 14px;
  67. }
  68. th, td {
  69. padding: 12px 14px;
  70. text-align: center;
  71. border-bottom: 1px solid var(--border);
  72. }
  73. th {
  74. background: #f8fafc;
  75. color: #64748b;
  76. font-weight: 600;
  77. font-size: 13px;
  78. }
  79. tbody tr:nth-child(even) { background: #fafafa; }
  80. tbody tr:hover { background: #f0fdf4; }
  81. .tag {
  82. display: inline-flex;
  83. align-items: center;
  84. padding: 2px 8px;
  85. border-radius: 4px;
  86. font-size: 12px;
  87. font-weight: 500;
  88. }
  89. .tag.success { background: #d1fae5; color: #047857; }
  90. .tag.warning { background: #fef3c7; color: #b45309; }
  91. .ops {
  92. display: flex;
  93. flex-wrap: wrap;
  94. gap: 6px;
  95. justify-content: center;
  96. }
  97. .btn {
  98. display: inline-flex;
  99. align-items: center;
  100. gap: 4px;
  101. height: 28px;
  102. padding: 0 10px;
  103. border-radius: 6px;
  104. border: 1px solid var(--border);
  105. background: #fff;
  106. color: var(--text-2);
  107. font-size: 13px;
  108. cursor: pointer;
  109. transition: all .15s;
  110. }
  111. .btn:hover { border-color: var(--primary); color: var(--primary); }
  112. .btn.primary {
  113. border-color: transparent;
  114. background: transparent;
  115. color: var(--primary);
  116. font-weight: 500;
  117. }
  118. .btn.primary:hover { background: var(--primary-bg); }
  119. .btn.main {
  120. height: 36px;
  121. padding: 0 16px;
  122. border: none;
  123. background: var(--primary);
  124. color: #fff;
  125. border-radius: 8px;
  126. font-weight: 500;
  127. }
  128. .btn.main:hover { background: var(--primary-dark); }
  129. .btn.ghost {
  130. height: 36px;
  131. padding: 0 16px;
  132. border-radius: 8px;
  133. background: #fff;
  134. }
  135. .btn svg { width: 14px; height: 14px; flex-shrink: 0; }
  136. .btn.main svg, .btn.ghost svg { width: 16px; height: 16px; }
  137. /* Mask + Dialog */
  138. .mask {
  139. position: fixed;
  140. inset: 0;
  141. background: rgba(15, 23, 42, 0.45);
  142. display: none;
  143. align-items: center;
  144. justify-content: center;
  145. padding: 16px;
  146. z-index: 100;
  147. backdrop-filter: none;
  148. }
  149. .mask.open { display: flex; }
  150. .dialog {
  151. width: min(720px, 100%);
  152. max-height: calc(100vh - 100px);
  153. background: #fff;
  154. border-radius: 10px;
  155. box-shadow: var(--shadow);
  156. display: flex;
  157. flex-direction: column;
  158. overflow: hidden;
  159. animation: pop .18s ease-out;
  160. }
  161. @keyframes pop {
  162. from { transform: translateY(8px); opacity: 0; }
  163. to { transform: none; opacity: 1; }
  164. }
  165. .dialog-header {
  166. display: flex;
  167. align-items: center;
  168. justify-content: space-between;
  169. padding: 16px 20px;
  170. border-bottom: 1px solid var(--border);
  171. flex-shrink: 0;
  172. }
  173. .dialog-header h2 {
  174. margin: 0;
  175. font-size: 16px;
  176. font-weight: 600;
  177. }
  178. .dialog-close {
  179. width: 28px;
  180. height: 28px;
  181. border: none;
  182. background: transparent;
  183. border-radius: 6px;
  184. cursor: pointer;
  185. color: var(--muted);
  186. font-size: 18px;
  187. line-height: 1;
  188. }
  189. .dialog-close:hover { background: var(--bg); color: var(--text); }
  190. .dialog-body {
  191. padding: 20px;
  192. overflow-y: auto;
  193. flex: 1;
  194. }
  195. .meta {
  196. display: grid;
  197. grid-template-columns: 1fr 1fr;
  198. gap: 12px 16px;
  199. margin-bottom: 20px;
  200. padding: 12px 14px;
  201. background: var(--bg);
  202. border-radius: 8px;
  203. border: 1px solid var(--border);
  204. font-size: 13px;
  205. }
  206. .meta .label { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
  207. .meta .value { color: var(--text-2); font-weight: 500; }
  208. .section-label {
  209. font-size: 13px;
  210. font-weight: 600;
  211. color: var(--text);
  212. margin: 0 0 10px;
  213. }
  214. .attachment-upload.is-dragover {
  215. outline: 2px dashed var(--primary);
  216. outline-offset: 4px;
  217. background: var(--primary-bg);
  218. border-radius: 8px;
  219. padding: 8px;
  220. }
  221. .attachment-list {
  222. display: flex;
  223. flex-wrap: wrap;
  224. gap: 12px;
  225. }
  226. .upload-card {
  227. width: 140px;
  228. height: 96px;
  229. border: 1px dashed var(--primary-border);
  230. border-radius: 8px;
  231. background: #f0fdf4;
  232. display: flex;
  233. flex-direction: column;
  234. align-items: center;
  235. justify-content: center;
  236. gap: 6px;
  237. cursor: pointer;
  238. transition: all .15s;
  239. user-select: none;
  240. }
  241. .upload-card:hover {
  242. border-color: var(--primary);
  243. border-style: solid;
  244. background: var(--primary-bg);
  245. }
  246. .upload-card .plus {
  247. width: 28px;
  248. height: 28px;
  249. color: var(--primary);
  250. }
  251. .upload-card-text {
  252. font-size: 12px;
  253. color: var(--primary);
  254. font-weight: 500;
  255. line-height: 1;
  256. }
  257. .attachment-item {
  258. width: 140px;
  259. border: 1px solid var(--border);
  260. border-radius: 8px;
  261. background: #fff;
  262. overflow: hidden;
  263. transition: all .15s;
  264. }
  265. .attachment-item:hover {
  266. border-color: var(--primary);
  267. box-shadow: 0 2px 8px rgba(16, 185, 129, 0.1);
  268. }
  269. .attachment-item.is-uploading {
  270. opacity: 0.6;
  271. pointer-events: none;
  272. }
  273. .attachment-preview {
  274. width: 100%;
  275. height: 96px;
  276. display: flex;
  277. align-items: center;
  278. justify-content: center;
  279. background: var(--bg);
  280. overflow: hidden;
  281. cursor: pointer;
  282. }
  283. .attachment-preview img {
  284. width: 100%;
  285. height: 100%;
  286. object-fit: cover;
  287. display: block;
  288. }
  289. .doc-icon {
  290. width: 48px;
  291. height: 48px;
  292. border-radius: 10px;
  293. background: #e0f2fe;
  294. color: #0284c7;
  295. display: flex;
  296. align-items: center;
  297. justify-content: center;
  298. font-size: 11px;
  299. font-weight: 700;
  300. }
  301. .attachment-footer {
  302. padding: 6px 8px 8px;
  303. }
  304. .attachment-name {
  305. display: -webkit-box;
  306. -webkit-line-clamp: 2;
  307. -webkit-box-orient: vertical;
  308. overflow: hidden;
  309. font-size: 11px;
  310. color: var(--text-2);
  311. line-height: 1.35;
  312. min-height: 30px;
  313. margin-bottom: 4px;
  314. }
  315. .attachment-actions {
  316. display: flex;
  317. justify-content: center;
  318. gap: 12px;
  319. }
  320. .action-btn {
  321. width: 22px;
  322. height: 22px;
  323. border: none;
  324. background: transparent;
  325. color: #64748b;
  326. cursor: pointer;
  327. border-radius: 4px;
  328. display: inline-flex;
  329. align-items: center;
  330. justify-content: center;
  331. padding: 0;
  332. }
  333. .action-btn:hover { color: var(--primary); background: var(--primary-bg); }
  334. .action-btn.danger:hover { color: var(--danger); background: #fef2f2; }
  335. .action-btn svg { width: 14px; height: 14px; }
  336. .upload-hint {
  337. display: block;
  338. font-size: 11px;
  339. color: var(--muted);
  340. margin-top: 8px;
  341. line-height: 1.4;
  342. }
  343. .dialog-footer {
  344. display: flex;
  345. justify-content: flex-end;
  346. gap: 10px;
  347. padding: 12px 20px 16px;
  348. border-top: 1px solid var(--border);
  349. flex-shrink: 0;
  350. }
  351. .toast {
  352. position: fixed;
  353. top: 24px;
  354. left: 50%;
  355. transform: translateX(-50%) translateY(-12px);
  356. background: #fff;
  357. border: 1px solid var(--primary-border);
  358. color: var(--primary-dark);
  359. padding: 10px 16px;
  360. border-radius: 8px;
  361. font-size: 13px;
  362. box-shadow: var(--shadow);
  363. opacity: 0;
  364. pointer-events: none;
  365. transition: all .2s;
  366. z-index: 200;
  367. }
  368. .toast.show {
  369. opacity: 1;
  370. transform: translateX(-50%) translateY(0);
  371. }
  372. .note {
  373. margin-top: 16px;
  374. padding: 12px 14px;
  375. background: #fff;
  376. border: 1px dashed var(--primary-border);
  377. border-radius: 8px;
  378. font-size: 13px;
  379. color: var(--text-2);
  380. line-height: 1.6;
  381. }
  382. .note strong { color: var(--primary-dark); }
  383. #fileInput { display: none; }
  384. </style>
  385. </head>
  386. <body>
  387. <div class="page-title">
  388. <h1>已办中心</h1>
  389. <span class="hint">Demo · 点击操作列「上传回执」打开弹窗</span>
  390. </div>
  391. <section class="panel">
  392. <table>
  393. <thead>
  394. <tr>
  395. <th style="width:68px">序号</th>
  396. <th>流程名称</th>
  397. <th>申请人</th>
  398. <th>申请时间</th>
  399. <th>当前节点</th>
  400. <th>流程状态</th>
  401. <th style="min-width:320px">操作</th>
  402. </tr>
  403. </thead>
  404. <tbody>
  405. <tr>
  406. <td>1</td>
  407. <td>费用报销申请</td>
  408. <td>张三</td>
  409. <td>2026-10-12 14:22</td>
  410. <td>—</td>
  411. <td><span class="tag success">已完成</span></td>
  412. <td>
  413. <div class="ops">
  414. <button class="btn primary" type="button">
  415. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12z"/><circle cx="12" cy="12" r="3"/></svg>
  416. 查看
  417. </button>
  418. <button class="btn" type="button">
  419. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 6 2 18 2 18 9"/><path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"/><rect x="6" y="14" width="12" height="8"/></svg>
  420. 打印
  421. </button>
  422. <button class="btn" type="button" onclick="openDialog()">
  423. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
  424. 上传回执
  425. </button>
  426. </div>
  427. </td>
  428. </tr>
  429. <tr>
  430. <td>2</td>
  431. <td>付款申请单</td>
  432. <td>李四</td>
  433. <td>2026-10-10 09:05</td>
  434. <td>财务复核</td>
  435. <td><span class="tag warning">进行中</span></td>
  436. <td>
  437. <div class="ops">
  438. <button class="btn primary" type="button">
  439. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8S1 12 1 12z"/><circle cx="12" cy="12" r="3"/></svg>
  440. 查看
  441. </button>
  442. <button class="btn" type="button">
  443. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 6 2 18 2 18 9"/><path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"/><rect x="6" y="14" width="12" height="8"/></svg>
  444. 打印
  445. </button>
  446. <button class="btn" type="button" onclick="openDialog()">
  447. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
  448. 上传回执
  449. </button>
  450. </div>
  451. </td>
  452. </tr>
  453. </tbody>
  454. </table>
  455. </section>
  456. <div class="note">
  457. <strong>交互说明:</strong>
  458. 操作列新增「上传回执」→ 弹窗回显该审批实例已上传的银行回执单(多张)→
  459. 左侧上传卡片可继续追加 → 支持预览/下载/删除 → 点「确定」保存。
  460. 本 Demo 为前端示意,文件不会真正上传到服务器。
  461. </div>
  462. <div class="mask" id="mask" onclick="onMaskClick(event)">
  463. <div class="dialog" role="dialog" aria-modal="true" aria-labelledby="dlgTitle">
  464. <div class="dialog-header">
  465. <h2 id="dlgTitle">上传银行回执单</h2>
  466. <button class="dialog-close" type="button" aria-label="关闭" onclick="closeDialog()">×</button>
  467. </div>
  468. <div class="dialog-body">
  469. <div class="meta">
  470. <div>
  471. <div class="label">流程名称</div>
  472. <div class="value">费用报销申请</div>
  473. </div>
  474. <div>
  475. <div class="label">申请人</div>
  476. <div class="value">张三</div>
  477. </div>
  478. <div>
  479. <div class="label">申请时间</div>
  480. <div class="value">2026-10-12 14:22</div>
  481. </div>
  482. <div>
  483. <div class="label">已上传</div>
  484. <div class="value"><span id="countText">2</span> 张回执单</div>
  485. </div>
  486. </div>
  487. <p class="section-label">银行回执单</p>
  488. <div
  489. class="attachment-upload"
  490. id="dropZone"
  491. ondragover="onDragOver(event)"
  492. ondragleave="onDragLeave(event)"
  493. ondrop="onDrop(event)"
  494. >
  495. <div class="attachment-list" id="list">
  496. <div class="upload-card" onclick="document.getElementById('fileInput').click()" title="点击或拖拽上传">
  497. <svg class="plus" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
  498. <line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/>
  499. </svg>
  500. <span class="upload-card-text">上传附件</span>
  501. </div>
  502. <!-- history items injected by JS -->
  503. </div>
  504. <span class="upload-hint">支持拖拽或点击上传图片、PDF 等文件,单文件不超过 20MB;可上传多张回执单</span>
  505. </div>
  506. <input id="fileInput" type="file" multiple accept="image/*,.pdf,.doc,.docx,.xls,.xlsx" />
  507. </div>
  508. <div class="dialog-footer">
  509. <button class="btn ghost" type="button" onclick="closeDialog()">
  510. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
  511. 取消
  512. </button>
  513. <button class="btn main" type="button" onclick="saveDialog()">
  514. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg>
  515. 确定
  516. </button>
  517. </div>
  518. </div>
  519. </div>
  520. <div class="toast" id="toast"></div>
  521. <script>
  522. const seedFiles = [
  523. { id: '1', fileName: '电子回单_工商银行_1012.pdf', kind: 'pdf' },
  524. { id: '2', fileName: '银行回执单_微信转账.jpg', kind: 'image',
  525. thumb: 'data:image/svg+xml,' + encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="280" height="192"><defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1"><stop stop-color="#ecfdf5"/><stop offset="1" stop-color="#d1fae5"/></linearGradient></defs><rect width="280" height="192" fill="url(#g)"/><rect x="24" y="24" width="232" height="144" rx="8" fill="#fff" stroke="#a7f3d0"/><text x="140" y="90" text-anchor="middle" font-family="sans-serif" font-size="14" fill="#059669">银行回执单</text><text x="140" y="114" text-anchor="middle" font-family="sans-serif" font-size="11" fill="#94a3b8">示意缩略图</text></svg>`)
  526. }
  527. ];
  528. let files = [];
  529. function openDialog() {
  530. files = seedFiles.map(f => ({ ...f }));
  531. renderList();
  532. document.getElementById('mask').classList.add('open');
  533. }
  534. function closeDialog() {
  535. document.getElementById('mask').classList.remove('open');
  536. }
  537. function onMaskClick(e) {
  538. if (e.target === document.getElementById('mask')) closeDialog();
  539. }
  540. function saveDialog() {
  541. showToast('已保存 ' + files.length + ' 张银行回执单(Demo)');
  542. closeDialog();
  543. }
  544. function showToast(msg) {
  545. const el = document.getElementById('toast');
  546. el.textContent = msg;
  547. el.classList.add('show');
  548. setTimeout(() => el.classList.remove('show'), 1800);
  549. }
  550. function updateCount() {
  551. document.getElementById('countText').textContent = String(files.length);
  552. }
  553. function renderList() {
  554. const list = document.getElementById('list');
  555. const uploadCard = list.querySelector('.upload-card');
  556. list.innerHTML = '';
  557. list.appendChild(uploadCard);
  558. files.forEach((file, index) => {
  559. const item = document.createElement('div');
  560. item.className = 'attachment-item' + (file._uploading ? ' is-uploading' : '');
  561. const previewInner = file.kind === 'image' && file.thumb
  562. ? `<img src="${file.thumb}" alt="${escapeHtml(file.fileName)}" />`
  563. : `<div class="doc-icon">PDF</div>`;
  564. item.innerHTML = `
  565. <div class="attachment-preview">${previewInner}</div>
  566. <div class="attachment-footer">
  567. <div class="attachment-name" title="${escapeHtml(file.fileName)}">${escapeHtml(file.fileName)}</div>
  568. <div class="attachment-actions">
  569. <button class="action-btn" type="button" title="下载" onclick="downloadFile(${index})">
  570. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
  571. </button>
  572. <button class="action-btn danger" type="button" title="删除" onclick="removeFile(${index})">
  573. <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><path d="M10 11v6M14 11v6"/><path d="M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>
  574. </button>
  575. </div>
  576. </div>`;
  577. list.appendChild(item);
  578. });
  579. updateCount();
  580. }
  581. function escapeHtml(s) {
  582. return String(s).replace(/[&<>"']/g, c => ({
  583. '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;'
  584. })[c]);
  585. }
  586. function removeFile(index) {
  587. files.splice(index, 1);
  588. renderList();
  589. showToast('已移除(未保存前可撤销感)');
  590. }
  591. function downloadFile(index) {
  592. showToast('下载:' + files[index].fileName);
  593. }
  594. function addFiles(fileList) {
  595. Array.from(fileList || []).forEach(raw => {
  596. const kind = raw.type.startsWith('image/') ? 'image' : 'pdf';
  597. const id = 'n' + Date.now() + Math.random().toString(16).slice(2, 6);
  598. const entry = { id, fileName: raw.name, kind, _uploading: true, thumb: '' };
  599. files.push(entry);
  600. renderList();
  601. // simulate upload
  602. const reader = new FileReader();
  603. reader.onload = () => {
  604. const idx = files.findIndex(f => f.id === id);
  605. if (idx < 0) return;
  606. files[idx]._uploading = false;
  607. if (kind === 'image') files[idx].thumb = reader.result;
  608. renderList();
  609. };
  610. if (kind === 'image') reader.readAsDataURL(raw);
  611. else setTimeout(() => {
  612. const idx = files.findIndex(f => f.id === id);
  613. if (idx < 0) return;
  614. files[idx]._uploading = false;
  615. renderList();
  616. }, 500);
  617. });
  618. }
  619. document.getElementById('fileInput').addEventListener('change', (e) => {
  620. addFiles(e.target.files);
  621. e.target.value = '';
  622. });
  623. function onDragOver(e) {
  624. e.preventDefault();
  625. document.getElementById('dropZone').classList.add('is-dragover');
  626. }
  627. function onDragLeave(e) {
  628. e.preventDefault();
  629. document.getElementById('dropZone').classList.remove('is-dragover');
  630. }
  631. function onDrop(e) {
  632. e.preventDefault();
  633. document.getElementById('dropZone').classList.remove('is-dragover');
  634. addFiles(e.dataTransfer.files);
  635. }
  636. document.addEventListener('keydown', (e) => {
  637. if (e.key === 'Escape') closeDialog();
  638. });
  639. </script>
  640. </body>
  641. </html>