fix-all-pages.sh 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #!/bin/bash
  2. # 定义颜色
  3. GREEN='\033[0;32m'
  4. BLUE='\033[0;34m'
  5. NC='\033[0m' # No Color
  6. # 确认函数
  7. confirm() {
  8. read -p "$1 (y/n): " choice
  9. case "$choice" in
  10. y|Y ) return 0;;
  11. * ) return 1;;
  12. esac
  13. }
  14. echo -e "${BLUE}爱智农平台页面修复工具${NC}"
  15. echo "-----------------------------------"
  16. echo "此脚本将批量修复所有页面的UI按钮遮挡问题"
  17. echo "-----------------------------------"
  18. # 获取未处理的页面
  19. pages_to_process=()
  20. for file in pages/*.html; do
  21. # 排除已经创建的content页面
  22. if [[ ! $file == *-content.html ]] && [[ ! -f "${file%.*}-content.html" ]] && [[ ! $file == "field-management.html" ]] && [[ ! $file == "device-management.html" ]] && [[ ! $file == "machine-monitor.html" ]] && [[ ! $file == "device-monitor.html" ]]; then
  23. pages_to_process+=("$file")
  24. fi
  25. done
  26. # 显示待处理的页面
  27. echo -e "\n${GREEN}找到以下待处理页面:${NC}"
  28. for page in "${pages_to_process[@]}"; do
  29. echo "- $page"
  30. done
  31. if confirm "是否继续处理这些页面?"; then
  32. for page in "${pages_to_process[@]}"; do
  33. base_name=$(basename "$page" .html)
  34. content_file="pages/${base_name}-content.html"
  35. echo -e "\n${GREEN}处理页面: $page${NC}"
  36. # 1. 复制原始文件为content文件
  37. cp "$page" "$content_file"
  38. echo "✓ 已创建内容页面: $content_file"
  39. # 2. 为内容页面添加必要的CSS和类
  40. sed -i '' 's/<html lang="zh-CN">/<html lang="zh-CN" class="iframe-content">/' "$content_file"
  41. sed -i '' 's/<div class="page-container">/<div class="page-container responsive-container">/' "$content_file"
  42. sed -i '' 's/<div class="flex justify-between items-center mb-6">/<div class="flex justify-between items-center mb-6 page-header">/' "$content_file"
  43. sed -i '' 's/<div class="flex gap-2">/<div class="flex gap-2 button-container">/' "$content_file"
  44. # 添加CSS样式到内容页面
  45. css_insert='body {\n padding-top: 15px; /* 添加顶部填充以确保内容不被系统元素遮挡 */\n}\n\n.page-container {\n position: relative;\n padding-top: 40px; /* 增加顶部内边距,给按钮腾出空间 */\n}\n\n/* 防止重复菜单 */\nbody > div:not(.page-container):not(.modal-container),\niframe#sidebar, \ndiv.system-menu,\n[id^="system-menu"],\n[class^="system-menu"],\n#admin-sidebar,\n.menu-popup,\n.user-avatar-circle {\n display: none !important;\n width: 0 !important;\n height: 0 !important;\n opacity: 0 !important;\n position: absolute !important;\n top: -9999px !important;\n left: -9999px !important;\n z-index: -9999 !important;\n pointer-events: none !important;\n}\n\n/* 防止右侧白圈和浮动元素 */\n.circle-btn,\n.floating-circle,\n.round-button,\n.scroll-top-btn,\n[class*="round"],\n[class*="circle"],\n.help-btn,\n.chat-btn,\nbody > .btn,\nbody > button,\nbody > div:not(.page-container):not(.modal-container) {\n display: none !important;\n visibility: hidden !important;\n opacity: 0 !important;\n pointer-events: none !important;\n}\n\n/* 页面标题和操作按钮容器 */\n.page-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 20px;\n padding-bottom: 16px;\n border-bottom: 1px solid #e0e0e0;\n padding-top: 10px;\n position: relative;\n z-index: 10;\n}\n\n/* 添加按钮的特定样式 */\n.button-container {\n position: relative;\n z-index: 20;\n}\n\n.btn {\n position: relative;\n z-index: 5;\n height: 38px;\n visibility: visible !important;\n opacity: 1 !important;\n display: inline-flex !important;\n}'
  46. sed -i '' "/<style>/a\\
  47. $css_insert
  48. " "$content_file"
  49. echo "✓ 已添加样式到内容页面"
  50. # 3. 创建iframe容器页面
  51. cat > "$page" << EOF
  52. <!DOCTYPE html>
  53. <html lang="zh-CN">
  54. <head>
  55. <meta charset="UTF-8">
  56. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  57. <title>${base_name//-/ } - 爱智农</title>
  58. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css">
  59. <link rel="stylesheet" href="https://at.alicdn.com/t/font_3114978_qe0b39no76.css">
  60. <link rel="stylesheet" href="../assets/css/global.css">
  61. <style>
  62. :root {
  63. --primary: #4CAF50;
  64. --primary-dark: #388E3C;
  65. --primary-light: #A5D6A7;
  66. --primary-bg: #F1F8E9;
  67. --success: #4CAF50;
  68. --warning: #FFC107;
  69. --danger: #F44336;
  70. --info: #2196F3;
  71. --disabled: #9E9E9E;
  72. --border: #E0E0E0;
  73. --text-primary: #212121;
  74. --text-secondary: #757575;
  75. --radius: 8px;
  76. }
  77. body {
  78. font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  79. background-color: #f5f7f9;
  80. color: var(--text-primary);
  81. margin: 0;
  82. padding: 0;
  83. height: 100vh;
  84. width: 100vw;
  85. overflow: hidden;
  86. }
  87. /* 内容页面框架 */
  88. #content-frame {
  89. width: 100%;
  90. height: 100%;
  91. border: none;
  92. overflow: hidden;
  93. margin-top: 0; /* 移除顶部外边距 */
  94. padding-top: 0; /* 移除顶部内边距 */
  95. }
  96. /* 移除白色圆形按钮 */
  97. .circle-btn,
  98. .floating-button,
  99. .round-button,
  100. button[class*='circle'],
  101. div[class*='circle'],
  102. [class*='float-btn'],
  103. body > div:not(#app),
  104. body > button {
  105. display: none !important;
  106. visibility: hidden !important;
  107. opacity: 0 !important;
  108. position: absolute !important;
  109. top: -9999px !important;
  110. left: -9999px !important;
  111. z-index: -9999 !important;
  112. pointer-events: none !important;
  113. }
  114. </style>
  115. </head>
  116. <body>
  117. <!-- 使用iframe来完全隔离和控制页面内容 -->
  118. <iframe id="content-frame" src="${base_name}-content.html" sandbox="allow-scripts allow-forms allow-same-origin allow-popups" loading="eager" scrolling="auto" frameborder="0" allowfullscreen></iframe>
  119. <script>
  120. // 监听iframe加载完成
  121. document.getElementById('content-frame').onload = function() {
  122. // 确保iframe高度铺满
  123. this.style.height = window.innerHeight + 'px';
  124. };
  125. // 页面大小变化时调整iframe大小
  126. window.addEventListener('resize', function() {
  127. document.getElementById('content-frame').style.height = window.innerHeight + 'px';
  128. });
  129. </script>
  130. </body>
  131. </html>
  132. EOF
  133. echo "✓ 已创建iframe容器页面: $page"
  134. echo "✓ 页面 $page 处理完成!"
  135. done
  136. echo -e "\n${GREEN}所有页面处理完成!${NC}"
  137. echo "共处理了 ${#pages_to_process[@]} 个页面"
  138. else
  139. echo "已取消操作"
  140. fi