UnisKB/ui/src/views/application/component/AddDatasetDialog.vue

150 lines
3.9 KiB
Vue
Raw Normal View History

2023-11-24 06:49:25 +00:00
<template>
2024-07-01 01:45:59 +00:00
<el-dialog
:title="$t('views.application.applicationForm.dialogues.addDataset')"
v-model="dialogVisible"
width="600"
append-to-body
class="addDataset-dialog"
2024-07-22 10:38:53 +00:00
align-center
2024-07-01 01:45:59 +00:00
>
2023-12-01 03:36:04 +00:00
<template #header="{ titleId, titleClass }">
<div class="flex-between mb-8">
2024-07-01 01:45:59 +00:00
<h4 :id="titleId" :class="titleClass">
{{ $t('views.application.applicationForm.dialogues.addDataset') }}
</h4>
<div class="flex align-center">
<el-button link class="ml-16" @click="refresh">
<el-icon class="mr-4"><Refresh /></el-icon
>{{ $t('views.application.applicationForm.dialogues.refresh') }}
</el-button>
<el-divider direction="vertical" />
</div>
2023-11-30 08:35:52 +00:00
</div>
<el-text type="info" class="color-secondary">
所选知识库必须使用相同的 Embedding 模型
</el-text>
2023-11-30 08:35:52 +00:00
</template>
2024-07-22 10:38:53 +00:00
<el-scrollbar>
<div class="max-height">
<el-row :gutter="12" v-loading="loading">
<el-col :span="12" v-for="(item, index) in filterData" :key="index" class="mb-16">
<CardCheckbox value-field="id" :data="item" v-model="checkList" @change="changeHandle">
<span class="ellipsis">
{{ item.name }}
</span>
</CardCheckbox>
</el-col>
</el-row>
</div>
</el-scrollbar>
2023-11-24 06:49:25 +00:00
<template #footer>
<div class="flex-between">
2024-07-22 10:38:53 +00:00
<div class="flex">
<el-text type="info" class="color-secondary mr-8" v-if="checkList.length > 0">
已选 {{ checkList.length }} 个知识库
</el-text>
<el-button link type="primary" v-if="checkList.length > 0" @click="clearCheck">
清空
</el-button>
</div>
<span>
<el-button @click.prevent="dialogVisible = false">
{{ $t('views.application.applicationForm.buttons.cancel') }}
</el-button>
<el-button type="primary" @click="submitHandle">
{{ $t('views.application.applicationForm.buttons.confirm') }}
</el-button>
</span>
</div>
2023-11-24 06:49:25 +00:00
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
2023-11-27 03:21:56 +00:00
const props = defineProps({
data: {
type: Array<any>,
default: () => []
2023-11-30 08:35:52 +00:00
},
loading: Boolean
2023-11-27 03:21:56 +00:00
})
2023-11-30 08:35:52 +00:00
const emit = defineEmits(['addData', 'refresh'])
2023-11-24 06:49:25 +00:00
const dialogVisible = ref<boolean>(false)
2023-11-24 11:02:52 +00:00
const checkList = ref([])
const currentEmbedding = ref('')
const filterData = computed(() => {
return currentEmbedding.value
? props.data.filter((v) => v.embedding_mode_id === currentEmbedding.value)
: props.data
})
2023-11-24 06:49:25 +00:00
watch(dialogVisible, (bool) => {
if (!bool) {
2023-11-24 11:02:52 +00:00
checkList.value = []
2024-07-24 06:39:41 +00:00
currentEmbedding.value = ''
2023-11-24 06:49:25 +00:00
}
})
function changeHandle() {
if (checkList.value.length === 1) {
currentEmbedding.value = props.data.filter(
(v) => v.id === checkList.value[0]
)[0].embedding_mode_id
2024-07-22 10:38:53 +00:00
} else if (checkList.value.length === 0) {
currentEmbedding.value = ''
}
}
function clearCheck() {
checkList.value = []
currentEmbedding.value = ''
}
2023-11-27 03:21:56 +00:00
const open = (checked: any) => {
checkList.value = checked
2024-07-22 10:38:53 +00:00
if (checkList.value.length > 0) {
currentEmbedding.value = props.data.filter(
(v) => v.id === checkList.value[0]
)[0].embedding_mode_id
}
2023-11-24 06:49:25 +00:00
dialogVisible.value = true
}
2023-11-27 03:21:56 +00:00
const submitHandle = () => {
emit('addData', checkList.value)
dialogVisible.value = false
2023-11-24 06:49:25 +00:00
}
2023-11-30 08:35:52 +00:00
const refresh = () => {
emit('refresh')
}
2023-11-24 06:49:25 +00:00
defineExpose({ open })
</script>
<style lang="scss" scope>
.addDataset-dialog {
2024-07-22 10:38:53 +00:00
padding: 0;
.el-dialog__header {
padding: 24px 24px 8px 24px;
}
.el-dialog__body {
padding: 8px !important;
}
.el-dialog__footer {
padding: 8px 24px 24px 24px;
}
.el-dialog__header.show-close {
2024-07-22 10:38:53 +00:00
padding-right: 34px;
}
.el-dialog__headerbtn {
top: 13px;
}
2024-07-22 10:38:53 +00:00
.max-height {
max-height: calc(100vh - 260px);
padding: 0 16px;
}
}
</style>