This commit is contained in:
renjue
2026-01-30 19:31:25 +08:00
parent 06020aa084
commit 788f79dd76
10 changed files with 4029 additions and 2 deletions

View File

@@ -4,6 +4,15 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RC707的工具箱</title>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-C2H4BGZJBD"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-C2H4BGZJBD');
</script>
</head>
<body>
<div id="app"></div>

279
package-lock.json generated
View File

@@ -9,6 +9,7 @@
"version": "1.0.0",
"dependencies": {
"@fortawesome/fontawesome-free": "^7.1.0",
"qrcode": "^1.5.4",
"vue": "^3.4.0",
"vue-router": "^4.2.5"
},
@@ -946,12 +947,86 @@
"integrity": "sha512-7Z6/y3uFI5PRoKeorTOSXKcDj0MSasfNNltcslbFrPpcw6aXRUALq4IfJlaTRspiWIUOEZbrpM+iQGmCOiWe4A==",
"license": "MIT"
},
"node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/ansi-regex/download/ansi-regex-5.0.1.tgz",
"integrity": "sha1-CCyyyJyf6GWaMRpTvWpNxTAdswQ=",
"engines": {
"node": ">=8"
}
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/ansi-styles/download/ansi-styles-4.3.0.tgz",
"integrity": "sha1-7dgDYornHATIWuegkG7a00tkiTc=",
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/camelcase": {
"version": "5.3.1",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/camelcase/download/camelcase-5.3.1.tgz",
"integrity": "sha1-48mzFWnhBoEd8kL3FXJaH0xJQyA=",
"engines": {
"node": ">=6"
}
},
"node_modules/cliui": {
"version": "6.0.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/cliui/download/cliui-6.0.0.tgz",
"integrity": "sha1-UR1wLAxOQcoVbX0OlgIfI+EyJbE=",
"dependencies": {
"string-width": "^4.2.0",
"strip-ansi": "^6.0.0",
"wrap-ansi": "^6.2.0"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/color-convert/download/color-convert-2.0.1.tgz",
"integrity": "sha1-ctOmjVmMm9s68q0ehPIdiWq9TeM=",
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/color-name/download/color-name-1.1.4.tgz",
"integrity": "sha1-wqCah6y95pVD3m9j+jmVyCbFNqI="
},
"node_modules/csstype": {
"version": "3.2.3",
"resolved": "https://registry.npmmirror.com/csstype/-/csstype-3.2.3.tgz",
"integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==",
"license": "MIT"
},
"node_modules/decamelize": {
"version": "1.2.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/decamelize/download/decamelize-1.2.0.tgz",
"integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/dijkstrajs": {
"version": "1.0.3",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/dijkstrajs/download/dijkstrajs-1.0.3.tgz",
"integrity": "sha1-TI296h8PZHi/+U2cSceE1iPk/CM="
},
"node_modules/emoji-regex": {
"version": "8.0.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/emoji-regex/download/emoji-regex-8.0.0.tgz",
"integrity": "sha1-6Bj9ac5cz8tARZT4QpY79TFkzDc="
},
"node_modules/entities": {
"version": "7.0.0",
"resolved": "https://registry.npmmirror.com/entities/-/entities-7.0.0.tgz",
@@ -1009,6 +1084,18 @@
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
"license": "MIT"
},
"node_modules/find-up": {
"version": "4.1.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/find-up/download/find-up-4.1.0.tgz",
"integrity": "sha1-l6/n1s3AvFkoWEt8jXsW6KmqXRk=",
"dependencies": {
"locate-path": "^5.0.0",
"path-exists": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz",
@@ -1024,6 +1111,33 @@
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/get-caller-file": {
"version": "2.0.5",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/get-caller-file/download/get-caller-file-2.0.5.tgz",
"integrity": "sha1-T5RBKoLbMvNuOwuXQfipf+sDH34=",
"engines": {
"node": "6.* || 8.* || >= 10.*"
}
},
"node_modules/is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/is-fullwidth-code-point/download/is-fullwidth-code-point-3.0.0.tgz",
"integrity": "sha1-8Rb4Bk/pCz94RKOJl8C3UFEmnx0=",
"engines": {
"node": ">=8"
}
},
"node_modules/locate-path": {
"version": "5.0.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/locate-path/download/locate-path-5.0.0.tgz",
"integrity": "sha1-Gvujlq/WdqbUJQTQpno6frn2KqA=",
"dependencies": {
"p-locate": "^4.1.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/magic-string": {
"version": "0.30.21",
"resolved": "https://registry.npmmirror.com/magic-string/-/magic-string-0.30.21.tgz",
@@ -1051,12 +1165,61 @@
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
}
},
"node_modules/p-limit": {
"version": "2.3.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/p-limit/download/p-limit-2.3.0.tgz",
"integrity": "sha1-PdM8ZHohT9//2DWTPrCG2g3CHbE=",
"dependencies": {
"p-try": "^2.0.0"
},
"engines": {
"node": ">=6"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/p-locate": {
"version": "4.1.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/p-locate/download/p-locate-4.1.0.tgz",
"integrity": "sha1-o0KLtwiLOmApL2aRkni3wpetTwc=",
"dependencies": {
"p-limit": "^2.2.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/p-try": {
"version": "2.2.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/p-try/download/p-try-2.2.0.tgz",
"integrity": "sha1-yyhoVA4xPWHeWPr741zpAE1VQOY=",
"engines": {
"node": ">=6"
}
},
"node_modules/path-exists": {
"version": "4.0.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/path-exists/download/path-exists-4.0.0.tgz",
"integrity": "sha1-UTvb4tO5XXdi6METfvoZXGxhtbM=",
"engines": {
"node": ">=8"
}
},
"node_modules/picocolors": {
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/picocolors/-/picocolors-1.1.1.tgz",
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
"license": "ISC"
},
"node_modules/pngjs": {
"version": "5.0.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/pngjs/download/pngjs-5.0.0.tgz",
"integrity": "sha1-553SshV2f9nARWHAEjbflgvOf7s=",
"engines": {
"node": ">=10.13.0"
}
},
"node_modules/postcss": {
"version": "8.5.6",
"resolved": "https://registry.npmmirror.com/postcss/-/postcss-8.5.6.tgz",
@@ -1085,6 +1248,35 @@
"node": "^10 || ^12 || >=14"
}
},
"node_modules/qrcode": {
"version": "1.5.4",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/qrcode/-/qrcode-1.5.4.tgz",
"integrity": "sha512-1ca71Zgiu6ORjHqFBDpnSMTR2ReToX4l1Au1VFLyVeBTFavzQnv5JxMFr3ukHVKpSrSA2MCk0lNJSykjUfz7Zg==",
"dependencies": {
"dijkstrajs": "^1.0.1",
"pngjs": "^5.0.0",
"yargs": "^15.3.1"
},
"bin": {
"qrcode": "bin/qrcode"
},
"engines": {
"node": ">=10.13.0"
}
},
"node_modules/require-directory": {
"version": "2.1.1",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/require-directory/download/require-directory-2.1.1.tgz",
"integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/require-main-filename": {
"version": "2.0.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/require-main-filename/download/require-main-filename-2.0.0.tgz",
"integrity": "sha1-0LMp7MfMD2Fkn2IhW+aa9UqomJs="
},
"node_modules/rollup": {
"version": "4.55.1",
"resolved": "https://registry.npmmirror.com/rollup/-/rollup-4.55.1.tgz",
@@ -1130,6 +1322,11 @@
"fsevents": "~2.3.2"
}
},
"node_modules/set-blocking": {
"version": "2.0.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/set-blocking/download/set-blocking-2.0.0.tgz",
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc="
},
"node_modules/source-map-js": {
"version": "1.2.1",
"resolved": "https://registry.npmmirror.com/source-map-js/-/source-map-js-1.2.1.tgz",
@@ -1139,13 +1336,36 @@
"node": ">=0.10.0"
}
},
"node_modules/string-width": {
"version": "4.2.3",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/string-width/download/string-width-4.2.3.tgz",
"integrity": "sha1-JpxxF9J7Ba0uU2gwqOyJXvnG0BA=",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/strip-ansi": {
"version": "6.0.1",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/strip-ansi/download/strip-ansi-6.0.1.tgz",
"integrity": "sha1-nibGPTD1NEPpSJSVshBdN7Z6hdk=",
"dependencies": {
"ansi-regex": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/vite": {
"version": "5.4.21",
"resolved": "https://registry.npmmirror.com/vite/-/vite-5.4.21.tgz",
"integrity": "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"esbuild": "^0.21.3",
"postcss": "^8.4.43",
@@ -1205,7 +1425,6 @@
"resolved": "https://registry.npmmirror.com/vue/-/vue-3.5.26.tgz",
"integrity": "sha512-SJ/NTccVyAoNUJmkM9KUqPcYlY+u8OVL1X5EW9RIs3ch5H2uERxyyIUI4MRxVCSOiEcupX9xNGde1tL9ZKpimA==",
"license": "MIT",
"peer": true,
"dependencies": {
"@vue/compiler-dom": "3.5.26",
"@vue/compiler-sfc": "3.5.26",
@@ -1236,6 +1455,62 @@
"peerDependencies": {
"vue": "^3.5.0"
}
},
"node_modules/which-module": {
"version": "2.0.1",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/which-module/-/which-module-2.0.1.tgz",
"integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ=="
},
"node_modules/wrap-ansi": {
"version": "6.2.0",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/wrap-ansi/download/wrap-ansi-6.2.0.tgz",
"integrity": "sha1-6Tk7oHEC5skaOyIUePAlfNKFblM=",
"dependencies": {
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/y18n": {
"version": "4.0.3",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/y18n/download/y18n-4.0.3.tgz",
"integrity": "sha1-tfJZyCzW4zaSHv17/Yv1YN6e7t8="
},
"node_modules/yargs": {
"version": "15.4.1",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/yargs/download/yargs-15.4.1.tgz",
"integrity": "sha1-DYehbeAa7p2L7Cv7909nhRcw9Pg=",
"dependencies": {
"cliui": "^6.0.0",
"decamelize": "^1.2.0",
"find-up": "^4.1.0",
"get-caller-file": "^2.0.1",
"require-directory": "^2.1.1",
"require-main-filename": "^2.0.0",
"set-blocking": "^2.0.0",
"string-width": "^4.2.0",
"which-module": "^2.0.0",
"y18n": "^4.0.0",
"yargs-parser": "^18.1.2"
},
"engines": {
"node": ">=8"
}
},
"node_modules/yargs-parser": {
"version": "18.1.3",
"resolved": "https://artifactory.devops.xiaohongshu.com/artifactory/api/npm/npm-public/yargs-parser/download/yargs-parser-18.1.3.tgz",
"integrity": "sha1-vmjEl1xrKr9GkjawyHA2L6sJp7A=",
"dependencies": {
"camelcase": "^5.0.0",
"decamelize": "^1.2.0"
},
"engines": {
"node": ">=6"
}
}
}
}

View File

@@ -10,6 +10,7 @@
},
"dependencies": {
"@fortawesome/fontawesome-free": "^7.1.0",
"qrcode": "^1.5.4",
"vue": "^3.4.0",
"vue-router": "^4.2.5"
},

View File

@@ -8,7 +8,10 @@
<div class="nav-links">
<router-link to="/" class="nav-link">首页</router-link>
<router-link to="/json-formatter" class="nav-link">JSON</router-link>
<router-link to="/comparator" class="nav-link">对比</router-link>
<router-link to="/encoder-decoder" class="nav-link">编解码</router-link>
<router-link to="/variable-name" class="nav-link">变量名</router-link>
<router-link to="/qr-code" class="nav-link">二维码</router-link>
<router-link to="/timestamp-converter" class="nav-link">时间戳</router-link>
<router-link to="/color-converter" class="nav-link">颜色</router-link>
</div>
@@ -68,6 +71,7 @@
.nav-links {
display: flex;
gap: 0;
align-items: center;
}
.nav-link {
@@ -82,6 +86,10 @@
margin-bottom: -1px;
transition: all 0.2s;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
line-height: 1.5;
}
.nav-link:hover {

View File

@@ -12,11 +12,26 @@ const routes = [
name: 'JsonFormatter',
component: () => import('../views/JsonFormatter.vue')
},
{
path: '/comparator',
name: 'Comparator',
component: () => import('../views/Comparator.vue')
},
{
path: '/encoder-decoder',
name: 'EncoderDecoder',
component: () => import('../views/EncoderDecoder.vue')
},
{
path: '/variable-name',
name: 'VariableNameConverter',
component: () => import('../views/VariableNameConverter.vue')
},
{
path: '/qr-code',
name: 'QRCodeGenerator',
component: () => import('../views/QRCodeGenerator.vue')
},
{
path: '/timestamp-converter',
name: 'TimestampConverter',

2457
src/views/Comparator.vue Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -30,11 +30,26 @@ const tools = ref([
title: 'JSON',
description: '格式化、验证和美化JSON数据'
},
{
path: '/comparator',
title: '对比',
description: '文本和JSON对比工具'
},
{
path: '/encoder-decoder',
title: '编解码',
description: '编码/解码工具'
},
{
path: '/variable-name',
title: '变量名',
description: '变量名格式转换'
},
{
path: '/qr-code',
title: '二维码',
description: '生成二维码'
},
{
path: '/timestamp-converter',
title: '时间戳',

View File

@@ -0,0 +1,700 @@
<template>
<div class="tool-page">
<!-- 浮层提示 -->
<Transition name="toast">
<div v-if="toastMessage" class="toast-notification" :class="toastType">
<div class="toast-content">
<i v-if="toastType === 'error'" class="fas fa-circle-exclamation"></i>
<i v-else class="fas fa-circle-check"></i>
<span>{{ toastMessage }}</span>
</div>
<button @click="closeToast" class="toast-close-btn" title="关闭">
<i class="fas fa-xmark"></i>
</button>
</div>
</Transition>
<div class="main-container">
<!-- 左侧侧栏历史记录 -->
<div class="sidebar" :class="{ 'sidebar-open': sidebarOpen }">
<div class="sidebar-header">
<h3>历史记录</h3>
<button @click="toggleSidebar" class="close-btn">×</button>
</div>
<div class="sidebar-content">
<div v-if="historyList.length === 0" class="empty-history">
暂无历史记录
</div>
<div
v-for="(item, index) in historyList"
:key="index"
class="history-item"
@click="loadHistory(item.text)"
>
<div class="history-time">{{ formatTime(item.time) }}</div>
<div class="history-preview">{{ truncateText(item.text, 50) }}</div>
</div>
</div>
</div>
<!-- 主内容区域 -->
<div class="content-wrapper" :class="{ 'sidebar-pushed': sidebarOpen }">
<div class="container">
<div class="qr-card">
<!-- 输入区域 -->
<div class="input-section">
<div class="input-wrapper">
<textarea
v-model="inputText"
@keydown.enter.prevent="generateQRCode"
placeholder="请输入要生成二维码的内容"
class="input-textarea"
rows="4"
></textarea>
</div>
<button @click="generateQRCode" class="generate-btn">
<i class="fas fa-qrcode"></i>
生成二维码
</button>
</div>
<!-- 二维码显示区域 -->
<div v-if="qrCodeDataUrl" class="qr-display-section">
<div class="qr-code-wrapper">
<img :src="qrCodeDataUrl" alt="二维码" class="qr-code-image" />
</div>
<div class="qr-actions">
<button @click="downloadQRCode" class="action-btn">
<i class="fas fa-download"></i>
下载
</button>
<button @click="copyQRCodeImage" class="action-btn">
<i class="far fa-copy"></i>
复制图片
</button>
</div>
</div>
</div>
</div>
<!-- 侧栏切换按钮 -->
<div class="sidebar-toggle">
<button @click="toggleSidebar" class="toggle-btn">
{{ sidebarOpen ? '◀' : '▶' }}
</button>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import QRCode from 'qrcode'
// 输入文本
const inputText = ref('')
// 二维码数据URL
const qrCodeDataUrl = ref('')
// 侧栏状态
const sidebarOpen = ref(false)
// 历史记录
const historyList = ref([])
const STORAGE_KEY = 'qr-code-history'
const MAX_HISTORY = 20
// 提示消息
const toastMessage = ref('')
const toastType = ref('success')
let toastTimer = null
// 显示提示
const showToast = (message, type = 'success', duration = 3000) => {
toastMessage.value = message
toastType.value = type
if (toastTimer) {
clearTimeout(toastTimer)
}
toastTimer = setTimeout(() => {
toastMessage.value = ''
}, duration)
}
// 关闭提示
const closeToast = () => {
if (toastTimer) {
clearTimeout(toastTimer)
toastTimer = null
}
toastMessage.value = ''
}
// 生成二维码
const generateQRCode = async () => {
if (!inputText.value.trim()) {
showToast('请输入要生成二维码的内容', 'error')
return
}
try {
// 生成二维码
const dataUrl = await QRCode.toDataURL(inputText.value.trim(), {
width: 300,
margin: 2,
color: {
dark: '#000000',
light: '#FFFFFF'
}
})
qrCodeDataUrl.value = dataUrl
// 保存到历史记录
saveToHistory(inputText.value.trim())
showToast('二维码生成成功', 'success', 2000)
} catch (error) {
showToast('生成二维码失败:' + error.message, 'error')
qrCodeDataUrl.value = ''
}
}
// 下载二维码
const downloadQRCode = () => {
if (!qrCodeDataUrl.value) {
showToast('没有可下载的二维码', 'error')
return
}
try {
const link = document.createElement('a')
link.download = `qrcode-${Date.now()}.png`
link.href = qrCodeDataUrl.value
link.click()
showToast('下载成功', 'success', 2000)
} catch (error) {
showToast('下载失败:' + error.message, 'error')
}
}
// 复制二维码图片
const copyQRCodeImage = async () => {
if (!qrCodeDataUrl.value) {
showToast('没有可复制的二维码', 'error')
return
}
try {
// 将 data URL 转换为 blob
const response = await fetch(qrCodeDataUrl.value)
const blob = await response.blob()
// 复制到剪贴板
await navigator.clipboard.write([
new ClipboardItem({
'image/png': blob
})
])
showToast('已复制到剪贴板', 'success', 2000)
} catch (error) {
// 降级方案:提示用户手动保存
showToast('复制失败,请使用下载功能', 'error')
}
}
// 保存到历史记录
const saveToHistory = (text) => {
const historyItem = {
text: text,
time: Date.now()
}
// 从localStorage读取现有历史
let history = []
try {
const stored = localStorage.getItem(STORAGE_KEY)
if (stored) {
history = JSON.parse(stored)
}
} catch (e) {
console.error('读取历史记录失败', e)
}
// 避免重复保存相同的记录
const lastHistory = history[0]
if (lastHistory && lastHistory.text === historyItem.text) {
return
}
// 添加到开头
history.unshift(historyItem)
// 限制最多20条
if (history.length > MAX_HISTORY) {
history = history.slice(0, MAX_HISTORY)
}
// 保存到localStorage
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(history))
loadHistoryList()
} catch (e) {
console.error('保存历史记录失败', e)
}
}
// 加载历史记录列表
const loadHistoryList = () => {
try {
const stored = localStorage.getItem(STORAGE_KEY)
if (stored) {
historyList.value = JSON.parse(stored)
}
} catch (e) {
console.error('加载历史记录失败', e)
historyList.value = []
}
}
// 加载历史记录
const loadHistory = (text) => {
inputText.value = text
generateQRCode()
}
// 切换侧栏
const toggleSidebar = () => {
sidebarOpen.value = !sidebarOpen.value
}
// 格式化时间
const formatTime = (timestamp) => {
const date = new Date(timestamp)
const now = new Date()
const diff = now - date
if (diff < 60000) return '刚刚'
if (diff < 3600000) return Math.floor(diff / 60000) + '分钟前'
if (diff < 86400000) return Math.floor(diff / 3600000) + '小时前'
return date.toLocaleString('zh-CN', {
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
})
}
// 截断文本
const truncateText = (text, maxLength) => {
if (text.length <= maxLength) return text
return text.substring(0, maxLength) + '...'
}
onMounted(() => {
loadHistoryList()
})
</script>
<style scoped>
.tool-page {
height: calc(100vh - 64px);
display: flex;
flex-direction: column;
margin: -1rem;
padding: 0;
background: #ffffff;
}
.main-container {
flex: 1;
display: flex;
flex-direction: column;
position: relative;
overflow: hidden;
background: #ffffff;
}
/* 侧栏样式 */
.sidebar {
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 300px;
background: #ffffff;
border-right: 1px solid #e5e5e5;
transform: translateX(-100%);
transition: transform 0.3s ease;
z-index: 10;
display: flex;
flex-direction: column;
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
}
.sidebar-open {
transform: translateX(0);
}
.content-wrapper.sidebar-pushed {
margin-left: 300px;
}
.sidebar-header {
padding: 1rem;
border-bottom: 1px solid #e5e5e5;
display: flex;
justify-content: space-between;
align-items: center;
background: #ffffff;
}
.sidebar-header h3 {
margin: 0;
font-size: 1rem;
color: #1a1a1a;
font-weight: 500;
}
.close-btn {
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
color: #666666;
padding: 0;
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
transition: color 0.2s;
}
.close-btn:hover {
color: #1a1a1a;
}
.sidebar-content {
flex: 1;
overflow-y: auto;
padding: 0.5rem;
background: #ffffff;
}
.empty-history {
padding: 2rem;
text-align: center;
color: #999999;
font-size: 0.875rem;
}
.history-item {
padding: 0.75rem;
margin-bottom: 0.5rem;
background: #ffffff;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s;
border: 1px solid #e5e5e5;
}
.history-item:hover {
background: #f5f5f5;
border-color: #d0d0d0;
}
.history-time {
font-size: 0.75rem;
color: #999999;
margin-bottom: 0.25rem;
}
.history-preview {
font-size: 0.875rem;
color: #1a1a1a;
word-break: break-all;
}
.content-wrapper {
flex: 1;
display: flex;
flex-direction: column;
transition: margin-left 0.3s ease;
overflow-y: auto;
padding: 1rem;
}
.container {
max-width: 600px;
margin: 0 auto;
width: 100%;
}
.qr-card {
background: #ffffff;
border-radius: 8px;
padding: 2rem;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
border: 1px solid #e5e5e5;
}
.input-section {
margin-bottom: 2rem;
}
.input-label {
display: block;
font-size: 0.875rem;
font-weight: 500;
color: #333333;
margin-bottom: 0.5rem;
}
.input-wrapper {
margin-bottom: 1rem;
}
.input-textarea {
width: 100%;
padding: 0.75rem;
border: 1px solid #d0d0d0;
border-radius: 6px;
font-size: 0.9375rem;
font-family: inherit;
resize: vertical;
transition: all 0.2s;
box-sizing: border-box;
}
.input-textarea:focus {
outline: none;
border-color: #1a1a1a;
box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
}
.generate-btn {
width: 100%;
padding: 0.75rem 1.5rem;
background: #1a1a1a;
color: #ffffff;
border: none;
border-radius: 6px;
font-size: 0.9375rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
}
.generate-btn:hover {
background: #333333;
}
.generate-btn:active {
transform: scale(0.98);
}
.qr-display-section {
margin-top: 2rem;
padding-top: 2rem;
border-top: 1px solid #e5e5e5;
}
.qr-code-wrapper {
display: flex;
justify-content: center;
align-items: center;
padding: 1.5rem;
background: #fafafa;
border-radius: 8px;
margin-bottom: 1.5rem;
}
.qr-code-image {
max-width: 100%;
height: auto;
display: block;
}
.qr-actions {
display: flex;
gap: 0.75rem;
justify-content: center;
}
.action-btn {
padding: 0.75rem 1.5rem;
background: #f5f5f5;
color: #333333;
border: 1px solid #d0d0d0;
border-radius: 6px;
font-size: 0.875rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
gap: 0.5rem;
}
.action-btn:hover {
background: #e5e5e5;
border-color: #1a1a1a;
color: #1a1a1a;
}
.action-btn:active {
transform: scale(0.98);
}
/* 侧栏切换按钮 */
.sidebar-toggle {
position: fixed;
left: 0;
bottom: 1rem;
z-index: 11;
}
.content-wrapper.sidebar-pushed .sidebar-toggle {
left: 300px;
}
.toggle-btn {
width: 32px;
height: 48px;
background: #1a1a1a;
color: #ffffff;
border: none;
border-radius: 0 4px 4px 0;
cursor: pointer;
font-size: 0.875rem;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1);
}
.toggle-btn:hover {
background: #333333;
}
/* 提示消息样式 */
.toast-notification {
position: fixed;
top: 80px;
right: 20px;
background: #ffffff;
border: 1px solid #e5e5e5;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
padding: 1rem 1.25rem;
display: flex;
align-items: center;
gap: 0.75rem;
z-index: 1000;
min-width: 280px;
max-width: 400px;
}
.toast-notification.success {
border-left: 4px solid #10b981;
}
.toast-notification.error {
border-left: 4px solid #ef4444;
}
.toast-content {
display: flex;
align-items: center;
gap: 0.5rem;
flex: 1;
font-size: 0.875rem;
color: #333333;
}
.toast-content svg,
.toast-content i {
flex-shrink: 0;
}
.toast-notification.success .toast-content i {
color: #10b981;
}
.toast-notification.error .toast-content i {
color: #ef4444;
}
.toast-close-btn {
background: transparent;
border: none;
color: #666666;
cursor: pointer;
padding: 0.25rem;
display: flex;
align-items: center;
justify-content: center;
transition: color 0.2s;
flex-shrink: 0;
}
.toast-close-btn:hover {
color: #1a1a1a;
}
.toast-enter-active,
.toast-leave-active {
transition: all 0.3s ease;
}
.toast-enter-from {
opacity: 0;
transform: translateX(100%);
}
.toast-leave-to {
opacity: 0;
transform: translateX(100%);
}
@media (max-width: 768px) {
.qr-card {
padding: 1.5rem;
}
.sidebar {
width: 280px;
}
.content-wrapper.sidebar-pushed {
margin-left: 0;
}
.sidebar-toggle {
bottom: 0.5rem;
}
.toggle-btn {
width: 28px;
height: 40px;
font-size: 0.75rem;
}
.toast-notification {
right: 10px;
left: 10px;
max-width: none;
top: 60px;
}
}
</style>

View File

@@ -0,0 +1,526 @@
<template>
<div class="variable-name-converter">
<!-- 浮层提示 -->
<Transition name="toast">
<div v-if="toastMessage" class="toast-notification" :class="toastType">
<div class="toast-content">
<i v-if="toastType === 'error'" class="fas fa-circle-exclamation"></i>
<i v-else class="fas fa-circle-check"></i>
<span>{{ toastMessage }}</span>
</div>
<button @click="closeToast" class="toast-close-btn" title="关闭">
<i class="fas fa-xmark"></i>
</button>
</div>
</Transition>
<div class="container">
<div class="conversion-card">
<!-- 输入区域 -->
<div class="input-section">
<div class="input-wrapper">
<input
v-model="inputText"
@input="convertVariableName"
type="text"
placeholder="请输入变量名(支持任意格式)"
class="input-field"
/>
<button @click="clearInput" class="clear-btn" title="清空">
<i class="fas fa-xmark"></i>
</button>
</div>
</div>
<!-- 输出区域 -->
<div class="output-section">
<div class="output-row">
<div
v-for="format in formats.slice(0, 3)"
:key="format.key"
class="output-item"
>
<div class="output-header">
<span class="output-label">{{ format.label }}</span>
<button
@click="copyToClipboard(format.value, format.label)"
class="copy-btn"
:title="`复制${format.label}`"
>
<i class="far fa-copy"></i>
</button>
</div>
<div class="output-value" :class="{ empty: !format.value }">
{{ format.value || '—' }}
</div>
</div>
</div>
<div class="output-row">
<div
v-for="format in formats.slice(3)"
:key="format.key"
class="output-item"
>
<div class="output-header">
<span class="output-label">{{ format.label }}</span>
<button
@click="copyToClipboard(format.value, format.label)"
class="copy-btn"
:title="`复制${format.label}`"
>
<i class="far fa-copy"></i>
</button>
</div>
<div class="output-value" :class="{ empty: !format.value }">
{{ format.value || '—' }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref, computed } from 'vue'
const inputText = ref('')
const toastMessage = ref('')
const toastType = ref('success')
let toastTimer = null
// 变量名格式定义
const formats = ref([
{ key: 'camelCase', label: '小驼峰 (camelCase)', value: '' },
{ key: 'PascalCase', label: '大驼峰 (PascalCase)', value: '' },
{ key: 'snake_case', label: '下划线 (snake_case)', value: '' },
{ key: 'kebab-case', label: '横线 (kebab-case)', value: '' },
{ key: 'CONSTANT_CASE', label: '常量 (CONSTANT_CASE)', value: '' }
])
// 显示提示
const showToast = (message, type = 'success', duration = 3000) => {
toastMessage.value = message
toastType.value = type
if (toastTimer) {
clearTimeout(toastTimer)
}
toastTimer = setTimeout(() => {
toastMessage.value = ''
}, duration)
}
// 关闭提示
const closeToast = () => {
if (toastTimer) {
clearTimeout(toastTimer)
toastTimer = null
}
toastMessage.value = ''
}
// 将输入文本解析为单词数组
const parseToWords = (text) => {
if (!text || !text.trim()) {
return []
}
let processed = text.trim()
// 处理各种分隔符:空格、下划线、横线、驼峰
// 1. 先处理连续大写字母的情况XMLHttpRequest -> XML Http Request
processed = processed.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
// 2. 先处理数字和字母的边界(必须在驼峰处理之前)
// 2.1 字母+数字+字母temp2Detail -> temp 2 Detail
processed = processed.replace(/([a-zA-Z])(\d+)([a-zA-Z])/g, '$1 $2 $3')
// 2.2 字母+数字后面跟着分隔符或结尾但不是字母item2 -> item 2
// 注意这里不匹配后面跟着字母的情况已由2.1处理)
processed = processed.replace(/([a-zA-Z])(\d+)(?=[_\-\s]|$)/g, '$1 $2')
// 2.3 数字+字母在单词开头或前面是分隔符2item -> 2 item
processed = processed.replace(/(\d+)([a-zA-Z])/g, '$1 $2')
// 3. 处理驼峰camelCase -> camel Case在数字处理之后
processed = processed.replace(/([a-z])([A-Z])/g, '$1 $2')
// 4. 统一分隔符:下划线、横线、空格统一为空格
processed = processed.replace(/[_\-\s]+/g, ' ')
// 5. 分割并处理
let words = processed
.split(' ')
.filter(word => word.length > 0)
.map(word => {
// 转换为小写,保留字母和数字
return word.toLowerCase()
})
.filter(word => word.length > 0) // 允许纯数字
return words
}
// 转换单词首字母为大写(处理数字情况)
const capitalizeWord = (word) => {
if (!word) return ''
// 如果单词是纯数字,直接返回
if (/^\d+$/.test(word)) return word
// 否则首字母大写
return word.charAt(0).toUpperCase() + word.slice(1)
}
// 转换为小驼峰 (camelCase)
const toCamelCase = (words) => {
if (words.length === 0) return ''
const firstWord = words[0]
const restWords = words.slice(1).map(word => capitalizeWord(word))
return firstWord + restWords.join('')
}
// 转换为大驼峰 (PascalCase)
const toPascalCase = (words) => {
if (words.length === 0) return ''
return words.map(word => capitalizeWord(word)).join('')
}
// 转换为下划线 (snake_case)
const toSnakeCase = (words) => {
if (words.length === 0) return ''
return words.join('_')
}
// 转换为横线 (kebab-case)
const toKebabCase = (words) => {
if (words.length === 0) return ''
return words.join('-')
}
// 转换为常量 (CONSTANT_CASE)
const toConstantCase = (words) => {
if (words.length === 0) return ''
return words.map(word => word.toUpperCase()).join('_')
}
// 转换变量名
const convertVariableName = () => {
const words = parseToWords(inputText.value)
if (words.length === 0) {
formats.value.forEach(format => {
format.value = ''
})
return
}
formats.value.forEach(format => {
switch (format.key) {
case 'camelCase':
format.value = toCamelCase(words)
break
case 'PascalCase':
format.value = toPascalCase(words)
break
case 'snake_case':
format.value = toSnakeCase(words)
break
case 'kebab-case':
format.value = toKebabCase(words)
break
case 'CONSTANT_CASE':
format.value = toConstantCase(words)
break
}
})
}
// 清空输入
const clearInput = () => {
inputText.value = ''
convertVariableName()
}
// 复制到剪贴板
const copyToClipboard = async (text, label) => {
if (!text || text === '—') {
showToast('没有可复制的内容', 'error')
return
}
try {
await navigator.clipboard.writeText(text)
showToast(`${label}已复制到剪贴板`, 'success', 2000)
} catch (error) {
showToast('复制失败:' + error.message, 'error')
}
}
</script>
<style scoped>
.variable-name-converter {
width: 100%;
min-height: 100vh;
background: #f5f5f5;
padding: 2rem 1rem;
}
.container {
max-width: 900px;
margin: 0 auto;
}
.conversion-card {
background: #ffffff;
border-radius: 8px;
padding: 2rem;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
border: 1px solid #e5e5e5;
}
.input-section {
margin-bottom: 2rem;
}
.input-label {
display: block;
font-size: 0.875rem;
font-weight: 500;
color: #333333;
margin-bottom: 0.5rem;
}
.input-wrapper {
position: relative;
display: flex;
align-items: center;
}
.input-field {
flex: 1;
padding: 0.75rem;
padding-right: 2.5rem;
border: 1px solid #d0d0d0;
border-radius: 6px;
font-size: 0.9375rem;
font-family: 'Courier New', monospace;
transition: all 0.2s;
}
.input-field:focus {
outline: none;
border-color: #1a1a1a;
box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.1);
}
.clear-btn {
position: absolute;
right: 0.5rem;
padding: 0.375rem;
background: transparent;
border: none;
border-radius: 4px;
color: #666666;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
width: 24px;
height: 24px;
}
.clear-btn:hover {
background: #f5f5f5;
color: #1a1a1a;
}
.output-section {
display: flex;
flex-direction: column;
gap: 1rem;
}
.output-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1rem;
}
.output-item {
border: 1px solid #e5e5e5;
border-radius: 6px;
padding: 1rem;
background: #fafafa;
transition: all 0.2s;
display: flex;
flex-direction: column;
}
.output-item:hover {
border-color: #d0d0d0;
background: #ffffff;
}
.output-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0.5rem;
}
.output-label {
font-size: 0.875rem;
font-weight: 500;
color: #333333;
}
.copy-btn {
padding: 0.375rem;
background: transparent;
border: 1px solid #d0d0d0;
border-radius: 4px;
color: #666666;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
width: 28px;
height: 28px;
}
.copy-btn:hover {
background: #f5f5f5;
border-color: #1a1a1a;
color: #1a1a1a;
}
.copy-btn:active {
transform: scale(0.98);
}
.copy-btn i {
font-size: 0.875rem;
}
.output-value {
font-family: 'Courier New', monospace;
font-size: 1rem;
color: #1a1a1a;
word-break: break-all;
min-height: 1.5rem;
padding: 0.5rem 0;
}
.output-value.empty {
color: #999999;
}
/* Toast通知样式 */
.toast-notification {
position: fixed;
top: 80px;
right: 20px;
background: #ffffff;
border: 1px solid #e5e5e5;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
padding: 1rem 1.25rem;
display: flex;
align-items: center;
gap: 0.75rem;
z-index: 1000;
min-width: 280px;
max-width: 400px;
}
.toast-notification.success {
border-left: 4px solid #10b981;
}
.toast-notification.error {
border-left: 4px solid #ef4444;
}
.toast-content {
display: flex;
align-items: center;
gap: 0.5rem;
flex: 1;
font-size: 0.875rem;
color: #333333;
}
.toast-content i {
flex-shrink: 0;
}
.toast-notification.success .toast-content i {
color: #10b981;
}
.toast-notification.error .toast-content i {
color: #ef4444;
}
.toast-close-btn {
background: transparent;
border: none;
color: #666666;
cursor: pointer;
padding: 0.25rem;
display: flex;
align-items: center;
justify-content: center;
transition: color 0.2s;
flex-shrink: 0;
}
.toast-close-btn:hover {
color: #1a1a1a;
}
.toast-enter-active,
.toast-leave-active {
transition: all 0.3s ease;
}
.toast-enter-from {
opacity: 0;
transform: translateX(100%);
}
.toast-leave-to {
opacity: 0;
transform: translateX(100%);
}
@media (max-width: 768px) {
.variable-name-converter {
padding: 1rem 0.5rem;
}
.conversion-card {
padding: 1.5rem;
}
.output-row {
grid-template-columns: 1fr;
}
.toast-notification {
right: 10px;
left: 10px;
max-width: none;
top: 60px;
}
}
</style>

View File

@@ -0,0 +1,21 @@
// vite.config.js
import { defineConfig } from "file:///Users/xufeng3/WebstormProjects/Toolbox/node_modules/vite/dist/node/index.js";
import vue from "file:///Users/xufeng3/WebstormProjects/Toolbox/node_modules/@vitejs/plugin-vue/dist/index.mjs";
import { resolve } from "path";
var __vite_injected_original_dirname = "/Users/xufeng3/WebstormProjects/Toolbox";
var vite_config_default = defineConfig({
plugins: [vue()],
resolve: {
alias: {
"@": resolve(__vite_injected_original_dirname, "src")
}
},
server: {
port: 3e3,
open: true
}
});
export {
vite_config_default as default
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcuanMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCIvVXNlcnMveHVmZW5nMy9XZWJzdG9ybVByb2plY3RzL1Rvb2xib3hcIjtjb25zdCBfX3ZpdGVfaW5qZWN0ZWRfb3JpZ2luYWxfZmlsZW5hbWUgPSBcIi9Vc2Vycy94dWZlbmczL1dlYnN0b3JtUHJvamVjdHMvVG9vbGJveC92aXRlLmNvbmZpZy5qc1wiO2NvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9pbXBvcnRfbWV0YV91cmwgPSBcImZpbGU6Ly8vVXNlcnMveHVmZW5nMy9XZWJzdG9ybVByb2plY3RzL1Rvb2xib3gvdml0ZS5jb25maWcuanNcIjtpbXBvcnQgeyBkZWZpbmVDb25maWcgfSBmcm9tICd2aXRlJ1xuaW1wb3J0IHZ1ZSBmcm9tICdAdml0ZWpzL3BsdWdpbi12dWUnXG5pbXBvcnQgeyByZXNvbHZlIH0gZnJvbSAncGF0aCdcblxuZXhwb3J0IGRlZmF1bHQgZGVmaW5lQ29uZmlnKHtcbiAgcGx1Z2luczogW3Z1ZSgpXSxcbiAgcmVzb2x2ZToge1xuICAgIGFsaWFzOiB7XG4gICAgICAnQCc6IHJlc29sdmUoX19kaXJuYW1lLCAnc3JjJylcbiAgICB9XG4gIH0sXG4gIHNlcnZlcjoge1xuICAgIHBvcnQ6IDMwMDAsXG4gICAgb3BlbjogdHJ1ZVxuICB9XG59KVxuXG4iXSwKICAibWFwcGluZ3MiOiAiO0FBQXVTLFNBQVMsb0JBQW9CO0FBQ3BVLE9BQU8sU0FBUztBQUNoQixTQUFTLGVBQWU7QUFGeEIsSUFBTSxtQ0FBbUM7QUFJekMsSUFBTyxzQkFBUSxhQUFhO0FBQUEsRUFDMUIsU0FBUyxDQUFDLElBQUksQ0FBQztBQUFBLEVBQ2YsU0FBUztBQUFBLElBQ1AsT0FBTztBQUFBLE1BQ0wsS0FBSyxRQUFRLGtDQUFXLEtBQUs7QUFBQSxJQUMvQjtBQUFBLEVBQ0Y7QUFBQSxFQUNBLFFBQVE7QUFBQSxJQUNOLE1BQU07QUFBQSxJQUNOLE1BQU07QUFBQSxFQUNSO0FBQ0YsQ0FBQzsiLAogICJuYW1lcyI6IFtdCn0K