-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathParagraphCard.vue
More file actions
98 lines (95 loc) · 2.9 KB
/
ParagraphCard.vue
File metadata and controls
98 lines (95 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<template>
<CardBox
shadow="never"
:title="index + 1 + '.' + data.title || '-'"
class="paragraph-source-card cursor mb-8 paragraph-source-card-height"
:style="{ height: data?.document_name?.trim() ? '300px' : '260px' }"
:class="data.is_active ? '' : 'disabled'"
:showIcon="false"
>
<template #tag>
<div class="color-primary">
{{ score?.toFixed(3) || data.similarity?.toFixed(3) }}
</div>
</template>
<el-scrollbar height="150">
<MdPreview ref="editorRef" editorId="preview-only" :modelValue="content" noImgZoomIn />
</el-scrollbar>
<template #footer>
<el-card
shadow="never"
style="--el-card-padding: 8px"
class="w-full mb-12"
v-if="data?.document_name?.trim()"
>
<el-text class="flex align-center item">
<img :src="getImgUrl(data?.document_name?.trim())" alt="" width="20" class="mr-4" />
<div class="ml-8">
<div class="ml-4" v-if="data?.meta?.source_file_id || data?.meta?.source_url">
<a
:href="getFileUrl(data?.meta?.source_file_id) || data?.meta?.source_url"
target="_blank"
class="ellipsis-1"
:title="data?.document_name?.trim()"
>
<span :title="data?.document_name?.trim()">{{ data?.document_name }}</span>
</a>
</div>
<div v-else @click="infoMessage(data)">
<span class="ellipsis-1 break-all" :title="data?.document_name?.trim()">
{{ data?.document_name?.trim() }}
</span>
</div>
</div>
</el-text>
</el-card>
<div class="flex align-center border-t" style="padding: 12px 0 8px">
<KnowledgeIcon :type="data?.knowledge_type" :size="18" class="mr-8" />
<span class="ellipsis-1 break-all" :title="data?.knowledge_name">
{{ data?.knowledge_name || '-' }}
</span>
</div>
</template>
</CardBox>
</template>
<script setup lang="ts">
import { getImgUrl, getFileUrl } from '@/utils/common'
import { computed } from 'vue'
import { MsgInfo } from '@/utils/message'
import { t } from '@/locales'
const props = defineProps({
data: {
type: Object,
default: () => {},
},
content: {
type: String,
default: '',
},
index: {
type: Number,
default: 0,
},
score: {
type: Number,
default: null,
},
})
const isMetaObject = computed(() => typeof props.data.meta === 'object')
const parsedMeta = computed(() => {
try {
return JSON.parse(props.data.meta)
} catch (e) {
return {}
}
})
const meta = computed(() => (isMetaObject.value ? props.data.meta : parsedMeta.value))
function infoMessage(data: any) {
if (data?.meta?.allow_download === false) {
MsgInfo(t('chat.noPermissionDownload'))
} else {
MsgInfo(t('chat.noDocument'))
}
}
</script>
<style lang="scss" scoped></style>