diff --git a/.gitignore b/.gitignore index 1e2d60c..c077a8d 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ dist-ssr *.sw? .cursor +/package-lock.json \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index 4432291..0ac184d 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -5,42 +5,66 @@ const routes = [ { path: '/', name: 'Home', - component: Home + component: Home, + meta: { + title: 'RC707的工具箱' + } }, { path: '/json-formatter', name: 'JsonFormatter', - component: () => import('../views/JsonFormatter.vue') + component: () => import('../views/JsonFormatter.vue'), + meta: { + title: 'RC707的工具箱-JSON' + } }, { path: '/comparator', name: 'Comparator', - component: () => import('../views/Comparator.vue') + component: () => import('../views/Comparator.vue'), + meta: { + title: 'RC707的工具箱-对比' + } }, { path: '/encoder-decoder', name: 'EncoderDecoder', - component: () => import('../views/EncoderDecoder.vue') + component: () => import('../views/EncoderDecoder.vue'), + meta: { + title: 'RC707的工具箱-编解码' + } }, { path: '/variable-name', name: 'VariableNameConverter', - component: () => import('../views/VariableNameConverter.vue') + component: () => import('../views/VariableNameConverter.vue'), + meta: { + title: 'RC707的工具箱-变量名' + } }, { path: '/qr-code', name: 'QRCodeGenerator', - component: () => import('../views/QRCodeGenerator.vue') + component: () => import('../views/QRCodeGenerator.vue'), + meta: { + title: 'RC707的工具箱-二维码' + } }, { path: '/timestamp-converter', name: 'TimestampConverter', - component: () => import('../views/TimestampConverter.vue') + component: () => import('../views/TimestampConverter.vue'), + meta: { + title: 'RC707的工具箱-时间戳' + } }, { path: '/color-converter', name: 'ColorConverter', - component: () => import('../views/ColorConverter.vue') + component: () => import('../views/ColorConverter.vue'), + meta: { + title: 'RC707的工具箱-颜色' + } } ] @@ -49,5 +73,13 @@ const router = createRouter({ routes }) +// 路由守卫:设置页面标题 +router.beforeEach((to, from, next) => { + if (to.meta.title) { + document.title = to.meta.title + } + next() +}) + export default router diff --git a/src/views/ColorConverter.vue b/src/views/ColorConverter.vue index 999037c..97ed1b5 100644 --- a/src/views/ColorConverter.vue +++ b/src/views/ColorConverter.vue @@ -66,6 +66,7 @@ = 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255) { + updating.value = true + rgb.value = { r, g, b } + + // 更新十六进制 + hex.value = rgbToHex(r, g, b) + + // 更新HSL + const hslValue = rgbToHsl(r, g, b) + hsl.value = hslValue + + updating.value = false + + // 保存到历史记录 + saveToHistory() + + showToast('RGB已粘贴并解析', 'info', 2000) + } else { + showToast('RGB值超出范围(0-255)', 'error') + } + } + // 如果不是RGB格式,允许默认粘贴行为(粘贴单个数字) +} + // 处理RGB输入 function handleRgbInput() { if (updating.value) return @@ -404,6 +454,65 @@ function handleHexInput() { } } +// 处理HSL粘贴事件 +function handleHslPaste(event) { + const pastedText = event.clipboardData?.getData('text') || '' + if (!pastedText || !pastedText.trim()) { + return // 如果没有粘贴内容,允许默认行为 + } + + const text = pastedText.trim() + + // 支持格式:hsl(0, 0%, 100%) 或 0, 0%, 100% 或 0, 0, 100(不带%) + const hslMatchWithPercent = text.match(/hsl\s*\(\s*(\d+)\s*,\s*(\d+)\s*%\s*,\s*(\d+)\s*%\s*\)/i) || + text.match(/(\d+)\s*,\s*(\d+)\s*%\s*,\s*(\d+)\s*%/) + const hslMatchWithoutPercent = text.match(/hsl\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i) || + text.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/) + + let hslMatch = hslMatchWithPercent || hslMatchWithoutPercent + const hasPercent = !!hslMatchWithPercent + + if (hslMatch) { + event.preventDefault() // 阻止默认粘贴行为 + + let h = parseInt(hslMatch[1]) + let s = parseInt(hslMatch[2]) + let l = parseInt(hslMatch[3]) + + // 如果匹配的是不带%的格式,假设值是百分比(0-100) + // 如果值在合理范围内(0-100),直接使用;否则可能是小数格式(0-1),需要转换 + if (!hasPercent) { + // 不带%的格式,如果值大于1,认为是百分比;否则认为是小数 + if (s <= 1 && l <= 1) { + s = Math.round(s * 100) + l = Math.round(l * 100) + } + } + + if (h >= 0 && h <= 360 && s >= 0 && s <= 100 && l >= 0 && l <= 100) { + updating.value = true + hsl.value = { h, s, l } + + // 更新RGB + const rgbValue = hslToRgb(h, s, l) + rgb.value = rgbValue + + // 更新十六进制 + hex.value = rgbToHex(rgb.value.r, rgb.value.g, rgb.value.b) + + updating.value = false + + // 保存到历史记录 + saveToHistory() + + showToast('HSL已粘贴并解析', 'info', 2000) + } else { + showToast('HSL值超出范围(H: 0-360, S/L: 0-100)', 'error') + } + } + // 如果不是HSL格式,允许默认粘贴行为(粘贴单个数字) +} + // 处理HSL输入 function handleHslInput() { if (updating.value) return diff --git a/src/views/Comparator.vue b/src/views/Comparator.vue index da6993e..2b1ffd7 100644 --- a/src/views/Comparator.vue +++ b/src/views/Comparator.vue @@ -15,8 +15,33 @@