【增加滚动分页】

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>
<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">
<!-- 更多 -->
<div class="more-container">
@ -42,18 +42,24 @@
<script setup lang="ts">
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";
const tabsRef = ref<any>() // tabs ref
//
const props = defineProps({
loading: {
type: Boolean,
required: true
},
roleList: {
type: Array as PropType<ChatRoleVO[]>,
required: true
}
})
//
const emits = defineEmits(['onDelete', 'onEdit', 'onUse'])
const emits = defineEmits(['onDelete', 'onEdit', 'onUse', 'onPage'])
// more
const handleMoreClick = async (data) => {
@ -71,6 +77,19 @@ const handleUseClick = (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(() => {
console.log('props', props.roleList)
})
@ -99,6 +118,9 @@ onMounted(() => {
flex-direction: row;
flex-wrap: wrap;
position: relative;
height: 100%;
overflow: auto;
padding: 0px 25px;
.card {
margin-right: 20px;

View File

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