refactor: ♻️ 界面设置页面重构,抽离逻辑 #96

This commit is contained in:
LOG1997
2025-12-11 23:18:10 +08:00
parent bfc593fa8e
commit c9efd62e34
14 changed files with 756 additions and 430 deletions

View File

@@ -2,10 +2,11 @@
import type { IFileData } from './type'
import { ListMusic, Upload, X } from 'lucide-vue-next'
import { ref } from 'vue'
import { readFileData } from '@/utils/file'
import { readFileAsJsonData, readFileData } from '@/utils/file'
defineProps<{
const props = defineProps<{
limitType?: string
mode?: 'file' | 'json'
}>()
const emits = defineEmits<{
@@ -17,6 +18,14 @@ const fileData = ref<IFileData | null>(null)
async function handleFileChange(e: Event) {
const file = ((e.target as HTMLInputElement).files as FileList)[0]
const type = file.type
if (props.mode === 'json') {
const fileRes = await readFileAsJsonData(file)
const jsonData = JSON.parse(fileRes)
fileData.value = { dataUrl: jsonData, fileName: file.name, type }
originFileName.value = file.name
emits('uploadFile', fileData.value)
return
}
const { dataUrl, fileName } = await readFileData(file)
fileData.value = { dataUrl, fileName, type }
originFileName.value = fileName