index.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>树莓派双面拍照</title>
  7. <style>
  8. :root {
  9. --bg: #f3efe6;
  10. --panel: #fffdf8;
  11. --line: #d7c8b6;
  12. --text: #2c241c;
  13. --muted: #7a6c5d;
  14. --accent: #a44c21;
  15. --accent-dark: #7d3818;
  16. }
  17. * {
  18. box-sizing: border-box;
  19. }
  20. body {
  21. margin: 0;
  22. font-family: "Microsoft YaHei", sans-serif;
  23. color: var(--text);
  24. background:
  25. radial-gradient(circle at top left, #f8d7b8 0, transparent 28%),
  26. radial-gradient(circle at bottom right, #ead7c5 0, transparent 24%),
  27. linear-gradient(135deg, #f5f0e7, #ebe2d5);
  28. min-height: 100vh;
  29. }
  30. .page {
  31. max-width: 1100px;
  32. margin: 0 auto;
  33. padding: 40px 20px 60px;
  34. }
  35. .header {
  36. margin-bottom: 24px;
  37. }
  38. .header h1 {
  39. margin: 0 0 10px;
  40. font-size: 34px;
  41. }
  42. .header p {
  43. margin: 0;
  44. color: var(--muted);
  45. line-height: 1.7;
  46. }
  47. .toolbar {
  48. display: flex;
  49. gap: 12px;
  50. align-items: center;
  51. flex-wrap: wrap;
  52. margin: 28px 0 20px;
  53. }
  54. button {
  55. border: 0;
  56. border-radius: 12px;
  57. padding: 14px 22px;
  58. font-size: 16px;
  59. cursor: pointer;
  60. color: #fff;
  61. background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  62. box-shadow: 0 10px 24px rgba(164, 76, 33, 0.2);
  63. }
  64. button:disabled {
  65. opacity: 0.65;
  66. cursor: not-allowed;
  67. }
  68. .status {
  69. min-height: 24px;
  70. color: var(--muted);
  71. }
  72. .result {
  73. display: grid;
  74. grid-template-columns: repeat(2, minmax(0, 1fr));
  75. gap: 20px;
  76. margin-top: 20px;
  77. }
  78. .card {
  79. background: var(--panel);
  80. border: 1px solid var(--line);
  81. border-radius: 18px;
  82. padding: 18px;
  83. box-shadow: 0 16px 40px rgba(90, 62, 36, 0.08);
  84. }
  85. .card h2 {
  86. margin: 0 0 12px;
  87. font-size: 20px;
  88. }
  89. .image-box {
  90. aspect-ratio: 1 / 1;
  91. border-radius: 14px;
  92. background: #efe5d8;
  93. border: 1px dashed #c7b39b;
  94. display: flex;
  95. align-items: center;
  96. justify-content: center;
  97. overflow: hidden;
  98. }
  99. .image-box img {
  100. width: 100%;
  101. height: 100%;
  102. object-fit: contain;
  103. display: none;
  104. background: #fff;
  105. }
  106. .placeholder {
  107. color: var(--muted);
  108. text-align: center;
  109. padding: 20px;
  110. line-height: 1.6;
  111. }
  112. .link {
  113. margin-top: 12px;
  114. word-break: break-all;
  115. font-size: 14px;
  116. }
  117. .link a {
  118. color: var(--accent-dark);
  119. }
  120. .info-card {
  121. margin-top: 20px;
  122. }
  123. .info-box {
  124. min-height: 180px;
  125. border-radius: 14px;
  126. border: 1px dashed #c7b39b;
  127. background: #f7f1e7;
  128. padding: 16px;
  129. white-space: pre-wrap;
  130. line-height: 1.7;
  131. overflow: auto;
  132. }
  133. @media (max-width: 800px) {
  134. .result {
  135. grid-template-columns: 1fr;
  136. }
  137. .header h1 {
  138. font-size: 28px;
  139. }
  140. }
  141. </style>
  142. </head>
  143. <body>
  144. <div class="page">
  145. <div class="header">
  146. <h1>树莓派正反面拍照</h1>
  147. <p>点击按钮后,页面会请求 <code>/capture-pair</code>,等待机械臂流程完成,然后展示 MinIO 图片链接和第一张图的识别结果。</p>
  148. </div>
  149. <div class="toolbar">
  150. <button id="captureBtn">开始拍照</button>
  151. <div class="status" id="statusText">等待操作</div>
  152. </div>
  153. <div class="result">
  154. <div class="card">
  155. <h2>图片 1 / front</h2>
  156. <div class="image-box">
  157. <img id="frontImage" alt="front">
  158. <div class="placeholder" id="frontPlaceholder">还没有图片</div>
  159. </div>
  160. <div class="link"><a id="frontLink" href="#" target="_blank"></a></div>
  161. </div>
  162. <div class="card">
  163. <h2>图片 2 / back</h2>
  164. <div class="image-box">
  165. <img id="backImage" alt="back">
  166. <div class="placeholder" id="backPlaceholder">还没有图片</div>
  167. </div>
  168. <div class="link"><a id="backLink" href="#" target="_blank"></a></div>
  169. </div>
  170. </div>
  171. <div class="card info-card">
  172. <h2>识别结果</h2>
  173. <div class="info-box" id="recognizedInfo">还没有识别结果</div>
  174. </div>
  175. </div>
  176. <script>
  177. const captureBtn = document.getElementById("captureBtn");
  178. const statusText = document.getElementById("statusText");
  179. const frontImage = document.getElementById("frontImage");
  180. const backImage = document.getElementById("backImage");
  181. const frontLink = document.getElementById("frontLink");
  182. const backLink = document.getElementById("backLink");
  183. const frontPlaceholder = document.getElementById("frontPlaceholder");
  184. const backPlaceholder = document.getElementById("backPlaceholder");
  185. const recognizedInfo = document.getElementById("recognizedInfo");
  186. function setStatus(text) {
  187. statusText.textContent = text;
  188. }
  189. function showImage(img, link, placeholder, url) {
  190. const finalUrl = `${url}${url.includes("?") ? "&" : "?"}t=${Date.now()}`;
  191. img.src = finalUrl;
  192. img.style.display = "block";
  193. placeholder.style.display = "none";
  194. link.href = url;
  195. link.textContent = url;
  196. }
  197. captureBtn.addEventListener("click", async () => {
  198. captureBtn.disabled = true;
  199. setStatus("正在请求拍照,请等待机械臂流程完成...");
  200. try {
  201. const response = await fetch("/capture-pair", { method: "POST" });
  202. const data = await response.json();
  203. if (!response.ok) {
  204. throw new Error(data.detail || "请求失败");
  205. }
  206. if (data.card_front_url) {
  207. showImage(frontImage, frontLink, frontPlaceholder, data.card_front_url);
  208. }
  209. if (data.card_back_url) {
  210. showImage(backImage, backLink, backPlaceholder, data.card_back_url);
  211. }
  212. recognizedInfo.textContent = data.recognizedInfoDTO
  213. ? JSON.stringify(data.recognizedInfoDTO, null, 2)
  214. : "未获取到识别结果";
  215. setStatus("拍照完成");
  216. } catch (error) {
  217. setStatus(`拍照失败:${error.message}`);
  218. } finally {
  219. captureBtn.disabled = false;
  220. }
  221. });
  222. </script>
  223. </body>
  224. </html>