debug-select-border.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /**
  2. * 下拉框边框调试脚本
  3. *
  4. * 使用方法:
  5. * 1. 打开浏览器开发者工具(F12)
  6. * 2. 进入 Console 控制台
  7. * 3. 复制并粘贴这整个脚本
  8. * 4. 按 Enter 执行
  9. * 5. 查看控制台输出的诊断信息
  10. */
  11. console.log('%c========== 下拉框边框诊断开始 ==========', 'color: #1ca851; font-size: 16px; font-weight: bold;');
  12. // 1. 查找所有下拉框
  13. const selects = document.querySelectorAll('.el-select, .el-select-v2');
  14. console.log(`%c找到 ${selects.length} 个下拉框`, 'color: #409eff; font-weight: bold;');
  15. if (selects.length === 0) {
  16. console.warn('⚠️ 没有找到任何下拉框!请确保页面已经加载完成。');
  17. } else {
  18. // 2. 检查每个下拉框的样式
  19. selects.forEach((select, index) => {
  20. console.group(`%c下拉框 #${index + 1}`, 'color: #67c23a; font-weight: bold;');
  21. // 查找 input wrapper
  22. const wrapper = select.querySelector('.el-input__wrapper');
  23. if (!wrapper) {
  24. console.error('❌ 没有找到 .el-input__wrapper 元素');
  25. console.groupEnd();
  26. return;
  27. }
  28. // 获取计算后的样式
  29. const styles = window.getComputedStyle(wrapper);
  30. // 检查边框相关样式
  31. console.log('📊 边框样式信息:');
  32. console.table({
  33. 'border': styles.border,
  34. 'border-width': styles.borderWidth,
  35. 'border-style': styles.borderStyle,
  36. 'border-color': styles.borderColor,
  37. 'box-shadow': styles.boxShadow,
  38. 'outline': styles.outline,
  39. 'background-color': styles.backgroundColor
  40. });
  41. // 检查是否有边框
  42. const hasBorder = styles.borderWidth !== '0px' && styles.borderStyle !== 'none';
  43. if (hasBorder) {
  44. console.log('%c✅ 有边框', 'color: green; font-weight: bold;');
  45. } else {
  46. console.log('%c❌ 没有边框', 'color: red; font-weight: bold;');
  47. }
  48. // 检查是否有 box-shadow
  49. if (styles.boxShadow !== 'none') {
  50. console.log(`%c⚠️ 有 box-shadow: ${styles.boxShadow}`, 'color: orange;');
  51. }
  52. // 显示元素的类名
  53. console.log('🏷️ 元素类名:', select.className);
  54. // 显示元素的 HTML 结构
  55. console.log('🔍 HTML 结构:');
  56. console.log(select.outerHTML.substring(0, 200) + '...');
  57. console.groupEnd();
  58. });
  59. }
  60. // 3. 检查相关的 CSS 变量
  61. console.group('%c📐 CSS 变量检查', 'color: #e6a23c; font-weight: bold;');
  62. const rootStyles = getComputedStyle(document.documentElement);
  63. const cssVars = ['--art-border-color', '--el-border-color', '--el-border-color-light', '--main-color', '--art-main-bg-color'];
  64. const varValues = {};
  65. cssVars.forEach((varName) => {
  66. const value = rootStyles.getPropertyValue(varName).trim();
  67. varValues[varName] = value || '(未定义)';
  68. });
  69. console.table(varValues);
  70. console.groupEnd();
  71. // 4. 动态添加修复样式
  72. console.group('%c🔧 尝试动态修复', 'color: #f56c6c; font-weight: bold;');
  73. const fixStyle = document.createElement('style');
  74. fixStyle.id = 'fix-select-border-dynamic';
  75. fixStyle.innerHTML = `
  76. /* 动态修复样式 */
  77. .el-select .el-input__wrapper,
  78. .el-select-v2 .el-input__wrapper {
  79. border: 2px solid #ff0000 !important; /* 红色边框,方便识别 */
  80. box-shadow: none !important;
  81. }
  82. .el-select .el-input__wrapper:hover,
  83. .el-select-v2 .el-input__wrapper:hover {
  84. border-color: #1ca851 !important;
  85. }
  86. .el-select .el-input__wrapper.is-focus,
  87. .el-select .el-input__wrapper.is-focused,
  88. .el-select-v2 .el-input__wrapper.is-focus,
  89. .el-select-v2 .el-input__wrapper.is-focused {
  90. border-color: #1ca851 !important;
  91. }
  92. `;
  93. // 检查是否已经添加过
  94. const existingFix = document.getElementById('fix-select-border-dynamic');
  95. if (existingFix) {
  96. console.log('⚠️ 已经添加过修复样式,先移除旧的');
  97. existingFix.remove();
  98. }
  99. document.head.appendChild(fixStyle);
  100. console.log('%c✅ 已添加动态修复样式(红色边框)', 'color: green; font-weight: bold;');
  101. console.log('如果现在看到红色边框,说明 CSS 选择器是正确的,问题在于样式优先级或加载顺序');
  102. console.log('如果还是没有边框,说明 DOM 结构可能不同,需要检查实际的 HTML 结构');
  103. console.groupEnd();
  104. // 5. 提供手动修复函数
  105. window.fixSelectBorder = function (color = '#dcdfe6') {
  106. const style = document.createElement('style');
  107. style.id = 'manual-fix-select-border';
  108. style.innerHTML = `
  109. .el-select .el-input__wrapper,
  110. .el-select-v2 .el-input__wrapper {
  111. border: 1px solid ${color} !important;
  112. box-shadow: none !important;
  113. }
  114. `;
  115. const existing = document.getElementById('manual-fix-select-border');
  116. if (existing) existing.remove();
  117. document.head.appendChild(style);
  118. console.log(`%c✅ 已应用边框颜色: ${color}`, 'color: green; font-weight: bold;');
  119. };
  120. console.log('%c========== 诊断完成 ==========', 'color: #1ca851; font-size: 16px; font-weight: bold;');
  121. console.log('%c💡 提示:', 'color: #409eff; font-weight: bold;');
  122. console.log('1. 检查上面的诊断信息,看看是否有边框');
  123. console.log('2. 如果看到红色边框,说明动态修复成功');
  124. console.log('3. 可以调用 fixSelectBorder("#dcdfe6") 来应用正常的边框颜色');
  125. console.log('4. 可以调用 fixSelectBorder("#1ca851") 来应用绿色边框');
  126. console.log('');
  127. console.log('%c📝 下一步建议:', 'color: #e6a23c; font-weight: bold;');
  128. console.log('1. 如果动态修复有效,说明问题在于 CSS 加载顺序或优先级');
  129. console.log('2. 如果动态修复无效,说明 DOM 结构可能不同,需要检查实际的 HTML');
  130. console.log('3. 使用开发者工具的 Elements 面板,选中一个下拉框,查看 Styles 面板');
  131. console.log('4. 查看是否有 border 样式被其他规则覆盖(会显示删除线)');