Commit e411a69f by pangchong

feat: pdf文件预览下载

parent 3804a457
...@@ -10,18 +10,22 @@ ...@@ -10,18 +10,22 @@
</div> </div>
<!-- 聊天信息 --> <!-- 聊天信息 -->
<template v-if="type == 'txt'"> <template v-if="type == 'txt'">
<div :class="{ 'bg-primary-hover': isSelf, 'bg-theme-bg3': !isSelf }" class="p-4 rounded leading-[22px] text-theme-text1">{{ data.message || '' }}</div> <div :class="{ 'bg-primary-hover': isSelf, 'bg-theme-bg3': !isSelf }" class="p-4 rounded leading-[22px] text-theme-text1 break-all">{{ data.message || '' }}</div>
</template> </template>
<template v-else-if="type == 'image'"> <template v-else-if="type == 'image'">
<a-image width="100%" :height="160" :src="data.src"></a-image> <a-image width="100%" :height="160" :src="data.src"></a-image>
</template> </template>
<template v-else-if="type == 'pdf'"> <template v-else-if="type == 'pdf'">
<div :class="{ 'bg-primary-hover': isSelf, 'bg-theme-bg3': !isSelf }" class="py-[10px] px-3 rounded flex-center justify-between leading-[22px] text-theme-text1 w-full"> <div
:class="{ 'bg-primary-hover': isSelf, 'bg-theme-bg3': !isSelf }"
class="py-[10px] px-3 rounded flex-center justify-between leading-[22px] text-theme-text1 w-full cursor-pointer"
@click="handlePreview"
>
<div class="flex-center"> <div class="flex-center">
<global-icon icon="file"></global-icon> <global-icon icon="file"></global-icon>
<span class="ml-3">{{ data.fileName || '' }}</span> <span class="ml-3">{{ data.fileName || '' }}</span>
</div> </div>
<a :href="data.src" download target="_blank"><global-icon icon="download" class="cursor-pointer"></global-icon></a> <global-icon icon="download" class="cursor-pointer" @click.stop="handleDown"></global-icon>
</div> </div>
</template> </template>
<template v-else> <template v-else>
...@@ -29,9 +33,16 @@ ...@@ -29,9 +33,16 @@
</template> </template>
</div> </div>
</div> </div>
<global-model v-model:visible="showPreview" width="80%" :footer="false" :simple="true">
<div style="height: 80vh">
<iframe :src="data.src" frameborder="0" width="100%" height="100%"></iframe>
</div>
</global-model>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { directlyDownloadFromURL } from '@/utils/downloadData/downloadBlob'
interface Props { interface Props {
isSelf?: boolean isSelf?: boolean
type?: 'txt' | 'image' | 'pdf' | 'video' type?: 'txt' | 'image' | 'pdf' | 'video'
...@@ -42,5 +53,14 @@ const ps = withDefaults(defineProps<Props>(), { ...@@ -42,5 +53,14 @@ const ps = withDefaults(defineProps<Props>(), {
type: 'txt', type: 'txt',
data: () => {} data: () => {}
}) })
//预览文件
const showPreview = ref(false)
const handlePreview = () => {
showPreview.value = true
}
//下载文件
const handleDown = () => {
directlyDownloadFromURL(ps.data?.src, ps.data?.fileName)
}
</script> </script>
<style lang="less" scoped></style> <style lang="less" scoped></style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment