UnisKB/ui/src/views/dataset/DatasetSetting.vue

186 lines
6.0 KiB
Vue
Raw Normal View History

2024-01-10 09:44:05 +00:00
<template>
<LayoutContainer header="设置">
<div class="dataset-setting main-calc-height">
<el-scrollbar>
<div class="p-24" v-loading="loading">
<h4 class="title-decoration-1 mb-16">基本信息</h4>
2024-01-10 09:44:05 +00:00
<BaseForm ref="BaseFormRef" :data="detail" />
<el-form
ref="webFormRef"
:rules="rules"
:model="form"
label-position="top"
require-asterisk-position="right"
>
<el-form-item label="知识库类型" required>
<el-card shadow="never" class="mb-8" v-if="detail.type === '0'">
<div class="flex align-center">
2024-02-23 07:00:29 +00:00
<AppAvatar class="mr-8" shape="square" :size="32">
<img src="@/assets/icon_document.svg" style="width: 58%" alt="" />
</AppAvatar>
2024-01-10 09:44:05 +00:00
<div>
2024-02-23 07:00:29 +00:00
<div>通用型</div>
2024-01-10 09:44:05 +00:00
<el-text type="info">可以通过上传文件或手动录入方式构建知识库</el-text>
</div>
</div>
</el-card>
<el-card shadow="never" class="mb-8" v-if="detail?.type === '1'">
<div class="flex align-center">
2024-02-23 07:00:29 +00:00
<AppAvatar class="mr-8 avatar-purple" shape="square" :size="32">
<img src="@/assets/icon_web.svg" style="width: 58%" alt="" />
</AppAvatar>
2024-01-10 09:44:05 +00:00
<div>
2024-02-23 07:00:29 +00:00
<div>Web 站点</div>
2024-01-10 09:44:05 +00:00
<el-text type="info"> 通过网站链接同步方式构建知识库 </el-text>
</div>
</div>
</el-card>
</el-form-item>
2024-01-10 10:36:04 +00:00
<el-form-item label="Web 根地址" prop="source_url" v-if="detail.type === '1'">
2024-01-10 09:44:05 +00:00
<el-input
2024-01-10 10:36:04 +00:00
v-model="form.source_url"
2024-01-10 09:44:05 +00:00
placeholder="请输入 Web 根地址"
2024-01-10 10:36:04 +00:00
@blur="form.source_url = form.source_url.trim()"
2024-01-10 09:44:05 +00:00
/>
</el-form-item>
<el-form-item label="选择器" v-if="detail.type === '1'">
<el-input
v-model="form.selector"
2024-01-17 08:29:37 +00:00
placeholder="默认为 body可输入 .classname/#idname/tagname"
2024-01-10 09:44:05 +00:00
@blur="form.selector = form.selector.trim()"
/>
</el-form-item>
</el-form>
2024-07-01 01:45:59 +00:00
<div v-if="application_id_list.length > 0">
<h4 class="title-decoration-1 mb-16">关联应用</h4>
<el-row :gutter="12">
<el-col
:span="12"
v-for="(item, index) in application_list.filter((obj: any) =>
application_id_list.some((v: any) => v === obj?.id)
)"
:key="index"
class="mb-16"
>
<el-card shadow="never">
<div class="flex-between">
<div class="flex align-center">
<AppAvatar
v-if="isAppIcon(item?.icon)"
shape="square"
:size="32"
style="background: none"
class="mr-12"
>
<img :src="item?.icon" alt="" />
</AppAvatar>
<AppAvatar
v-else-if="item?.name"
:name="item?.name"
pinyinColor
shape="square"
:size="32"
class="mr-12"
/>
{{ item.name }}
</div>
</div>
</el-card>
</el-col>
</el-row>
</div>
2024-01-10 09:44:05 +00:00
<div class="text-right">
<el-button @click="submit" type="primary"> 保存 </el-button>
2024-01-10 09:44:05 +00:00
</div>
</div>
</el-scrollbar>
</div>
</LayoutContainer>
</template>
<script setup lang="ts">
import { ref, onMounted, reactive } from 'vue'
import { useRoute } from 'vue-router'
import BaseForm from '@/views/dataset/component/BaseForm.vue'
import datasetApi from '@/api/dataset'
import type { ApplicationFormType } from '@/api/type/application'
import { MsgSuccess } from '@/utils/message'
import { isAppIcon } from '@/utils/application'
2024-01-10 09:44:05 +00:00
import useStore from '@/stores'
const route = useRoute()
const {
params: { id }
} = route as any
const { dataset } = useStore()
const webFormRef = ref()
const BaseFormRef = ref()
const loading = ref(false)
const detail = ref<any>({})
const application_list = ref<Array<ApplicationFormType>>([])
const application_id_list = ref([])
const form = ref<any>({
2024-01-10 10:36:04 +00:00
source_url: '',
2024-01-10 09:44:05 +00:00
selector: ''
})
const rules = reactive({
2024-01-10 10:36:04 +00:00
source_url: [{ required: true, message: '请输入 Web 根地址', trigger: 'blur' }]
2024-01-10 09:44:05 +00:00
})
async function submit() {
if (await BaseFormRef.value?.validate()) {
await webFormRef.value.validate((valid: any) => {
if (valid) {
loading.value = true
2024-01-10 10:36:04 +00:00
const obj =
detail.value.type === '1'
? {
2024-02-26 06:02:24 +00:00
application_id_list: application_id_list.value,
2024-02-28 07:49:22 +00:00
meta: form.value,
...BaseFormRef.value.form
2024-01-10 10:36:04 +00:00
}
: {
application_id_list: application_id_list.value,
...BaseFormRef.value.form
}
2024-01-10 09:44:05 +00:00
datasetApi
2024-04-15 10:46:03 +00:00
.putDataset(id, obj)
2024-01-10 09:44:05 +00:00
.then((res) => {
MsgSuccess('保存成功')
loading.value = false
})
.catch(() => {
loading.value = false
})
}
})
}
}
function getDetail() {
2024-04-15 10:46:03 +00:00
dataset.asyncGetDatasetDetail(id, loading).then((res: any) => {
2024-01-10 09:44:05 +00:00
detail.value = res.data
2024-01-10 10:36:04 +00:00
if (detail.value.type === '1') {
form.value = res.data.meta
}
2024-01-10 09:44:05 +00:00
application_id_list.value = res.data?.application_id_list
datasetApi.listUsableApplication(id, loading).then((ok) => {
application_list.value = ok.data
})
})
}
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
.dataset-setting {
width: 70%;
margin: 0 auto;
}
</style>