/** * Switch 开关组件样式 */ /* Switch 基础样式 */ .switch { position: relative; display: inline-block; width: 44px; height: 24px; background-color: #e9ecef; border-radius: 12px; cursor: pointer; transition: background-color 0.3s ease, border-color 0.3s ease; border: 1px solid #dee2e6; flex-shrink: 0; box-sizing: border-box; padding: 0; } /* 移除 button 默认样式 */ .switch::-webkit-inner-spin-button, .switch::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; } .switch { appearance: none; -webkit-appearance: none; -moz-appearance: none; } /* Switch 选中状态 - 绿色 */ .switch-checked { background-color: #00684a; border-color: #00684a; } .switch-unchecked { background-color: #e9ecef; border-color: #dee2e6; } /* Switch 滑块 */ .switch-handle { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; background-color: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); transition: transform 0.3s ease; display: flex; align-items: center; justify-content: center; } .switch-handle-checked { transform: translateX(20px); } .switch-handle-unchecked { transform: translateX(0); } /* Switch 禁用状态 */ .switch-disabled { cursor: not-allowed; opacity: 0.5; } .switch-disabled.switch-checked { background-color: rgba(0, 104, 74, 0.5); border-color: rgba(0, 104, 74, 0.5); } /* Switch 加载状态 */ .switch-loading { cursor: wait; } /* 加载动画图标 */ .switch-loading-icon { display: block; width: 10px; height: 10px; border: 2px solid #00684a; border-top-color: transparent; border-radius: 50%; animation: switch-spin 0.8s linear infinite; } @keyframes switch-spin { to { transform: rotate(360deg); } } /* Hover 效果(仅非禁用状态) */ .switch:not(.switch-disabled):hover { box-shadow: 0 0 0 4px rgba(0, 104, 74, 0.1); } /* Focus 样式 */ .switch:focus-visible { outline: 2px solid #00684a; outline-offset: 2px; }