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

170 lines
5.5 KiB
Vue
Raw Normal View History

2023-10-16 10:58:51 +00:00
<template>
2023-12-04 08:55:54 +00:00
<div class="dataset-list-container p-24" style="padding-top: 16px">
2023-12-04 09:24:00 +00:00
<div class="flex-between mb-16">
2023-12-18 03:32:29 +00:00
<h3>知识库</h3>
2023-11-10 09:18:00 +00:00
<el-input
2023-12-06 11:09:54 +00:00
v-model="searchValue"
@change="searchHandle"
2023-11-10 09:18:00 +00:00
placeholder="按 名称 搜索"
prefix-icon="Search"
class="w-240"
/>
2023-11-02 01:56:14 +00:00
</div>
2023-12-11 02:35:26 +00:00
<div v-loading.fullscreen.lock="paginationConfig.current_page === 1 && loading">
<InfiniteScroll
:size="datasetList.length"
:total="paginationConfig.total"
:page_size="paginationConfig.page_size"
v-model:current_page="paginationConfig.current_page"
@load="getList"
:loading="loading"
2023-11-02 01:56:14 +00:00
>
2023-12-11 02:35:26 +00:00
<el-row :gutter="15">
2023-12-06 11:09:54 +00:00
<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb-16">
2023-12-18 03:32:29 +00:00
<CardAdd title="创建知识库" @click="router.push({ path: '/dataset/create' })" />
2023-12-06 11:09:54 +00:00
</el-col>
2023-12-11 02:35:26 +00:00
<template v-for="(item, index) in datasetList" :key="index">
<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb-16">
<CardBox
:title="item.name"
:description="item.desc"
class="cursor"
@click="router.push({ path: `/dataset/${item.id}/document` })"
>
2024-01-09 09:49:47 +00:00
<div class="delete-button">
<el-tag v-if="item.type === '0'"></el-tag>
<el-tag v-else-if="item.type === '1'" type="warning">Web 站点</el-tag>
</div>
2023-12-11 02:35:26 +00:00
<template #footer>
2024-01-09 09:49:47 +00:00
<div class="footer-content flex-between">
<div>
<span class="bold">{{ item?.document_count || 0 }}</span>
文档<el-divider direction="vertical" />
<span class="bold">{{ numberFormat(item?.char_length) || 0 }}</span>
字符<el-divider direction="vertical" />
<span class="bold">{{ item?.application_mapping_count || 0 }}</span>
关联应用
</div>
<div @click.stop>
<el-dropdown trigger="click">
2024-01-17 10:06:24 +00:00
<el-button text @click.stop>
2024-01-09 09:49:47 +00:00
<el-icon><MoreFilled /></el-icon>
2024-01-17 10:06:24 +00:00
</el-button>
2024-01-09 09:49:47 +00:00
<template #dropdown>
<el-dropdown-menu>
2024-01-10 09:44:05 +00:00
<el-dropdown-item
icon="Refresh"
@click.stop="syncDataset(item)"
v-if="item.type === '1'"
>同步</el-dropdown-item
>
2024-01-09 09:49:47 +00:00
<el-dropdown-item
icon="Setting"
@click.stop="router.push({ path: `/dataset/${item.id}/setting` })"
>设置</el-dropdown-item
>
<el-dropdown-item icon="Delete" @click.stop="deleteDateset(item)"
>删除</el-dropdown-item
>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
2023-12-11 02:35:26 +00:00
</div>
</template>
</CardBox>
</el-col>
</template>
</el-row>
</InfiniteScroll>
2023-09-15 09:40:35 +00:00
</div>
2024-01-10 09:44:05 +00:00
<SyncWebDialog ref="SyncWebDialogRef" @refresh="refresh" />
2023-11-02 01:56:14 +00:00
</div>
2023-09-15 09:40:35 +00:00
</template>
<script setup lang="ts">
2023-12-06 11:09:54 +00:00
import { ref, onMounted, reactive, computed } from 'vue'
2024-01-10 09:44:05 +00:00
import SyncWebDialog from '@/views/dataset/component/SyncWebDialog.vue'
2023-10-25 10:35:28 +00:00
import datasetApi from '@/api/dataset'
2023-10-26 10:37:13 +00:00
import { MsgSuccess, MsgConfirm } from '@/utils/message'
2023-10-27 09:49:06 +00:00
import { useRouter } from 'vue-router'
2023-11-07 07:30:15 +00:00
import { numberFormat } from '@/utils/utils'
2023-10-27 09:49:06 +00:00
const router = useRouter()
2023-10-25 10:35:28 +00:00
2024-01-10 09:44:05 +00:00
const SyncWebDialogRef = ref()
2023-10-25 10:35:28 +00:00
const loading = ref(false)
const datasetList = ref<any[]>([])
2023-12-11 02:35:26 +00:00
const paginationConfig = reactive({
2023-10-25 10:35:28 +00:00
current_page: 1,
page_size: 20,
2023-12-06 11:09:54 +00:00
total: 0
2023-10-25 10:35:28 +00:00
})
2023-12-06 11:09:54 +00:00
const searchValue = ref('')
2024-01-10 09:44:05 +00:00
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)
}
2023-12-06 11:09:54 +00:00
function searchHandle() {
2023-12-11 02:35:26 +00:00
paginationConfig.current_page = 1
2023-12-06 11:09:54 +00:00
datasetList.value = []
2023-11-10 09:18:00 +00:00
getList()
}
2023-10-26 10:37:13 +00:00
function deleteDateset(row: any) {
2023-10-27 09:49:06 +00:00
MsgConfirm(
2023-12-18 03:32:29 +00:00
`是否删除知识库:${row.name} ?`,
2023-12-26 08:56:14 +00:00
`此知识库关联 ${row.application_mapping_count} 个应用,删除后无法恢复,请谨慎操作。`,
2023-10-27 09:49:06 +00:00
{
2023-11-08 11:08:54 +00:00
confirmButtonText: '删除',
2023-10-27 09:49:06 +00:00
confirmButtonClass: 'danger'
}
)
2023-10-26 10:37:13 +00:00
.then(() => {
2023-12-12 06:30:03 +00:00
datasetApi.delDateset(row.id, loading).then(() => {
const index = datasetList.value.findIndex((v) => v.id === row.id)
datasetList.value.splice(index, 1)
MsgSuccess('删除成功')
})
2023-10-26 10:37:13 +00:00
})
.catch(() => {})
}
2023-10-25 10:35:28 +00:00
function getList() {
datasetApi
2023-12-11 02:35:26 +00:00
.getDateset(paginationConfig, searchValue.value && { name: searchValue.value }, loading)
2023-10-25 10:35:28 +00:00
.then((res) => {
2023-12-11 02:35:26 +00:00
paginationConfig.total = res.data.total
2023-12-06 11:09:54 +00:00
datasetList.value = [...datasetList.value, ...res.data.records]
2023-10-25 10:35:28 +00:00
})
}
2023-09-15 09:40:35 +00:00
2023-10-25 10:35:28 +00:00
onMounted(() => {
getList()
})
2023-09-15 09:40:35 +00:00
</script>
2023-10-25 10:35:28 +00:00
<style lang="scss" scoped>
.dataset-list-container {
.delete-button {
position: absolute;
2023-11-03 08:12:57 +00:00
right: 12px;
top: 18px;
height: auto;
}
.footer-content {
.bold {
2023-11-13 11:02:13 +00:00
color: var(--app-text-color);
2023-11-03 08:12:57 +00:00
}
2023-10-25 10:35:28 +00:00
}
2023-12-29 07:13:30 +00:00
:deep(.el-divider__text) {
background: var(--app-layout-bg-color);
}
2023-10-25 10:35:28 +00:00
}
</style>