index.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>EPS to SVG Converter</title>
  7. <style>
  8. body {
  9. font-family: Arial, sans-serif;
  10. max-width: 800px;
  11. margin: 20px auto;
  12. padding: 20px;
  13. }
  14. .upload-container {
  15. border: 2px dashed #ccc;
  16. padding: 20px;
  17. text-align: center;
  18. margin: 20px 0;
  19. }
  20. .upload-container.dragover {
  21. border-color: #4CAF50;
  22. background: #e8f5e9;
  23. }
  24. #uploadForm {
  25. margin-bottom: 20px;
  26. }
  27. #result {
  28. margin-top: 20px;
  29. padding: 10px;
  30. border-radius: 4px;
  31. }
  32. .success {
  33. background-color: #e8f5e9;
  34. color: #2e7d32;
  35. }
  36. .error {
  37. background-color: #ffebee;
  38. color: #c62828;
  39. }
  40. button {
  41. background-color: #4CAF50;
  42. color: white;
  43. padding: 10px 20px;
  44. border: none;
  45. border-radius: 4px;
  46. cursor: pointer;
  47. }
  48. button:hover {
  49. background-color: #45a049;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. <h1>EPS to SVG Converter</h1>
  55. <div class="upload-container" id="dropZone">
  56. <form id="uploadForm">
  57. <input type="file" id="fileInput" accept=".eps" style="display: none">
  58. <button type="button" onclick="document.getElementById('fileInput').click()">选择EPS文件</button>
  59. <p>或拖拽文件到此处</p>
  60. </form>
  61. <div id="fileName"></div>
  62. </div>
  63. <div id="result"></div>
  64. <script>
  65. const dropZone = document.getElementById('dropZone');
  66. const fileInput = document.getElementById('fileInput');
  67. const resultDiv = document.getElementById('result');
  68. const fileNameDiv = document.getElementById('fileName');
  69. // Drag and drop handlers
  70. dropZone.addEventListener('dragover', (e) => {
  71. e.preventDefault();
  72. dropZone.classList.add('dragover');
  73. });
  74. dropZone.addEventListener('dragleave', () => {
  75. dropZone.classList.remove('dragover');
  76. });
  77. dropZone.addEventListener('drop', (e) => {
  78. e.preventDefault();
  79. dropZone.classList.remove('dragover');
  80. const files = e.dataTransfer.files;
  81. if (files.length > 0) {
  82. handleFile(files[0]);
  83. }
  84. });
  85. fileInput.addEventListener('change', (e) => {
  86. if (e.target.files.length > 0) {
  87. handleFile(e.target.files[0]);
  88. }
  89. });
  90. function handleFile(file) {
  91. if (!file.name.toLowerCase().endsWith('.eps')) {
  92. showResult('请选择EPS文件', false);
  93. return;
  94. }
  95. if (file.size > 10 * 1024 * 1024) {
  96. showResult('文件大小不能超过10MB', false);
  97. return;
  98. }
  99. fileNameDiv.textContent = `已选择: ${file.name}`;
  100. uploadFile(file);
  101. }
  102. async function uploadFile(file) {
  103. const formData = new FormData();
  104. formData.append('file', file);
  105. try {
  106. const response = await fetch('https://www.infish.cn/sku3d/v1/eps2svg/convert', {
  107. method: 'POST',
  108. body: formData
  109. });
  110. const data = await response.json();
  111. if (response.ok) {
  112. showResult(`转换成功! OBS路径: ${data.obs_key}`, true);
  113. } else {
  114. showResult(`错误: ${data.detail || '转换失败'}`, false);
  115. }
  116. } catch (error) {
  117. showResult(`错误: ${error.message}`, false);
  118. }
  119. }
  120. function showResult(message, isSuccess) {
  121. resultDiv.textContent = message;
  122. resultDiv.className = isSuccess ? 'success' : 'error';
  123. }
  124. </script>
  125. </body>
  126. </html>