feat: 分页

This commit is contained in:
wangdan-fit2cloud 2023-12-06 19:09:54 +08:00
parent ee9ee02c22
commit 79807c2f6d
6 changed files with 153 additions and 103 deletions

View File

@ -16,17 +16,20 @@ const getAllAppilcation: () => Promise<Result<any[]>> = () => {
/** /**
* *
* @param { * page {
"current_page": "string", "current_page": "string",
"page_size": "string", "page_size": "string",
}
* param {
"name": "string", "name": "string",
} }
*/ */
const getApplication: (param: pageRequest) => Promise<Result<any>> = (param) => { const getApplication: (
return get( page: pageRequest,
`${prefix}/${param.current_page}/${param.page_size}`, param: any,
param.name && { name: param.name } loading?: Ref<boolean>
) ) => Promise<Result<any>> = (page, param, loading) => {
return get(`${prefix}/${page.current_page}/${page.page_size}`, param, loading)
} }
/** /**
@ -221,7 +224,6 @@ const putChatVote: (
) )
} }
export default { export default {
getAllAppilcation, getAllAppilcation,
getApplication, getApplication,
@ -237,5 +239,5 @@ export default {
getAccessToken, getAccessToken,
postAppAuthentication, postAppAuthentication,
getProfile, getProfile,
putChatVote, putChatVote
} }

View File

@ -8,17 +8,21 @@ const prefix = '/dataset'
/** /**
* *
* @param { * @param
* page {
"current_page": "string", "current_page": "string",
"page_size": "string", "page_size": "string",
}
* param {
"name": "string", "name": "string",
} }
*/ */
const getDateset: (param: pageRequest) => Promise<Result<any>> = (param) => { const getDateset: (
return get( page: pageRequest,
`${prefix}/${param.current_page}/${param.page_size}`, param: any,
param.name && { name: param.name } loading?: Ref<boolean>
) ) => Promise<Result<any>> = (page, param, loading) => {
return get(`${prefix}/${page.current_page}/${page.page_size}`, param, loading)
} }
/** /**

View File

@ -421,10 +421,15 @@ h4 {
} }
} }
.file-List-card { .file-List-card {
border-radius: 4px; border-radius: 4px;
.el-card__body { .el-card__body {
padding: 8px 16px 8px 12px; padding: 8px 16px 8px 12px;
} }
} }
.custom-divider {
.el-divider__text {
background: var(--app-layout-bg-color);
}
}

View File

@ -3,14 +3,14 @@
<div class="flex-between mb-16"> <div class="flex-between mb-16">
<h3>应用</h3> <h3>应用</h3>
<el-input <el-input
v-model="pageConfig.name" v-model="searchValue"
@change="search" @change="searchHandle"
placeholder="按 名称 搜索" placeholder="按 名称 搜索"
prefix-icon="Search" prefix-icon="Search"
class="w-240" class="w-240"
/> />
</div> </div>
<div v-loading.fullscreen.lock="loading"> <div v-loading.fullscreen.lock="pageConfig.current_page === 1 && loading">
<el-row <el-row
:gutter="15" :gutter="15"
v-infinite-scroll="loadDataset" v-infinite-scroll="loadDataset"
@ -92,13 +92,20 @@
</CardBox> </CardBox>
</el-col> </el-col>
</el-row> </el-row>
<div style="padding: 16px 10px">
<el-divider class="custom-divider" v-if="applicationList.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>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, reactive } from 'vue' import { ref, onMounted, reactive, computed } from 'vue'
import applicationApi from '@/api/application' import applicationApi from '@/api/application'
import type { pageRequest } from '@/api/type/common'
import { MsgSuccess, MsgConfirm } from '@/utils/message' import { MsgSuccess, MsgConfirm } from '@/utils/message'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import useStore from '@/stores' import useStore from '@/stores'
@ -106,22 +113,40 @@ const { application } = useStore()
const router = useRouter() const router = useRouter()
const loading = ref(false) const loading = ref(false)
const disabledScroll = ref(false)
const pageConfig = reactive<pageRequest>({
current_page: 1,
page_size: 20,
name: ''
})
const applicationList = ref<any[]>([]) const applicationList = ref<any[]>([])
function loadDataset() {} const pageConfig = reactive({
current_page: 1,
page_size: 20,
total: 0
})
function search() { const searchValue = ref('')
pageConfig.current_page = 1
const noMore = computed(
() =>
applicationList.value.length > 0 &&
applicationList.value.length === pageConfig.total &&
pageConfig.total > 20
)
const disabledScroll = computed(
() => applicationList.value.length > 0 && (loading.value || noMore.value)
)
function loadDataset() {
if (pageConfig.total > pageConfig.page_size) {
pageConfig.current_page += 1
getList() getList()
} }
}
function searchHandle() {
pageConfig.total = 0
pageConfig.current_page = 1
applicationList.value = []
getList()
}
function getAccessToken(id: string) { function getAccessToken(id: string) {
application.asyncGetAccessToken(id, loading).then((res) => { application.asyncGetAccessToken(id, loading).then((res) => {
window.open(application.location + res?.data?.access_token) window.open(application.location + res?.data?.access_token)
@ -164,15 +189,11 @@ function deleteApplication(row: any) {
// } // }
function getList() { function getList() {
loading.value = true
applicationApi applicationApi
.getApplication(pageConfig) .getApplication(pageConfig, searchValue.value && { name: searchValue.value }, loading)
.then((res) => { .then((res) => {
applicationList.value = res.data?.records applicationList.value = [...applicationList.value, ...res.data.records]
loading.value = false pageConfig.total = res.data.total
})
.catch(() => {
loading.value = false
}) })
} }

View File

@ -3,14 +3,14 @@
<div class="flex-between mb-16"> <div class="flex-between mb-16">
<h3>数据集</h3> <h3>数据集</h3>
<el-input <el-input
v-model="pageConfig.name" v-model="searchValue"
@change="search" @change="searchHandle"
placeholder="按 名称 搜索" placeholder="按 名称 搜索"
prefix-icon="Search" prefix-icon="Search"
class="w-240" class="w-240"
/> />
</div> </div>
<div v-loading.fullscreen.lock="loading"> <div v-loading.fullscreen.lock="pageConfig.current_page === 1 && loading">
<el-row <el-row
:gutter="15" :gutter="15"
v-infinite-scroll="loadDataset" v-infinite-scroll="loadDataset"
@ -19,16 +19,8 @@
<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb-16"> <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb-16">
<CardAdd title="创建数据集" @click="router.push({ path: '/dataset/create' })" /> <CardAdd title="创建数据集" @click="router.push({ path: '/dataset/create' })" />
</el-col> </el-col>
<el-col <template v-for="(item, index) in datasetList" :key="index">
:xs="24" <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb-16">
:sm="12"
:md="8"
:lg="6"
:xl="4"
v-for="(item, index) in datasetList"
:key="index"
class="mb-16"
>
<CardBox <CardBox
:title="item.name" :title="item.name"
:description="item.desc" :description="item.desc"
@ -55,14 +47,22 @@
</template> </template>
</CardBox> </CardBox>
</el-col> </el-col>
</template>
</el-row> </el-row>
<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>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, reactive } from 'vue' import { ref, onMounted, reactive, computed } from 'vue'
import datasetApi from '@/api/dataset' import datasetApi from '@/api/dataset'
import type { pageRequest } from '@/api/type/common'
import { MsgSuccess, MsgConfirm } from '@/utils/message' import { MsgSuccess, MsgConfirm } from '@/utils/message'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { numberFormat } from '@/utils/utils' import { numberFormat } from '@/utils/utils'
@ -70,17 +70,34 @@ const router = useRouter()
const loading = ref(false) const loading = ref(false)
const datasetList = ref<any[]>([]) const datasetList = ref<any[]>([])
const disabledScroll = ref(false) const pageConfig = reactive({
const pageConfig = reactive<pageRequest>({
current_page: 1, current_page: 1,
page_size: 20, page_size: 20,
name: '' total: 0
}) })
function loadDataset() {} const searchValue = ref('')
function search() { const noMore = computed(
() =>
datasetList.value.length > 0 &&
datasetList.value.length === pageConfig.total &&
pageConfig.total > 20
)
const disabledScroll = computed(
() => datasetList.value.length > 0 && (loading.value || noMore.value)
)
function loadDataset() {
if (pageConfig.total > pageConfig.page_size) {
pageConfig.current_page += 1
getList()
}
}
function searchHandle() {
pageConfig.current_page = 1 pageConfig.current_page = 1
datasetList.value = []
getList() getList()
} }
@ -109,15 +126,11 @@ function deleteDateset(row: any) {
} }
function getList() { function getList() {
loading.value = true
datasetApi datasetApi
.getDateset(pageConfig) .getDateset(pageConfig, searchValue.value && { name: searchValue.value }, loading)
.then((res) => { .then((res) => {
datasetList.value = res.data?.records pageConfig.total = res.data.total
loading.value = false datasetList.value = [...datasetList.value, ...res.data.records]
})
.catch(() => {
loading.value = false
}) })
} }

View File

@ -26,7 +26,7 @@
<el-scrollbar> <el-scrollbar>
<div class="document-detail-height" v-loading="pageConfig.current_page === 1 && loading"> <div class="document-detail-height" v-loading="pageConfig.current_page === 1 && loading">
<el-empty v-if="paragraphDetail.length == 0" description="暂无数据" /> <el-empty v-if="paragraphDetail.length == 0" description="暂无数据" />
<el-row v-else v-infinite-scroll="loadDataset" :infinite-scroll-disabled="disabledLoad"> <el-row v-else v-infinite-scroll="loadDataset" :infinite-scroll-disabled="disabledScroll">
<el-col <el-col
:xs="24" :xs="24"
:sm="12" :sm="12"
@ -111,16 +111,21 @@ const pageConfig = reactive({
}) })
const noMore = computed( const noMore = computed(
() => paragraphDetail.value.length > 0 && paragraphDetail.value.length === pageConfig.total () =>
paragraphDetail.value.length > 0 &&
paragraphDetail.value.length === pageConfig.total &&
pageConfig.total > 20
) )
const disabledLoad = computed( const disabledScroll = computed(
() => paragraphDetail.value.length > 0 && (loading.value || noMore.value) () => paragraphDetail.value.length > 0 && (loading.value || noMore.value)
) )
function loadDataset() { function loadDataset() {
if (pageConfig.total > pageConfig.page_size) {
pageConfig.current_page += 1 pageConfig.current_page += 1
getParagraphList() getParagraphList()
} }
}
function searchHandle() { function searchHandle() {
pageConfig.current_page = 1 pageConfig.current_page = 1