✨ feat: 完善文件状态、取件记录与表格交互
* 支持当前页下载状态的手动和定时检测,仅显示标签与检测时间 * 区分查件时间和下载点击时间,保留重复查件前的取件时间 * 将查件事件按时间并入现有取件记录,共用展开与收起 * 统一表头居中,支持拖拽和键盘调整列宽并限制最小宽度 * 修复筛选面板收起结束时顶部间距突然消失的顿挫 * 补充单元、集成与浏览器验证,覆盖查询下载、列宽和动画行为
This commit is contained in:
1 parent
272741ee49
commit
4fefcd0f0a
29 files changed
+765
-41
No files matched your search
@@ -0,0 +1,43 @@
|
||||
.resizable-columns th {
|
||||
position: relative;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.column-resize-handle {
|
||||
position: absolute;
|
||||
inset: 0 -4px 0 auto;
|
||||
width: 9px;
|
||||
z-index: 1;
|
||||
cursor: col-resize;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
.column-resize-handle::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 25% 4px;
|
||||
background: currentColor;
|
||||
opacity: 0.25;
|
||||
}
|
||||
|
||||
.column-resize-handle:hover::after,
|
||||
.column-resize-handle:focus-visible::after {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.column-resize-handle:focus-visible {
|
||||
outline: 2px solid currentColor;
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
.columns-resizing,
|
||||
.columns-resizing * {
|
||||
cursor: col-resize !important;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.columns-sized td {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
@@ -20,6 +20,7 @@
|
||||
</div>
|
||||
<div class="overflow-x-auto" tabindex="0" role="region" :aria-label="title">
|
||||
<table
|
||||
v-resizable-columns
|
||||
class="divide-y"
|
||||
:class="[tableClass, isDarkMode ? 'divide-[#495765]' : 'divide-[#d7e3e5]']"
|
||||
>
|
||||
@@ -30,7 +31,7 @@
|
||||
v-for="header in headers"
|
||||
:key="header"
|
||||
scope="col"
|
||||
class="px-6 py-3.5 text-left text-xs font-medium uppercase tracking-wider"
|
||||
class="whitespace-nowrap px-6 py-3.5 text-center text-xs font-medium uppercase tracking-wider"
|
||||
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']"
|
||||
>
|
||||
{{ header }}
|
||||
@@ -50,6 +51,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { vResizableColumns } from '@/directives/resizable-columns'
|
||||
import { inject, useSlots } from 'vue'
|
||||
|
||||
interface Props {
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
<div class="min-w-0"><p class="text-xs opacity-70">{{ t('fileRecord.filename') }}</p><p class="mt-1 break-all font-medium leading-6">{{ record.filename }}</p></div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<div class="flex items-start gap-3"><CalendarIcon class="mt-1 h-5 w-5 shrink-0 opacity-70" aria-hidden="true" /><div class="min-w-0"><p class="text-xs opacity-70">{{ t('fileRecord.date') }}</p><p class="mt-1 break-words leading-6">{{ record.date }}</p></div></div>
|
||||
<div class="flex items-start gap-3"><CalendarIcon class="mt-1 h-5 w-5 shrink-0 opacity-70" aria-hidden="true" /><div class="min-w-0"><p class="text-xs opacity-70">{{ t('fileRecord.queryTime') }}</p><p class="mt-1 break-words leading-6">{{ formatRecordTime(queriedAt(record)) }}</p></div></div>
|
||||
<div class="flex items-start gap-3"><CalendarIcon class="mt-1 h-5 w-5 shrink-0 opacity-70" aria-hidden="true" /><div class="min-w-0"><p class="text-xs opacity-70">{{ t('fileRecord.retrieveTime') }}</p><p class="mt-1 break-words leading-6">{{ formatRecordTime(record.retrievedAt) || t('fileRecord.notRetrieved') }}</p><p class="mt-1 text-xs opacity-70">{{ t('fileRecord.retrieveTimeHint') }}</p></div></div>
|
||||
<div class="flex items-start gap-3"><HardDriveIcon class="mt-1 h-5 w-5 shrink-0 opacity-70" aria-hidden="true" /><div><p class="text-xs opacity-70">{{ t('fileRecord.size') }}</p><p class="mt-1 leading-6">{{ record.size }}</p></div></div>
|
||||
</div>
|
||||
<div class="border-t pt-4" :class="isDarkMode ? 'border-gray-700' : 'border-gray-200'">
|
||||
<BaseButton v-if="record.filename === 'Text'" @click="$emit('preview-content')">{{ t('fileDetail.previewContent') }}</BaseButton>
|
||||
<a v-else :href="getDownloadUrl(record)" target="_blank" rel="noopener noreferrer" class="fcb-action fcb-button-primary inline-flex min-h-11 items-center gap-2 rounded-[30px] px-4 py-2 font-medium"><DownloadIcon class="h-4 w-4" aria-hidden="true" />{{ t('fileDetail.download') }}</a>
|
||||
<BaseButton v-if="record.type === 'text' || typeof record.content === 'string'" @click="$emit('preview-content')">{{ t('fileDetail.previewContent') }}</BaseButton>
|
||||
<BaseButton v-else @click="$emit('download-record', record)"><DownloadIcon class="mr-2 h-4 w-4" aria-hidden="true" />{{ t('fileDetail.download') }}</BaseButton>
|
||||
</div>
|
||||
<div class="flex flex-col items-center gap-2 rounded-2xl p-4" :class="isDarkMode ? 'bg-gray-900/30' : 'bg-white/40'">
|
||||
<h4 class="font-semibold">{{ t('fileDetail.qrCode') }}</h4>
|
||||
@@ -31,7 +32,8 @@ import { FileIcon, CalendarIcon, HardDriveIcon, DownloadIcon } from 'lucide-vue-
|
||||
import BaseModal from './BaseModal.vue'
|
||||
import BaseButton from './BaseButton.vue'
|
||||
import type { ReceivedFileRecord } from '@/types'
|
||||
import { buildDownloadUrl, buildReceivedRecordQrValue } from '@/utils/share-url'
|
||||
import { buildReceivedRecordQrValue } from '@/utils/share-url'
|
||||
import { queriedAt, formatRecordTime } from '@/utils/receive-record'
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
@@ -41,6 +43,7 @@ interface Props {
|
||||
interface Emits {
|
||||
close: []
|
||||
'preview-content': []
|
||||
'download-record': [record: ReceivedFileRecord]
|
||||
}
|
||||
|
||||
defineProps<Props>()
|
||||
@@ -49,10 +52,6 @@ const { t } = useI18n()
|
||||
const isDarkMode = inject('isDarkMode')
|
||||
const QRCode = defineAsyncComponent(() => import('qrcode.vue'))
|
||||
|
||||
const getDownloadUrl = (record: ReceivedFileRecord) => {
|
||||
return buildDownloadUrl(record.downloadUrl)
|
||||
}
|
||||
|
||||
const getQRCodeValue = (record: ReceivedFileRecord) => {
|
||||
return buildReceivedRecordQrValue(record)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
<FileIcon class="h-9 w-9 shrink-0" :class="[isDarkMode ? 'text-indigo-400' : 'text-indigo-600']" aria-hidden="true" />
|
||||
<div class="min-w-0 flex-1">
|
||||
<p class="truncate text-base font-medium" :title="record.filename" :class="[isDarkMode ? 'text-white' : 'text-gray-800']">{{ record.filename }}</p>
|
||||
<p class="truncate text-sm" :class="[isDarkMode ? 'text-gray-400' : 'text-gray-600']">{{ record.date }} · {{ record.size }}</p>
|
||||
<p class="truncate text-sm" :class="[isDarkMode ? 'text-gray-400' : 'text-gray-600']">{{ t('fileRecord.queryTime') }}:{{ formatRecordTime(queriedAt(record)) }} · {{ record.size }}</p>
|
||||
<p class="text-sm" :class="[isDarkMode ? 'text-gray-400' : 'text-gray-600']">{{ t('fileRecord.retrieveTime') }}:{{ formatRecordTime(record.retrievedAt) || t('fileRecord.notRetrieved') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3 grid grid-cols-3 gap-2">
|
||||
@@ -38,6 +39,7 @@ import { computed, inject } from 'vue'
|
||||
import { FileIcon, EyeIcon, DownloadIcon, TrashIcon } from 'lucide-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import type { ReceivedFileRecord } from '@/types'
|
||||
import { queriedAt, formatRecordTime } from '@/utils/receive-record'
|
||||
|
||||
defineProps<{ records: ReceivedFileRecord[] }>()
|
||||
defineEmits<{ 'view-details': [record: ReceivedFileRecord]; 'download-record': [record: ReceivedFileRecord]; 'delete-record': [id: number] }>()
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<template>
|
||||
<div class="space-y-1" role="status">
|
||||
<span class="inline-flex items-center rounded-full px-2 py-1 text-xs font-medium" :class="badgeClass">
|
||||
<RefreshCw v-if="result.status === 'checking'" class="mr-1 h-3 w-3 animate-spin" />
|
||||
{{ labels[result.status] }}
|
||||
</span>
|
||||
<div v-if="result.checkedAt" class="whitespace-nowrap text-xs opacity-60">{{ new Date(result.checkedAt).toLocaleString() }}</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { RefreshCw } from 'lucide-vue-next'
|
||||
import type { DownloadCheck } from '@/types/download-check'
|
||||
const props = defineProps<{ result: DownloadCheck; dark: boolean }>()
|
||||
const labels = { available: '可下载', unavailable: '不可下载', unknown: '未检测', checking: '检测中' }
|
||||
const badgeClass = computed(() => {
|
||||
if (props.result.status === 'available') return props.dark ? 'bg-emerald-900/40 text-emerald-200' : 'bg-emerald-50 text-emerald-800'
|
||||
if (props.result.status === 'unavailable') return props.dark ? 'bg-red-900/40 text-red-200' : 'bg-red-50 text-red-800'
|
||||
return props.dark ? 'bg-gray-700 text-gray-200' : 'bg-gray-100 text-gray-700'
|
||||
})
|
||||
</script>
|
||||
@@ -16,3 +16,5 @@ export { useTheme } from './useTheme'
|
||||
export { useTransferAnalytics } from './useTransferAnalytics'
|
||||
|
||||
export { useLocalFiles } from './useLocalFiles'
|
||||
|
||||
export { useDownloadChecks } from './useDownloadChecks'
|
||||
@@ -651,7 +651,7 @@ export function useAdminFiles() {
|
||||
if (numericValue !== null) return t('fileManage.remaining', { count: numericValue })
|
||||
}
|
||||
|
||||
if ((item.key === 'retrieved' || item.key === 'retrieved_event') && hasNumericTimelineValue(item)) {
|
||||
if ((item.key === 'retrieved' || item.key === 'retrieved_event' || item.key === 'queried_event') && hasNumericTimelineValue(item)) {
|
||||
return `${normalizeTimelineNumber(item.value)} ${t('common.times')}`
|
||||
}
|
||||
|
||||
@@ -673,7 +673,7 @@ export function useAdminFiles() {
|
||||
}
|
||||
|
||||
const formatTimelineTitleValue = (item: AdminFileDetailTimelineItem, valueText: string) => {
|
||||
if (item.key === 'retrieved_event') {
|
||||
if (item.key === 'retrieved_event' || item.key === 'queried_event') {
|
||||
const numericValue = normalizeTimelineNumber(item.value)
|
||||
return numericValue === null ? '' : String(numericValue)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import { onScopeDispose, ref, watch, type Ref } from 'vue'
|
||||
import { DownloadCheckService, ConfigService } from '@/services'
|
||||
import type { DownloadCheck } from '@/types/download-check'
|
||||
|
||||
export function useDownloadChecks(files: Ref<{ id: number }[]>) {
|
||||
const checks = ref<Record<number, DownloadCheck>>({})
|
||||
const interval = ref(300)
|
||||
const saving = ref(false)
|
||||
const error = ref('')
|
||||
const checking = ref(false)
|
||||
let controller: AbortController | undefined
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
let disposed = false
|
||||
|
||||
const statusFor = (id: number): DownloadCheck => checks.value[id] ?? {
|
||||
id, status: 'unknown', message: '尚未检测', checkedAt: null
|
||||
}
|
||||
const schedule = () => {
|
||||
clearTimeout(timer)
|
||||
if (!disposed && interval.value > 0) timer = setTimeout(() => {
|
||||
if (typeof document !== 'undefined' && document.hidden) schedule()
|
||||
else void refresh()
|
||||
}, interval.value * 1000)
|
||||
}
|
||||
const refresh = async () => {
|
||||
controller?.abort()
|
||||
const current = new AbortController()
|
||||
controller = current
|
||||
clearTimeout(timer)
|
||||
checking.value = true
|
||||
const ids = files.value.map(file => file.id)
|
||||
checks.value = Object.fromEntries(ids.map(id => [id, {
|
||||
...statusFor(id), status: 'checking', message: '正在检测'
|
||||
}]))
|
||||
try {
|
||||
for (let offset = 0; offset < ids.length; offset += 20) {
|
||||
const batch = ids.slice(offset, offset + 20)
|
||||
try {
|
||||
const response = await DownloadCheckService.check(batch, current.signal)
|
||||
if (current.signal.aborted || disposed) return
|
||||
if (response.code !== 200 || !Array.isArray(response.detail)) throw new Error('检测请求失败')
|
||||
for (const id of batch) {
|
||||
checks.value[id] = response.detail.find(item => item.id === id) ?? {
|
||||
id, status: 'unknown', message: '未返回检测结果,请重试', checkedAt: null
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
if (current.signal.aborted || disposed) return
|
||||
for (const id of batch) checks.value[id] = {
|
||||
id, status: 'unknown', message: '检测请求失败,请刷新重试', checkedAt: null
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (controller === current && !disposed) {
|
||||
checking.value = false
|
||||
schedule()
|
||||
}
|
||||
}
|
||||
}
|
||||
const loadInterval = async () => {
|
||||
try {
|
||||
const response = await ConfigService.getConfig()
|
||||
if (!disposed && response.code === 200) {
|
||||
interval.value = response.detail?.downloadCheckInterval ?? 300
|
||||
schedule()
|
||||
}
|
||||
} catch { error.value = '无法读取检测间隔,暂按 5 分钟刷新' }
|
||||
}
|
||||
const saveInterval = async (value: number) => {
|
||||
if (saving.value) return
|
||||
saving.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const response = await ConfigService.updateConfig({ downloadCheckInterval: value })
|
||||
if (response.code !== 200) throw new Error('save failed')
|
||||
interval.value = value
|
||||
schedule()
|
||||
} catch { error.value = '检测间隔保存失败,请重试' }
|
||||
finally { saving.value = false }
|
||||
}
|
||||
// Every successful list load (refresh, page, filter, or edit) gets fresh results.
|
||||
watch(files, () => { void refresh() })
|
||||
onScopeDispose(() => {
|
||||
disposed = true
|
||||
controller?.abort()
|
||||
clearTimeout(timer)
|
||||
})
|
||||
return { checks, interval, saving, error, checking, statusFor, refresh, loadInterval, saveInterval }
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { copyToClipboard } from '@/utils/clipboard'
|
||||
import { getErrorMessage } from '@/utils/common'
|
||||
import { renderMarkdownPreview } from '@/utils/content-preview'
|
||||
import { downloadReceivedRecord } from '@/utils/download-action'
|
||||
import { markRecordRetrieved } from '@/utils/receive-record'
|
||||
|
||||
type InputStatus = {
|
||||
readonly: boolean
|
||||
@@ -60,8 +61,9 @@ export function useRetrieveFlow() {
|
||||
? detail.type === 'text'
|
||||
: detail.name === 'Text' && !detail.text.startsWith('/share/download')
|
||||
const content = isText ? (detail.content ?? detail.text) : null
|
||||
const downloadUrl = isText ? null : (detail.download_url ?? detail.text)
|
||||
const downloadUrl = detail.download_url ?? (isText ? null : detail.text)
|
||||
|
||||
const queriedAt = new Date().toISOString()
|
||||
return {
|
||||
id: Date.now(),
|
||||
code: detail.code,
|
||||
@@ -69,7 +71,9 @@ export function useRetrieveFlow() {
|
||||
size: formatFileSize(detail.size),
|
||||
downloadUrl,
|
||||
content,
|
||||
date: new Date().toLocaleString(),
|
||||
date: queriedAt,
|
||||
queriedAt,
|
||||
retrievedAt: null,
|
||||
type: isText ? 'text' : 'file',
|
||||
remainingDownloads: detail.remaining_downloads
|
||||
}
|
||||
@@ -130,6 +134,7 @@ export function useRetrieveFlow() {
|
||||
(file) => file.code === newFileData.code
|
||||
)
|
||||
if (existingIndex !== -1) {
|
||||
newFileData.retrievedAt = fileStore.receiveData[existingIndex].retrievedAt ?? null
|
||||
fileStore.deleteReceiveData(existingIndex)
|
||||
}
|
||||
fileStore.addReceiveData(newFileData)
|
||||
@@ -186,7 +191,9 @@ export function useRetrieveFlow() {
|
||||
}
|
||||
|
||||
const downloadRecord = (record: ReceivedFileRecord) => {
|
||||
downloadReceivedRecord(record)
|
||||
if (downloadReceivedRecord(record)) {
|
||||
markRecordRetrieved(record)
|
||||
}
|
||||
}
|
||||
|
||||
const showContentPreview = () => {
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
import type { ObjectDirective } from 'vue'
|
||||
import { resizeColumn } from '../utils/column-width'
|
||||
import '../assets/style/resizable-columns.css'
|
||||
|
||||
const states = new WeakMap<HTMLTableElement, { cleanup: () => void; signature: () => boolean }>()
|
||||
|
||||
function mount(table: HTMLTableElement) {
|
||||
const view = table.ownerDocument.defaultView!
|
||||
const headers = Array.from(table.querySelectorAll<HTMLTableCellElement>('thead th'))
|
||||
const labels = headers.map(header => header.textContent?.trim() || '')
|
||||
const handles: HTMLElement[] = []
|
||||
let stopDrag = () => {}
|
||||
table.classList.add('resizable-columns')
|
||||
|
||||
function measure() {
|
||||
return headers.map(header => header.getBoundingClientRect().width)
|
||||
}
|
||||
|
||||
function minimum(header: HTMLTableCellElement) {
|
||||
const range = table.ownerDocument.createRange()
|
||||
range.selectNodeContents(header)
|
||||
// Keep the label and padding visible even when the data column is narrowed.
|
||||
const labelWidth = Array.from(range.getClientRects()).reduce((max, rect) => Math.max(max, rect.width), 0)
|
||||
const style = view.getComputedStyle(header)
|
||||
return Math.ceil(Math.max(72, labelWidth + parseFloat(style.paddingLeft) + parseFloat(style.paddingRight)))
|
||||
}
|
||||
|
||||
function apply(widths: number[]) {
|
||||
table.style.tableLayout = 'fixed'
|
||||
table.style.minWidth = '0'
|
||||
table.style.width = `${widths.reduce((sum, width) => sum + width, 0)}px`
|
||||
table.classList.add('columns-sized')
|
||||
headers.forEach((header, index) => {
|
||||
header.style.width = `${widths[index]}px`
|
||||
handles[index]!.setAttribute('aria-valuenow', String(Math.round(widths[index]!)))
|
||||
})
|
||||
}
|
||||
|
||||
headers.forEach((header, index) => {
|
||||
const handle = table.ownerDocument.createElement('span')
|
||||
handle.className = 'column-resize-handle'
|
||||
handle.tabIndex = 0
|
||||
handle.setAttribute('role', 'separator')
|
||||
handle.setAttribute('aria-orientation', 'vertical')
|
||||
header.setAttribute('aria-label', labels[index]!)
|
||||
handle.setAttribute('aria-label', `${labels[index]} — ↔`)
|
||||
handle.setAttribute('aria-valuenow', String(Math.round(header.getBoundingClientRect().width)))
|
||||
header.append(handle)
|
||||
handles.push(handle)
|
||||
|
||||
handle.onpointerdown = event => {
|
||||
if (event.button !== 0) return
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
stopDrag()
|
||||
const widths = measure()
|
||||
const min = minimum(header)
|
||||
const startX = event.clientX
|
||||
const pointerId = event.pointerId
|
||||
handle.setPointerCapture(pointerId)
|
||||
table.classList.add('columns-resizing')
|
||||
const move = (event: PointerEvent) => {
|
||||
if (event.pointerId === pointerId) apply(resizeColumn(widths, index, event.clientX - startX, min))
|
||||
}
|
||||
const finish = (event: PointerEvent) => {
|
||||
if (event.pointerId === pointerId) stopDrag()
|
||||
}
|
||||
stopDrag = () => {
|
||||
view.removeEventListener('pointermove', move)
|
||||
view.removeEventListener('pointerup', finish)
|
||||
view.removeEventListener('pointercancel', finish)
|
||||
view.removeEventListener('blur', stopDrag)
|
||||
handle.removeEventListener('lostpointercapture', finish)
|
||||
if (handle.hasPointerCapture(pointerId)) handle.releasePointerCapture(pointerId)
|
||||
table.classList.remove('columns-resizing')
|
||||
stopDrag = () => {}
|
||||
}
|
||||
view.addEventListener('pointermove', move)
|
||||
view.addEventListener('pointerup', finish)
|
||||
view.addEventListener('pointercancel', finish)
|
||||
view.addEventListener('blur', stopDrag)
|
||||
handle.addEventListener('lostpointercapture', finish)
|
||||
}
|
||||
handle.onkeydown = event => {
|
||||
if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return
|
||||
event.preventDefault()
|
||||
apply(resizeColumn(measure(), index, event.key === 'ArrowRight' ? 16 : -16, minimum(header)))
|
||||
}
|
||||
})
|
||||
states.set(table, { signature: () => {
|
||||
const current = Array.from(table.querySelectorAll('thead th'))
|
||||
return current.length === headers.length && current.every((header, index) =>
|
||||
header === headers[index] && header.textContent?.trim() === labels[index] && handles[index]?.isConnected)
|
||||
}, cleanup: () => {
|
||||
stopDrag()
|
||||
handles.forEach(handle => handle.remove())
|
||||
headers.forEach(header => header.removeAttribute('aria-label'))
|
||||
} })
|
||||
}
|
||||
|
||||
export const vResizableColumns: ObjectDirective<HTMLTableElement> = {
|
||||
mounted: mount,
|
||||
updated(table) {
|
||||
const state = states.get(table)
|
||||
if (!state?.signature()) {
|
||||
state?.cleanup()
|
||||
mount(table)
|
||||
}
|
||||
},
|
||||
beforeUnmount(table) {
|
||||
states.get(table)?.cleanup()
|
||||
states.delete(table)
|
||||
}
|
||||
}
|
||||
@@ -406,7 +406,11 @@ export default {
|
||||
fileRecord: {
|
||||
filename: 'Filename',
|
||||
size: 'Size',
|
||||
date: 'Date',
|
||||
date: 'Lookup time',
|
||||
queryTime: 'Lookup time',
|
||||
retrieveTime: 'Retrieval time',
|
||||
notRetrieved: 'Not retrieved yet',
|
||||
retrieveTimeHint: 'Most recent download click; does not indicate completion.',
|
||||
code: 'Code',
|
||||
actions: 'Actions',
|
||||
download: 'Download',
|
||||
@@ -666,13 +670,17 @@ export default {
|
||||
title: 'Retrieval History',
|
||||
description: 'Retrieved {value}; current status is {status}.'
|
||||
},
|
||||
queried_event: {
|
||||
title: 'Lookup #{value}',
|
||||
description: 'Lookup succeeded. Source IP: {detail}.'
|
||||
},
|
||||
retrieved_event: {
|
||||
title: 'Retrieval #{value}',
|
||||
description: 'This retrieval is complete; current status is {status}.'
|
||||
description: 'Retrieval started; this does not indicate download completion.'
|
||||
},
|
||||
retrieved_event_unknown: {
|
||||
title: 'Retrieval History',
|
||||
description: 'This retrieval is complete; current status is {status}.'
|
||||
description: 'Retrieval started; this does not indicate download completion.'
|
||||
}
|
||||
},
|
||||
headers: {
|
||||
|
||||
@@ -581,7 +581,7 @@ export default {
|
||||
lifecycle: '生命周期',
|
||||
expandLifecycle: '展开全部生命周期记录(共 {count} 条)',
|
||||
collapseLifecycle: '收起生命周期记录',
|
||||
expandRetrievalHistory: '展开全部取件记录(共 {count} 次)',
|
||||
expandRetrievalHistory: '展开全部取件记录(共 {count} 条)',
|
||||
collapseRetrievalHistory: '收起取件记录',
|
||||
permanent: '永久有效',
|
||||
createdAt: '创建时间',
|
||||
@@ -662,13 +662,17 @@ export default {
|
||||
title: '取件记录',
|
||||
description: '累计取件 {value},当前状态为 {status}。'
|
||||
},
|
||||
queried_event: {
|
||||
title: '第 {value} 次查件',
|
||||
description: '查件成功,来源 IP:{detail}。'
|
||||
},
|
||||
retrieved_event: {
|
||||
title: '第 {value} 次取件',
|
||||
description: '本次取件已完成,当前状态为 {status}。'
|
||||
description: '已发起取件,不代表下载完成。'
|
||||
},
|
||||
retrieved_event_unknown: {
|
||||
title: '取件记录',
|
||||
description: '本次取件已完成,当前状态为 {status}。'
|
||||
description: '已发起取件,不代表下载完成。'
|
||||
}
|
||||
},
|
||||
headers: {
|
||||
@@ -709,7 +713,11 @@ export default {
|
||||
fileRecord: {
|
||||
filename: '文件名',
|
||||
size: '文件大小',
|
||||
date: '取件日期',
|
||||
date: '查件时间',
|
||||
queryTime: '查件时间',
|
||||
retrieveTime: '取件时间',
|
||||
notRetrieved: '尚未取件',
|
||||
retrieveTimeHint: '最近一次点击下载的时间,不代表下载完成。',
|
||||
code: '取件码',
|
||||
actions: '操作',
|
||||
download: '下载',
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import api from './client'
|
||||
import type { ApiResponse } from '@/types'
|
||||
import type { DownloadCheck } from '@/types/download-check'
|
||||
|
||||
export const DownloadCheckService = {
|
||||
check(ids: number[], signal?: AbortSignal): Promise<ApiResponse<DownloadCheck[]>> {
|
||||
return api.post('/admin/file/download-check', { ids }, { signal, timeout: 70000 })
|
||||
}
|
||||
}
|
||||
@@ -11,3 +11,5 @@ export { uploadChunkedFile } from './upload-strategy'
|
||||
export { LocalShareService } from './local-share'
|
||||
|
||||
export { UploadCancellation, UploadInterrupted, isUploadInterrupted } from './upload-cancellation'
|
||||
|
||||
export { DownloadCheckService } from './download-check'
|
||||
@@ -47,6 +47,7 @@ export interface ConfigState {
|
||||
opacity: number
|
||||
enableChunk: number
|
||||
chunkSizeMB: number
|
||||
downloadCheckInterval?: number
|
||||
s3_access_key_id: string
|
||||
background: string
|
||||
showAdminAddr: number
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export interface DownloadCheck {
|
||||
id: number
|
||||
status: 'available' | 'unavailable' | 'unknown' | 'checking'
|
||||
message: string
|
||||
checkedAt: string | null
|
||||
}
|
||||
@@ -453,7 +453,10 @@ export interface ReceivedFileRecord {
|
||||
size: string
|
||||
downloadUrl: string | null
|
||||
content: string | null
|
||||
/** Legacy query time, retained for existing records. */
|
||||
date: string
|
||||
queriedAt?: string
|
||||
retrievedAt?: string | null
|
||||
type?: 'file' | 'text'
|
||||
remainingDownloads?: number | null
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export function resizeColumn(widths: number[], index: number, delta: number, minimum: number): number[] {
|
||||
return widths.map((width, column) => column === index ? Math.max(minimum, width + delta) : width)
|
||||
}
|
||||
@@ -7,16 +7,18 @@ const unsafeFilenamePattern = new RegExp(
|
||||
'g'
|
||||
)
|
||||
|
||||
export function downloadReceivedRecord(record: ReceivedFileRecord): void {
|
||||
export function downloadReceivedRecord(record: ReceivedFileRecord): boolean {
|
||||
if (record.downloadUrl) {
|
||||
window.open(buildDownloadUrl(record.downloadUrl), '_blank')
|
||||
return
|
||||
return true
|
||||
}
|
||||
|
||||
if (record.content) {
|
||||
if (typeof record.content === 'string') {
|
||||
const blob = new Blob([record.content], { type: 'text/plain;charset=utf-8' })
|
||||
saveAs(blob, `${record.filename}.txt`)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export const getSafeFilename = (name: string) =>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { ReceivedFileRecord } from '../types/file'
|
||||
|
||||
/** Legacy date was written on lookup, never on download. */
|
||||
export function queriedAt(record: ReceivedFileRecord): string {
|
||||
return record.queriedAt || record.date
|
||||
}
|
||||
|
||||
export function formatRecordTime(value?: string | null): string {
|
||||
if (!value) return ''
|
||||
// Old records contain locale-formatted dates; retain them without guessing.
|
||||
if (!/^\d{4}-\d{2}-\d{2}T/.test(value)) return value
|
||||
const time = new Date(value)
|
||||
return Number.isNaN(time.getTime()) ? value : time.toLocaleString()
|
||||
}
|
||||
|
||||
export function markRecordRetrieved(record: ReceivedFileRecord, at = new Date()): void {
|
||||
record.retrievedAt = at.toISOString()
|
||||
}
|
||||
@@ -44,6 +44,7 @@
|
||||
:record="selectedRecord"
|
||||
@close="closeDetails"
|
||||
@preview-content="showContentPreview"
|
||||
@download-record="downloadRecord"
|
||||
/>
|
||||
|
||||
<ContentPreviewModal
|
||||
|
||||
@@ -329,31 +329,32 @@
|
||||
</div>
|
||||
<div class="overflow-x-auto" tabindex="0" role="region" :aria-label="t('admin.dashboard.topDownloads.title')">
|
||||
<table
|
||||
v-resizable-columns
|
||||
class="min-w-full divide-y"
|
||||
:class="[isDarkMode ? 'divide-gray-700' : 'divide-gray-200']"
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
<th
|
||||
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
||||
class="px-4 py-3 text-center text-xs font-semibold uppercase"
|
||||
:class="[mutedTextClass]"
|
||||
>
|
||||
{{ t('admin.dashboard.topDownloads.file') }}
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
||||
class="px-4 py-3 text-center text-xs font-semibold uppercase"
|
||||
:class="[mutedTextClass]"
|
||||
>
|
||||
{{ t('admin.dashboard.topDownloads.downloads') }}
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
||||
class="px-4 py-3 text-center text-xs font-semibold uppercase"
|
||||
:class="[mutedTextClass]"
|
||||
>
|
||||
{{ t('admin.dashboard.topDownloads.traffic') }}
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
||||
class="px-4 py-3 text-center text-xs font-semibold uppercase"
|
||||
:class="[mutedTextClass]"
|
||||
>
|
||||
{{ t('admin.dashboard.topDownloads.status') }}
|
||||
@@ -417,6 +418,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { vResizableColumns } from '@/directives/resizable-columns'
|
||||
import { computed, defineComponent, h, onMounted, ref } from 'vue'
|
||||
import type { Component, PropType } from 'vue'
|
||||
import { storeToRefs } from 'pinia'
|
||||
|
||||
@@ -14,6 +14,22 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-4 flex flex-wrap items-center gap-3 text-sm" :class="mutedTextClass">
|
||||
<label class="flex items-center gap-2">
|
||||
下载状态刷新
|
||||
<select :value="downloadCheckInterval" :disabled="savingCheckInterval" class="min-h-11 rounded-lg border px-3" :class="fieldClass" @change="handleCheckIntervalChange">
|
||||
<option :value="0">仅手动刷新</option>
|
||||
<option :value="30">每 30 秒</option>
|
||||
<option :value="60">每分钟</option>
|
||||
<option :value="300">每 5 分钟</option>
|
||||
<option :value="600">每 10 分钟</option>
|
||||
<option :value="1800">每 30 分钟</option>
|
||||
</select>
|
||||
</label>
|
||||
<span class="text-xs">仅检测当前页;刷新列表会重新检测,不消耗取件次数。</span>
|
||||
<span v-if="checkIntervalError" role="alert" class="text-red-500">{{ checkIntervalError }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="!hasSelectedFiles" class="mb-5 grid grid-cols-2 gap-3 sm:mb-6 sm:gap-4 xl:grid-cols-4">
|
||||
<div
|
||||
v-for="card in summaryCards"
|
||||
@@ -70,7 +86,8 @@
|
||||
</div>
|
||||
|
||||
<Transition :css="false" @before-enter="beforeExpandPanelEnter" @enter="enterExpandPanel" @after-enter="afterExpandPanelEnter" @before-leave="beforeExpandPanelLeave" @leave="leaveExpandPanel">
|
||||
<div id="file-filter-panel" v-show="filterBodyVisible" class="fcb-expand-content mt-4 grid gap-4">
|
||||
<div id="file-filter-panel" v-show="filterBodyVisible" class="fcb-expand-content">
|
||||
<div class="grid gap-4 pt-4">
|
||||
<div class="flex flex-col gap-3 lg:flex-row lg:items-center">
|
||||
<label class="min-w-0 flex-1">
|
||||
<span class="sr-only">{{ t('fileManage.searchPlaceholder') }}</span>
|
||||
@@ -256,6 +273,7 @@
|
||||
</BaseButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</section>
|
||||
|
||||
@@ -362,6 +380,7 @@
|
||||
{{ file.displayHealthState }}
|
||||
</span>
|
||||
</div>
|
||||
<DownloadCheckStatus class="mt-2" :result="downloadStatusFor(file.id)" :dark="isDarkMode" />
|
||||
<div class="mt-2 grid grid-cols-2 gap-x-3 gap-y-1 text-xs" :class="[mutedTextClass]">
|
||||
<span>{{ file.code }} · {{ file.displaySize }}</span>
|
||||
<span class="text-right">{{ file.displayUsage }}</span>
|
||||
@@ -694,6 +713,9 @@
|
||||
{{ file.isExpiredFile ? t('fileManage.expired') : t('fileManage.active') }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4" :class="primaryTextClass">
|
||||
<DownloadCheckStatus :result="downloadStatusFor(file.id)" :dark="isDarkMode" />
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
<div class="flex items-center justify-end gap-2">
|
||||
<button
|
||||
@@ -806,55 +828,56 @@
|
||||
</div>
|
||||
<div class="overflow-x-auto" tabindex="0" role="region" :aria-label="t('fileManage.history.title')">
|
||||
<table
|
||||
v-resizable-columns
|
||||
class="min-w-full divide-y"
|
||||
:class="[isDarkMode ? 'divide-gray-700' : 'divide-gray-200']"
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
<th
|
||||
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
||||
class="px-4 py-3 text-center text-xs font-semibold uppercase"
|
||||
:class="[mutedTextClass]"
|
||||
>
|
||||
文件
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
||||
class="px-4 py-3 text-center text-xs font-semibold uppercase"
|
||||
:class="[mutedTextClass]"
|
||||
>
|
||||
大小
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
||||
class="px-4 py-3 text-center text-xs font-semibold uppercase"
|
||||
:class="[mutedTextClass]"
|
||||
>
|
||||
取件码
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
||||
class="px-4 py-3 text-center text-xs font-semibold uppercase"
|
||||
:class="[mutedTextClass]"
|
||||
>
|
||||
上传时间
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
||||
class="px-4 py-3 text-center text-xs font-semibold uppercase"
|
||||
:class="[mutedTextClass]"
|
||||
>
|
||||
过期时间
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
||||
class="px-4 py-3 text-center text-xs font-semibold uppercase"
|
||||
:class="[mutedTextClass]"
|
||||
>
|
||||
下载
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
||||
class="px-4 py-3 text-center text-xs font-semibold uppercase"
|
||||
:class="[mutedTextClass]"
|
||||
>
|
||||
流量
|
||||
</th>
|
||||
<th
|
||||
class="px-4 py-3 text-left text-xs font-semibold uppercase"
|
||||
class="px-4 py-3 text-center text-xs font-semibold uppercase"
|
||||
:class="[mutedTextClass]"
|
||||
>
|
||||
状态
|
||||
@@ -1704,6 +1727,8 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { vResizableColumns } from '@/directives/resizable-columns'
|
||||
import DownloadCheckStatus from '@/components/manage/DownloadCheckStatus.vue'
|
||||
import { getHistoryStatusLabel } from '@/utils/history-status'
|
||||
import { computed, nextTick, onMounted, onUnmounted, ref, watch, type Component } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
@@ -1749,7 +1774,7 @@ import NativeDateSelect from '@/components/common/NativeDateSelect.vue'
|
||||
import BaseModal from '@/components/common/BaseModal.vue'
|
||||
import BaseButton from '@/components/common/BaseButton.vue'
|
||||
import AdaptiveValue from '@/components/common/AdaptiveValue.vue'
|
||||
import { useAdminFiles, useInjectedDarkMode, useTransferAnalytics } from '@/composables'
|
||||
import { useAdminFiles, useInjectedDarkMode, useTransferAnalytics, useDownloadChecks } from '@/composables'
|
||||
import { formatFileSize, formatTimestamp } from '@/utils/common'
|
||||
import { createDetailMotion } from '@/utils/detailMotion'
|
||||
|
||||
@@ -1768,6 +1793,7 @@ const fileTableHeaders = computed(() => [
|
||||
t('fileManage.headers.usage'),
|
||||
t('fileManage.headers.expiration'),
|
||||
t('fileManage.headers.status'),
|
||||
'可下载状态',
|
||||
t('fileManage.headers.actions')
|
||||
])
|
||||
|
||||
@@ -1852,6 +1878,15 @@ const {
|
||||
toggleFileSelection
|
||||
} = useAdminFiles()
|
||||
|
||||
const {
|
||||
interval: downloadCheckInterval, saving: savingCheckInterval, error: checkIntervalError,
|
||||
statusFor: downloadStatusFor, loadInterval: loadCheckInterval, saveInterval: saveCheckInterval
|
||||
} = useDownloadChecks(tableData)
|
||||
const handleCheckIntervalChange = (event: Event) => {
|
||||
void saveCheckInterval(Number((event.target as HTMLSelectElement).value))
|
||||
}
|
||||
|
||||
|
||||
const isFilterPanelOpen = ref(false)
|
||||
const showMobilePolicyActions = ref(false)
|
||||
const mobileMediaQuery = window.matchMedia('(max-width: 767px)')
|
||||
@@ -1864,12 +1899,12 @@ const lifecycleViewportRef = ref<HTMLElement | null>(null)
|
||||
let lifecycleHeightRevision = 0
|
||||
const isRetrievalHistoryExpanded = ref(false)
|
||||
const retrievalTimelineEvents = computed(() =>
|
||||
(selectedFileDetail.value?.detailTimeline || []).filter((item) => item.key === 'retrieved_event')
|
||||
(selectedFileDetail.value?.detailTimeline || []).filter((item) => item.key === 'retrieved_event' || item.key === 'queried_event')
|
||||
)
|
||||
const retrievalTimelineCount = computed(() => retrievalTimelineEvents.value.length)
|
||||
const detailTimelineRows = computed(() => {
|
||||
const timeline = selectedFileDetail.value?.detailTimeline || []
|
||||
return timeline.filter((item) => item.key !== 'retrieved_event')
|
||||
return timeline.filter((item) => item.key !== 'retrieved_event' && item.key !== 'queried_event')
|
||||
})
|
||||
const visibleDetailTimeline = computed(() =>
|
||||
isLifecycleExpanded.value ? detailTimelineRows.value : detailTimelineRows.value.slice(0, 3)
|
||||
@@ -2509,6 +2544,7 @@ watch(
|
||||
onMounted(() => {
|
||||
mobileMediaQuery.addEventListener('change', syncMobileViewport)
|
||||
params.value.health = getRouteHealthFilter()
|
||||
void loadCheckInterval()
|
||||
void loadViewPresets()
|
||||
void loadFiles()
|
||||
void loadHistoryFiles()
|
||||
|
||||
Reference in new issue
Block a user