UnisKB/ui/src/views/dataset/component/BaseForm.vue

121 lines
3.1 KiB
Vue
Raw Normal View History

2023-10-27 09:49:06 +00:00
<template>
2023-11-03 09:45:01 +00:00
<h4 class="title-decoration-1 mb-16">基本信息</h4>
2023-11-22 09:04:47 +00:00
<el-form
ref="FormRef"
:model="form"
:rules="rules"
label-position="top"
require-asterisk-position="right"
>
2023-10-27 09:49:06 +00:00
<el-form-item label="数据集名称" prop="name">
<el-input
v-model.trim="form.name"
placeholder="请输入数据集名称"
maxlength="64"
show-word-limit
/>
</el-form-item>
2023-11-02 01:56:14 +00:00
<el-form-item label="数据集描述" prop="desc">
2023-10-27 09:49:06 +00:00
<el-input
2023-11-02 01:56:14 +00:00
v-model.trim="form.desc"
2023-10-27 09:49:06 +00:00
type="textarea"
placeholder="描述数据集的内容详尽的描述将帮助AI能深入理解该数据集的内容能更准确的检索到内容提高该数据集的命中率。"
maxlength="500"
show-word-limit
:autosize="{ minRows: 3 }"
/>
</el-form-item>
2023-12-04 08:32:50 +00:00
<el-form-item v-loading="loading">
<el-row justify="space-between" style="width: 100%">
<el-col :span="11" v-for="(item, index) in application_list" :key="index" class="mb-16">
<CardCheckbox value-field="id" :data="item" v-model="form.application_id_list">
2023-12-04 09:00:44 +00:00
<template #icon>
<AppAvatar
v-if="item.name"
:name="item.name"
pinyinColor
class="mr-12"
shape="square"
:size="32"
/>
</template>
2023-12-04 08:32:50 +00:00
{{ item.name }}
</CardCheckbox>
</el-col>
</el-row>
</el-form-item>
2023-10-27 09:49:06 +00:00
</el-form>
</template>
<script setup lang="ts">
2023-11-14 10:12:55 +00:00
import { ref, reactive, onMounted, onUnmounted, computed, watch } from 'vue'
2023-11-10 09:18:00 +00:00
import useStore from '@/stores'
2023-12-04 08:32:50 +00:00
import DatasetApi from '@/api/dataset'
import CardCheckbox from '@/components/card-checkbox/index.vue'
import type { ApplicationFormType } from '@/api/type/application'
2023-11-10 09:18:00 +00:00
const props = defineProps({
data: {
type: Object,
default: () => {}
}
})
2023-12-04 08:32:50 +00:00
const loading = ref<boolean>(false)
2023-11-10 09:18:00 +00:00
const { dataset } = useStore()
const baseInfo = computed(() => dataset.baseInfo)
2023-12-04 08:32:50 +00:00
const application_list = ref<Array<ApplicationFormType>>([])
2023-11-10 09:18:00 +00:00
const form = ref<any>({
2023-10-27 09:49:06 +00:00
name: '',
2023-12-04 08:32:50 +00:00
desc: '',
application_id_list: []
2023-10-27 09:49:06 +00:00
})
const rules = reactive({
name: [{ required: true, message: '请输入数据集名称', trigger: 'blur' }],
2023-11-02 01:56:14 +00:00
desc: [{ required: true, message: '请输入数据集描述', trigger: 'blur' }]
2023-10-27 09:49:06 +00:00
})
const FormRef = ref()
2023-11-10 09:18:00 +00:00
watch(
() => props.data,
(value) => {
2023-11-10 11:05:52 +00:00
if (value && JSON.stringify(value) !== '{}') {
2023-11-10 09:18:00 +00:00
form.value.name = value.name
form.value.desc = value.desc
2023-12-04 08:32:50 +00:00
form.value.application_id_list = value.application_id_list
DatasetApi.listUsableApplication(value.id, loading).then((ok) => {
application_list.value = ok.data
})
2023-11-10 09:18:00 +00:00
}
},
{
immediate: true
}
)
2023-11-22 03:05:06 +00:00
/*
表单校验
*/
2023-10-27 09:49:06 +00:00
function validate() {
if (!FormRef.value) return
2023-11-02 01:56:14 +00:00
return FormRef.value.validate((valid: any) => {
2023-10-27 09:49:06 +00:00
return valid
})
}
2023-11-10 09:18:00 +00:00
onMounted(() => {
if (baseInfo.value) {
form.value = baseInfo.value
}
})
2023-11-14 10:12:55 +00:00
onUnmounted(() => {
form.value = {
name: '',
desc: ''
}
})
2023-10-27 09:49:06 +00:00
defineExpose({
2023-11-02 01:56:14 +00:00
validate,
form
2023-10-27 09:49:06 +00:00
})
</script>
<style scoped lang="scss"></style>