-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathKnowledge.vue
More file actions
75 lines (67 loc) · 1.92 KB
/
Knowledge.vue
File metadata and controls
75 lines (67 loc) · 1.92 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
<template>
<div class="w-full">
<el-select
v-model="selectedIds"
multiple
class="w-full"
:placeholder="$t('dynamicsForm.Knowledge.placeholder', '请选择知识库')"
>
<el-option v-for="item in availableList" :key="item.id" :label="item.name" :value="item.id">
<div class="flex align-center">
<KnowledgeIcon :type="item.type" class="mr-8" :size="20" />
<span>{{ item.name }}</span>
</div>
</el-option>
<template #tag>
<el-tag
v-for="item in selectedItems"
:key="item.id"
closable
type="info"
@close="removeItem(item.id)"
style="margin-right: 4px"
>
<div class="flex align-center">
<KnowledgeIcon :type="item.type" class="mr-4" :size="16" />
<span>{{ item.name }}</span>
</div>
</el-tag>
</template>
</el-select>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import type { FormField } from '../../type'
const props = withDefaults(
defineProps<{
modelValue?: string[]
formField: FormField
}>(),
{ modelValue: () => [] },
)
const emit = defineEmits(['update:modelValue', 'change'])
const model_value = computed({
get: () => props.modelValue || [],
set: (value: string[]) => {
emit('update:modelValue', value)
emit('change', props.formField)
},
})
const availableList = computed(() => {
return (props.formField.attrs?.knowledge_list as any[]) || []
})
const selectedItems = computed(() => {
return availableList.value.filter((k: any) => selectedIds.value.includes(k.id))
})
const selectedIds = computed({
get: () => model_value.value || [],
set: (ids: string[]) => {
model_value.value = ids
},
})
function removeItem(id: string) {
model_value.value = model_value.value.filter((item_id: string) => item_id !== id)
}
</script>
<style lang="scss" scoped></style>