mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
38 lines
1.6 KiB
Vue
38 lines
1.6 KiB
Vue
<script lang="ts" setup>
|
||
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'
|
||
|
||
const props = defineProps<{
|
||
data: filehandleData | texthandleData
|
||
}>()
|
||
|
||
const emit = defineEmits<{
|
||
(e: 'change', key: string): void
|
||
}>()
|
||
|
||
const handleList: { component: Component<{ data: filehandleData | texthandleData }>; key: handleKey }[] = [
|
||
{ component: FileShareResult, key: 'file-share' },
|
||
{ component: TextShareResult, key: 'text-share' },
|
||
{ component: ImageCompressResult, key: 'file-image-compress' },
|
||
]
|
||
|
||
const activeHandle = computed(() => {
|
||
return handleList.find((item) => item.key === props?.data?.handle_type)
|
||
})
|
||
// vue这个ts蠢的没边了,本来想写component: FileShareResult | TextShareResult,结果不行
|
||
</script>
|
||
<template>
|
||
<div>
|
||
<component v-if="'file' 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>
|