img2img.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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>AI 测试页面</title>
  7. <style>
  8. body {
  9. display: flex;
  10. justify-content: center;
  11. align-items: center;
  12. min-height: 100vh;
  13. padding: 20px;
  14. }
  15. .container {
  16. display: grid;
  17. container-type: inline-size;
  18. width: 100%;
  19. max-width: 900px;
  20. gap: 20px;
  21. }
  22. textarea {
  23. width: 100%;
  24. padding: 10px;
  25. min-height: 120px;
  26. }
  27. button {
  28. width: 100%;
  29. padding: 10px;
  30. }
  31. button:disabled {
  32. opacity: 0.6;
  33. }
  34. .loading {
  35. display: none;
  36. }
  37. .loading.active {
  38. display: block;
  39. }
  40. .spinner {
  41. width: 20px;
  42. height: 20px;
  43. border: 3px solid #f3f3f3;
  44. border-top: 3px solid #000;
  45. border-radius: 50%;
  46. animation: spin 1s linear infinite;
  47. display: inline-block;
  48. }
  49. @keyframes spin {
  50. 0% { transform: rotate(0deg); }
  51. 100% { transform: rotate(360deg); }
  52. }
  53. .result-box {
  54. padding: 20px;
  55. min-height: 200px;
  56. max-height: 500px;
  57. overflow-y: auto;
  58. white-space: pre-wrap;
  59. border: 1px solid #ccc;
  60. }
  61. </style>
  62. </head>
  63. <body>
  64. <div class="container">
  65. <textarea id="prompt" placeholder="请输入提示词..."></textarea>
  66. <button id="sendBtn" onclick="sendRequest()">
  67. <span>发送</span>
  68. </button>
  69. <div class="loading" id="loading">
  70. <div class="spinner"></div>
  71. <span>正在处理...</span>
  72. </div>
  73. <div class="result-box" id="resultBox"></div>
  74. </div>
  75. <script>
  76. const apiUrl = 'https://' + window.location.hostname;
  77. const promptTextarea = document.getElementById('prompt');
  78. const sendBtn = document.getElementById('sendBtn');
  79. const loadingDiv = document.getElementById('loading');
  80. const resultBox = document.getElementById('resultBox');
  81. async function sendRequest() {
  82. const prompt = promptTextarea.value.trim();
  83. if (!prompt) {
  84. alert('请输入提示词!');
  85. return;
  86. }
  87. sendBtn.disabled = true;
  88. loadingDiv.classList.add('active');
  89. resultBox.textContent = '';
  90. try {
  91. const response = await fetch(`${apiUrl}/api/chat`, {
  92. method: 'POST',
  93. headers: { 'Content-Type': 'application/json' },
  94. body: JSON.stringify({ prompt })
  95. });
  96. const data = await response.json();
  97. resultBox.textContent = data.success
  98. ? JSON.stringify(data.data, null, 2)
  99. : `错误: ${data.error}`;
  100. } catch (error) {
  101. resultBox.textContent = `请求失败: ${error.message}`;
  102. } finally {
  103. sendBtn.disabled = false;
  104. loadingDiv.classList.remove('active');
  105. }
  106. }
  107. promptTextarea.addEventListener('keydown', (e) => {
  108. if (e.key === 'Enter' && e.ctrlKey) sendRequest();
  109. });
  110. </script>
  111. </body>
  112. </html>