Skip to content

Commit 897b928

Browse files
ice201508Jiuling.Lei
andauthored
fix-organizations-pagenum-update (#1392)
Co-authored-by: Jiuling.Lei <[email protected]>
1 parent 27d5012 commit 897b928

File tree

1 file changed

+58
-52
lines changed

1 file changed

+58
-52
lines changed

frontend/src/components/shared/ProfileRepoList.vue

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -232,81 +232,57 @@
232232
const hasSpaces = computed(() => spaces.value?.data?.length > 0)
233233
const hasMcps = computed(() => mcps.value?.data?.length > 0)
234234
235-
// 根据activeTab和是否有更多数据来决定显示数量
236235
const displayedCollections = computed(() => {
237236
const data = collections.value?.data || []
238-
// 在"全部"tab下,如果已经展开则显示所有数据,否则只显示前6个
239-
if (activeTab.value === '') {
240-
return expandedSections.value.collections ? data : data.slice(0, INITIAL_PER_PAGE)
241-
}
242-
// 在特定tab下,如果已经展开则显示所有数据,否则只显示前6个
243-
if (activeTab.value === 'collections' && expandedSections.value.collections) {
237+
if (data.length > INITIAL_PER_PAGE) {
244238
return data
245239
}
246240
return data.slice(0, INITIAL_PER_PAGE)
247241
})
248242
249243
const displayedModels = computed(() => {
250244
const data = models.value?.data || []
251-
if (activeTab.value === '') {
252-
return expandedSections.value.models ? data : data.slice(0, INITIAL_PER_PAGE)
253-
}
254-
if (activeTab.value === 'models' && expandedSections.value.models) {
245+
if (data.length > INITIAL_PER_PAGE) {
255246
return data
256247
}
257248
return data.slice(0, INITIAL_PER_PAGE)
258249
})
259250
260251
const displayedDatasets = computed(() => {
261252
const data = datasets.value?.data || []
262-
if (activeTab.value === '') {
263-
return expandedSections.value.datasets ? data : data.slice(0, INITIAL_PER_PAGE)
264-
}
265-
if (activeTab.value === 'datasets' && expandedSections.value.datasets) {
253+
if (data.length > INITIAL_PER_PAGE) {
266254
return data
267255
}
268256
return data.slice(0, INITIAL_PER_PAGE)
269257
})
270258
271259
const displayedCodes = computed(() => {
272260
const data = codes.value?.data || []
273-
if (activeTab.value === '') {
274-
return expandedSections.value.codes ? data : data.slice(0, INITIAL_PER_PAGE)
275-
}
276-
if (activeTab.value === 'codes' && expandedSections.value.codes) {
261+
if (data.length > INITIAL_PER_PAGE) {
277262
return data
278263
}
279264
return data.slice(0, INITIAL_PER_PAGE)
280265
})
281266
282267
const displayedPrompts = computed(() => {
283268
const data = prompts.value?.data || []
284-
if (activeTab.value === '') {
285-
return expandedSections.value.prompts ? data : data.slice(0, INITIAL_PER_PAGE)
286-
}
287-
if (activeTab.value === 'prompts' && expandedSections.value.prompts) {
269+
if (data.length > INITIAL_PER_PAGE) {
288270
return data
289271
}
290272
return data.slice(0, INITIAL_PER_PAGE)
291273
})
292274
293275
const displayedSpaces = computed(() => {
294276
const data = spaces.value?.data || []
295-
if (activeTab.value === '') {
296-
return expandedSections.value.spaces ? data : data.slice(0, INITIAL_PER_PAGE)
297-
}
298-
if (activeTab.value === 'spaces' && expandedSections.value.spaces) {
277+
if (data.length > INITIAL_PER_PAGE) {
299278
return data
300279
}
301280
return data.slice(0, INITIAL_PER_PAGE)
302281
})
303282
304283
const displayedMcps = computed(() => {
305284
const data = mcps.value?.data || []
306-
if (activeTab.value === '') {
307-
return expandedSections.value.mcps ? data : data.slice(0, INITIAL_PER_PAGE)
308-
}
309-
if (activeTab.value === 'mcps' && expandedSections.value.mcps) {
285+
if (data.length > INITIAL_PER_PAGE) {
310286
return data
311287
}
312288
return data.slice(0, INITIAL_PER_PAGE)
@@ -328,14 +304,13 @@
328304
lastFetchTime.value = Date.now()
329305
330306
try {
331-
const timestamp = Date.now()
332-
const collectionsUrl = `${reposUrl("collections")}?_t=${timestamp}`
333-
const modelsUrl = `${reposUrl("models")}?_t=${timestamp}`
334-
const datasetsUrl = `${reposUrl("datasets")}?_t=${timestamp}`
335-
const spacesUrl = `${reposUrl("spaces")}?_t=${timestamp}`
336-
const codesUrl = `${reposUrl("codes")}?_t=${timestamp}`
337-
const promptsUrl = `${reposUrl("prompts")}?_t=${timestamp}`
338-
const mcpsUrl = `${reposUrl("mcps")}?_t=${timestamp}`
307+
const collectionsUrl = `${reposUrl("collections")}`
308+
const modelsUrl = `${reposUrl("models")}`
309+
const datasetsUrl = `${reposUrl("datasets")}`
310+
const spacesUrl = `${reposUrl("spaces")}`
311+
const codesUrl = `${reposUrl("codes")}`
312+
const promptsUrl = `${reposUrl("prompts")}`
313+
const mcpsUrl = `${reposUrl("mcps")}`
339314
340315
const promises = [
341316
fetchData(collectionsUrl, collections, INITIAL_PER_PAGE, 1),
@@ -355,44 +330,63 @@
355330
}
356331
357332
const viewMoreTargets = async (target) => {
358-
// 标记该类型已展开
359-
expandedSections.value[target] = true
360-
361333
switch (target) {
362334
case "collections":
363335
collectionsLoading.value = true
364336
await fetchMoreCollections()
365337
collectionsLoading.value = false
338+
// 只有当没有更多数据时才标记为已展开
339+
if (!collections.value.more) {
340+
expandedSections.value.collections = true
341+
}
366342
break
367343
case "models":
368344
modelsLoading.value = true
369345
await fetchMoreModels()
370346
modelsLoading.value = false
347+
if (!models.value.more) {
348+
expandedSections.value.models = true
349+
}
371350
break
372351
case "datasets":
373352
datasetsLoading.value = true
374353
await fetchMoreDatasets()
375354
datasetsLoading.value = false
355+
if (!datasets.value.more) {
356+
expandedSections.value.datasets = true
357+
}
376358
break
377359
case "spaces":
378360
spacesLoading.value = true
379361
await fetchMoreSpaces()
380362
spacesLoading.value = false
363+
if (!spaces.value.more) {
364+
expandedSections.value.spaces = true
365+
}
381366
break
382367
case "codes":
383368
codeLoading.value = true
384369
await fetchMoreCodes()
385370
codeLoading.value = false
371+
if (!codes.value.more) {
372+
expandedSections.value.codes = true
373+
}
386374
break
387375
case "prompts":
388376
promptsLoading.value = true
389377
await fetchMorePrompts()
390378
promptsLoading.value = false
379+
if (!prompts.value.more) {
380+
expandedSections.value.prompts = true
381+
}
391382
break
392383
case "mcps":
393384
mcpsLoading.value = true
394385
await fetchMoreMcp()
395386
mcpsLoading.value = false
387+
if (!mcps.value.more) {
388+
expandedSections.value.mcps = true
389+
}
396390
break
397391
}
398392
}
@@ -407,15 +401,18 @@
407401
}
408402
}
409403
410-
const updatePageAndData = (response, targetRef, pageRef) => {
411-
if (!targetRef.value.data || pageRef.value === 1) {
412-
targetRef.value.data = []
413-
}
404+
const updatePageAndData = (response, targetRef, pageRef, isFirstExpand = false) => {
414405
const addData = targetRef === mcps ? response.data.data : response.data
415-
targetRef.value.data = [...targetRef.value.data, ...addData]
416406
const repoTotal = targetRef === mcps ? response.data.total : response.total
407+
408+
if (isFirstExpand) {
409+
targetRef.value.data = addData
410+
pageRef.value = 1
411+
} else {
412+
targetRef.value.data = [...targetRef.value.data, ...addData]
413+
}
414+
417415
targetRef.value.total = repoTotal
418-
419416
const loadedCount = targetRef.value.data.length
420417
const hasMore = loadedCount < repoTotal
421418
targetRef.value.more = hasMore
@@ -430,8 +427,10 @@
430427
params.append("per", perPage)
431428
params.append("page", page)
432429
430+
const timestamp = Date.now()
431+
433432
try {
434-
const { data, error } = await useFetchApi(`${url}?${params}`).json()
433+
const { data, error } = await useFetchApi(`${url}?${params}&_t=${timestamp}`).json()
435434
436435
if (error.value) {
437436
ElMessage({
@@ -452,7 +451,9 @@
452451
targetRef.value.more = data.value.total > perPage
453452
}
454453
} else {
455-
updatePageAndData(data.value, targetRef, getPageRef(targetRef))
454+
const pageRef = getPageRef(targetRef)
455+
const isFirstExpand = pageRef.value === 1 && perPage === PER_PAGE
456+
updatePageAndData(data.value, targetRef, pageRef, isFirstExpand)
456457
}
457458
458459
return data.value
@@ -475,7 +476,13 @@
475476
const fetchMore = async (targetRef, type) => {
476477
const pageRef = getPageRef(targetRef)
477478
const url = reposUrl(type)
478-
await fetchData(url, targetRef, PER_PAGE, pageRef.value)
479+
const currentLoadedCount = targetRef.value.data?.length || 0
480+
481+
if (currentLoadedCount <= INITIAL_PER_PAGE) {
482+
await fetchData(url, targetRef, PER_PAGE, 1)
483+
} else {
484+
await fetchData(url, targetRef, PER_PAGE, pageRef.value)
485+
}
479486
}
480487
481488
const fetchMoreCollections = () => fetchMore(collections, "collections")
@@ -487,7 +494,6 @@
487494
const fetchMoreMcp = () => fetchMore(mcps, "mcps")
488495
489496
490-
// 添加处理浏览器前进后退的函数
491497
const handlePopState = () => {
492498
if (isLoading.value) {
493499
return

0 commit comments

Comments
 (0)