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

158 lines
4.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-11-02 01:56:14 +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-06 11:09:54 +00:00
<div v-loading.fullscreen.lock="pageConfig.current_page === 1 && loading">
2023-11-02 01:56:14 +00:00
<el-row
:gutter="15"
v-infinite-scroll="loadDataset"
:infinite-scroll-disabled="disabledScroll"
>
2023-12-04 09:24:00 +00:00
<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb-16">
2023-11-02 01:56:14 +00:00
<CardAdd title="创建数据集" @click="router.push({ path: '/dataset/create' })" />
</el-col>
2023-12-06 11:09:54 +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` })"
>
<template #mouseEnter>
<el-tooltip effect="dark" content="删除" placement="top">
<el-button text @click.stop="deleteDateset(item)" class="delete-button">
<el-icon><Delete /></el-icon>
</el-button>
</el-tooltip>
</template>
2023-10-25 10:35:28 +00:00
2023-12-06 11:09:54 +00:00
<template #footer>
<div class="footer-content">
<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>
</template>
</CardBox>
</el-col>
</template>
2023-11-02 01:56:14 +00:00
</el-row>
2023-12-06 11:09:54 +00:00
<div style="padding: 16px 10px">
<el-divider class="custom-divider" v-if="datasetList.length > 0 && loading">
<el-text type="info"> 加载中...</el-text>
</el-divider>
<el-divider class="custom-divider" v-if="noMore">
<el-text type="info"> 到底啦</el-text>
</el-divider>
</div>
2023-09-15 09:40:35 +00:00
</div>
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'
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
const loading = ref(false)
const datasetList = ref<any[]>([])
2023-12-06 11:09:54 +00:00
const pageConfig = 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('')
const noMore = computed(
() =>
datasetList.value.length > 0 &&
datasetList.value.length === pageConfig.total &&
2023-12-07 07:22:07 +00:00
pageConfig.total > 20 &&
!loading.value
2023-12-06 11:09:54 +00:00
)
const disabledScroll = computed(
() => datasetList.value.length > 0 && (loading.value || noMore.value)
)
function loadDataset() {
if (pageConfig.total > pageConfig.page_size) {
pageConfig.current_page += 1
getList()
}
}
2023-10-26 10:37:13 +00:00
2023-12-06 11:09:54 +00:00
function searchHandle() {
2023-11-10 09:18:00 +00:00
pageConfig.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-11-10 03:36:04 +00:00
`是否删除数据集:${row.name} ?`,
2023-11-08 11:08:54 +00:00
`此数据集关联 ${row.char_length} 个应用,删除后无法恢复,请谨慎操作。`,
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(() => {
loading.value = true
2023-10-27 09:49:06 +00:00
datasetApi
.delDateset(row.id)
2023-10-26 10:37:13 +00:00
.then(() => {
2023-12-07 07:22:07 +00:00
const index = datasetList.value.findIndex((v) => v.id === row.id)
datasetList.value.splice(index, 1)
2023-10-26 10:37:13 +00:00
MsgSuccess('删除成功')
})
.catch(() => {
loading.value = false
})
})
.catch(() => {})
}
2023-10-25 10:35:28 +00:00
function getList() {
datasetApi
2023-12-06 11:09:54 +00:00
.getDateset(pageConfig, searchValue.value && { name: searchValue.value }, loading)
2023-10-25 10:35:28 +00:00
.then((res) => {
2023-12-06 11:09:54 +00:00
pageConfig.total = res.data.total
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
}
}
</style>