4848</template >
4949<script setup lang="ts">
5050import { cloneDeep } from ' lodash'
51- import { ref , computed } from ' vue'
51+ import { ref , computed , watchEffect } from ' vue'
5252import EditParagraphDialog from ' ./EditParagraphDialog.vue'
5353import { MsgConfirm } from ' @/utils/message'
5454import { t } from ' @/locales'
55+
5556const page_size = ref <number >(30 )
5657const current_page = ref <number >(1 )
5758const currentCIndex = ref <number >(0 )
5859const EditParagraphDialogRef = ref ()
5960const emit = defineEmits ([' update:modelValue' ])
6061const loading = ref <boolean >(false )
61- const editHandle = (item : any , cIndex : number ) => {
62- currentCIndex .value = cIndex
63- EditParagraphDialogRef .value .open (item )
64- }
62+ const localParagraphList = ref <any []>([])
6563
6664const props = defineProps ({
6765 modelValue: {
@@ -72,14 +70,32 @@ const props = defineProps({
7270 knowledgeId: String
7371})
7472
73+ // 监听分页变化,只加载需要的数据
74+ watchEffect (() => {
75+ const start = 0 ;
76+ const end = page_size .value * current_page .value ;
77+ // 只获取所需数量的数据,而不是每次都对整个数组进行切片
78+ if (end <= props .modelValue .length ) {
79+ localParagraphList .value = props .modelValue .slice (start , end );
80+ }
81+ })
82+
7583const paragraph_list = computed (() => {
76- return props . modelValue . slice ( 0 , page_size . value * ( current_page . value - 1 ) + page_size . value )
84+ return localParagraphList . value ;
7785})
7886
7987const next = () => {
80- loading .value = true
81- current_page .value += 1
82- loading .value = false
88+ loading .value = true ;
89+ setTimeout (() => {
90+ current_page .value += 1 ;
91+ loading .value = false ;
92+ }, 100 ); // 添加小延迟让UI有时间更新
93+ }
94+
95+ const editHandle = (item : any , cIndex : number ) => {
96+ // 计算实际索引,考虑分页
97+ currentCIndex .value = cIndex + (page_size .value * (current_page .value - 1 ));
98+ EditParagraphDialogRef .value .open (item )
8399}
84100
85101const updateContent = (data : any ) => {
@@ -95,9 +111,18 @@ const updateContent = (data: any) => {
95111 }
96112 new_value [currentCIndex .value ] = cloneDeep (data )
97113 emit (' update:modelValue' , new_value )
114+
115+ // 更新本地列表
116+ const localIndex = currentCIndex .value - (page_size .value * (current_page .value - 1 ));
117+ if (localIndex >= 0 && localIndex < localParagraphList .value .length ) {
118+ localParagraphList .value [localIndex ] = cloneDeep (data );
119+ }
98120}
99121
100122const deleteHandle = (item : any , cIndex : number ) => {
123+ // 计算实际索引,考虑分页
124+ const actualIndex = cIndex + (page_size .value * (current_page .value - 1 ));
125+
101126 MsgConfirm (
102127 ` ${t (' views.paragraph.delete.confirmTitle' )}${item .title || ' -' } ? ` ,
103128 t (' views.paragraph.delete.confirmMessage' ),
@@ -108,8 +133,18 @@ const deleteHandle = (item: any, cIndex: number) => {
108133 )
109134 .then (() => {
110135 const new_value = [... props .modelValue ]
111- new_value .splice (cIndex , 1 )
136+ new_value .splice (actualIndex , 1 )
112137 emit (' update:modelValue' , new_value )
138+
139+ // 更新本地列表
140+ localParagraphList .value .splice (cIndex , 1 );
141+ // 如果当前页删除完了,从总数据中再取一条添加到末尾
142+ if (props .modelValue .length > localParagraphList .value .length * current_page .value ) {
143+ const nextItem = props .modelValue [localParagraphList .value .length * current_page .value ];
144+ if (nextItem ) {
145+ localParagraphList .value .push (nextItem );
146+ }
147+ }
113148 })
114149 .catch (() => {})
115150}
0 commit comments