|
| 1 | +<script setup lang="ts"> |
| 2 | +import { storeToRefs } from "pinia"; |
| 3 | +import { useStore } from "../store"; |
| 4 | +
|
| 5 | +const props = defineProps<{ |
| 6 | + isOpen: boolean; |
| 7 | +}>(); |
| 8 | +
|
| 9 | +const emit = defineEmits(["update:isOpen"]); |
| 10 | +
|
| 11 | +const toggleSidebar = () => { |
| 12 | + emit("update:isOpen", !props.isOpen); |
| 13 | +}; |
| 14 | +
|
| 15 | +const store = useStore(); |
| 16 | +const { settings } = storeToRefs(store); |
| 17 | +
|
| 18 | +const rangeConfigs = { |
| 19 | + targetSpeed: { name: "目标速度", unit: "WPM", min: 10, max: 120 }, |
| 20 | + targetAccuracy: { name: "目标准确率", unit: "%", min: 80, max: 100 }, |
| 21 | +}; |
| 22 | +</script> |
| 23 | + |
| 24 | +<template> |
| 25 | + <aside :class="['sidebar', { 'is-open': isOpen }]"> |
| 26 | + <button |
| 27 | + class="toggle-btn" |
| 28 | + @click="toggleSidebar" |
| 29 | + :title="isOpen ? '收起' : '展开设置'" |
| 30 | + > |
| 31 | + <div :class="['arrow-icon', { 'is-active': isOpen }]"></div> |
| 32 | + </button> |
| 33 | + |
| 34 | + <div class="sidebar-inner" v-if="isOpen"> |
| 35 | + <h3 class="sidebar-title">训练设置</h3> |
| 36 | + |
| 37 | + <div class="range-setting-container"> |
| 38 | + <div |
| 39 | + v-for="(config, key) in rangeConfigs" |
| 40 | + :key="key" |
| 41 | + class="range-item" |
| 42 | + > |
| 43 | + <div class="range-header"> |
| 44 | + <span class="setting-name">{{ config.name }}</span> |
| 45 | + <span class="setting-value" |
| 46 | + >{{ settings[key] }}{{ config.unit }}</span |
| 47 | + > |
| 48 | + </div> |
| 49 | + <input |
| 50 | + type="range" |
| 51 | + class="custom-slider" |
| 52 | + :min="config.min" |
| 53 | + :max="config.max" |
| 54 | + v-model.number="settings[key]" |
| 55 | + /> |
| 56 | + </div> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + </aside> |
| 60 | +</template> |
| 61 | + |
| 62 | +<style lang="less" scoped> |
| 63 | +@import "../styles/color.less"; |
| 64 | +@import "../styles/animation.less"; |
| 65 | +
|
| 66 | +.sidebar:not(.is-open) { |
| 67 | + .toggle-btn { |
| 68 | + opacity: 0.8; |
| 69 | + &:hover { |
| 70 | + opacity: 1; |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | +
|
| 75 | +.sidebar { |
| 76 | + position: absolute; |
| 77 | + right: 0; |
| 78 | + top: 50%; |
| 79 | + transform: translate(100%, -50%); |
| 80 | + width: 280px; |
| 81 | + background: var(--white, #fff); |
| 82 | + box-shadow: -8px 0 32px rgba(0, 0, 0, 0.05); |
| 83 | + border-radius: 20px 0 0 20px; |
| 84 | + transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1); |
| 85 | + z-index: 1000; |
| 86 | + padding: 32px 24px; |
| 87 | + border: 1px solid rgba(0, 0, 0, 0.05); |
| 88 | +
|
| 89 | + &.is-open { |
| 90 | + transform: translate(0, -50%); |
| 91 | + } |
| 92 | +
|
| 93 | + .toggle-btn { |
| 94 | + position: absolute; |
| 95 | + left: -36px; |
| 96 | + top: 50%; |
| 97 | + transform: translateY(-50%); |
| 98 | + width: 36px; |
| 99 | + height: 80px; |
| 100 | +
|
| 101 | + background: rgba(255, 255, 255, 0.9); |
| 102 | + backdrop-filter: blur(12px); |
| 103 | +
|
| 104 | + border: 1px solid rgba(0, 0, 0, 0.08); |
| 105 | + border-right: none; |
| 106 | + border-radius: 18px 0 0 18px; |
| 107 | +
|
| 108 | + cursor: pointer; |
| 109 | + display: flex; |
| 110 | + align-items: center; |
| 111 | + justify-content: center; |
| 112 | + transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); |
| 113 | + box-shadow: -6px 0 15px rgba(0, 0, 0, 0.05); |
| 114 | +
|
| 115 | + &:hover { |
| 116 | + background: #fff; |
| 117 | + left: -40px; |
| 118 | + width: 40px; |
| 119 | + box-shadow: -8px 0 20px rgba(0, 0, 0, 0.08); |
| 120 | +
|
| 121 | + .arrow-icon { |
| 122 | + border-color: @primary-color; |
| 123 | + transform: translateX(0px) rotate(-45deg) scale(1.1); |
| 124 | + } |
| 125 | + } |
| 126 | +
|
| 127 | + .arrow-icon { |
| 128 | + width: 9px; |
| 129 | + height: 9px; |
| 130 | + border-top: 2.5px solid rgba(0, 0, 0, 0.4); |
| 131 | + border-left: 2.5px solid rgba(0, 0, 0, 0.4); |
| 132 | + transform: translateX(3px) rotate(-45deg); |
| 133 | + transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); |
| 134 | +
|
| 135 | + &.is-active { |
| 136 | + transform: translateX(-1px) rotate(135deg); |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | +
|
| 141 | + .sidebar-inner { |
| 142 | + display: flex; |
| 143 | + flex-direction: column; |
| 144 | + gap: 28px; |
| 145 | + } |
| 146 | +
|
| 147 | + .sidebar-title { |
| 148 | + margin: 0; |
| 149 | + font-size: 1.1rem; |
| 150 | + font-weight: bold; |
| 151 | + color: var(--black); |
| 152 | + opacity: 0.9; |
| 153 | + border-left: 4px solid @primary-color; |
| 154 | + padding-left: 12px; |
| 155 | + } |
| 156 | +
|
| 157 | + .range-setting-container { |
| 158 | + display: flex; |
| 159 | + flex-direction: column; |
| 160 | + gap: 24px; |
| 161 | + } |
| 162 | +
|
| 163 | + .range-item { |
| 164 | + display: flex; |
| 165 | + flex-direction: column; |
| 166 | +
|
| 167 | + .range-header { |
| 168 | + display: flex; |
| 169 | + justify-content: space-between; |
| 170 | + margin-bottom: 10px; |
| 171 | + font-weight: bold; |
| 172 | + font-size: 0.9rem; |
| 173 | +
|
| 174 | + .setting-name { |
| 175 | + color: @primary-color; |
| 176 | + } |
| 177 | + .setting-value { |
| 178 | + color: var(--black); |
| 179 | + opacity: 0.7; |
| 180 | + } |
| 181 | + } |
| 182 | + } |
| 183 | +
|
| 184 | + .custom-slider { |
| 185 | + appearance: none; |
| 186 | + -webkit-appearance: none; |
| 187 | + width: 100%; |
| 188 | + height: 4px; |
| 189 | + background: rgba(0, 0, 0, 0.06); |
| 190 | + border-radius: 2px; |
| 191 | + outline: none; |
| 192 | +
|
| 193 | + &::-webkit-slider-thumb { |
| 194 | + appearance: none; |
| 195 | + -webkit-appearance: none; |
| 196 | + width: 16px; |
| 197 | + height: 16px; |
| 198 | + background: @primary-color; |
| 199 | + border-radius: 50%; |
| 200 | + cursor: pointer; |
| 201 | + border: 2px solid #fff; |
| 202 | + box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15); |
| 203 | + transition: transform 0.2s; |
| 204 | +
|
| 205 | + &:hover { |
| 206 | + transform: scale(1.1); |
| 207 | + } |
| 208 | + } |
| 209 | + } |
| 210 | +} |
| 211 | +</style> |
0 commit comments