|
| 1 | +<template> |
| 2 | + <div class="w-full"> |
| 3 | + <el-select |
| 4 | + v-model="selectedIds" |
| 5 | + multiple |
| 6 | + class="w-full" |
| 7 | + :placeholder="$t('views.chatLog.selectKnowledgePlaceholder')" |
| 8 | + > |
| 9 | + <el-option v-for="item in availableList" :key="item.id" :label="item.name" :value="item.id"> |
| 10 | + <el-space :size="8"> |
| 11 | + <KnowledgeIcon :type="item.type" :size="20" style="--el-avatar-border-radius: 6px" /> |
| 12 | + <span>{{ item.name }}</span> |
| 13 | + </el-space> |
| 14 | + </el-option> |
| 15 | + <template #label="{ label, value }"> |
| 16 | + <el-space :size="8"> |
| 17 | + <KnowledgeIcon |
| 18 | + :type="relatedObject(availableList, value, 'id')?.type" |
| 19 | + :size="14" |
| 20 | + style="--el-avatar-border-radius: 4px" |
| 21 | + /> |
| 22 | + <span>{{ label }}</span> |
| 23 | + </el-space> |
| 24 | + </template> |
| 25 | + </el-select> |
| 26 | + </div> |
| 27 | +</template> |
| 28 | + |
| 29 | +<script setup lang="ts"> |
| 30 | +import { computed } from 'vue' |
| 31 | +import type { FormField } from '../../type' |
| 32 | +import { relatedObject } from '@/utils/array' |
| 33 | +const props = withDefaults( |
| 34 | + defineProps<{ |
| 35 | + modelValue?: string[] |
| 36 | + formField: FormField |
| 37 | + }>(), |
| 38 | + { modelValue: () => [] }, |
| 39 | +) |
| 40 | +
|
| 41 | +const emit = defineEmits(['update:modelValue', 'change']) |
| 42 | +
|
| 43 | +const model_value = computed({ |
| 44 | + get: () => props.modelValue || [], |
| 45 | + set: (value: string[]) => { |
| 46 | + emit('update:modelValue', value) |
| 47 | + emit('change', props.formField) |
| 48 | + }, |
| 49 | +}) |
| 50 | +// 可用 |
| 51 | +const availableList = computed(() => { |
| 52 | + return (props.formField.attrs?.knowledge_list as any[]) || [] |
| 53 | +}) |
| 54 | +
|
| 55 | +const selectedIds = computed({ |
| 56 | + get: () => model_value.value || [], |
| 57 | + set: (ids: string[]) => { |
| 58 | + model_value.value = ids |
| 59 | + }, |
| 60 | +}) |
| 61 | +</script> |
| 62 | +<style lang="scss" scoped></style> |
0 commit comments