✨ 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>
|
||||||
<div class="overflow-x-auto" tabindex="0" role="region" :aria-label="title">
|
<div class="overflow-x-auto" tabindex="0" role="region" :aria-label="title">
|
||||||
<table
|
<table
|
||||||
|
v-resizable-columns
|
||||||
class="divide-y"
|
class="divide-y"
|
||||||
:class="[tableClass, isDarkMode ? 'divide-[#495765]' : 'divide-[#d7e3e5]']"
|
:class="[tableClass, isDarkMode ? 'divide-[#495765]' : 'divide-[#d7e3e5]']"
|
||||||
>
|
>
|
||||||
@@ -30,7 +31,7 @@
|
|||||||
v-for="header in headers"
|
v-for="header in headers"
|
||||||
:key="header"
|
:key="header"
|
||||||
scope="col"
|
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']"
|
:class="[isDarkMode ? 'text-gray-400' : 'text-gray-500']"
|
||||||
>
|
>
|
||||||
{{ header }}
|
{{ header }}
|
||||||
@@ -50,6 +51,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { vResizableColumns } from '@/directives/resizable-columns'
|
||||||
import { inject, useSlots } from 'vue'
|
import { inject, useSlots } from 'vue'
|
||||||
|
|
||||||
interface Props {
|
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 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>
|
||||||
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
<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 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>
|
||||||
<div class="border-t pt-4" :class="isDarkMode ? 'border-gray-700' : 'border-gray-200'">
|
<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>
|
<BaseButton v-if="record.type === 'text' || typeof record.content === 'string'" @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-else @click="$emit('download-record', record)"><DownloadIcon class="mr-2 h-4 w-4" aria-hidden="true" />{{ t('fileDetail.download') }}</BaseButton>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col items-center gap-2 rounded-2xl p-4" :class="isDarkMode ? 'bg-gray-900/30' : 'bg-white/40'">
|
<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>
|
<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 BaseModal from './BaseModal.vue'
|
||||||
import BaseButton from './BaseButton.vue'
|
import BaseButton from './BaseButton.vue'
|
||||||
import type { ReceivedFileRecord } from '@/types'
|
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 {
|
interface Props {
|
||||||
visible: boolean
|
visible: boolean
|
||||||
@@ -41,6 +43,7 @@ interface Props {
|
|||||||
interface Emits {
|
interface Emits {
|
||||||
close: []
|
close: []
|
||||||
'preview-content': []
|
'preview-content': []
|
||||||
|
'download-record': [record: ReceivedFileRecord]
|
||||||
}
|
}
|
||||||
|
|
||||||
defineProps<Props>()
|
defineProps<Props>()
|
||||||
@@ -49,10 +52,6 @@ const { t } = useI18n()
|
|||||||
const isDarkMode = inject('isDarkMode')
|
const isDarkMode = inject('isDarkMode')
|
||||||
const QRCode = defineAsyncComponent(() => import('qrcode.vue'))
|
const QRCode = defineAsyncComponent(() => import('qrcode.vue'))
|
||||||
|
|
||||||
const getDownloadUrl = (record: ReceivedFileRecord) => {
|
|
||||||
return buildDownloadUrl(record.downloadUrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
const getQRCodeValue = (record: ReceivedFileRecord) => {
|
const getQRCodeValue = (record: ReceivedFileRecord) => {
|
||||||
return buildReceivedRecordQrValue(record)
|
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" />
|
<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">
|
<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-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>
|
</div>
|
||||||
<div class="mt-3 grid grid-cols-3 gap-2">
|
<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 { FileIcon, EyeIcon, DownloadIcon, TrashIcon } from 'lucide-vue-next'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import type { ReceivedFileRecord } from '@/types'
|
import type { ReceivedFileRecord } from '@/types'
|
||||||
|
import { queriedAt, formatRecordTime } from '@/utils/receive-record'
|
||||||
|
|
||||||
defineProps<{ records: ReceivedFileRecord[] }>()
|
defineProps<{ records: ReceivedFileRecord[] }>()
|
||||||
defineEmits<{ 'view-details': [record: ReceivedFileRecord]; 'download-record': [record: ReceivedFileRecord]; 'delete-record': [id: number] }>()
|
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 { useTransferAnalytics } from './useTransferAnalytics'
|
||||||
|
|
||||||
export { useLocalFiles } from './useLocalFiles'
|
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 (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')}`
|
return `${normalizeTimelineNumber(item.value)} ${t('common.times')}`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -673,7 +673,7 @@ export function useAdminFiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const formatTimelineTitleValue = (item: AdminFileDetailTimelineItem, valueText: string) => {
|
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)
|
const numericValue = normalizeTimelineNumber(item.value)
|
||||||
return numericValue === null ? '' : String(numericValue)
|
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 { getErrorMessage } from '@/utils/common'
|
||||||
import { renderMarkdownPreview } from '@/utils/content-preview'
|
import { renderMarkdownPreview } from '@/utils/content-preview'
|
||||||
import { downloadReceivedRecord } from '@/utils/download-action'
|
import { downloadReceivedRecord } from '@/utils/download-action'
|
||||||
|
import { markRecordRetrieved } from '@/utils/receive-record'
|
||||||
|
|
||||||
type InputStatus = {
|
type InputStatus = {
|
||||||
readonly: boolean
|
readonly: boolean
|
||||||
@@ -60,8 +61,9 @@ export function useRetrieveFlow() {
|
|||||||
? detail.type === 'text'
|
? detail.type === 'text'
|
||||||
: detail.name === 'Text' && !detail.text.startsWith('/share/download')
|
: detail.name === 'Text' && !detail.text.startsWith('/share/download')
|
||||||
const content = isText ? (detail.content ?? detail.text) : null
|
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 {
|
return {
|
||||||
id: Date.now(),
|
id: Date.now(),
|
||||||
code: detail.code,
|
code: detail.code,
|
||||||
@@ -69,7 +71,9 @@ export function useRetrieveFlow() {
|
|||||||
size: formatFileSize(detail.size),
|
size: formatFileSize(detail.size),
|
||||||
downloadUrl,
|
downloadUrl,
|
||||||
content,
|
content,
|
||||||
date: new Date().toLocaleString(),
|
date: queriedAt,
|
||||||
|
queriedAt,
|
||||||
|
retrievedAt: null,
|
||||||
type: isText ? 'text' : 'file',
|
type: isText ? 'text' : 'file',
|
||||||
remainingDownloads: detail.remaining_downloads
|
remainingDownloads: detail.remaining_downloads
|
||||||
}
|
}
|
||||||
@@ -130,6 +134,7 @@ export function useRetrieveFlow() {
|
|||||||
(file) => file.code === newFileData.code
|
(file) => file.code === newFileData.code
|
||||||
)
|
)
|
||||||
if (existingIndex !== -1) {
|
if (existingIndex !== -1) {
|
||||||
|
newFileData.retrievedAt = fileStore.receiveData[existingIndex].retrievedAt ?? null
|
||||||
fileStore.deleteReceiveData(existingIndex)
|
fileStore.deleteReceiveData(existingIndex)
|
||||||
}
|
}
|
||||||
fileStore.addReceiveData(newFileData)
|
fileStore.addReceiveData(newFileData)
|
||||||
@@ -186,7 +191,9 @@ export function useRetrieveFlow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const downloadRecord = (record: ReceivedFileRecord) => {
|
const downloadRecord = (record: ReceivedFileRecord) => {
|
||||||
downloadReceivedRecord(record)
|
if (downloadReceivedRecord(record)) {
|
||||||
|
markRecordRetrieved(record)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const showContentPreview = () => {
|
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: {
|
fileRecord: {
|
||||||
filename: 'Filename',
|
filename: 'Filename',
|
||||||
size: 'Size',
|
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',
|
code: 'Code',
|
||||||
actions: 'Actions',
|
actions: 'Actions',
|
||||||
download: 'Download',
|
download: 'Download',
|
||||||
@@ -666,13 +670,17 @@ export default {
|
|||||||
title: 'Retrieval History',
|
title: 'Retrieval History',
|
||||||
description: 'Retrieved {value}; current status is {status}.'
|
description: 'Retrieved {value}; current status is {status}.'
|
||||||
},
|
},
|
||||||
|
queried_event: {
|
||||||
|
title: 'Lookup #{value}',
|
||||||
|
description: 'Lookup succeeded. Source IP: {detail}.'
|
||||||
|
},
|
||||||
retrieved_event: {
|
retrieved_event: {
|
||||||
title: 'Retrieval #{value}',
|
title: 'Retrieval #{value}',
|
||||||
description: 'This retrieval is complete; current status is {status}.'
|
description: 'Retrieval started; this does not indicate download completion.'
|
||||||
},
|
},
|
||||||
retrieved_event_unknown: {
|
retrieved_event_unknown: {
|
||||||
title: 'Retrieval History',
|
title: 'Retrieval History',
|
||||||
description: 'This retrieval is complete; current status is {status}.'
|
description: 'Retrieval started; this does not indicate download completion.'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -581,7 +581,7 @@ export default {
|
|||||||
lifecycle: '生命周期',
|
lifecycle: '生命周期',
|
||||||
expandLifecycle: '展开全部生命周期记录(共 {count} 条)',
|
expandLifecycle: '展开全部生命周期记录(共 {count} 条)',
|
||||||
collapseLifecycle: '收起生命周期记录',
|
collapseLifecycle: '收起生命周期记录',
|
||||||
expandRetrievalHistory: '展开全部取件记录(共 {count} 次)',
|
expandRetrievalHistory: '展开全部取件记录(共 {count} 条)',
|
||||||
collapseRetrievalHistory: '收起取件记录',
|
collapseRetrievalHistory: '收起取件记录',
|
||||||
permanent: '永久有效',
|
permanent: '永久有效',
|
||||||
createdAt: '创建时间',
|
createdAt: '创建时间',
|
||||||
@@ -662,13 +662,17 @@ export default {
|
|||||||
title: '取件记录',
|
title: '取件记录',
|
||||||
description: '累计取件 {value},当前状态为 {status}。'
|
description: '累计取件 {value},当前状态为 {status}。'
|
||||||
},
|
},
|
||||||
|
queried_event: {
|
||||||
|
title: '第 {value} 次查件',
|
||||||
|
description: '查件成功,来源 IP:{detail}。'
|
||||||
|
},
|
||||||
retrieved_event: {
|
retrieved_event: {
|
||||||
title: '第 {value} 次取件',
|
title: '第 {value} 次取件',
|
||||||
description: '本次取件已完成,当前状态为 {status}。'
|
description: '已发起取件,不代表下载完成。'
|
||||||
},
|
},
|
||||||
retrieved_event_unknown: {
|
retrieved_event_unknown: {
|
||||||
title: '取件记录',
|
title: '取件记录',
|
||||||
description: '本次取件已完成,当前状态为 {status}。'
|
description: '已发起取件,不代表下载完成。'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
headers: {
|
headers: {
|
||||||
@@ -709,7 +713,11 @@ export default {
|
|||||||
fileRecord: {
|
fileRecord: {
|
||||||
filename: '文件名',
|
filename: '文件名',
|
||||||
size: '文件大小',
|
size: '文件大小',
|
||||||
date: '取件日期',
|
date: '查件时间',
|
||||||
|
queryTime: '查件时间',
|
||||||
|
retrieveTime: '取件时间',
|
||||||
|
notRetrieved: '尚未取件',
|
||||||
|
retrieveTimeHint: '最近一次点击下载的时间,不代表下载完成。',
|
||||||
code: '取件码',
|
code: '取件码',
|
||||||
actions: '操作',
|
actions: '操作',
|
||||||
download: '下载',
|
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 { LocalShareService } from './local-share'
|
||||||
|
|
||||||
export { UploadCancellation, UploadInterrupted, isUploadInterrupted } from './upload-cancellation'
|
export { UploadCancellation, UploadInterrupted, isUploadInterrupted } from './upload-cancellation'
|
||||||
|
|
||||||
|
export { DownloadCheckService } from './download-check'
|
||||||
@@ -47,6 +47,7 @@ export interface ConfigState {
|
|||||||
opacity: number
|
opacity: number
|
||||||
enableChunk: number
|
enableChunk: number
|
||||||
chunkSizeMB: number
|
chunkSizeMB: number
|
||||||
|
downloadCheckInterval?: number
|
||||||
s3_access_key_id: string
|
s3_access_key_id: string
|
||||||
background: string
|
background: string
|
||||||
showAdminAddr: number
|
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
|
size: string
|
||||||
downloadUrl: string | null
|
downloadUrl: string | null
|
||||||
content: string | null
|
content: string | null
|
||||||
|
/** Legacy query time, retained for existing records. */
|
||||||
date: string
|
date: string
|
||||||
|
queriedAt?: string
|
||||||
|
retrievedAt?: string | null
|
||||||
type?: 'file' | 'text'
|
type?: 'file' | 'text'
|
||||||
remainingDownloads?: number | null
|
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'
|
'g'
|
||||||
)
|
)
|
||||||
|
|
||||||
export function downloadReceivedRecord(record: ReceivedFileRecord): void {
|
export function downloadReceivedRecord(record: ReceivedFileRecord): boolean {
|
||||||
if (record.downloadUrl) {
|
if (record.downloadUrl) {
|
||||||
window.open(buildDownloadUrl(record.downloadUrl), '_blank')
|
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' })
|
const blob = new Blob([record.content], { type: 'text/plain;charset=utf-8' })
|
||||||
saveAs(blob, `${record.filename}.txt`)
|
saveAs(blob, `${record.filename}.txt`)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getSafeFilename = (name: string) =>
|
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"
|
:record="selectedRecord"
|
||||||
@close="closeDetails"
|
@close="closeDetails"
|
||||||
@preview-content="showContentPreview"
|
@preview-content="showContentPreview"
|
||||||
|
@download-record="downloadRecord"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ContentPreviewModal
|
<ContentPreviewModal
|
||||||
|
|||||||
@@ -329,31 +329,32 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="overflow-x-auto" tabindex="0" role="region" :aria-label="t('admin.dashboard.topDownloads.title')">
|
<div class="overflow-x-auto" tabindex="0" role="region" :aria-label="t('admin.dashboard.topDownloads.title')">
|
||||||
<table
|
<table
|
||||||
|
v-resizable-columns
|
||||||
class="min-w-full divide-y"
|
class="min-w-full divide-y"
|
||||||
:class="[isDarkMode ? 'divide-gray-700' : 'divide-gray-200']"
|
:class="[isDarkMode ? 'divide-gray-700' : 'divide-gray-200']"
|
||||||
>
|
>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<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]"
|
:class="[mutedTextClass]"
|
||||||
>
|
>
|
||||||
{{ t('admin.dashboard.topDownloads.file') }}
|
{{ t('admin.dashboard.topDownloads.file') }}
|
||||||
</th>
|
</th>
|
||||||
<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]"
|
:class="[mutedTextClass]"
|
||||||
>
|
>
|
||||||
{{ t('admin.dashboard.topDownloads.downloads') }}
|
{{ t('admin.dashboard.topDownloads.downloads') }}
|
||||||
</th>
|
</th>
|
||||||
<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]"
|
:class="[mutedTextClass]"
|
||||||
>
|
>
|
||||||
{{ t('admin.dashboard.topDownloads.traffic') }}
|
{{ t('admin.dashboard.topDownloads.traffic') }}
|
||||||
</th>
|
</th>
|
||||||
<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]"
|
:class="[mutedTextClass]"
|
||||||
>
|
>
|
||||||
{{ t('admin.dashboard.topDownloads.status') }}
|
{{ t('admin.dashboard.topDownloads.status') }}
|
||||||
@@ -417,6 +418,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { vResizableColumns } from '@/directives/resizable-columns'
|
||||||
import { computed, defineComponent, h, onMounted, ref } from 'vue'
|
import { computed, defineComponent, h, onMounted, ref } from 'vue'
|
||||||
import type { Component, PropType } from 'vue'
|
import type { Component, PropType } from 'vue'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
|
|||||||
@@ -14,6 +14,22 @@
|
|||||||
</div>
|
</div>
|
||||||
</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-if="!hasSelectedFiles" class="mb-5 grid grid-cols-2 gap-3 sm:mb-6 sm:gap-4 xl:grid-cols-4">
|
||||||
<div
|
<div
|
||||||
v-for="card in summaryCards"
|
v-for="card in summaryCards"
|
||||||
@@ -70,7 +86,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Transition :css="false" @before-enter="beforeExpandPanelEnter" @enter="enterExpandPanel" @after-enter="afterExpandPanelEnter" @before-leave="beforeExpandPanelLeave" @leave="leaveExpandPanel">
|
<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">
|
<div class="flex flex-col gap-3 lg:flex-row lg:items-center">
|
||||||
<label class="min-w-0 flex-1">
|
<label class="min-w-0 flex-1">
|
||||||
<span class="sr-only">{{ t('fileManage.searchPlaceholder') }}</span>
|
<span class="sr-only">{{ t('fileManage.searchPlaceholder') }}</span>
|
||||||
@@ -256,6 +273,7 @@
|
|||||||
</BaseButton>
|
</BaseButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -362,6 +380,7 @@
|
|||||||
{{ file.displayHealthState }}
|
{{ file.displayHealthState }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</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]">
|
<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>{{ file.code }} · {{ file.displaySize }}</span>
|
||||||
<span class="text-right">{{ file.displayUsage }}</span>
|
<span class="text-right">{{ file.displayUsage }}</span>
|
||||||
@@ -694,6 +713,9 @@
|
|||||||
{{ file.isExpiredFile ? t('fileManage.expired') : t('fileManage.active') }}
|
{{ file.isExpiredFile ? t('fileManage.expired') : t('fileManage.active') }}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</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">
|
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||||
<div class="flex items-center justify-end gap-2">
|
<div class="flex items-center justify-end gap-2">
|
||||||
<button
|
<button
|
||||||
@@ -806,55 +828,56 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="overflow-x-auto" tabindex="0" role="region" :aria-label="t('fileManage.history.title')">
|
<div class="overflow-x-auto" tabindex="0" role="region" :aria-label="t('fileManage.history.title')">
|
||||||
<table
|
<table
|
||||||
|
v-resizable-columns
|
||||||
class="min-w-full divide-y"
|
class="min-w-full divide-y"
|
||||||
:class="[isDarkMode ? 'divide-gray-700' : 'divide-gray-200']"
|
:class="[isDarkMode ? 'divide-gray-700' : 'divide-gray-200']"
|
||||||
>
|
>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<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]"
|
:class="[mutedTextClass]"
|
||||||
>
|
>
|
||||||
文件
|
文件
|
||||||
</th>
|
</th>
|
||||||
<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]"
|
:class="[mutedTextClass]"
|
||||||
>
|
>
|
||||||
大小
|
大小
|
||||||
</th>
|
</th>
|
||||||
<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]"
|
:class="[mutedTextClass]"
|
||||||
>
|
>
|
||||||
取件码
|
取件码
|
||||||
</th>
|
</th>
|
||||||
<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]"
|
:class="[mutedTextClass]"
|
||||||
>
|
>
|
||||||
上传时间
|
上传时间
|
||||||
</th>
|
</th>
|
||||||
<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]"
|
:class="[mutedTextClass]"
|
||||||
>
|
>
|
||||||
过期时间
|
过期时间
|
||||||
</th>
|
</th>
|
||||||
<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]"
|
:class="[mutedTextClass]"
|
||||||
>
|
>
|
||||||
下载
|
下载
|
||||||
</th>
|
</th>
|
||||||
<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]"
|
:class="[mutedTextClass]"
|
||||||
>
|
>
|
||||||
流量
|
流量
|
||||||
</th>
|
</th>
|
||||||
<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]"
|
:class="[mutedTextClass]"
|
||||||
>
|
>
|
||||||
状态
|
状态
|
||||||
@@ -1704,6 +1727,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { vResizableColumns } from '@/directives/resizable-columns'
|
||||||
|
import DownloadCheckStatus from '@/components/manage/DownloadCheckStatus.vue'
|
||||||
import { getHistoryStatusLabel } from '@/utils/history-status'
|
import { getHistoryStatusLabel } from '@/utils/history-status'
|
||||||
import { computed, nextTick, onMounted, onUnmounted, ref, watch, type Component } from 'vue'
|
import { computed, nextTick, onMounted, onUnmounted, ref, watch, type Component } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
@@ -1749,7 +1774,7 @@ import NativeDateSelect from '@/components/common/NativeDateSelect.vue'
|
|||||||
import BaseModal from '@/components/common/BaseModal.vue'
|
import BaseModal from '@/components/common/BaseModal.vue'
|
||||||
import BaseButton from '@/components/common/BaseButton.vue'
|
import BaseButton from '@/components/common/BaseButton.vue'
|
||||||
import AdaptiveValue from '@/components/common/AdaptiveValue.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 { formatFileSize, formatTimestamp } from '@/utils/common'
|
||||||
import { createDetailMotion } from '@/utils/detailMotion'
|
import { createDetailMotion } from '@/utils/detailMotion'
|
||||||
|
|
||||||
@@ -1768,6 +1793,7 @@ const fileTableHeaders = computed(() => [
|
|||||||
t('fileManage.headers.usage'),
|
t('fileManage.headers.usage'),
|
||||||
t('fileManage.headers.expiration'),
|
t('fileManage.headers.expiration'),
|
||||||
t('fileManage.headers.status'),
|
t('fileManage.headers.status'),
|
||||||
|
'可下载状态',
|
||||||
t('fileManage.headers.actions')
|
t('fileManage.headers.actions')
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -1852,6 +1878,15 @@ const {
|
|||||||
toggleFileSelection
|
toggleFileSelection
|
||||||
} = useAdminFiles()
|
} = 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 isFilterPanelOpen = ref(false)
|
||||||
const showMobilePolicyActions = ref(false)
|
const showMobilePolicyActions = ref(false)
|
||||||
const mobileMediaQuery = window.matchMedia('(max-width: 767px)')
|
const mobileMediaQuery = window.matchMedia('(max-width: 767px)')
|
||||||
@@ -1864,12 +1899,12 @@ const lifecycleViewportRef = ref<HTMLElement | null>(null)
|
|||||||
let lifecycleHeightRevision = 0
|
let lifecycleHeightRevision = 0
|
||||||
const isRetrievalHistoryExpanded = ref(false)
|
const isRetrievalHistoryExpanded = ref(false)
|
||||||
const retrievalTimelineEvents = computed(() =>
|
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 retrievalTimelineCount = computed(() => retrievalTimelineEvents.value.length)
|
||||||
const detailTimelineRows = computed(() => {
|
const detailTimelineRows = computed(() => {
|
||||||
const timeline = selectedFileDetail.value?.detailTimeline || []
|
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(() =>
|
const visibleDetailTimeline = computed(() =>
|
||||||
isLifecycleExpanded.value ? detailTimelineRows.value : detailTimelineRows.value.slice(0, 3)
|
isLifecycleExpanded.value ? detailTimelineRows.value : detailTimelineRows.value.slice(0, 3)
|
||||||
@@ -2509,6 +2544,7 @@ watch(
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
mobileMediaQuery.addEventListener('change', syncMobileViewport)
|
mobileMediaQuery.addEventListener('change', syncMobileViewport)
|
||||||
params.value.health = getRouteHealthFilter()
|
params.value.health = getRouteHealthFilter()
|
||||||
|
void loadCheckInterval()
|
||||||
void loadViewPresets()
|
void loadViewPresets()
|
||||||
void loadFiles()
|
void loadFiles()
|
||||||
void loadHistoryFiles()
|
void loadHistoryFiles()
|
||||||
|
|||||||
@@ -89,3 +89,35 @@ Playwright Page。Vite 固定运行于 `127.0.0.1:5180`;分别传入 `http`
|
|||||||
`uploadStrategy.integration.test.mjs` 验证配置决定新会话请求大小,服务端返回的
|
`uploadStrategy.integration.test.mjs` 验证配置决定新会话请求大小,服务端返回的
|
||||||
会话大小决定续传切片。`chunkSizeSettings.browser.mjs` 验证真实设置页面拒绝无效值、
|
会话大小决定续传切片。`chunkSizeSettings.browser.mjs` 验证真实设置页面拒绝无效值、
|
||||||
保存/刷新后保留以及发送页读取公共配置;全部 API 拦截为隔离数据。
|
保存/刷新后保留以及发送页读取公共配置;全部 API 拦截为隔离数据。
|
||||||
|
|
||||||
|
|
||||||
|
## 可下载状态
|
||||||
|
|
||||||
|
`downloadChecks.integration.test.mjs` 覆盖当前页批量检测、分页乱序响应隔离、
|
||||||
|
请求失败与重试、间隔保存及失败保留旧值、自动刷新与离开页面取消、状态组件渲染。
|
||||||
|
沿用 `node --experimental-strip-types --test --experimental-test-coverage tests/*.test.mjs`。
|
||||||
|
真实测试站验收另验证 WebDAV 小文件上传、检测不扣次数、桌面/移动端显示和间隔持久化;
|
||||||
|
验收完成后恢复间隔并清理验收文件。
|
||||||
|
|
||||||
|
## 查件与取件时间
|
||||||
|
|
||||||
|
- `receiveRecord.test.mjs`:旧日期按查件时间兼容、ISO 显示、最近下载时间独立更新。
|
||||||
|
- `retrieveTimes.integration.test.mjs`:真实 Vue/Pinia 查件流程、两种时间分离、
|
||||||
|
再次查件保留取件时间、重复下载更新、无下载动作不生成取件时间、弹窗与列表文案。
|
||||||
|
- 浏览器验收:测试站创建独立次数限制文件,查件不扣次数,分别点击弹窗和记录下载,
|
||||||
|
核对显示时间及后台次数,结束后清理测试文件。
|
||||||
|
- 表头验收:1440/1024/800px 下所有表头单行,390px 移动端无页面横向溢出。
|
||||||
|
|
||||||
|
### 表格列宽、查件生命周期和筛选动画
|
||||||
|
|
||||||
|
- `columnWidth.test.mjs` 覆盖指定列增减宽度、最小宽度及相邻列不受影响。
|
||||||
|
- `retrieveTimes.integration.test.mjs` 同时验证签名文本下载入口,以及查件和取件事件的顺序与显示。
|
||||||
|
- `tests/browser/admin-tables.cjs` 用真实浏览器验证所有文件、历史文件、下载排行表头居中及拖拽,
|
||||||
|
包括键盘调整、松开/失焦/卸载清理、窄屏无页面溢出、精简下载状态。
|
||||||
|
同时逐帧测量筛选收起末段,验证快速反向切换及减少动态效果模式。
|
||||||
|
- 浏览器脚本需要有现存文件的测试站、Playwright 和 Chromium,以及环境变量
|
||||||
|
`FCB_TEST_PASSWORD`;可通过 `FCB_TEST_URL` 指定站点。用 Playwright skill 的 `run.js`
|
||||||
|
运行该脚本,或在安装 Playwright 的环境中直接运行。`FCB_FRONTEND_DIST` 可指定本地构建目录,
|
||||||
|
仅在浏览器内替换静态资源进行部署前验证,不修改站点。
|
||||||
|
- 前端单元/集成 72 项通过;新增列宽计算工具覆盖率 100%。Node 原生覆盖率
|
||||||
|
不涵盖 Vite SSR 动态载入的 Vue 和指令模块,真实 DOM 行为由浏览器验收覆盖。
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
const {chromium}=require('playwright');
|
||||||
|
const {expect}=require('playwright/test');
|
||||||
|
const assert=require('node:assert/strict');
|
||||||
|
const fs=require('node:fs');
|
||||||
|
const path=require('node:path');
|
||||||
|
const site=process.env.FCB_TEST_URL || 'https://filetest.orionc.me';
|
||||||
|
(async()=>{
|
||||||
|
const browser=await chromium.launch({headless:false});
|
||||||
|
try {
|
||||||
|
const context=await browser.newContext({viewport:{width:1440,height:1000}});
|
||||||
|
const page=await context.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message));
|
||||||
|
const login=await page.request.post(site+'/admin/login',{data:{password:process.env.FCB_TEST_PASSWORD}});
|
||||||
|
const body=await login.json();assert.ok(body.detail?.token,'Test login must succeed');
|
||||||
|
await context.addInitScript(token=>localStorage.setItem('token',token),body.detail.token);
|
||||||
|
if(process.env.FCB_FRONTEND_DIST){
|
||||||
|
await page.route(site+'/**',async route=>{
|
||||||
|
const url=new URL(route.request().url());
|
||||||
|
const relative=url.pathname==='/'?'index.html':url.pathname.startsWith('/theme-assets/')?url.pathname.slice('/theme-assets/'.length):null;
|
||||||
|
const file=relative&&path.join(process.env.FCB_FRONTEND_DIST,relative);
|
||||||
|
if(file&&fs.existsSync(file)&&fs.statSync(file).isFile())await route.fulfill({path:file});else await route.continue();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await page.goto(site+'/#/admin/files');
|
||||||
|
const all=page.locator('.data-table-2026 table');
|
||||||
|
await all.getByRole('status').first().waitFor();
|
||||||
|
await all.getByRole('status').filter({hasText:'可下载'}).first().waitFor();
|
||||||
|
const statuses=await all.getByRole('status').evaluateAll(nodes=>nodes.map(n=>({children:n.children.length,title:n.getAttribute('title'),text:n.textContent})));
|
||||||
|
statuses.forEach(s=>{assert.ok(s.children<=2,JSON.stringify(s));assert.equal(s.title,null)});
|
||||||
|
async function verifyTable(table,name) {
|
||||||
|
await table.scrollIntoViewIfNeeded();
|
||||||
|
const headers=table.locator('th');const handles=table.getByRole('separator');
|
||||||
|
assert.equal(await handles.count(),await headers.count());
|
||||||
|
for(const style of await headers.evaluateAll(hs=>hs.map(h=>({align:getComputedStyle(h).textAlign,whiteSpace:getComputedStyle(h).whiteSpace})))){
|
||||||
|
assert.equal(style.align,'center');assert.equal(style.whiteSpace,'nowrap');
|
||||||
|
}
|
||||||
|
const widths=()=>headers.evaluateAll(hs=>hs.map(h=>h.getBoundingClientRect().width));
|
||||||
|
const index=1;const handle=handles.nth(index);await handle.scrollIntoViewIfNeeded();
|
||||||
|
const before=await widths();const box=await handle.boundingBox();
|
||||||
|
await page.mouse.move(box.x+box.width/2,box.y+box.height/2);await page.mouse.down();
|
||||||
|
await page.mouse.move(box.x+box.width/2+90,box.y+box.height/2,{steps:12});await page.mouse.up();
|
||||||
|
const after=await widths();assert.ok(Math.abs(after[index]-before[index]-90)<2,`${name}: ${before} -> ${after}`);
|
||||||
|
before.forEach((w,i)=>{if(i!==index)assert.ok(Math.abs(w-after[i])<2,`${name} other column changed`)})
|
||||||
|
// Continued widening and keyboard narrowing must agree with the actual geometry.
|
||||||
|
await handle.focus();await page.keyboard.press('ArrowRight');assert.ok(Math.abs((await widths())[index]-after[index]-16)<2);
|
||||||
|
await page.keyboard.press('ArrowLeft');assert.ok(Math.abs((await widths())[index]-after[index])<2);
|
||||||
|
const b=await handle.boundingBox();await page.mouse.move(b.x+4,b.y+b.height/2);await page.mouse.down();
|
||||||
|
await page.mouse.move(b.x-500,b.y+b.height/2,{steps:10});await page.mouse.up();
|
||||||
|
assert.ok((await widths())[index]>=72);assert.equal(await table.evaluate(t=>t.classList.contains('columns-resizing')),false);
|
||||||
|
const frozen=await widths();await page.mouse.move(900,500);assert.deepEqual(await widths(),frozen);
|
||||||
|
console.log(name+': centered, drag +/- and minimum, keyboard, other columns stable, release cleanup OK');
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggle=page.locator('[aria-controls="file-filter-panel"]');
|
||||||
|
await toggle.scrollIntoViewIfNeeded();await toggle.click();
|
||||||
|
await page.waitForFunction(()=>{const p=document.querySelector('#file-filter-panel');return getComputedStyle(p).display!=='none'&&!p.style.height});
|
||||||
|
const samples=await page.evaluate(async()=>{
|
||||||
|
const panel=document.querySelector('#file-filter-panel'),card=panel.closest('section'),samples=[];
|
||||||
|
const start=performance.now();document.querySelector('[aria-controls="file-filter-panel"]').click();
|
||||||
|
await new Promise(resolve=>{const frame=()=>{const elapsed=performance.now()-start;samples.push({t:elapsed,height:card.getBoundingClientRect().height});if(elapsed<650)requestAnimationFrame(frame);else resolve()};requestAnimationFrame(frame)});
|
||||||
|
return samples;
|
||||||
|
});
|
||||||
|
let lateJump=0;for(let i=1;i<samples.length;i++)if(samples[i-1].t>=300)lateJump=Math.max(lateJump,Math.abs(samples[i].height-samples[i-1].height));
|
||||||
|
fs.writeFileSync('/tmp/fcb-filter-animation-samples.json',JSON.stringify(samples));
|
||||||
|
assert.ok(lateJump<5,'Filter final collapse jump: '+lateJump);
|
||||||
|
await page.evaluate(async()=>{const b=document.querySelector('[aria-controls="file-filter-panel"]');b.click();await new Promise(r=>setTimeout(r,80));b.click();await new Promise(r=>setTimeout(r,80));b.click()});
|
||||||
|
await page.waitForFunction(()=>{const p=document.querySelector('#file-filter-panel');return getComputedStyle(p).display!=='none'&&!p.style.height});
|
||||||
|
await page.emulateMedia({reducedMotion:'reduce'});await toggle.click();
|
||||||
|
await page.waitForFunction(()=>getComputedStyle(document.querySelector('#file-filter-panel')).display==='none');
|
||||||
|
await page.emulateMedia({reducedMotion:'no-preference'});
|
||||||
|
console.log('Filter collapse final frame delta '+lateJump.toFixed(2)+'px; rapid reversal and reduced motion PASS');
|
||||||
|
|
||||||
|
await verifyTable(all,'All files');
|
||||||
|
const history=page.locator('table').filter({has:page.getByRole('columnheader',{name:'流量',exact:true})});
|
||||||
|
await verifyTable(history,'History');
|
||||||
|
await all.scrollIntoViewIfNeeded();await page.screenshot({path:'/tmp/fcb-columns-light.png'});
|
||||||
|
await page.goto(site+'/#/admin/dashboard');
|
||||||
|
const dashboard=page.locator('table');await expect(dashboard).toHaveCount(1);await dashboard.getByRole('separator').first().waitFor();
|
||||||
|
await verifyTable(dashboard,'Download ranking');
|
||||||
|
await page.goto(site+'/#/admin/files');await expect(page.locator('table')).toHaveCount(2);await all.getByRole('separator').first().waitFor();
|
||||||
|
// Cancel the active drag through page blur, then navigate away during another drag.
|
||||||
|
const h=all.getByRole('separator').nth(1);await h.scrollIntoViewIfNeeded();let b=await h.boundingBox();
|
||||||
|
await page.mouse.move(b.x+4,b.y+b.height/2);await page.mouse.down();await page.evaluate(()=>window.dispatchEvent(new Event('blur')));await page.mouse.up();
|
||||||
|
assert.equal(await all.evaluate(t=>t.classList.contains('columns-resizing')),false);
|
||||||
|
b=await h.boundingBox();await page.mouse.move(b.x+4,b.y+b.height/2);await page.mouse.down();
|
||||||
|
await page.goto(site+'/#/admin/dashboard');await page.mouse.up();
|
||||||
|
await page.goto(site+'/#/admin/files');await expect(page.locator('table')).toHaveCount(2);await all.getByRole('separator').first().waitFor();
|
||||||
|
for(const width of [1024,800,390]){
|
||||||
|
await page.setViewportSize({width,height:1000});
|
||||||
|
assert.ok(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+1),'No document horizontal overflow '+width);
|
||||||
|
}
|
||||||
|
await page.setViewportSize({width:1440,height:1000});await page.emulateMedia({colorScheme:'dark'});await page.reload();
|
||||||
|
await all.getByRole('separator').first().waitFor();await all.scrollIntoViewIfNeeded();await page.screenshot({path:'/tmp/fcb-columns-dark.png'});
|
||||||
|
assert.deepEqual(errors,[]);console.log('Compact status, responsive widths, navigation/blur cleanup: PASS');
|
||||||
|
}finally{await browser.close()}
|
||||||
|
})().catch(e=>{console.error(e);process.exitCode=1});
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { test } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { resizeColumn } from '../src/utils/column-width.ts'
|
||||||
|
|
||||||
|
test('dragging changes only the selected column and preserves the starting widths', () => {
|
||||||
|
const widths = [100, 240, 180]
|
||||||
|
assert.deepEqual(resizeColumn(widths, 1, 65, 80), [100, 305, 180])
|
||||||
|
assert.deepEqual(resizeColumn(widths, 1, -50, 80), [100, 190, 180])
|
||||||
|
assert.deepEqual(widths, [100, 240, 180])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('narrowing stops at the header minimum and widening works again', () => {
|
||||||
|
const widths = [100, 240, 180]
|
||||||
|
assert.deepEqual(resizeColumn(widths, 2, -1000, 96), [100, 240, 96])
|
||||||
|
assert.deepEqual(resizeColumn([100, 240, 96], 2, 16, 96), [100, 240, 112])
|
||||||
|
assert.deepEqual(resizeColumn(widths, 0, 0, 72), widths)
|
||||||
|
})
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import { test, before, after } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { effectScope, ref, nextTick } from 'vue'
|
||||||
|
import { createServer } from 'vite'
|
||||||
|
let server, create, service, config
|
||||||
|
before(async () => {
|
||||||
|
server = await createServer({ server: { middlewareMode: true, watch: null }, appType: 'custom' })
|
||||||
|
create = (await server.ssrLoadModule('/src/composables/useDownloadChecks.ts')).useDownloadChecks
|
||||||
|
const exports = await server.ssrLoadModule('/src/services/index.ts')
|
||||||
|
service = exports.DownloadCheckService; config = exports.ConfigService
|
||||||
|
})
|
||||||
|
after(async () => await server?.close())
|
||||||
|
const ok = ids => ({ code: 200, detail: ids.map(id => ({id, status: 'available', message: 'ok', checkedAt: '2026-09-18T00:00:00Z'})) })
|
||||||
|
test('refresh batches large pages, preserves list on failure, and retries', async () => {
|
||||||
|
const scope = effectScope(), files = ref(Array.from({length: 45}, (_, i) => ({id: i + 1})))
|
||||||
|
const flow = scope.run(() => create(files)), original = service.check, batches = []
|
||||||
|
try {
|
||||||
|
service.check = async ids => { batches.push(ids.length); if (ids[0] === 21) throw Error('offline'); return ok(ids) }
|
||||||
|
await flow.refresh()
|
||||||
|
assert.deepEqual(batches, [20,20,5]); assert.equal(files.value.length, 45)
|
||||||
|
assert.equal(flow.statusFor(1).status, 'available'); assert.equal(flow.statusFor(21).status, 'unknown')
|
||||||
|
service.check = async ids => ok(ids); await flow.refresh()
|
||||||
|
assert.equal(flow.statusFor(21).status, 'available')
|
||||||
|
} finally { scope.stop(); service.check = original }
|
||||||
|
})
|
||||||
|
test('navigation cancels old checks and stale responses cannot change current page', async () => {
|
||||||
|
const scope = effectScope(), files = ref([{id: 1}]), flow = scope.run(() => create(files))
|
||||||
|
const original = service.check, pending = new Map(), signals = []
|
||||||
|
service.check = (ids, signal) => { signals.push(signal); return new Promise(resolve => pending.set(ids[0], resolve)) }
|
||||||
|
try {
|
||||||
|
const first = flow.refresh(); files.value = [{id: 2}]; await nextTick()
|
||||||
|
assert.equal(signals[0].aborted, true)
|
||||||
|
pending.get(2)(ok([2])); await new Promise(resolve => setImmediate(resolve))
|
||||||
|
pending.get(1)(ok([1])); await first
|
||||||
|
assert.deepEqual(Object.keys(flow.checks.value), ['2'])
|
||||||
|
assert.equal(flow.statusFor(2).status, 'available')
|
||||||
|
} finally { scope.stop(); service.check = original }
|
||||||
|
})
|
||||||
|
test('interval settings persist, save failures retain old value, manual refresh works with timer off', async () => {
|
||||||
|
const scope = effectScope(), flow = scope.run(() => create(ref([{id: 1}])))
|
||||||
|
const oldGet = config.getConfig, oldSave = config.updateConfig, oldCheck = service.check
|
||||||
|
try {
|
||||||
|
config.getConfig = async () => ({code: 200, detail: {downloadCheckInterval: 60}})
|
||||||
|
await flow.loadInterval(); assert.equal(flow.interval.value, 60)
|
||||||
|
config.updateConfig = async data => {assert.equal(data.downloadCheckInterval, 0); return {code:200}}
|
||||||
|
await flow.saveInterval(0); assert.equal(flow.interval.value, 0)
|
||||||
|
config.updateConfig = async () => {throw Error('offline')}
|
||||||
|
await flow.saveInterval(300); assert.equal(flow.interval.value, 0); assert.ok(flow.error.value)
|
||||||
|
service.check = async ids => ok(ids); await flow.refresh(); assert.equal(flow.statusFor(1).status,'available')
|
||||||
|
} finally {scope.stop();config.getConfig=oldGet;config.updateConfig=oldSave;service.check=oldCheck}
|
||||||
|
})
|
||||||
|
test('automatic timer refreshes and stops after scope disposal', async t => {
|
||||||
|
const scope=effectScope(), flow=scope.run(()=>create(ref([{id:1}]))), original=service.check
|
||||||
|
let calls=0
|
||||||
|
t.mock.timers.enable({apis:['setTimeout']})
|
||||||
|
try {
|
||||||
|
service.check=async ids=>{calls++;return ok(ids)}
|
||||||
|
await flow.refresh(); assert.equal(calls,1)
|
||||||
|
t.mock.timers.tick(300000); await new Promise(resolve=>setImmediate(resolve));assert.equal(calls,2)
|
||||||
|
scope.stop();t.mock.timers.tick(300000);assert.equal(calls,2)
|
||||||
|
} finally {scope.stop();service.check=original;t.mock.timers.reset()}
|
||||||
|
})
|
||||||
|
test('status component renders all states and the last checked time', async () => {
|
||||||
|
const {createSSRApp}=await import('vue'), {renderToString}=await import('vue/server-renderer')
|
||||||
|
const Component=(await server.ssrLoadModule('/src/components/manage/DownloadCheckStatus.vue')).default
|
||||||
|
for (const [status,label] of Object.entries({available:'可下载',unavailable:'不可下载',unknown:'未检测',checking:'检测中'})) {
|
||||||
|
const html=await renderToString(createSSRApp(Component,{result:{id:1,status,message:'reason',checkedAt:'2026-09-18T00:00:00Z'},dark:false}))
|
||||||
|
assert.ok(html.includes(label));assert.ok(!html.includes('reason'));assert.ok(html.includes('2026'))
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { test } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { queriedAt, formatRecordTime, markRecordRetrieved } from '../src/utils/receive-record.ts'
|
||||||
|
|
||||||
|
test('legacy lookup dates never imply a retrieval happened', () => {
|
||||||
|
const record = { date: '2026/9/18 15:08:09' }
|
||||||
|
assert.equal(queriedAt(record), record.date)
|
||||||
|
assert.equal(formatRecordTime(queriedAt(record)), record.date)
|
||||||
|
assert.equal(formatRecordTime(record.retrievedAt), '')
|
||||||
|
})
|
||||||
|
test('download click updates retrieval independently of query and legacy timestamps', () => {
|
||||||
|
const record = { date: 'legacy', queriedAt: '2026-09-18T07:00:00.000Z' }
|
||||||
|
markRecordRetrieved(record, new Date('2026-09-18T07:01:00Z'))
|
||||||
|
assert.equal(record.retrievedAt, '2026-09-18T07:01:00.000Z')
|
||||||
|
markRecordRetrieved(record, new Date('2026-09-18T07:02:00Z'))
|
||||||
|
assert.equal(record.retrievedAt, '2026-09-18T07:02:00.000Z')
|
||||||
|
assert.equal(queriedAt(record), '2026-09-18T07:00:00.000Z')
|
||||||
|
assert.equal(record.date, 'legacy')
|
||||||
|
})
|
||||||
|
test('ISO dates display in local time while invalid legacy values are preserved', () => {
|
||||||
|
const iso = '2026-09-18T07:00:00.000Z'
|
||||||
|
assert.equal(formatRecordTime(iso), new Date(iso).toLocaleString())
|
||||||
|
assert.equal(formatRecordTime('2026-99-99T00:00:00Z'), '2026-99-99T00:00:00Z')
|
||||||
|
assert.equal(formatRecordTime(null), '')
|
||||||
|
})
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import { test, before, after } from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { createServer } from 'vite'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import { createSSRApp, h } from 'vue'
|
||||||
|
import { renderToString } from 'vue/server-renderer'
|
||||||
|
import { createPinia } from 'pinia'
|
||||||
|
import { createI18n } from 'vue-i18n'
|
||||||
|
let server, createFlow, service, Detail, List, zh, oldWindow, opened
|
||||||
|
before(async () => {
|
||||||
|
oldWindow = globalThis.window; opened = []
|
||||||
|
globalThis.window = { location: {origin:'https://example.test'}, open: url => { opened.push(url); return {} } }
|
||||||
|
server = await createServer({resolve:{alias:{'file-saver':fileURLToPath(new URL('./fixtures/browser-save.stub.mjs',import.meta.url))}},server:{middlewareMode:true,watch:null},appType:'custom'})
|
||||||
|
createFlow = (await server.ssrLoadModule('/src/composables/useRetrieveFlow.ts')).useRetrieveFlow
|
||||||
|
service = (await server.ssrLoadModule('/src/services/index.ts')).FileService
|
||||||
|
Detail = (await server.ssrLoadModule('/src/components/common/FileDetailModal.vue')).default
|
||||||
|
List = (await server.ssrLoadModule('/src/components/common/FileRecordList.vue')).default
|
||||||
|
zh = (await server.ssrLoadModule('/src/i18n/locales/zh-CN.ts')).default
|
||||||
|
})
|
||||||
|
after(async () => { await server?.close(); globalThis.window = oldWindow })
|
||||||
|
const i18n = () => createI18n({legacy:false,locale:'zh-CN',messages:{'zh-CN':zh}})
|
||||||
|
async function flow() {
|
||||||
|
let result
|
||||||
|
const app=createSSRApp({setup(){result=createFlow();return()=>h('div')}})
|
||||||
|
app.use(createPinia()); app.use(i18n()); await renderToString(app); return result
|
||||||
|
}
|
||||||
|
const detail={code:'ABCD2345',name:'file.apk',size:3,text:'/share/download?code=ABCD2345',download_url:'/share/download?code=ABCD2345',type:'file',is_text:false,remaining_downloads:2}
|
||||||
|
test('lookup creates only query time; click records retrieval; querying again preserves retrieval', async t => {
|
||||||
|
const original=service.selectFile; const f=await flow()
|
||||||
|
t.mock.timers.enable({apis:['Date'],now:Date.parse('2026-09-18T07:00:00Z')})
|
||||||
|
service.selectFile=async()=>({code:200,detail})
|
||||||
|
try {
|
||||||
|
f.code.value=detail.code; await f.handleSubmit()
|
||||||
|
const first=f.selectedRecord.value
|
||||||
|
assert.equal(first.queriedAt,'2026-09-18T07:00:00.000Z')
|
||||||
|
assert.equal(first.retrievedAt,null)
|
||||||
|
f.viewDetails(first); assert.equal(first.retrievedAt,null)
|
||||||
|
t.mock.timers.tick(1000); f.downloadRecord(first)
|
||||||
|
assert.equal(first.retrievedAt,'2026-09-18T07:00:01.000Z')
|
||||||
|
assert.equal(f.records.value[0].retrievedAt,first.retrievedAt)
|
||||||
|
assert.ok(opened.at(-1).includes('/share/download?code=ABCD2345'))
|
||||||
|
t.mock.timers.tick(1000); f.code.value=detail.code; await f.handleSubmit()
|
||||||
|
assert.equal(f.records.value.length,1)
|
||||||
|
assert.equal(f.selectedRecord.value.queriedAt,'2026-09-18T07:00:02.000Z')
|
||||||
|
assert.equal(f.selectedRecord.value.retrievedAt,'2026-09-18T07:00:01.000Z')
|
||||||
|
t.mock.timers.tick(1000);f.downloadRecord(f.records.value[0])
|
||||||
|
assert.equal(f.selectedRecord.value.retrievedAt,'2026-09-18T07:00:03.000Z')
|
||||||
|
} finally {service.selectFile=original;t.mock.timers.reset()}
|
||||||
|
})
|
||||||
|
test('empty or failed download actions do not fabricate retrieval times', async () => {
|
||||||
|
const f=await flow(), record={id:1,code:'ABCD2345',filename:'a',size:'0',date:'legacy',content:null,downloadUrl:null}
|
||||||
|
f.downloadRecord(record);assert.equal(record.retrievedAt,undefined)
|
||||||
|
assert.throws(()=>f.downloadRecord({...record,content:''}), /Browser download/)
|
||||||
|
assert.equal(record.retrievedAt,undefined)
|
||||||
|
})
|
||||||
|
async function render(component,props){
|
||||||
|
const context={},app=createSSRApp({render:()=>h(component,props)});app.use(i18n())
|
||||||
|
return (await renderToString(app,context))+Object.values(context.teleports||{}).join('')
|
||||||
|
}
|
||||||
|
test('dialog and records show legacy date as query time and no invented retrieval',async()=>{
|
||||||
|
const record={id:1,code:'ABCD2345',filename:'file.apk',size:'3 B',date:'2026/9/18 15:00:00',content:null,downloadUrl:'/share/download?code=ABCD2345'}
|
||||||
|
for(const [component,props] of [[Detail,{visible:true,record}],[List,{records:[record]}]]){
|
||||||
|
const html=await render(component,props)
|
||||||
|
for(const text of ['查件时间','取件时间','尚未取件',record.date]) assert.ok(html.includes(text),text)
|
||||||
|
}
|
||||||
|
record.retrievedAt='2026-09-18T07:01:00Z'
|
||||||
|
const html=await render(Detail,{visible:true,record})
|
||||||
|
assert.ok(!html.includes('尚未取件'));assert.ok(html.includes(new Date(record.retrievedAt).toLocaleString()))
|
||||||
|
assert.ok(html.includes('不代表下载完成'))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('text lookups preserve the signed download entry and clicking records retrieval', async () => {
|
||||||
|
const original=service.selectFile, f=await flow()
|
||||||
|
service.selectFile=async()=>({code:200,detail:{...detail,type:'text',is_text:true,content:'',text:''}})
|
||||||
|
try {
|
||||||
|
f.code.value=detail.code;await f.handleSubmit()
|
||||||
|
assert.equal(f.selectedRecord.value.content,'')
|
||||||
|
assert.equal(f.selectedRecord.value.downloadUrl,detail.download_url)
|
||||||
|
assert.equal(f.selectedRecord.value.retrievedAt,null)
|
||||||
|
f.downloadRecord(f.selectedRecord.value)
|
||||||
|
assert.ok(opened.at(-1).includes(detail.download_url))
|
||||||
|
assert.ok(f.selectedRecord.value.retrievedAt)
|
||||||
|
} finally { service.selectFile=original }
|
||||||
|
})
|
||||||
|
|
||||||
|
test('admin lifecycle formats lookup and retrieval events in the supplied chronological order', async () => {
|
||||||
|
const createAdmin=(await server.ssrLoadModule('/src/composables/useAdminFiles.ts')).useAdminFiles
|
||||||
|
let admin
|
||||||
|
const app=createSSRApp({setup(){admin=createAdmin();return()=>h('div')}})
|
||||||
|
app.use(createPinia());app.use(i18n());await renderToString(app)
|
||||||
|
const original=service.getAdminFileDetail
|
||||||
|
const file={id:42,code:'LIFE2345',prefix:'sample',suffix:'.txt',size:3,used_count:1,expired_count:3,created_at:'2026-09-18T07:00:00Z',timeline:[
|
||||||
|
{key:'retrieved',value:1,status:'done'},
|
||||||
|
{key:'queried_event',value:1,status:'done',detail:'127.0.0.1',timestamp:'2026-09-18T07:01:00Z'},
|
||||||
|
{key:'retrieved_event',value:1,status:'done',detail:'127.0.0.1',timestamp:'2026-09-18T07:02:00Z'},
|
||||||
|
{key:'queried_event',value:2,status:'done',detail:'127.0.0.1',timestamp:'2026-09-18T07:03:00Z'}
|
||||||
|
]}
|
||||||
|
service.getAdminFileDetail=async()=>({code:200,detail:file})
|
||||||
|
try {
|
||||||
|
await admin.openFileDetail(file)
|
||||||
|
const rows=admin.selectedFileDetail.value.detailTimeline
|
||||||
|
assert.deepEqual(rows.map(x=>x.displayTitle),['取件记录','第 1 次查件','第 1 次取件','第 2 次查件'])
|
||||||
|
assert.ok(rows[1].displayDescription.includes('127.0.0.1'))
|
||||||
|
assert.ok(rows[2].displayDescription.includes('不代表下载完成'))
|
||||||
|
} finally { service.getAdminFileDetail=original }
|
||||||
|
})
|
||||||
Reference in new issue
Block a user