mirror of
https://github.com/keven1024/015.git
synced 2026-06-08 05:14:33 +00:00
feat(front): add FilePreviewView and FileShareHandle components for improved file preview and sharing options
This commit is contained in:
@@ -1,21 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import FileUpload from '~/components/FileUpload.vue'
|
import FileUpload from '~/components/FileUpload.vue'
|
||||||
import { cx } from 'class-variance-authority'
|
import { cx } from 'class-variance-authority'
|
||||||
import { filesize } from 'filesize'
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
name: string
|
name: string
|
||||||
rules?: string
|
rules?: string
|
||||||
}>()
|
}>()
|
||||||
const { value, setValue } = useField<File>(props?.name, props?.rules)
|
const { value, setValue } = useField<File>(props?.name, props?.rules)
|
||||||
watch(value, (v) => {
|
|
||||||
console.log('value', v)
|
|
||||||
})
|
|
||||||
|
|
||||||
const fileInfo = computed(() => {
|
|
||||||
const [, name, ext] = value?.value?.name?.match(/^(.+)\.(.+)$/) || []
|
|
||||||
return { name, ext }
|
|
||||||
})
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -27,14 +19,7 @@ const fileInfo = computed(() => {
|
|||||||
isOverDropZone && '!bg-green-100/50 '
|
isOverDropZone && '!bg-green-100/50 '
|
||||||
)">
|
)">
|
||||||
<template v-if="!!value">
|
<template v-if="!!value">
|
||||||
<FileIcon :file="value" />
|
<FilePreviewView :value="value" />
|
||||||
<div class="flex flex-col gap-0.5 items-center">
|
|
||||||
<div class="flex max-w-30 w-full">
|
|
||||||
<div class="truncate">{{ fileInfo?.name }}</div>
|
|
||||||
<div>{{ `.${fileInfo?.ext}` }}</div>
|
|
||||||
</div>
|
|
||||||
<div class="text-xs opacity-50">{{ filesize(value?.size) }}</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<LucideUpload class="size-10" />
|
<LucideUpload class="size-10" />
|
||||||
|
|||||||
21
front/components/FilePreviewView.vue
Normal file
21
front/components/FilePreviewView.vue
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { filesize } from 'filesize'
|
||||||
|
const props = defineProps<{
|
||||||
|
value: File
|
||||||
|
}>()
|
||||||
|
const fileInfo = computed(() => {
|
||||||
|
const [, name, ext] = props?.value?.name?.match(/^(.+)\.(.+)$/) || []
|
||||||
|
return { name, ext }
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<FileIcon :file="value" />
|
||||||
|
<div class="flex flex-col gap-0.5 items-center">
|
||||||
|
<div class="flex max-w-30 w-full">
|
||||||
|
<div class="truncate">{{ fileInfo?.name }}</div>
|
||||||
|
<div>{{ `.${fileInfo?.ext}` }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="text-xs opacity-50">{{ filesize(value?.size) }}</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -6,7 +6,9 @@ import FormButton from '../Field/FormButton.vue';
|
|||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
hide: () => void
|
hide: () => void
|
||||||
file: File
|
file: File
|
||||||
|
onFileHandle: ({ data, type }: { data: any, type: string }) => void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -40,7 +42,8 @@ const props = defineProps<{
|
|||||||
<InputField v-if="!!values.has_download_notify" name="download_notify_email" placeholder="请输入邮箱" />
|
<InputField v-if="!!values.has_download_notify" name="download_notify_email" placeholder="请输入邮箱" />
|
||||||
</div>
|
</div>
|
||||||
<FormButton @click="(form) => {
|
<FormButton @click="(form) => {
|
||||||
console.log(form.values)
|
onFileHandle({ data: form?.values?.value, type: 'file-share' })
|
||||||
|
hide()
|
||||||
}">提交</FormButton>
|
}">提交</FormButton>
|
||||||
</div>
|
</div>
|
||||||
</VeeForm>
|
</VeeForm>
|
||||||
Reference in New Issue
Block a user