refactor: simplify useLocalStorage (remove APP_PREFIX) and finalize QR Code tool

This commit is contained in:
2026-02-28 04:05:07 +00:00
parent 2a1897f68d
commit d5d3d37804
2 changed files with 18 additions and 15 deletions

View File

@@ -3,11 +3,12 @@ import { ref, watch, onMounted } from 'vue'
import { Download } from 'lucide-vue-next' import { Download } from 'lucide-vue-next'
import QRCode from 'qrcode' import QRCode from 'qrcode'
import { useFillHeight } from '../../composables/useFillHeight' import { useFillHeight } from '../../composables/useFillHeight'
import { useLocalStorage } from '../../composables/useLocalStorage'
const text = ref('') const text = useLocalStorage('text', '', 'qr-code')
const ecc = ref('M') const ecc = useLocalStorage('ecc', 'M', 'qr-code')
const size = ref(300) const size = useLocalStorage('size', 300, 'qr-code')
const format = ref('png') const format = useLocalStorage('format', 'png', 'qr-code')
const svgContent = ref('') const svgContent = ref('')
const previewRef = ref(null) const previewRef = ref(null)
@@ -250,12 +251,12 @@ const triggerDownload = (blob, filename) => {
padding: 1rem; padding: 1rem;
overflow: hidden; /* Prevent overflow if QR is too big */ overflow: hidden; /* Prevent overflow if QR is too big */
min-height: 0; min-height: 0;
container-type: size;
} }
.qr-frame { .qr-frame {
flex: 1; width: calc(100cqmin - 4rem);
width: 100%; height: calc(100cqmin - 4rem);
max-height: 100%;
background: white; background: white;
padding: 1rem; padding: 1rem;
border-radius: 8px; border-radius: 8px;
@@ -268,10 +269,8 @@ const triggerDownload = (blob, filename) => {
.qr-frame :deep(svg) { .qr-frame :deep(svg) {
display: block; display: block;
max-width: 100%; width: 100%;
max-height: 100%; height: 100%;
width: auto;
height: auto;
} }
.actions { .actions {

View File

@@ -1,16 +1,20 @@
import { ref, watch } from 'vue' import { ref, watch } from 'vue'
export function useLocalStorage(key, defaultValue) { export function useLocalStorage(key, defaultValue, toolPrefix = '') {
// Construct prefixed key: [toolPrefix-]key
const prefixPart = toolPrefix ? `${toolPrefix}-` : ''
const prefixedKey = `${prefixPart}${key}`
// Initialize state from local storage or default value // Initialize state from local storage or default value
const storedValue = localStorage.getItem(key) const storedValue = localStorage.getItem(prefixedKey)
const data = ref(storedValue ? JSON.parse(storedValue) : defaultValue) const data = ref(storedValue ? JSON.parse(storedValue) : defaultValue)
// Watch for changes and update local storage // Watch for changes and update local storage
watch(data, (newValue) => { watch(data, (newValue) => {
if (newValue === null || newValue === undefined) { if (newValue === null || newValue === undefined) {
localStorage.removeItem(key) localStorage.removeItem(prefixedKey)
} else { } else {
localStorage.setItem(key, JSON.stringify(newValue)) localStorage.setItem(prefixedKey, JSON.stringify(newValue))
} }
}, { deep: true }) }, { deep: true })