index.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. @media (max-width: 800px) {
  121. .result {
  122. grid-template-columns: 1fr;
  123. }
  124. .header h1 {
  125. font-size: 28px;
  126. }
  127. }
  128. </style>
  129. </head>
  130. <body>
  131. <div class="page">
  132. <div class="header">
  133. <h1>树莓派正反面拍照</h1>
  134. <p>点击按钮后,页面会请求 <code>/capture-pair</code>,等待机械臂流程完成,再展示返回的两张图片。</p>
  135. </div>
  136. <div class="toolbar">
  137. <button id="captureBtn">开始拍照</button>
  138. <div class="status" id="statusText">等待操作</div>
  139. </div>
  140. <div class="result">
  141. <div class="card">
  142. <h2>图片 1 / front</h2>
  143. <div class="image-box">
  144. <img id="frontImage" alt="front">
  145. <div class="placeholder" id="frontPlaceholder">还没有图片</div>
  146. </div>
  147. <div class="link"><a id="frontLink" href="#" target="_blank"></a></div>
  148. </div>
  149. <div class="card">
  150. <h2>图片 2 / back</h2>
  151. <div class="image-box">
  152. <img id="backImage" alt="back">
  153. <div class="placeholder" id="backPlaceholder">还没有图片</div>
  154. </div>
  155. <div class="link"><a id="backLink" href="#" target="_blank"></a></div>
  156. </div>
  157. </div>
  158. </div>
  159. <script>
  160. const captureBtn = document.getElementById("captureBtn");
  161. const statusText = document.getElementById("statusText");
  162. const frontImage = document.getElementById("frontImage");
  163. const backImage = document.getElementById("backImage");
  164. const frontLink = document.getElementById("frontLink");
  165. const backLink = document.getElementById("backLink");
  166. const frontPlaceholder = document.getElementById("frontPlaceholder");
  167. const backPlaceholder = document.getElementById("backPlaceholder");
  168. function setStatus(text) {
  169. statusText.textContent = text;
  170. }
  171. function showImage(img, link, placeholder, url) {
  172. const finalUrl = `${url}${url.includes("?") ? "&" : "?"}t=${Date.now()}`;
  173. img.src = finalUrl;
  174. img.style.display = "block";
  175. placeholder.style.display = "none";
  176. link.href = url;
  177. link.textContent = url;
  178. }
  179. captureBtn.addEventListener("click", async () => {
  180. captureBtn.disabled = true;
  181. setStatus("正在请求拍照,请等待机械臂流程完成...");
  182. try {
  183. const response = await fetch("/capture-pair", { method: "POST" });
  184. const data = await response.json();
  185. if (!response.ok) {
  186. throw new Error(data.detail || "请求失败");
  187. }
  188. showImage(frontImage, frontLink, frontPlaceholder, data.front_url);
  189. showImage(backImage, backLink, backPlaceholder, data.back_url);
  190. setStatus(`拍照完成,status=${data.status},request_id=${data.request_id}`);
  191. } catch (error) {
  192. setStatus(`拍照失败:${error.message}`);
  193. } finally {
  194. captureBtn.disabled = false;
  195. }
  196. });
  197. </script>
  198. </body>
  199. </html>