-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathKnowledge.vue
More file actions
64 lines (60 loc) · 1.71 KB
/
Knowledge.vue
File metadata and controls
64 lines (60 loc) · 1.71 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
<template>
<div class="w-full">
<el-select
v-model="selectedIds"
multiple
class="w-full"
:placeholder="$t('views.chatLog.selectKnowledgePlaceholder')"
>
<el-option v-for="item in availableList" :key="item.id" :label="item.name" :value="item.id">
<el-space :size="8">
<KnowledgeIcon :type="item.type" :size="20" style="--el-avatar-border-radius: 6px" />
<span>{{ item.name }}</span>
</el-space>
</el-option>
<template #label="{ label, value }">
<el-space :size="8">
<KnowledgeIcon
:type="relatedObject(availableList, value, 'id')?.type"
:size="14"
style="--el-avatar-border-radius: 4px"
/>
<span>{{ label }}</span>
</el-space>
</template>
</el-select>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import type { FormField } from '../../type'
import { relatedObject } from '@/utils/array'
const props = withDefaults(
defineProps<{
modelValue?: string[]
formField: FormField
}>(),
{ modelValue: () => [] },
)
const emit = defineEmits(['update:modelValue', 'change'])
const model_value = computed({
get: () =>
props.modelValue.filter((id: string) => availableList.value.some((item) => item.id === id)) ||
[],
set: (value: string[]) => {
emit('update:modelValue', value)
emit('change', props.formField)
},
})
// 可用
const availableList = computed(() => {
return (props.formField.attrs?.knowledge_list as any[]) || []
})
const selectedIds = computed({
get: () => model_value.value || [],
set: (ids: string[]) => {
model_value.value = ids
},
})
</script>
<style lang="scss" scoped></style>