mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 23:19:37 +00:00
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:
@@ -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
|
||||
}>()
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
11
front/components/Result/types.ts
Normal file
11
front/components/Result/types.ts
Normal 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>
|
||||
Reference in New Issue
Block a user