fix: PDF Preview (#3504)
This commit is contained in:
parent
754c309b52
commit
b40c76d3f3
@ -96,7 +96,7 @@ class FileSerializer(serializers.Serializer):
|
|||||||
content_type = mime_types.get(file_type, 'application/octet-stream')
|
content_type = mime_types.get(file_type, 'application/octet-stream')
|
||||||
headers = {
|
headers = {
|
||||||
'Content-Type': content_type,
|
'Content-Type': content_type,
|
||||||
'Content-Disposition': f'attachment; filename="{file.file_name}"'
|
'Content-Disposition': f'{"inline" if file_type == "pdf" else "attachment"}; filename="{file.file_name}"'
|
||||||
}
|
}
|
||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
file.get_bytes(),
|
file.get_bytes(),
|
||||||
|
|||||||
@ -20,14 +20,14 @@
|
|||||||
<div
|
<div
|
||||||
class="ml-4 ellipsis-1"
|
class="ml-4 ellipsis-1"
|
||||||
:title="item?.document_name"
|
:title="item?.document_name"
|
||||||
v-if="!item.source_url"
|
v-if="showPDF(item)"
|
||||||
@click="openParagraphDocument(item)"
|
@click="openParagraphDocument(item)"
|
||||||
>
|
>
|
||||||
<p>{{ item && item?.document_name }}</p>
|
<p>{{ item && item?.document_name }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-8" v-else>
|
<div class="ml-8" v-else>
|
||||||
<a
|
<a
|
||||||
:href="getNormalizedUrl(item?.source_url)"
|
:href="getFileUrl(item?.meta?.source_file_id)"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="ellipsis-1"
|
class="ellipsis-1"
|
||||||
:title="item?.document_name?.trim()"
|
:title="item?.document_name?.trim()"
|
||||||
@ -89,7 +89,7 @@ import ExecutionDetailContent from './ExecutionDetailContent.vue'
|
|||||||
import ParagraphDocumentContent from './ParagraphDocumentContent.vue'
|
import ParagraphDocumentContent from './ParagraphDocumentContent.vue'
|
||||||
import ParagraphSourceContent from './ParagraphSourceContent.vue'
|
import ParagraphSourceContent from './ParagraphSourceContent.vue'
|
||||||
import { arraySort } from '@/utils/array'
|
import { arraySort } from '@/utils/array'
|
||||||
import { getImgUrl, getNormalizedUrl } from '@/utils/common'
|
import { getImgUrl, getFileUrl } from '@/utils/common'
|
||||||
import { t } from '@/locales'
|
import { t } from '@/locales'
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
data: {
|
data: {
|
||||||
@ -107,7 +107,9 @@ const props = defineProps({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['openExecutionDetail', 'openParagraph', 'openParagraphDocument'])
|
const emit = defineEmits(['openExecutionDetail', 'openParagraph', 'openParagraphDocument'])
|
||||||
|
const showPDF = (item: any) => {
|
||||||
|
return item.document_name.toLocaleLowerCase().endsWith('.pdf') && item.meta?.source_file_id
|
||||||
|
}
|
||||||
const dialogVisible = ref(false)
|
const dialogVisible = ref(false)
|
||||||
const dialogTitle = ref('')
|
const dialogTitle = ref('')
|
||||||
const currentComponent = shallowRef<any>(null)
|
const currentComponent = shallowRef<any>(null)
|
||||||
|
|||||||
@ -143,6 +143,12 @@ export function getNormalizedUrl(url: string) {
|
|||||||
}
|
}
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
export function getFileUrl(fileId?: string) {
|
||||||
|
if (fileId) {
|
||||||
|
return `${window.MaxKB.prefix}/oss/file/${fileId}`
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
}
|
||||||
export const resetUrl = (url: string, defaultUrl?: string) => {
|
export const resetUrl = (url: string, defaultUrl?: string) => {
|
||||||
if (url && url.startsWith('./')) {
|
if (url && url.startsWith('./')) {
|
||||||
return `${window.MaxKB.prefix}/${url.substring(2)}`
|
return `${window.MaxKB.prefix}/${url.substring(2)}`
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user