fix(documents): sort newest rows first

This commit is contained in:
caoxiaozhu
2026-06-03 16:52:49 +08:00
parent 4717ee6086
commit 8c2f301d85
4 changed files with 84 additions and 4 deletions

View File

@@ -0,0 +1,24 @@
function normalizeSortTime(value) {
const time = Number(value)
return Number.isFinite(time) ? time : 0
}
export function compareDocumentRowsByLatestTime(left, right) {
const latestDiff = normalizeSortTime(right?.sortTime) - normalizeSortTime(left?.sortTime)
if (latestDiff !== 0) {
return latestDiff
}
const createdDiff = normalizeSortTime(right?.createdSortTime) - normalizeSortTime(left?.createdSortTime)
if (createdDiff !== 0) {
return createdDiff
}
const rightKey = String(right?.documentKey || right?.documentNo || '').trim()
const leftKey = String(left?.documentKey || left?.documentNo || '').trim()
return rightKey.localeCompare(leftKey, 'zh-CN')
}
export function sortDocumentRowsByLatestTime(rows) {
return (Array.isArray(rows) ? [...rows] : []).sort(compareDocumentRowsByLatestTime)
}

View File

@@ -250,6 +250,7 @@ import { useMinimumVisibleState } from '../composables/useMinimumVisibleState.js
import { mapExpenseClaimToRequest } from '../composables/useRequests.js'
import { fetchApprovalExpenseClaims, fetchArchivedExpenseClaims } from '../services/reimbursements.js'
import { countNewDocuments, isNewDocument, markDocumentViewed, markDocumentsViewed, readDocumentScope, readViewedDocumentKeys, writeDocumentScope } from '../utils/documentCenterNewState.js'
import { sortDocumentRowsByLatestTime } from '../utils/documentCenterSort.js'
import { extractDateText, formatDocumentListTime, resolveDocumentSortTime, resolveDocumentStayTimeDisplay } from '../utils/documentCenterTime.js'
import { excludeArchivedDocumentRows, filterApplicationScopeNewRows, isArchivedDocumentRow, prepareApplicationScopeRows } from '../utils/documentCenterRows.js'
import { normalizeRequestForUi } from '../utils/requestViewModel.js'
@@ -535,7 +536,7 @@ const statusFilterLabel = computed(() =>
const filteredRows = computed(() => {
const keyword = listKeyword.value.trim().toLowerCase()
return activeScopeRows.value.filter((row) => {
return sortDocumentRowsByLatestTime(activeScopeRows.value.filter((row) => {
const matchesKeyword = !keyword || [
row.documentNo,
row.documentTypeLabel,
@@ -556,7 +557,7 @@ const filteredRows = computed(() => {
const matchesDateRange = matchesAppliedDateRange(row)
return matchesKeyword && matchesDocumentType && matchesScene && matchesStatus && matchesDateRange
})
}))
})
const totalPages = computed(() => Math.max(1, Math.ceil(filteredRows.value.length / pageSize.value)))
@@ -653,6 +654,8 @@ function buildDocumentRow(request, options = {}) {
const claimId = normalized.claimId || normalized.id || documentNo
const createdAtSource = normalized.createdAt || normalized.submittedAt || normalized.applyTime || normalized.updatedAt
const updatedAtSource = normalized.updatedAt || normalized.submittedAt || normalized.createdAt || normalized.applyTime
const createdSortTime = resolveDocumentSortTime(createdAtSource)
const updatedSortTime = resolveDocumentSortTime(updatedAtSource)
const documentTypeCode = normalized.documentTypeCode || DOCUMENT_TYPE_REIMBURSEMENT
const documentTypeLabel =
normalized.documentTypeLabel
@@ -689,7 +692,9 @@ function buildDocumentRow(request, options = {}) {
? false
: isNewDocument({ ...normalized, source: options.source || 'owned', claimId, documentNo }, viewedDocumentKeys.value),
updatedAtDisplay: formatDocumentListTime(updatedAtSource),
sortTime: resolveDocumentSortTime(updatedAtSource)
createdSortTime,
updatedSortTime,
sortTime: Math.max(createdSortTime, updatedSortTime)
}
}
@@ -751,7 +756,7 @@ function mergeDocumentRows(rows) {
}
})
return Array.from(rowMap.values()).sort((left, right) => right.sortTime - left.sortTime)
return sortDocumentRowsByLatestTime(Array.from(rowMap.values()))
}
function resolveSourcePriority(row) {