xyZjz_batchAdd.ss.jsp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. <%@ page import="ss.page.PageC" %>
  2. <%@ page language="java" pageEncoding="UTF-8" isELIgnored="false" %>
  3. <%@ taglib uri="/ssTag" prefix="ss" %>
  4. <% pageContext.setAttribute(PageC.PAGE_objName, "xy"); %>
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <%@ include file="/page/clip/header.jsp" %>
  9. <script>window.xyZjzBatchLoginStatus="${empty sessionScope['ssUser']?'0':'1'}";</script>
  10. <link rel="stylesheet" type="text/css" href="/ss/window/theme/dhtmlxwindows.css">
  11. <link rel="stylesheet" type="text/css" href="/ss/window/theme/dhx_blue/dhtmlxwindows_dhx_blue.css">
  12. <script type="text/javascript" src="/ss/window/dhtmlxcommon.js"></script>
  13. <script type="text/javascript" src="/ss/window/dhtmlxwindows.js"></script>
  14. <script type="text/javascript" src="/ss/window/dhtmlxcontainer.js"></script>
  15. <script type="text/javascript" src="/ss/js/display.js"></script>
  16. <script type="text/javascript" src="/ss/js/upload.js"></script>
  17. <style>
  18. html, body, body.env-input-body {
  19. height: 100%;
  20. margin: 0;
  21. overflow: hidden;
  22. background: #f5f7fb;
  23. font-family: Arial, "Microsoft YaHei", sans-serif;
  24. color: #333;
  25. }
  26. .form-container {
  27. height: 100%;
  28. min-height: 0;
  29. margin: 0;
  30. }
  31. .batch-photo-page {
  32. display: flex;
  33. height: 100%;
  34. min-height: 0;
  35. overflow: hidden;
  36. }
  37. .batch-photo-main {
  38. flex: 0 0 55%;
  39. display: flex;
  40. min-width: 0;
  41. min-height: 0;
  42. flex-direction: column;
  43. align-items: center;
  44. padding: 20px 42px 24px;
  45. box-sizing: border-box;
  46. background: #fff;
  47. border-right: 1px solid #e1e5ec;
  48. }
  49. .batch-photo-preview-shell {
  50. display: flex;
  51. flex: 1;
  52. width: 100%;
  53. min-height: 0;
  54. align-items: flex-start;
  55. justify-content: center;
  56. }
  57. .batch-photo-preview {
  58. flex: 0 0 auto;
  59. position: relative;
  60. width: min(100%, 540px);
  61. height: auto;
  62. max-width: 100%;
  63. max-height: 100%;
  64. aspect-ratio: 1000 / 1515;
  65. overflow: hidden;
  66. background: #858585;
  67. border: 1px solid #d8dce4;
  68. box-sizing: border-box;
  69. }
  70. .batch-photo-preview video,
  71. .batch-photo-preview > img.batch-photo-captured {
  72. position: absolute;
  73. inset: 0;
  74. z-index: 1;
  75. display: none;
  76. width: 100%;
  77. height: 100%;
  78. object-fit: cover;
  79. }
  80. .batch-photo-preview.is-live {
  81. border-color: #409eff;
  82. }
  83. .batch-photo-placeholder {
  84. position: absolute;
  85. inset: 0;
  86. z-index: 2;
  87. display: flex;
  88. align-items: center;
  89. justify-content: center;
  90. padding: 32px;
  91. box-sizing: border-box;
  92. color: rgba(255, 255, 255, .86);
  93. text-align: center;
  94. font-size: 18px;
  95. line-height: 1.6;
  96. background: linear-gradient(180deg, rgba(0,0,0,.08), rgba(0,0,0,.22));
  97. }
  98. .batch-photo-guide {
  99. position: absolute;
  100. inset: 0;
  101. z-index: 3;
  102. display: none;
  103. pointer-events: none;
  104. box-sizing: border-box;
  105. background: transparent url("/image/xyZjz/batch-face-guide.png?v=20260827-face3") center center / 100% 100% no-repeat;
  106. }
  107. .batch-photo-action-bar {
  108. display: flex;
  109. flex-wrap: wrap;
  110. gap: 12px;
  111. justify-content: center;
  112. width: min(100%, 430px);
  113. padding-top: 20px;
  114. }
  115. .batch-photo-action-bar button,
  116. .batch-photo-toolbar button {
  117. min-width: 138px;
  118. height: 42px;
  119. padding: 0 22px;
  120. border: 1px solid #d7dce5;
  121. border-radius: 4px;
  122. background: #fff;
  123. color: #555;
  124. cursor: pointer;
  125. font-size: 16px;
  126. }
  127. .batch-photo-action-bar button:hover,
  128. .batch-photo-toolbar button:hover {
  129. border-color: #409eff;
  130. color: #409eff;
  131. }
  132. .batch-photo-action-bar button.primary,
  133. .batch-photo-toolbar button.primary {
  134. border-color: #1f2937;
  135. background: #1f2937;
  136. color: #fff;
  137. }
  138. .batch-photo-action-bar button.primary:hover,
  139. .batch-photo-toolbar button.primary:hover {
  140. border-color: #111827;
  141. background: #111827;
  142. color: #fff;
  143. }
  144. .batch-photo-action-bar button:disabled,
  145. .batch-photo-toolbar button:disabled {
  146. cursor: not-allowed;
  147. opacity: .55;
  148. }
  149. .batch-photo-toolbar {
  150. display: flex;
  151. align-items: center;
  152. gap: 8px;
  153. width: 100%;
  154. margin-bottom: 0;
  155. }
  156. .batch-photo-toolbar select {
  157. max-width: 220px;
  158. height: 34px;
  159. padding: 0 8px;
  160. border: 1px solid #d7dce5;
  161. border-radius: 4px;
  162. background: #fff;
  163. }
  164. .batch-photo-right {
  165. display: grid;
  166. grid-template-rows: 248px 1px minmax(0, 1fr);
  167. flex: 1 1 42%;
  168. min-width: 380px;
  169. min-height: 0;
  170. overflow: hidden;
  171. background: #f7f8fa;
  172. }
  173. .batch-photo-student-card {
  174. margin: 20px 32px;
  175. padding: 16px 20px;
  176. overflow: hidden;
  177. border: 1px solid #e0e4eb;
  178. border-radius: 5px;
  179. background: #fff;
  180. box-sizing: border-box;
  181. }
  182. .batch-photo-student-name {
  183. margin-bottom: 18px;
  184. color: #111;
  185. font-size: 21px;
  186. font-weight: 600;
  187. }
  188. .batch-photo-student-body {
  189. display: flex;
  190. align-items: flex-start;
  191. gap: 18px;
  192. }
  193. .batch-photo-avatar {
  194. width: 80px;
  195. height: 121px;
  196. flex: 0 0 80px;
  197. overflow: hidden;
  198. border: 1px solid #e3e6ec;
  199. border-radius: 3px;
  200. background: #f1f3f6;
  201. }
  202. .batch-photo-avatar img {
  203. display: block;
  204. width: 100%;
  205. height: 100%;
  206. object-fit: cover;
  207. }
  208. .batch-photo-student-lines {
  209. min-width: 0;
  210. color: #555;
  211. font-size: 16px;
  212. line-height: 1.8;
  213. }
  214. .batch-photo-student-lines div {
  215. overflow: hidden;
  216. text-overflow: ellipsis;
  217. white-space: nowrap;
  218. }
  219. .batch-photo-right-divider {
  220. height: 1px;
  221. background: #e1e5ec;
  222. }
  223. .batch-photo-list-panel {
  224. display: flex;
  225. min-width: 0;
  226. min-height: 0;
  227. flex-direction: column;
  228. padding: 16px 18px 12px;
  229. box-sizing: border-box;
  230. }
  231. .batch-photo-list-header {
  232. display: flex;
  233. align-items: center;
  234. min-width: 0;
  235. gap: 10px;
  236. margin-bottom: 12px;
  237. padding: 0 8px;
  238. }
  239. .batch-photo-list-labels {
  240. display: grid;
  241. grid-template-columns: 34px auto;
  242. align-items: center;
  243. flex: 0 0 auto;
  244. gap: 12px;
  245. color: #4b5563;
  246. font-size: 17px;
  247. font-weight: 600;
  248. white-space: nowrap;
  249. }
  250. .batch-photo-list-index-label {
  251. text-align: center;
  252. }
  253. .batch-photo-list-name-label {
  254. overflow: hidden;
  255. text-overflow: ellipsis;
  256. }
  257. .batch-photo-progress {
  258. color: #6b7280;
  259. font-size: 14px;
  260. white-space: nowrap;
  261. margin-left: auto;
  262. }
  263. .batch-photo-search {
  264. flex: 0 1 200px;
  265. width: 200px;
  266. min-width: 180px;
  267. height: 32px;
  268. padding: 0 10px;
  269. border: 1px solid #d7dce5;
  270. border-radius: 4px;
  271. box-sizing: border-box;
  272. }
  273. .batch-photo-list {
  274. flex: 1;
  275. min-width: 0;
  276. min-height: 0;
  277. overflow-y: auto;
  278. border-top: 1px solid #e8ebf0;
  279. }
  280. .batch-photo-student-row {
  281. display: grid;
  282. min-width: 0;
  283. grid-template-columns: 34px max-content max-content 48px;
  284. align-items: center;
  285. gap: 12px;
  286. min-height: 42px;
  287. padding: 0 8px;
  288. border-radius: 4px;
  289. cursor: pointer;
  290. font-size: 14px;
  291. justify-content: start;
  292. }
  293. .batch-photo-student-row:hover {
  294. background: #eef4fb;
  295. }
  296. .batch-photo-student-row.active {
  297. background: #e0e7f0;
  298. }
  299. .batch-photo-student-row.completed .batch-photo-status {
  300. color: #16834b;
  301. }
  302. .batch-photo-student-row.failed .batch-photo-status {
  303. color: #d14343;
  304. }
  305. .batch-photo-index {
  306. color: #9ca3af;
  307. text-align: center;
  308. }
  309. .batch-photo-student-name-cell,
  310. .batch-photo-student-id-cell {
  311. overflow: hidden;
  312. text-overflow: ellipsis;
  313. white-space: nowrap;
  314. }
  315. .batch-photo-student-name-cell {
  316. color: #1f2937;
  317. font-weight: 600;
  318. }
  319. .batch-photo-student-id-cell {
  320. color: #6b7280;
  321. font-variant-numeric: tabular-nums;
  322. }
  323. .batch-photo-status {
  324. color: #9ca3af;
  325. font-size: 12px;
  326. text-align: right;
  327. white-space: nowrap;
  328. }
  329. .batch-photo-message {
  330. min-height: 24px;
  331. width: min(100%, 520px);
  332. padding-top: 8px;
  333. color: #6b7280;
  334. font-size: 14px;
  335. text-align: center;
  336. }
  337. .batch-photo-message.error {
  338. color: #c0392b;
  339. }
  340. @media (max-width: 900px) {
  341. .batch-photo-main {
  342. flex-basis: 55%;
  343. padding: 20px;
  344. }
  345. .batch-photo-right {
  346. flex-basis: 42%;
  347. min-width: 360px;
  348. }
  349. .batch-photo-student-card {
  350. margin: 20px 16px;
  351. }
  352. .batch-photo-list-panel {
  353. padding-right: 12px;
  354. padding-left: 12px;
  355. }
  356. .batch-photo-list-header {
  357. gap: 6px;
  358. padding: 0 4px;
  359. }
  360. .batch-photo-list-labels {
  361. grid-template-columns: 28px auto;
  362. gap: 12px;
  363. font-size: 15px;
  364. }
  365. .batch-photo-search {
  366. flex-basis: 160px;
  367. width: 160px;
  368. min-width: 160px;
  369. }
  370. .batch-photo-student-row {
  371. grid-template-columns: 28px max-content max-content 42px;
  372. gap: 12px;
  373. padding-right: 4px;
  374. padding-left: 4px;
  375. }
  376. }
  377. </style>
  378. </head>
  379. <body class="env-input-body">
  380. <form id="app" class="form-container" onsubmit="return false;">
  381. <input id="batchBjid" type="hidden" value="${bjid}">
  382. <div class="batch-photo-page" id="batchPhotoPage">
  383. <section class="batch-photo-main">
  384. <div class="batch-photo-toolbar">
  385. <select id="batchPhotoDeviceSelect" hidden></select>
  386. <button type="button" id="batchPhotoDeviceSwitch" hidden>切换摄像头</button>
  387. </div>
  388. <div class="batch-photo-preview-shell">
  389. <div class="batch-photo-preview" id="batchPhotoPreview">
  390. <div class="batch-photo-placeholder" id="batchPhotoPlaceholder">正在加载班级学生名单...</div>
  391. <video id="batchPhotoVideo" autoplay muted playsinline></video>
  392. <img id="batchPhotoImage" class="batch-photo-captured" alt="当前拍摄照片">
  393. <div class="batch-photo-guide" id="batchPhotoGuide"></div>
  394. <canvas id="batchPhotoCanvas"></canvas>
  395. </div>
  396. </div>
  397. <div class="batch-photo-action-bar" id="batchPhotoActions">
  398. <button type="button" id="batchPhotoConnectButton">连接摄像头</button>
  399. <button type="button" id="batchPhotoCaptureButton" hidden>拍照</button>
  400. <button type="button" id="batchPhotoRetakeButton" hidden>重新拍照</button>
  401. <button type="button" id="batchPhotoSaveButton" class="primary" hidden>保存并提交</button>
  402. </div>
  403. <div class="batch-photo-message" id="batchPhotoMessage">正在加载学生名单...</div>
  404. </section>
  405. <aside class="batch-photo-right">
  406. <section class="batch-photo-student-card">
  407. <div class="batch-photo-student-name" id="batchPhotoStudentName">--</div>
  408. <div class="batch-photo-student-body">
  409. <div class="batch-photo-avatar"><img id="batchPhotoStudentAvatar" alt="学生照片"></div>
  410. <div class="batch-photo-student-lines">
  411. <div id="batchPhotoStudentGender">性别:--</div>
  412. <div id="batchPhotoStudentStudy">就读方式:--</div>
  413. <div>班级:<span id="batchPhotoClassName">${bjmc}</span></div>
  414. <div id="batchPhotoStudentNumber">学号:--</div>
  415. </div>
  416. </div>
  417. </section>
  418. <div class="batch-photo-right-divider"></div>
  419. <section class="batch-photo-list-panel">
  420. <div class="batch-photo-list-header">
  421. <div class="batch-photo-list-labels">
  422. <div class="batch-photo-list-index-label">序号</div>
  423. <div class="batch-photo-list-name-label">姓名</div>
  424. </div>
  425. <div class="batch-photo-progress" id="batchPhotoProgress">0/0</div>
  426. <input class="batch-photo-search" id="batchPhotoSearch" type="text" placeholder="姓名/身份证号">
  427. </div>
  428. <div class="batch-photo-list" id="batchPhotoStudentList"></div>
  429. </section>
  430. </aside>
  431. </div>
  432. </form>
  433. <script>
  434. (function () {
  435. "use strict";
  436. var state = {
  437. mode: "loading",
  438. stream: null,
  439. students: [],
  440. currentIndex: -1,
  441. capturedBlob: null,
  442. capturedUrl: "",
  443. capturedRyid: null,
  444. saving: false,
  445. devices: [],
  446. requestSequence: 0,
  447. previewResizeObserver: null
  448. };
  449. var elements = {};
  450. var emptyImage = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='121'%3E%3Crect width='80' height='121' fill='%23f1f3f6'/%3E%3Ctext x='40' y='66' font-size='11' fill='%23999' text-anchor='middle'%3E无照片%3C/text%3E%3C/svg%3E";
  451. var batchPhotoWidth = 1000;
  452. var batchPhotoHeight = 1515;
  453. var batchPhotoRatio = batchPhotoWidth / batchPhotoHeight;
  454. function getElement(id) {
  455. return document.getElementById(id);
  456. }
  457. function initElements() {
  458. elements.bjid = getElement("batchBjid");
  459. elements.preview = getElement("batchPhotoPreview");
  460. elements.previewShell = elements.preview.parentNode;
  461. elements.placeholder = getElement("batchPhotoPlaceholder");
  462. elements.video = getElement("batchPhotoVideo");
  463. elements.image = getElement("batchPhotoImage");
  464. elements.guide = getElement("batchPhotoGuide");
  465. elements.canvas = getElement("batchPhotoCanvas");
  466. elements.connect = getElement("batchPhotoConnectButton");
  467. elements.capture = getElement("batchPhotoCaptureButton");
  468. elements.retake = getElement("batchPhotoRetakeButton");
  469. elements.save = getElement("batchPhotoSaveButton");
  470. elements.deviceSelect = getElement("batchPhotoDeviceSelect");
  471. elements.deviceSwitch = getElement("batchPhotoDeviceSwitch");
  472. elements.message = getElement("batchPhotoMessage");
  473. elements.name = getElement("batchPhotoStudentName");
  474. elements.avatar = getElement("batchPhotoStudentAvatar");
  475. elements.gender = getElement("batchPhotoStudentGender");
  476. elements.study = getElement("batchPhotoStudentStudy");
  477. elements.number = getElement("batchPhotoStudentNumber");
  478. elements.className = getElement("batchPhotoClassName");
  479. elements.progress = getElement("batchPhotoProgress");
  480. elements.list = getElement("batchPhotoStudentList");
  481. elements.search = getElement("batchPhotoSearch");
  482. }
  483. function resizePreview() {
  484. if (!elements.preview || !elements.previewShell) {
  485. return;
  486. }
  487. var availableWidth = elements.previewShell.clientWidth;
  488. var availableHeight = elements.previewShell.clientHeight;
  489. if (!availableWidth || !availableHeight) {
  490. return;
  491. }
  492. var maxWidth = 540;
  493. var width = Math.min(maxWidth, availableWidth, availableHeight * batchPhotoRatio);
  494. var height = width / batchPhotoRatio;
  495. elements.preview.style.width = width + "px";
  496. elements.preview.style.height = height + "px";
  497. }
  498. function watchPreviewResize() {
  499. resizePreview();
  500. if (window.ResizeObserver) {
  501. state.previewResizeObserver = new ResizeObserver(resizePreview);
  502. state.previewResizeObserver.observe(elements.previewShell);
  503. } else {
  504. window.addEventListener("resize", resizePreview);
  505. }
  506. }
  507. function setMessage(message, isError) {
  508. elements.message.textContent = message || "";
  509. elements.message.className = isError ? "batch-photo-message error" : "batch-photo-message";
  510. }
  511. function setPlaceholder(message) {
  512. elements.placeholder.textContent = message || "";
  513. elements.placeholder.style.display = "flex";
  514. }
  515. function hidePlaceholder() {
  516. elements.placeholder.style.display = "none";
  517. }
  518. function stopStream() {
  519. if (state.stream && state.stream.getTracks) {
  520. state.stream.getTracks().forEach(function (track) {
  521. track.stop();
  522. });
  523. }
  524. state.stream = null;
  525. elements.video.pause();
  526. elements.video.srcObject = null;
  527. }
  528. function revokeCapturedUrl() {
  529. if (state.capturedUrl) {
  530. URL.revokeObjectURL(state.capturedUrl);
  531. state.capturedUrl = "";
  532. }
  533. }
  534. function clearCapturedPhoto() {
  535. revokeCapturedUrl();
  536. state.capturedBlob = null;
  537. state.capturedRyid = null;
  538. elements.image.removeAttribute("src");
  539. }
  540. function setMode(mode) {
  541. state.mode = mode;
  542. var live = mode === "live";
  543. var captured = mode === "captured" || mode === "saveError";
  544. var saving = mode === "saving";
  545. var cameraError = mode === "cameraError";
  546. elements.connect.hidden = !(mode === "loading" || mode === "cameraDisconnected" || cameraError);
  547. elements.capture.hidden = !live;
  548. elements.retake.hidden = !captured;
  549. elements.save.hidden = !captured;
  550. elements.capture.disabled = saving;
  551. elements.retake.disabled = saving;
  552. elements.save.disabled = saving;
  553. elements.preview.classList.toggle("is-live", live);
  554. elements.video.style.display = live ? "block" : "none";
  555. elements.image.style.display = captured ? "block" : "none";
  556. elements.guide.style.display = live ? "block" : "none";
  557. if (live) {
  558. hidePlaceholder();
  559. } else if (!captured && !cameraError && mode !== "completed") {
  560. setPlaceholder(mode === "saving" ? "正在保存照片..." : "点击“连接摄像头”开始拍照");
  561. } else if (cameraError) {
  562. setPlaceholder("摄像头连接失败,请检查权限或设备后重试");
  563. }
  564. if (mode === "listError") {
  565. setPlaceholder("学生名单加载失败,请刷新页面后重试");
  566. } else if (mode === "completed") {
  567. setPlaceholder("全班学生证件照已完成,可从右侧选择学生补拍");
  568. }
  569. }
  570. function currentStudent() {
  571. return state.currentIndex < 0 ? null : state.students[state.currentIndex];
  572. }
  573. function imageUrl(path) {
  574. return path ? "/service?ssServ=dlByHttp&type=img&path=" + encodeURIComponent(path) : emptyImage;
  575. }
  576. function updateStudentCard() {
  577. var student = currentStudent();
  578. if (!student) {
  579. elements.name.textContent = "--";
  580. elements.avatar.src = emptyImage;
  581. elements.gender.textContent = "性别:--";
  582. elements.study.textContent = "就读方式:--";
  583. elements.number.textContent = "学号:--";
  584. return;
  585. }
  586. elements.name.textContent = student.xm || "--";
  587. var temporaryPhoto = state.capturedUrl && state.capturedRyid != null &&
  588. String(state.capturedRyid) === String(student.ryid) ? state.capturedUrl : "";
  589. elements.avatar.src = temporaryPhoto || imageUrl(student.zjzwj);
  590. elements.gender.textContent = "性别:" + (student.xbmc || student.xbm || "--");
  591. elements.study.textContent = "就读方式:" + (student.jdfsmc || student.jdfsm || "--");
  592. elements.number.textContent = "学号:" + (student.ryh || "--");
  593. }
  594. function updateProgress() {
  595. var completedCount = state.students.filter(function (student) { return !!student.sfypzjz; }).length;
  596. elements.progress.textContent = completedCount + "/" + state.students.length;
  597. }
  598. function renderList() {
  599. var keyword = (elements.search.value || "").trim().toLowerCase();
  600. elements.list.innerHTML = "";
  601. state.students.forEach(function (student, index) {
  602. var searchable = ((student.xm || "") + " " + (student.sfzh || "")).toLowerCase();
  603. if (keyword && searchable.indexOf(keyword) < 0) {
  604. return;
  605. }
  606. var row = document.createElement("div");
  607. row.className = "batch-photo-student-row";
  608. if (index === state.currentIndex) {
  609. row.classList.add("active");
  610. }
  611. if (student.sfypzjz) {
  612. row.classList.add("completed");
  613. }
  614. if (student.saveError) {
  615. row.classList.add("failed");
  616. }
  617. row.innerHTML = "<div class='batch-photo-index'></div><div class='batch-photo-student-name-cell'></div><div class='batch-photo-student-id-cell'></div><div class='batch-photo-status'></div>";
  618. row.children[0].textContent = String(index + 1);
  619. row.children[1].textContent = student.xm || "未命名学生";
  620. row.children[2].textContent = student.sfzh || "未录入身份证号";
  621. row.children[3].textContent = student.saveError ? "失败" : (student.sfypzjz ? "已拍" : "未拍");
  622. row.addEventListener("click", function () { selectStudent(index, false); });
  623. elements.list.appendChild(row);
  624. });
  625. updateProgress();
  626. }
  627. function scrollCurrentStudentIntoView() {
  628. if (!elements.list) {
  629. return;
  630. }
  631. var scroll = function () {
  632. var activeRow = elements.list.querySelector(".active");
  633. if (activeRow) {
  634. activeRow.scrollIntoView({block: "nearest"});
  635. }
  636. };
  637. if (window.requestAnimationFrame) {
  638. window.requestAnimationFrame(scroll);
  639. } else {
  640. scroll();
  641. }
  642. }
  643. function resetPreviewForStudent() {
  644. clearCapturedPhoto();
  645. var student = currentStudent();
  646. if (state.stream) {
  647. elements.image.style.display = "none";
  648. elements.video.style.display = "block";
  649. setMode("live");
  650. } else {
  651. elements.video.style.display = "none";
  652. setMode("cameraDisconnected");
  653. elements.image.src = imageUrl(student && student.zjzwj);
  654. elements.image.style.display = student && student.zjzwj ? "block" : "none";
  655. }
  656. }
  657. function selectStudent(index, skipConfirmation) {
  658. if (index < 0 || index >= state.students.length || index === state.currentIndex) {
  659. return;
  660. }
  661. if (!skipConfirmation && state.capturedBlob && !window.confirm("当前照片尚未保存,切换学生将放弃本次拍照,是否继续?")) {
  662. return;
  663. }
  664. state.currentIndex = index;
  665. updateStudentCard();
  666. renderList();
  667. resetPreviewForStudent();
  668. scrollCurrentStudentIntoView();
  669. }
  670. function firstIncompleteIndex() {
  671. for (var index = 0; index < state.students.length; index++) {
  672. if (!state.students[index].sfypzjz) {
  673. return index;
  674. }
  675. }
  676. return -1;
  677. }
  678. function parseJson(value) {
  679. if (typeof value === "string") {
  680. return JSON.parse(value);
  681. }
  682. return value;
  683. }
  684. function loadStudents() {
  685. var bjid = elements.bjid.value;
  686. fetch("/service?ssServ=xyZjz_batchListByA&bjid=" + encodeURIComponent(bjid), {credentials: "same-origin"})
  687. .then(function (response) { return response.text(); })
  688. .then(parseJson)
  689. .then(function (result) {
  690. if (!result || result.ssCode !== 0) {
  691. throw new Error(result && result.ssMsg ? result.ssMsg : "学生列表加载失败");
  692. }
  693. var data = result.ssData || {};
  694. state.students = Array.isArray(data.students) ? data.students : [];
  695. if (data.bjmc) {
  696. elements.className.textContent = data.bjmc;
  697. }
  698. var firstIndex = firstIncompleteIndex();
  699. state.currentIndex = firstIndex >= 0 ? firstIndex : (state.students.length ? 0 : -1);
  700. updateStudentCard();
  701. renderList();
  702. scrollCurrentStudentIntoView();
  703. if (firstIndex < 0) {
  704. setMode("completed");
  705. setMessage(state.students.length ? "当前班级学生证件照已全部完成" : "当前班级没有可拍照学生");
  706. } else {
  707. resetPreviewForStudent();
  708. setMessage("请连接摄像头后开始拍照");
  709. }
  710. })
  711. .catch(function (error) {
  712. setMode("listError");
  713. setMessage(error.message || "学生列表加载失败", true);
  714. });
  715. }
  716. function enumerateCameras() {
  717. if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
  718. throw new Error("当前浏览器不支持摄像头访问");
  719. }
  720. return navigator.mediaDevices.getUserMedia({video: true, audio: false})
  721. .then(function (permissionStream) {
  722. return navigator.mediaDevices.enumerateDevices().then(function (devices) {
  723. permissionStream.getTracks().forEach(function (track) { track.stop(); });
  724. state.devices = devices.filter(function (device) { return device.kind === "videoinput"; });
  725. if (!state.devices.length) {
  726. throw new Error("未检测到摄像头");
  727. }
  728. elements.deviceSelect.innerHTML = "";
  729. state.devices.forEach(function (device, index) {
  730. var option = document.createElement("option");
  731. option.value = device.deviceId;
  732. option.textContent = device.label || ("摄像头" + (index + 1));
  733. elements.deviceSelect.appendChild(option);
  734. });
  735. elements.deviceSelect.hidden = state.devices.length < 2;
  736. elements.deviceSwitch.hidden = state.devices.length < 2;
  737. return elements.deviceSelect.value || state.devices[0].deviceId;
  738. });
  739. });
  740. }
  741. function connectCamera() {
  742. if (state.mode === "saving") {
  743. return;
  744. }
  745. setMode("connecting");
  746. setMessage("正在请求摄像头权限...");
  747. enumerateCameras()
  748. .then(function (deviceId) {
  749. stopStream();
  750. return navigator.mediaDevices.getUserMedia({video: {deviceId: {exact: deviceId}}, audio: false});
  751. })
  752. .then(function (stream) {
  753. state.stream = stream;
  754. elements.video.srcObject = stream;
  755. return elements.video.play();
  756. })
  757. .then(function () {
  758. var videoTrack = state.stream && state.stream.getVideoTracks()[0];
  759. if (videoTrack) {
  760. videoTrack.addEventListener("ended", function () {
  761. stopStream();
  762. setMode("cameraError");
  763. setMessage("摄像头已断开,请重新连接", true);
  764. });
  765. }
  766. setMode("live");
  767. setMessage("请对准取景框,按 Enter 或点击“拍照”");
  768. })
  769. .catch(function (error) {
  770. stopStream();
  771. setMode("cameraError");
  772. setMessage(error.message || "摄像头连接失败", true);
  773. });
  774. }
  775. function capturePhoto() {
  776. var student = currentStudent();
  777. if (state.mode !== "live" || !state.stream || state.saving || !student) {
  778. return;
  779. }
  780. var videoWidth = elements.video.videoWidth;
  781. var videoHeight = elements.video.videoHeight;
  782. if (!videoWidth || !videoHeight) {
  783. setMessage("摄像头画面尚未准备好,请稍后重试", true);
  784. return;
  785. }
  786. var targetRatio = batchPhotoRatio;
  787. var sourceRatio = videoWidth / videoHeight;
  788. var cropWidth = sourceRatio > targetRatio ? Math.round(videoHeight * targetRatio) : videoWidth;
  789. var cropHeight = sourceRatio > targetRatio ? videoHeight : Math.round(videoWidth / targetRatio);
  790. var sourceX = Math.round((videoWidth - cropWidth) / 2);
  791. var sourceY = Math.round((videoHeight - cropHeight) / 2);
  792. elements.canvas.width = batchPhotoWidth;
  793. elements.canvas.height = batchPhotoHeight;
  794. elements.canvas.getContext("2d").drawImage(elements.video, sourceX, sourceY, cropWidth, cropHeight, 0, 0, batchPhotoWidth, batchPhotoHeight);
  795. elements.canvas.toBlob(function (blob) {
  796. if (!blob) {
  797. setMessage("照片截图失败,请重试", true);
  798. return;
  799. }
  800. clearCapturedPhoto();
  801. state.capturedBlob = blob;
  802. state.capturedUrl = URL.createObjectURL(blob);
  803. state.capturedRyid = student.ryid;
  804. elements.image.src = state.capturedUrl;
  805. updateStudentCard();
  806. setMode("captured");
  807. setMessage("请确认照片,按 Enter 或点击“保存并提交”");
  808. }, "image/jpeg", .92);
  809. }
  810. function retakePhoto() {
  811. if (state.saving) {
  812. return;
  813. }
  814. clearCapturedPhoto();
  815. updateStudentCard();
  816. if (state.stream) {
  817. setMode("live");
  818. setMessage("请对准取景框,按 Enter 或点击“拍照”");
  819. } else {
  820. setMode("cameraDisconnected");
  821. }
  822. }
  823. function uploadCapturedPhoto(blob) {
  824. var formData = new FormData();
  825. formData.append("application", "");
  826. formData.append("fileEdit", new File([blob], "batch_" + Date.now() + ".jpg", {type: "image/jpeg"}));
  827. return fetch("/service?ssServ=ulByHttp&type=img", {
  828. method: "POST",
  829. body: formData,
  830. credentials: "same-origin"
  831. }).then(function (response) { return response.text(); })
  832. .then(parseJson)
  833. .then(function (result) {
  834. var path = result && result.fileList && result.fileList[0] && result.fileList[0].path;
  835. if (!path) {
  836. throw new Error("照片上传后未返回文件路径");
  837. }
  838. return path;
  839. });
  840. }
  841. function savePhoto() {
  842. if (state.mode !== "captured" && state.mode !== "saveError") {
  843. return;
  844. }
  845. var student = currentStudent();
  846. if (!student || !state.capturedBlob || state.saving) {
  847. return;
  848. }
  849. state.saving = true;
  850. state.requestSequence += 1;
  851. var requestId = Date.now() + "_" + state.requestSequence;
  852. setMode("saving");
  853. setMessage("正在上传并处理照片...");
  854. uploadCapturedPhoto(state.capturedBlob)
  855. .then(function (path) {
  856. var body = new URLSearchParams();
  857. body.set("bjid", elements.bjid.value);
  858. body.set("ryid", String(student.ryid));
  859. body.set("zjzwj", path);
  860. body.set("requestId", requestId);
  861. return fetch("/service?ssServ=xyZjz_batchSaveByA", {
  862. method: "POST",
  863. headers: {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"},
  864. body: body.toString(),
  865. credentials: "same-origin"
  866. }).then(function (response) { return response.text(); }).then(parseJson);
  867. })
  868. .then(function (result) {
  869. if (!result || result.ssCode !== 0) {
  870. throw new Error(result && result.ssMsg ? result.ssMsg : "照片保存失败");
  871. }
  872. var data = result.ssData || {};
  873. student.sfypzjz = true;
  874. if (data.savedPhoto) {
  875. student.zjzwj = data.savedPhoto;
  876. }
  877. student.saveError = false;
  878. clearCapturedPhoto();
  879. state.saving = false;
  880. renderList();
  881. updateStudentCard();
  882. if (data.allCompleted) {
  883. setMode("completed");
  884. setMessage("全班学生证件照已完成");
  885. return;
  886. }
  887. var nextIndex = state.students.findIndex(function (item) {
  888. return data.nextStudent && String(item.ryid) === String(data.nextStudent.ryid);
  889. });
  890. if (nextIndex < 0) {
  891. nextIndex = firstIncompleteIndex();
  892. }
  893. if (nextIndex >= 0) {
  894. state.currentIndex = nextIndex;
  895. updateStudentCard();
  896. renderList();
  897. scrollCurrentStudentIntoView();
  898. setMode(state.stream ? "live" : "cameraDisconnected");
  899. setMessage(state.stream ? "请对准取景框,按 Enter 或点击“拍照”" : "请重新连接摄像头");
  900. } else {
  901. setMode("completed");
  902. setMessage("全班学生证件照已完成");
  903. }
  904. })
  905. .catch(function (error) {
  906. state.saving = false;
  907. if (student) {
  908. student.saveError = true;
  909. }
  910. setMode("saveError");
  911. renderList();
  912. setMessage(error.message || "照片保存失败,请重试", true);
  913. });
  914. }
  915. function handleKeydown(event) {
  916. var target = event.target || {};
  917. var tagName = (target.tagName || "").toLowerCase();
  918. if (tagName === "input" || tagName === "textarea" || tagName === "select" || target.isContentEditable || event.repeat) {
  919. return;
  920. }
  921. if (event.key === "Enter") {
  922. event.preventDefault();
  923. if (state.mode === "live") {
  924. capturePhoto();
  925. } else if (state.mode === "captured" || state.mode === "saveError") {
  926. savePhoto();
  927. } else if (state.mode === "cameraDisconnected" || state.mode === "cameraError") {
  928. connectCamera();
  929. }
  930. } else if (event.key === "ArrowLeft" || event.key === "Left" || event.keyCode === 37 || event.which === 37) {
  931. if (state.mode === "captured" || state.mode === "saveError") {
  932. event.preventDefault();
  933. retakePhoto();
  934. }
  935. } else if (event.key === "ArrowUp" || event.key === "ArrowDown") {
  936. event.preventDefault();
  937. if (state.mode === "saving" || state.currentIndex < 0) {
  938. return;
  939. }
  940. var nextIndex = state.currentIndex + (event.key === "ArrowUp" ? -1 : 1);
  941. selectStudent(nextIndex, false);
  942. }
  943. }
  944. function initBatchPhotoPage() {
  945. elements = {};
  946. initElements();
  947. elements.connect.addEventListener("click", connectCamera);
  948. elements.capture.addEventListener("click", capturePhoto);
  949. elements.retake.addEventListener("click", retakePhoto);
  950. elements.save.addEventListener("click", savePhoto);
  951. elements.deviceSwitch.addEventListener("click", connectCamera);
  952. elements.search.addEventListener("input", renderList);
  953. document.addEventListener("keydown", handleKeydown);
  954. window.addEventListener("beforeunload", function (event) {
  955. if (state.capturedBlob) {
  956. event.preventDefault();
  957. event.returnValue = "当前照片尚未保存";
  958. }
  959. stopStream();
  960. if (state.previewResizeObserver) {
  961. state.previewResizeObserver.disconnect();
  962. }
  963. });
  964. watchPreviewResize();
  965. loadStudents();
  966. }
  967. if (window.SS && window.SS.__appMounted) {
  968. initBatchPhotoPage();
  969. } else {
  970. document.addEventListener("ssAppMounted", initBatchPhotoPage, {once: true});
  971. }
  972. })();
  973. </script>
  974. <%@ include file="/page/clip/footer.jsp" %>
  975. </body>
  976. </html>