feat(frontend): 更新三种切分模式与PDF定位

This commit is contained in:
caoxiaozhu
2026-07-25 18:00:44 +08:00
parent ea08478a37
commit 9193f10e3e
10 changed files with 81 additions and 44 deletions

View File

@@ -66,7 +66,13 @@ const locationText = computed(() => {
})
function pageForItem(item: PreviewItem | null) {
if (!item || item.sourceStart == null || item.sourceEnd == null) return null
if (!item) return null
if (item.sourceStart == null || item.sourceEnd == null) {
const pageNumber = item.sourcePages?.[0]
return pageNumber == null
? null
: pageRanges.value.find((page) => page.page_number === pageNumber) ?? null
}
return pageRanges.value.find((page) => (
item.sourceStart! >= page.source_start && item.sourceStart! < page.source_end
)) ?? pageRanges.value.find((page) => (
@@ -76,7 +82,10 @@ function pageForItem(item: PreviewItem | null) {
function selectedTextForPage(page: DataProcessPdfPageRange) {
const item = props.selectedItem
if (!item || item.sourceStart == null || item.sourceEnd == null) return ''
if (!item) return ''
if (item.sourceStart == null || item.sourceEnd == null) {
return item.sourcePages?.includes(page.page_number) ? item.originalContent : ''
}
const intersectionStart = Math.max(item.sourceStart, page.source_start)
const intersectionEnd = Math.min(item.sourceEnd, page.source_end)
if (intersectionEnd <= intersectionStart) return ''
@@ -145,7 +154,10 @@ function applySelectedHighlight(page: DataProcessPdfPageRange | null) {
for (const element of textLayer?.textDivs ?? []) {
element.classList.remove('is-slice-highlighted')
}
if (!item || item.sourceStart == null || item.sourceEnd == null) {
if (!item || (
(item.sourceStart == null || item.sourceEnd == null)
&& !item.sourcePages?.length
)) {
highlightState.value = item ? 'manual' : 'idle'
return
}
@@ -248,7 +260,10 @@ async function renderCurrentPage(force = false) {
async function locateSelectedItem() {
if (!documentRef.value) return
const item = props.selectedItem
if (!item || item.sourceStart == null || item.sourceEnd == null) {
if (!item || (
(item.sourceStart == null || item.sourceEnd == null)
&& !item.sourcePages?.length
)) {
applySelectedHighlight(null)
return
}