feat: 同步

This commit is contained in:
wangdan-fit2cloud 2024-01-10 17:44:05 +08:00
parent 7349f00c54
commit d0ca56d9fe
9 changed files with 365 additions and 122 deletions

View File

@ -97,8 +97,11 @@ const postWebDateset: (data: any, loading?: Ref<boolean>) => Promise<Result<any>
*
* @param dataset_id
*/
const getDatesetDetail: (dataset_id: string) => Promise<Result<any>> = (dataset_id) => {
return get(`${prefix}/${dataset_id}`)
const getDatesetDetail: (dataset_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
dataset_id,
loading
) => {
return get(`${prefix}/${dataset_id}`, undefined, loading)
}
/**
@ -144,6 +147,19 @@ const getDatasetHitTest: (
return get(`${prefix}/${dataset_id}/hit_test`, data, loading)
}
/**
*
* @param dataset_id
* @query sync_type // 同步类型->replace:替换同步,complete:完整同步
*/
const getSyncWebDateset: (
dataset_id: string,
sync_type: string,
loading?: Ref<boolean>
) => Promise<Result<any>> = (dataset_id, sync_type, loading) => {
return get(`${prefix}/${dataset_id}`, { sync_type }, loading)
}
export default {
getDateset,
getAllDateset,
@ -153,5 +169,6 @@ export default {
putDateset,
listUsableApplication,
getDatasetHitTest,
postWebDateset
postWebDateset,
getSyncWebDateset
}

View File

@ -60,7 +60,7 @@ const datasetRouter = {
parentPath: '/dataset/:id',
parentName: 'DatasetDetail'
},
component: () => import('@/views/document/DatasetSetting.vue')
component: () => import('@/views/dataset/DatasetSetting.vue')
}
]
},

View File

@ -38,6 +38,30 @@ const useDatasetStore = defineStore({
reject(error)
})
})
},
async asyncGetDatesetDetail(id: string, loading?: Ref<boolean>) {
return new Promise((resolve, reject) => {
datasetApi
.getDatesetDetail(id, loading)
.then((data) => {
resolve(data)
})
.catch((error) => {
reject(error)
})
})
},
async asyncSyncDateset(id: string, sync_type: string, loading?: Ref<boolean>) {
return new Promise((resolve, reject) => {
datasetApi
.getSyncWebDateset(id, sync_type, loading)
.then((data) => {
resolve(data)
})
.catch((error) => {
reject(error)
})
})
}
}
})

View File

@ -0,0 +1,150 @@
<template>
<LayoutContainer header="设置">
<div class="dataset-setting main-calc-height">
<el-scrollbar>
<div class="p-24" v-loading="loading">
<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">
<el-icon size="32" class="mr-8 info"><Document /></el-icon>
<div>
<p>通用型</p>
<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">
<el-icon size="32" class="mr-8 info"><Monitor /></el-icon>
<div>
<p>Web 站点</p>
<el-text type="info"> 通过网站链接同步方式构建知识库 </el-text>
</div>
</div>
</el-card>
</el-form-item>
<el-form-item label="Web 根地址" prop="url" v-if="detail.type === '1'">
<el-input
v-model="form.url"
placeholder="请输入 Web 根地址"
@blur="form.url = form.url.trim()"
/>
</el-form-item>
<el-form-item label="选择器" v-if="detail.type === '1'">
<el-input
v-model="form.selector"
placeholder="请输入选择器"
@blur="form.selector = form.selector.trim()"
/>
</el-form-item>
</el-form>
<h4 class="title-decoration-1 mb-16">关联应用</h4>
<el-row :gutter="12">
<el-col :span="12" v-for="(item, index) in application_list" :key="index" class="mb-16">
<CardCheckbox value-field="id" :data="item" v-model="application_id_list">
<template #icon>
<AppAvatar
v-if="item.name"
:name="item.name"
pinyinColor
class="mr-12"
shape="square"
:size="32"
/>
</template>
{{ item.name }}
</CardCheckbox>
</el-col>
</el-row>
<div class="text-right">
<el-button @click="submit" type="primary"> 保存 </el-button>
</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 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>({
url: '',
selector: ''
})
const rules = reactive({
url: [{ required: true, message: '请输入 Web 根地址', trigger: 'blur' }]
})
async function submit() {
if (await BaseFormRef.value?.validate()) {
await webFormRef.value.validate((valid: any) => {
if (valid) {
loading.value = true
const obj = {
application_id_list: application_id_list.value,
...BaseFormRef.value.form
}
datasetApi
.putDateset(id, obj)
.then((res) => {
MsgSuccess('保存成功')
loading.value = false
})
.catch(() => {
loading.value = false
})
}
})
}
}
function getDetail() {
dataset.asyncGetDatesetDetail(id, loading).then((res: any) => {
detail.value = res.data
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>

View File

@ -0,0 +1,88 @@
<template>
<el-dialog
title="同步知识库"
v-model="dialogVisible"
width="600px"
:close-on-click-modal="false"
:close-on-press-escape="false"
:destroy-on-close="true"
>
<p class="mb-8">同步方式</p>
<el-radio-group v-model="method" class="card__radio">
<el-card shadow="never" class="mb-16" :class="method === 'replace' ? 'active' : ''">
<el-radio label="replace" size="large">
<p class="mb-4">替换同步</p>
<el-text type="info">重新获取 Web 站点文档覆盖替换本地知识库中的文档</el-text>
</el-radio>
</el-card>
<el-card shadow="never" class="mb-16" :class="method === 'complete' ? 'active' : ''">
<el-radio label="complete" size="large">
<p class="mb-4">整体同步</p>
<el-text type="info">先删除本地知识库所有文档重新获取 Web 站点文档</el-text>
</el-radio>
</el-card>
</el-radio-group>
<p class="danger">注意所有同步都会删除已有数据重新获取新数据请谨慎操作</p>
<template #footer>
<span class="dialog-footer">
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
<el-button type="primary" @click="submit" :loading="loading"> 确定 </el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { MsgSuccess } from '@/utils/message'
import useStore from '@/stores'
const { dataset } = useStore()
const emit = defineEmits(['refresh'])
const loading = ref<boolean>(false)
const method = ref('replace')
const datasetId = ref('')
const dialogVisible = ref<boolean>(false)
watch(dialogVisible, (bool) => {
if (!bool) {
method.value = 'replace'
}
})
const open = (id: string) => {
datasetId.value = id
dialogVisible.value = true
}
const submit = () => {
dataset.asyncSyncDateset(datasetId.value, method.value, loading).then((res: any) => {
// MsgSuccess('')
emit('refresh', res.data)
dialogVisible.value = false
})
}
defineExpose({ open })
</script>
<style lang="scss" scoped>
.select-provider {
font-size: 16px;
color: rgba(100, 106, 115, 1);
font-weight: 400;
line-height: 24px;
cursor: pointer;
&:hover {
color: var(--el-color-primary);
}
}
.active-breadcrumb {
font-size: 16px;
color: rgba(31, 35, 41, 1);
font-weight: 500;
line-height: 24px;
}
</style>

View File

@ -53,7 +53,12 @@
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item icon="Refresh" v-if="item.type === '1'">同步</el-dropdown-item>
<el-dropdown-item
icon="Refresh"
@click.stop="syncDataset(item)"
v-if="item.type === '1'"
>同步</el-dropdown-item
>
<el-dropdown-item
icon="Setting"
@click.stop="router.push({ path: `/dataset/${item.id}/setting` })"
@ -74,16 +79,19 @@
</el-row>
</InfiniteScroll>
</div>
<SyncWebDialog ref="SyncWebDialogRef" @refresh="refresh" />
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, reactive, computed } from 'vue'
import SyncWebDialog from '@/views/dataset/component/SyncWebDialog.vue'
import datasetApi from '@/api/dataset'
import { MsgSuccess, MsgConfirm } from '@/utils/message'
import { useRouter } from 'vue-router'
import { numberFormat } from '@/utils/utils'
const router = useRouter()
const SyncWebDialogRef = ref()
const loading = ref(false)
const datasetList = ref<any[]>([])
const paginationConfig = reactive({
@ -94,6 +102,15 @@ const paginationConfig = reactive({
const searchValue = ref('')
function refresh(row: any) {
const index = datasetList.value.findIndex((v) => v.id === row.id)
datasetList.value.splice(index, 1, row)
}
function syncDataset(row: any) {
SyncWebDialogRef.value.open(row.id)
}
function searchHandle() {
paginationConfig.current_page = 1
datasetList.value = []

View File

@ -4,6 +4,7 @@
<!-- 基本信息 -->
<BaseForm ref="BaseFormRef" v-if="isCreate" />
<el-form
v-if="isCreate"
ref="webFormRef"
:rules="rules"
:model="form"

View File

@ -1,100 +0,0 @@
<template>
<LayoutContainer header="设置">
<div class="dataset-setting main-calc-height">
<el-scrollbar>
<div class="p-24" v-loading="loading">
<BaseForm ref="BaseFormRef" :data="detail" />
<h4 class="title-decoration-1 mb-16">关联应用</h4>
<el-row :gutter="12">
<el-col :span="12" v-for="(item, index) in application_list" :key="index" class="mb-16">
<CardCheckbox value-field="id" :data="item" v-model="application_id_list">
<template #icon>
<AppAvatar
v-if="item.name"
:name="item.name"
pinyinColor
class="mr-12"
shape="square"
:size="32"
/>
</template>
{{ item.name }}
</CardCheckbox>
</el-col>
</el-row>
<div class="text-right">
<el-button @click="submit" type="primary"> 保存 </el-button>
</div>
</div>
</el-scrollbar>
</div>
</LayoutContainer>
</template>
<script setup lang="ts">
import { ref, onMounted } 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'
const route = useRoute()
const {
params: { id }
} = route as any
const BaseFormRef = ref()
const loading = ref(false)
const detail = ref({})
const application_list = ref<Array<ApplicationFormType>>([])
const application_id_list = ref([])
async function submit() {
if (await BaseFormRef.value?.validate()) {
loading.value = true
const obj = {
application_id_list: application_id_list.value,
...BaseFormRef.value.form
}
datasetApi
.putDateset(id, obj)
.then((res) => {
MsgSuccess('保存成功')
loading.value = false
})
.catch(() => {
loading.value = false
})
}
}
function getDetail() {
loading.value = true
datasetApi
.getDatesetDetail(id)
.then((res) => {
detail.value = res.data
application_id_list.value = res.data?.application_id_list
datasetApi.listUsableApplication(id, loading).then((ok) => {
application_list.value = ok.data
loading.value = false
})
})
.catch(() => {
loading.value = false
})
}
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
.dataset-setting {
width: 70%;
margin: 0 auto;
}
</style>

View File

@ -3,11 +3,18 @@
<div class="main-calc-height">
<div class="p-24">
<div class="flex-between">
<el-button
type="primary"
@click="router.push({ path: '/dataset/upload', query: { id: id } })"
>上传文档</el-button
>
<div>
<el-button
v-if="datasetDetail.type === '0'"
type="primary"
@click="router.push({ path: '/dataset/upload', query: { id: id } })"
>上传文档</el-button
>
<el-button v-if="datasetDetail.type === '1'" type="primary">导入文档</el-button>
<!-- <el-button v-if="datasetDetail.type === '1'">批量同步</el-button> -->
<el-button>批量删除</el-button>
</div>
<el-input
v-model="filterText"
placeholder="按 文档名称 搜索"
@ -20,7 +27,7 @@
class="mt-16"
:data="documentData"
:pagination-config="paginationConfig"
quick-create
:quick-create="datasetDetail.type === '0'"
@sizeChange="handleSizeChange"
@changePage="getList"
@cell-mouse-enter="cellMouseEnter"
@ -80,20 +87,49 @@
</el-table-column>
<el-table-column label="操作" align="center">
<template #default="{ row }">
<span v-if="row.status === '2'" class="mr-4">
<el-tooltip effect="dark" content="重试" placement="top">
<div v-if="datasetDetail.type === '0'">
<span v-if="row.status === '2'" class="mr-4">
<el-tooltip effect="dark" content="重试" placement="top">
<el-button type="primary" text @click.stop="refreshDocument(row)">
<el-icon><RefreshRight /></el-icon>
</el-button>
</el-tooltip>
</span>
<span>
<el-tooltip effect="dark" content="删除" placement="top">
<el-button type="primary" text @click.stop="deleteDocument(row)">
<el-icon><Delete /></el-icon>
</el-button>
</el-tooltip>
</span>
</div>
<div v-if="datasetDetail.type === '1'">
<el-tooltip
effect="dark"
content="同步"
placement="top"
v-if="datasetDetail.type === '1'"
>
<el-button type="primary" text @click.stop="refreshDocument(row)">
<el-icon><RefreshRight /></el-icon>
<el-icon><Refresh /></el-icon>
</el-button>
</el-tooltip>
</span>
<span>
<el-tooltip effect="dark" content="删除" placement="top">
<el-button type="primary" text @click.stop="deleteDocument(row)">
<el-icon><Delete /></el-icon>
</el-button>
</el-tooltip>
</span>
<span @click.stop>
<el-dropdown trigger="click">
<span class="el-dropdown-link cursor">
<el-icon><MoreFilled /></el-icon>
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item icon="Setting">设置</el-dropdown-item>
<el-dropdown-item icon="Delete" @click.stop="deleteDocument(row)"
>删除</el-dropdown-item
>
</el-dropdown-menu>
</template>
</el-dropdown>
</span>
</div>
</template>
</el-table-column>
</app-table>
@ -108,17 +144,20 @@ import documentApi from '@/api/document'
import { numberFormat } from '@/utils/utils'
import { datetimeFormat } from '@/utils/time'
import { MsgSuccess, MsgConfirm } from '@/utils/message'
import useStore from '@/stores'
const router = useRouter()
const route = useRoute()
const {
params: { id }
} = route as any
const { dataset } = useStore()
const loading = ref(false)
let interval: any
const filterText = ref('')
const documentData = ref<any[]>([])
const currentMouseId = ref(null)
const datasetDetail = ref<any>({})
const paginationConfig = reactive({
current_page: 1,
@ -258,7 +297,14 @@ function getList(bool?: boolean) {
})
}
function getDetail() {
dataset.asyncGetDatesetDetail(id, loading).then((res: any) => {
datasetDetail.value = res.data
})
}
onMounted(() => {
getDetail()
getList()
//
initInterval()