refactor(front): update component props and types for FileShareResult and TextShareResult, and introduce a new types file for better type management

This commit is contained in:
keven1024
2025-12-17 08:11:02 +08:00
parent a82c894119
commit d7d2a5c00b
4 changed files with 18 additions and 17 deletions

View File

@@ -12,11 +12,9 @@ import showDrawer from '@/lib/showDrawer'
import QrCoreDrawer from '@/components/Drawer/QrCoreDrawer.vue'
import { h } from 'vue'
import { cx } from 'class-variance-authority'
import type { FileHandleKey } from '../Preprocessing/types'
import type { handleFileComponentProps } from './types'
const props = defineProps<{
data: { files: { id: string; file: File }[]; config: Record<string, any>; handle_type: FileHandleKey }
}>()
const props = defineProps<handleFileComponentProps>()
const emit = defineEmits<{
(e: 'change', key: string): void
}>()

View File

@@ -2,13 +2,7 @@
import FileShareResult from '@/components/Result/FileShareResult.vue'
import TextShareResult from '@/components/Result/TextShareResult.vue'
import ImageCompressResult from '@/components/Result/ImageCompressResult.vue'
import type { FileHandleKey, TextHandleKey } from '../Preprocessing/types'
type basehandleData = { config: Record<string, any> }
type filehandleData = { files: { id: string; file: File }[]; handle_type: FileHandleKey } & basehandleData
type texthandleData = { text: string; handle_type: TextHandleKey } & basehandleData
type handleKey = 'file-share' | 'text-share' | 'file-image-compress'
import type { filehandleData, handleComponent, handleKey, texthandleData } from './types'
const props = defineProps<{
data: filehandleData | texthandleData
@@ -18,7 +12,7 @@ const emit = defineEmits<{
(e: 'change', key: string): void
}>()
const handleList: { component: Component<{ data: filehandleData | texthandleData }>; key: handleKey }[] = [
const handleList: { component: handleComponent; key: handleKey }[] = [
{ component: FileShareResult, key: 'file-share' },
{ component: TextShareResult, key: 'text-share' },
{ component: ImageCompressResult, key: 'file-image-compress' },
@@ -31,7 +25,7 @@ const activeHandle = computed(() => {
</script>
<template>
<div>
<component v-if="'file' in data" :is="activeHandle?.component" :data="data" @change="(key: string) => emit('change', key)" />
<component v-if="'files' in data" :is="activeHandle?.component" :data="data" @change="(key: string) => emit('change', key)" />
<component v-if="'text' in data" :is="activeHandle?.component" :data="data" @change="(key: string) => emit('change', key)" />
</div>
</template>

View File

@@ -10,11 +10,9 @@ import showDrawer from '@/lib/showDrawer'
import QrCoreDrawer from '@/components/Drawer/QrCoreDrawer.vue'
import dayjs from 'dayjs'
import { h } from 'vue'
import type { TextHandleKey } from '../Preprocessing/types'
import type { handleTextComponentProps } from './types'
const props = defineProps<{
data: { text: string; config: Record<string, any>; handle_type: TextHandleKey }
}>()
const props = defineProps<handleTextComponentProps>()
const emit = defineEmits<{
(e: 'change', key: string): void

View File

@@ -0,0 +1,11 @@
import type { FileHandleKey, TextHandleKey } from '../Preprocessing/types'
type basehandleData = { config: Record<string, any> }
export type filehandleData = { files: { id: string; file: File }[]; handle_type: FileHandleKey } & basehandleData
export type texthandleData = { text: string; handle_type: TextHandleKey } & basehandleData
export type handleKey = FileHandleKey | TextHandleKey
export type handleTextComponentProps = { data: texthandleData }
export type handleFileComponentProps = { data: filehandleData }
export type handleComponent = Component<handleTextComponentProps | handleFileComponentProps>