【增加滚动分页】

pull/449/MERGE
cherishsince 2024-05-17 15:30:50 +08:00
parent da65de038e
commit 0d44b6cb37
2 changed files with 123 additions and 32 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="card-list"> <div class="card-list" ref="tabsRef" @scroll="handleTabsScroll">
<el-card class="card" body-class="card-body" v-for="role in roleList" :key="role.id"> <el-card class="card" body-class="card-body" v-for="role in roleList" :key="role.id">
<!-- 更多 --> <!-- 更多 -->
<div class="more-container"> <div class="more-container">
@ -42,18 +42,24 @@
<script setup lang="ts"> <script setup lang="ts">
import {ChatRoleVO} from '@/api/ai/model/chatRole' import {ChatRoleVO} from '@/api/ai/model/chatRole'
import {PropType} from "vue"; import {PropType, ref} from "vue";
import {Delete, EditPen, More} from "@element-plus/icons-vue"; import {Delete, EditPen, More} from "@element-plus/icons-vue";
const tabsRef = ref<any>() // tabs ref
// //
const props = defineProps({ const props = defineProps({
loading: {
type: Boolean,
required: true
},
roleList: { roleList: {
type: Array as PropType<ChatRoleVO[]>, type: Array as PropType<ChatRoleVO[]>,
required: true required: true
} }
}) })
// //
const emits = defineEmits(['onDelete', 'onEdit', 'onUse']) const emits = defineEmits(['onDelete', 'onEdit', 'onUse', 'onPage'])
// more // more
const handleMoreClick = async (data) => { const handleMoreClick = async (data) => {
@ -71,6 +77,19 @@ const handleUseClick = (role) => {
emits('onUse', role) emits('onUse', role)
} }
const handleTabsScroll = async () => {
if (tabsRef.value) {
const { scrollTop, scrollHeight, clientHeight } = tabsRef.value;
console.log('scrollTop', scrollTop)
if (scrollTop + clientHeight >= scrollHeight - 20 && !props.loading) {
console.log('分页')
// page.value++;
// fetchData(page.value);
await emits('onPage')
}
}
}
onMounted(() => { onMounted(() => {
console.log('props', props.roleList) console.log('props', props.roleList)
}) })
@ -99,6 +118,9 @@ onMounted(() => {
flex-direction: row; flex-direction: row;
flex-wrap: wrap; flex-wrap: wrap;
position: relative; position: relative;
height: 100%;
overflow: auto;
padding: 0px 25px;
.card { .card {
margin-right: 20px; margin-right: 20px;

View File

@ -1,13 +1,15 @@
<!-- chat 角色仓库 --> <!-- chat 角色仓库 -->
<template> <template>
<el-container class="role-container"> <el-container class="role-container">
<ChatRoleForm ref="formRef" @success="handlerAddRoleSuccess" /> <ChatRoleForm ref="formRef" @success="handlerAddRoleSuccess"/>
<!-- header -->
<Header title="角色仓库"/> <Header title="角色仓库" style="position: relative"/>
<!-- main -->
<el-main class="role-main"> <el-main class="role-main">
<div class="search-container"> <div class="search-container">
<!-- 搜索按钮 --> <!-- 搜索按钮 -->
<el-input <el-input
:loading="loading"
v-model="search" v-model="search"
class="search-input" class="search-input"
size="default" size="default"
@ -16,18 +18,38 @@
@change="getActiveTabsRole" @change="getActiveTabsRole"
/> />
<el-button type="primary" @click="handlerAddRole" style="margin-left: 20px;"> <el-button type="primary" @click="handlerAddRole" style="margin-left: 20px;">
<el-icon><User /></el-icon> <el-icon>
<User/>
</el-icon>
添加角色 添加角色
</el-button> </el-button>
</div> </div>
<!-- tabs --> <!-- tabs -->
<el-tabs v-model="activeRole" class="tabs" @tab-click="handleTabsClick"> <el-tabs v-model="activeRole" class="tabs" @tab-click="handleTabsClick">
<el-tab-pane class="role-pane" label="我的角色" name="my-role"> <el-tab-pane class="role-pane" label="我的角色" name="my-role">
<RoleList :role-list="myRoleList" @onDelete="handlerCardDelete" @onEdit="handlerCardEdit" @onUse="handlerCardUse" style="margin-top: 20px;" /> <RoleList
:loading="loading"
:role-list="myRoleList"
@on-delete="handlerCardDelete"
@on-edit="handlerCardEdit"
@on-use="handlerCardUse"
@on-page="handlerCardPage('my')"
style="margin-top: 20px;"/>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="公共角色" name="public-role"> <el-tab-pane label="公共角色" name="public-role">
<RoleCategoryList :category-list="categoryList" :active="activeCategory" @onCategoryClick="handlerCategoryClick" /> <RoleCategoryList
<RoleList :role-list="publicRoleList" @onDelete="handlerCardDelete" @onEdit="handlerCardEdit" style="margin-top: 20px;" /> class="role-category-list"
:category-list="categoryList"
:active="activeCategory"
@on-category-click="handlerCategoryClick"
/>
<RoleList
:role-list="publicRoleList"
@on-delete="handlerCardDelete"
@on-edit="handlerCardEdit"
@on-page="handlerCardPage('public')"
style="margin-top: 20px;"
/>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</el-main> </el-main>
@ -51,14 +73,14 @@ import {Search, User} from "@element-plus/icons-vue";
const router = useRouter() const router = useRouter()
// //
const loading = ref<boolean>(false) //
const activeRole = ref<string>('my-role') // const activeRole = ref<string>('my-role') //
const loadding = ref<boolean>(true) //
const search = ref<string>('') // const search = ref<string>('') //
const myPageNo = ref<number>(1) // my const myPageNo = ref<number>(1) // my
const myPageSize = ref<number>(20) // my const myPageSize = ref<number>(50) // my
const myRoleList = ref<ChatRoleVO[]>([]) // my const myRoleList = ref<ChatRoleVO[]>([]) // my
const publicPageNo = ref<number>(1) // public const publicPageNo = ref<number>(1) // public
const publicPageSize = ref<number>(20) // public const publicPageSize = ref<number>(50) // public
const publicRoleList = ref<ChatRoleVO[]>([]) // public const publicRoleList = ref<ChatRoleVO[]>([]) // public
const activeCategory = ref<string>('') // const activeCategory = ref<string>('') //
const categoryList = ref<string[]>([]) // const categoryList = ref<string[]>([]) //
@ -74,29 +96,38 @@ const handleTabsClick = async (tab: TabsPaneContext) => {
} }
// my role // my role
const getMyRole = async () => { const getMyRole = async (append?: boolean) => {
const params:ChatRolePageReqVO = { const params: ChatRolePageReqVO = {
pageNo: myPageNo.value, pageNo: myPageNo.value,
pageSize: myPageSize.value, pageSize: myPageSize.value,
category: activeCategory.value, category: activeCategory.value,
name: search.value, name: search.value,
publicStatus: false publicStatus: false
} }
const { total, list } = await ChatRoleApi.getMyPage(params) const {total, list} = await ChatRoleApi.getMyPage(params)
myRoleList.value = list if (append) {
myRoleList.value.push.apply(myRoleList.value, list)
console.log('myRoleList.value.push', myRoleList.value)
} else {
myRoleList.value = list
}
} }
// public role // public role
const getPublicRole = async () => { const getPublicRole = async (append?: boolean) => {
const params:ChatRolePageReqVO = { const params: ChatRolePageReqVO = {
pageNo: publicPageNo.value, pageNo: publicPageNo.value,
pageSize: publicPageSize.value, pageSize: publicPageSize.value,
category: activeCategory.value, category: activeCategory.value,
name: search.value, name: search.value,
publicStatus: true publicStatus: true
} }
const { total, list } = await ChatRoleApi.getMyPage(params) const {total, list} = await ChatRoleApi.getMyPage(params)
publicRoleList.value = list if (append) {
publicRoleList.value.push.apply(publicRoleList.value, list)
} else {
publicRoleList.value = list
}
} }
// tabs // tabs
@ -140,9 +171,26 @@ const handlerCardEdit = async (role) => {
formRef.value.open('my-update', role.id, '编辑角色') formRef.value.open('my-update', role.id, '编辑角色')
} }
// card
const handlerCardPage = async (type) => {
console.log('handlerCardPage', type)
try {
loading.value = true
if (type === 'public') {
publicPageNo.value++
await getPublicRole(true)
} else {
myPageNo.value++
await getMyRole(true)
}
} finally {
loading.value = false
}
}
// card 使 // card 使
const handlerCardUse = async (role) => { const handlerCardUse = async (role) => {
const data : ChatConversationVO = { const data: ChatConversationVO = {
roleId: role.id roleId: role.id
} as unknown as ChatConversationVO } as unknown as ChatConversationVO
// //
@ -157,47 +205,60 @@ const handlerCardUse = async (role) => {
} }
// //
const handlerAddRoleSuccess = async (e) => { const handlerAddRoleSuccess = async (e) => {
console.log(e) console.log(e)
// //
await getActiveTabsRole() await getActiveTabsRole()
} }
// //
onMounted( async () => { onMounted(async () => {
// //
await getRoleCategoryList() await getRoleCategoryList()
// role // role
await getActiveTabsRole() await getActiveTabsRole()
}) })
</script> </script>
<style lang="css">
.el-tabs__content {
position: relative;
height: 100%;
overflow: hidden;
}
.el-tabs__nav-scroll {
margin: 10px 20px;
}
</style>
<!-- 样式 --> <!-- 样式 -->
<style scoped lang="scss"> <style scoped lang="scss">
// //
.role-container { .role-container {
position: absolute; position: absolute;
margin: 0;
padding: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
margin: 0;
padding: 0;
left: 0; left: 0;
right: 0; right: 0;
top: 0; top: 0;
bottom: 0; bottom: 0;
background-color: #ffffff; background-color: #ffffff;
overflow: hidden;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
.role-main { .role-main {
position: relative; flex: 1;
overflow: hidden;
margin: 0;
padding: 0;
.search-container { .search-container {
//position: absolute; margin: 20px 20px 0px 20px;
//right: 20px;
//top: 10px;
//z-index: 100;
} }
.search-input { .search-input {
@ -206,11 +267,19 @@ onMounted( async () => {
.tabs { .tabs {
position: relative; position: relative;
height: 100%;
.role-category-list {
margin: 0 27px;
}
} }
.role-pane { .role-pane {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100%;
overflow-y: auto;
position: relative;
} }
} }
} }