88 <span class =" ml-4" >{{ item?.name }}</span >
99 </div >
1010 </template >
11- <el-scrollbar >
11+ <el-scrollbar ref = " scrollRef " :key = " index " >
1212 <div class =" mb-16" >
1313 <el-text type =" info" >{{ item.content.length }} 段落</el-text >
1414 </div >
15-
16- <div class =" paragraph-list" >
15+ <div class =" paragraph-list" v-infinite-scroll =" loadScroll" >
1716 <el-card
18- v-for =" (child, cIndex) in item.content "
17+ v-for =" (child, cIndex) in scrollData "
1918 :key =" cIndex"
2019 shadow =" never"
2120 class =" card-never mb-16"
5251 />
5352</template >
5453<script setup lang="ts">
55- import { ref , reactive , onMounted , watch } from ' vue'
54+ import { ref , reactive , onMounted , watch , nextTick } from ' vue'
5655import { cloneDeep } from ' lodash'
5756import type { TabsPaneContext } from ' element-plus'
5857import EditParagraphDialog from ' ./EditParagraphDialog.vue'
@@ -70,23 +69,49 @@ const props = defineProps({
7069const emit = defineEmits ([' update:data' ])
7170
7271const EditParagraphDialogRef = ref ()
72+ const scrollRef = ref ()
7373
7474const activeName = ref (0 )
7575const currentPIndex = ref (null ) as any
7676const currentCIndex = ref (null ) as any
7777
7878const newData = ref <any []>([])
7979
80+ // 滚动加载数据
81+ const paginationConfig = reactive ({
82+ current_page: 1 ,
83+ page_size: 20
84+ })
85+
86+ const scrollData = ref <any []>([])
87+
8088watch (
8189 () => props .data ,
8290 (value ) => {
8391 newData .value = value
92+ paginationConfig .current_page = 1
93+ nextTick (() => {
94+ scrollRef .value ?.[activeName .value ]?.scrollTo (0 , 0 )
95+ })
96+ scrollData .value = newData .value [activeName .value ]?.content .slice (0 , paginationConfig .page_size )
8497 },
8598 {
8699 immediate: true
87100 }
88101)
89102
103+ function loadScroll() {
104+ if (newData .value [activeName .value ]?.content .length > scrollData .value .length ) {
105+ paginationConfig .current_page += 1
106+ scrollData .value .push (
107+ ... newData .value [activeName .value ].content .slice (
108+ (paginationConfig .current_page - 1 ) * paginationConfig .page_size ,
109+ paginationConfig .current_page * paginationConfig .page_size
110+ )
111+ )
112+ }
113+ }
114+
90115function editHandle(item : any , index : number , cIndex : number ) {
91116 currentPIndex .value = index
92117 currentCIndex .value = cIndex
@@ -100,17 +125,22 @@ function deleteHandle(item: any, index: number, cIndex: number) {
100125 })
101126 .then (() => {
102127 newData .value [index ].content .splice (cIndex , 1 )
128+ scrollData .value .splice (cIndex , 1 )
103129 emit (' update:data' , newData .value )
104130 })
105131 .catch (() => {})
106132}
107133
108134function updateContent(data : any ) {
109135 newData .value [currentPIndex .value ].content [currentCIndex .value ] = cloneDeep (data )
136+ scrollData .value [currentCIndex .value ] = cloneDeep (data )
110137 emit (' update:data' , newData .value )
111138}
112139
113- const handleClick = (tab : TabsPaneContext , event : Event ) => {}
140+ const handleClick = (tab : TabsPaneContext , event : Event ) => {
141+ paginationConfig .current_page = 1
142+ scrollData .value = newData .value [Number (tab .index )]?.content .slice (0 , paginationConfig .page_size )
143+ }
114144
115145onMounted (() => {})
116146 </script >
0 commit comments