index.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. margin: 0;
  10. padding: 0;
  11. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  12. display: flex;
  13. flex-direction: column;
  14. height: 100vh;
  15. }
  16. .navbar {
  17. display: flex;
  18. background: #333;
  19. padding: 0;
  20. }
  21. .navbar a {
  22. flex: 1;
  23. color: white;
  24. text-align: center;
  25. padding: 15px 20px;
  26. text-decoration: none;
  27. transition: background 0.3s;
  28. cursor: pointer;
  29. }
  30. .navbar a:hover,
  31. .navbar a.active {
  32. background: #555;
  33. }
  34. .view-container {
  35. flex: 1;
  36. overflow: auto;
  37. display: flex;
  38. justify-content: center;
  39. align-items: flex-start;
  40. padding: 20px;
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <nav class="navbar">
  46. <a href="#" data-view="text2text.html">文生文(text2text)</a>
  47. <a href="#" data-view="img2text.html">图生文(img2text)</a>
  48. <a href="#" data-view="img2img.html">图生图(img2img)</a>
  49. <a href="#" data-view="text2img.html">文生图(text2img)</a>
  50. </nav>
  51. <div class="view-container" id="viewContainer"></div>
  52. <script>
  53. const viewContainer = document.getElementById('viewContainer');
  54. const navLinks = document.querySelectorAll('.navbar a');
  55. const loadedStyles = new Set();
  56. async function loadView(viewFile) {
  57. try {
  58. const response = await fetch(viewFile);
  59. const html = await response.text();
  60. const parser = new DOMParser();
  61. const doc = parser.parseFromString(html, 'text/html');
  62. document.querySelectorAll('style[data-view-style]').forEach(s => s.remove());
  63. loadedStyles.clear();
  64. viewContainer.innerHTML = '';
  65. const bodyContent = doc.body.innerHTML;
  66. const styles = doc.head.querySelectorAll('style');
  67. const scripts = doc.body.querySelectorAll('script');
  68. styles.forEach(style => {
  69. let styleText = style.textContent;
  70. styleText = styleText.replace(/body\s*\{[^}]*\}/g, '');
  71. if (styleText.trim() && !loadedStyles.has(styleText)) {
  72. const styleEl = document.createElement('style');
  73. styleEl.setAttribute('data-view-style', 'true');
  74. styleEl.textContent = styleText;
  75. document.head.appendChild(styleEl);
  76. loadedStyles.add(styleText);
  77. }
  78. });
  79. viewContainer.innerHTML = bodyContent;
  80. scripts.forEach(script => {
  81. const scriptEl = document.createElement('script');
  82. if (script.src) {
  83. scriptEl.src = script.src;
  84. } else {
  85. scriptEl.textContent = script.textContent;
  86. }
  87. viewContainer.appendChild(scriptEl);
  88. });
  89. } catch (error) {
  90. viewContainer.innerHTML = `<div style="padding: 20px;">加载失败: ${error.message}</div>`;
  91. }
  92. }
  93. navLinks.forEach(link => {
  94. link.addEventListener('click', (e) => {
  95. e.preventDefault();
  96. navLinks.forEach(l => l.classList.remove('active'));
  97. link.classList.add('active');
  98. loadView(link.dataset.view);
  99. });
  100. });
  101. loadView('text2text.html');
  102. navLinks[0].classList.add('active');
  103. </script>
  104. </body>
  105. </html>