2026-09-19 10:54:15 +08:00
|
|
|
|
<script setup>
|
|
|
|
|
|
defineOptions({ name: 'AttachmentCenter' })
|
|
|
|
|
|
import { onActivated, onMounted, reactive, ref } from 'vue'
|
2026-09-20 14:52:36 +08:00
|
|
|
|
import { ElMessage } from 'element-plus'
|
2026-09-19 10:54:15 +08:00
|
|
|
|
import request from '../utils/request'
|
|
|
|
|
|
import { fmtTime } from '../utils/format'
|
2026-09-20 14:52:36 +08:00
|
|
|
|
import { can, isAdmin } from '../utils/perm'
|
|
|
|
|
|
import { confirmAction } from '../utils/confirm'
|
2026-09-19 10:54:15 +08:00
|
|
|
|
import PageHelp from '../components/PageHelp.vue'
|
|
|
|
|
|
import { helpAttachment } from '../help'
|
|
|
|
|
|
|
|
|
|
|
|
// 文件类型(大写枚举 → 中文显示)
|
|
|
|
|
|
const fileTypeOptions = [
|
|
|
|
|
|
{ value: 'PROCESS_PDF', label: '工艺流程' },
|
|
|
|
|
|
{ value: 'INSPECTION_PHOTO', label: '检验照片' },
|
|
|
|
|
|
{ value: 'INSPECTION_PDF', label: '检验报告' },
|
|
|
|
|
|
{ value: 'DRAWING', label: '图纸' },
|
|
|
|
|
|
{ value: 'PROCESS_CARD', label: '流程卡' },
|
|
|
|
|
|
{ value: 'PACKAGE_PHOTO', label: '包装照片' },
|
|
|
|
|
|
{ value: 'EXCEL_IMPORT', label: 'Excel导入' },
|
2026-10-26 16:32:35 +08:00
|
|
|
|
{ value: 'IMAGE', label: '图片' },
|
2026-09-19 10:54:15 +08:00
|
|
|
|
{ value: 'OTHER', label: '其他' }
|
|
|
|
|
|
]
|
|
|
|
|
|
const bizTypeOptions = [
|
|
|
|
|
|
{ value: 'inbound', label: '入库' },
|
|
|
|
|
|
{ value: 'material', label: '物料档案' },
|
|
|
|
|
|
{ value: 'inspection', label: '质量检验' },
|
|
|
|
|
|
{ value: 'semi', label: '半成品' },
|
|
|
|
|
|
{ value: 'outbound', label: '出库' }
|
|
|
|
|
|
]
|
|
|
|
|
|
function fileTypeText(t) {
|
|
|
|
|
|
const f = fileTypeOptions.find((x) => x.value === t)
|
|
|
|
|
|
return f ? f.label : (t || '其他')
|
|
|
|
|
|
}
|
|
|
|
|
|
function bizTypeText(t) {
|
|
|
|
|
|
const f = bizTypeOptions.find((x) => x.value === t)
|
|
|
|
|
|
return f ? f.label : (t || '-')
|
|
|
|
|
|
}
|
|
|
|
|
|
function sizeText(n) {
|
|
|
|
|
|
if (!n) return '-'
|
|
|
|
|
|
if (n < 1024) return n + ' B'
|
|
|
|
|
|
if (n < 1024 * 1024) return (n / 1024).toFixed(1) + ' KB'
|
|
|
|
|
|
return (n / 1024 / 1024).toFixed(2) + ' MB'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const filters = reactive({ fileType: '', bizType: '', bizId: '', fileName: '', includeDeleted: false })
|
|
|
|
|
|
const dateRange = ref([])
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const list = ref([])
|
|
|
|
|
|
const total = ref(0)
|
|
|
|
|
|
const page = reactive({ current: 1, size: 20 })
|
|
|
|
|
|
const disk = ref(null)
|
|
|
|
|
|
|
|
|
|
|
|
async function load() {
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
const data = await request.get('/attachments/all', {
|
|
|
|
|
|
params: {
|
|
|
|
|
|
fileType: filters.fileType,
|
|
|
|
|
|
bizType: filters.bizType,
|
|
|
|
|
|
bizId: filters.bizId.trim(),
|
|
|
|
|
|
fileName: filters.fileName.trim(),
|
|
|
|
|
|
includeDeleted: filters.includeDeleted ? 'true' : '',
|
|
|
|
|
|
startDate: dateRange.value?.[0] || '',
|
|
|
|
|
|
endDate: dateRange.value?.[1] || '',
|
|
|
|
|
|
page: page.current,
|
|
|
|
|
|
pageSize: page.size
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
list.value = data?.list || []
|
|
|
|
|
|
total.value = data?.total || 0
|
|
|
|
|
|
if (data?.disk) disk.value = data.disk
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
function search() {
|
|
|
|
|
|
page.current = 1
|
|
|
|
|
|
load()
|
|
|
|
|
|
}
|
|
|
|
|
|
function resetFilters() {
|
|
|
|
|
|
filters.fileType = ''
|
|
|
|
|
|
filters.bizType = ''
|
|
|
|
|
|
filters.bizId = ''
|
|
|
|
|
|
filters.fileName = ''
|
|
|
|
|
|
filters.includeDeleted = false
|
|
|
|
|
|
dateRange.value = []
|
|
|
|
|
|
search()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function download(row) {
|
|
|
|
|
|
window.open(row.url + '?dl=1', '_blank')
|
|
|
|
|
|
}
|
|
|
|
|
|
async function remove(row) {
|
2026-10-28 10:10:17 +08:00
|
|
|
|
const okDel = await confirmAction(`确认删除附件「${row.fileName}」?删除后索引标记为已删除(可由管理员在「已删除附件」中物理清除文件)。工艺流程/流程卡及保留期内的检验记录不可删除。`, '删除确认')
|
2026-09-20 14:52:36 +08:00
|
|
|
|
if (!okDel) return
|
2026-09-19 10:54:15 +08:00
|
|
|
|
try {
|
2026-09-20 14:52:36 +08:00
|
|
|
|
await request.post('/attachments/delete', { id: row.id })
|
|
|
|
|
|
ElMessage.success('已删除')
|
|
|
|
|
|
await load()
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
ElMessage.error(e?.response?.data?.message || e?.message || '删除失败(可能为受保护附件)')
|
2026-09-19 10:54:15 +08:00
|
|
|
|
}
|
2026-09-20 14:52:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-28 10:10:17 +08:00
|
|
|
|
// 已删除附件抽屉:物理清理已删附件(仅管理员),
|
|
|
|
|
|
// 先「预检」(dryRun) 展示影响范围,再「执行」前二次确认。
|
|
|
|
|
|
const cleaner = reactive({ show: false, busy: '', purgePreview: null })
|
2026-09-20 14:52:36 +08:00
|
|
|
|
function openCleaner() {
|
|
|
|
|
|
cleaner.show = true
|
|
|
|
|
|
cleaner.purgePreview = null
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 物理清理已删附件:先预检,再确认执行
|
|
|
|
|
|
async function purgePreview() {
|
|
|
|
|
|
cleaner.busy = 'purge'
|
|
|
|
|
|
try {
|
|
|
|
|
|
cleaner.purgePreview = await request.post('/attachments/purge-deleted', { dryRun: true })
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
cleaner.busy = ''
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
async function purgeRun() {
|
|
|
|
|
|
const p = cleaner.purgePreview
|
|
|
|
|
|
const go = await confirmAction(`将物理删除 ${p?.removed || 0} 个已标记删除的附件文件,预计释放 ${((p?.freed || 0) / 1024 / 1024).toFixed(2)} MB。此操作不可恢复(索引保留),是否继续?`, '物理清理确认', { type: 'error' })
|
|
|
|
|
|
if (!go) return
|
|
|
|
|
|
cleaner.busy = 'purge'
|
|
|
|
|
|
try {
|
|
|
|
|
|
const d = await request.post('/attachments/purge-deleted', { dryRun: false })
|
|
|
|
|
|
ElMessage.success(`清理完成:删除 ${d?.removed || 0}、释放 ${((d?.freed || 0) / 1024 / 1024).toFixed(2)} MB`)
|
|
|
|
|
|
cleaner.purgePreview = null
|
|
|
|
|
|
await load()
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
cleaner.busy = ''
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-19 10:54:15 +08:00
|
|
|
|
const diskType = (lvl) => (lvl === 'critical' ? 'error' : lvl === 'warn' ? 'warning' : 'success')
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(load)
|
|
|
|
|
|
onActivated(() => load())
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<el-card shadow="never" class="mb12">
|
|
|
|
|
|
<el-alert v-if="disk && disk.level !== 'ok' && disk.level !== 'unknown'"
|
|
|
|
|
|
:type="diskType(disk.level)" :closable="false" show-icon
|
|
|
|
|
|
:title="disk.message"
|
|
|
|
|
|
:description="`附件目录:${disk.rootDir} 剩余 ${(100 - disk.usedPercent)}% 可用 ${(disk.freeBytes / 1024 / 1024 / 1024).toFixed(1)} GB / 共 ${(disk.totalBytes / 1024 / 1024 / 1024).toFixed(1)} GB`" />
|
|
|
|
|
|
<el-alert v-else-if="disk && disk.level === 'ok'" type="info" :closable="false" show-icon
|
|
|
|
|
|
:title="`磁盘空间正常(剩余 ${(100 - disk.usedPercent)}%,${disk.rootDir})`" />
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
|
|
|
|
|
|
<el-card shadow="never">
|
|
|
|
|
|
<el-form inline style="margin-bottom:14px" @submit.prevent="search">
|
|
|
|
|
|
<el-form-item label="文件类型">
|
|
|
|
|
|
<el-select v-model="filters.fileType" placeholder="全部" clearable style="width:130px" @change="search">
|
|
|
|
|
|
<el-option v-for="f in fileTypeOptions" :key="f.value" :value="f.value" :label="f.label" />
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="业务类型">
|
|
|
|
|
|
<el-select v-model="filters.bizType" placeholder="全部" clearable style="width:130px" @change="search">
|
|
|
|
|
|
<el-option v-for="b in bizTypeOptions" :key="b.value" :value="b.value" :label="b.label" />
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="业务标识">
|
|
|
|
|
|
<el-input v-model="filters.bizId" placeholder="单号/编码/ID" clearable style="width:170px" @keyup.enter="search" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="文件名">
|
|
|
|
|
|
<el-input v-model="filters.fileName" placeholder="文件名(模糊)" clearable style="width:170px" @keyup.enter="search" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="上传时间">
|
|
|
|
|
|
<el-date-picker v-model="dateRange" type="daterange" value-format="YYYY-MM-DD"
|
|
|
|
|
|
range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width:240px" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item>
|
|
|
|
|
|
<el-checkbox v-model="filters.includeDeleted" @change="search">含已删除</el-checkbox>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item>
|
|
|
|
|
|
<el-button type="primary" :loading="loading" @click="search">查询</el-button>
|
|
|
|
|
|
<el-button @click="resetFilters">重置</el-button>
|
2026-10-28 10:10:17 +08:00
|
|
|
|
<el-button v-if="can('attachment:manage')" type="warning" @click="openCleaner">已删除附件</el-button>
|
|
|
|
|
|
<span v-if="can('attachment:manage')" class="del-hint">删除的附件仍占用磁盘空间,需彻底删除才释放</span>
|
2026-09-19 10:54:15 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
|
|
<el-table :data="list" border size="small" v-loading="loading" empty-text="暂无附件">
|
|
|
|
|
|
<el-table-column prop="id" label="ID" width="70" align="center" />
|
|
|
|
|
|
<el-table-column prop="fileName" label="文件名" min-width="220" show-overflow-tooltip />
|
|
|
|
|
|
<el-table-column label="文件类型" width="110" align="center">
|
|
|
|
|
|
<template #default="{ row }"><el-tag size="small" type="info">{{ fileTypeText(row.fileType) }}</el-tag></template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column label="业务类型" width="100" align="center">
|
|
|
|
|
|
<template #default="{ row }">{{ bizTypeText(row.bizType) }}</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column prop="bizId" label="业务标识" min-width="150" show-overflow-tooltip />
|
|
|
|
|
|
<el-table-column label="大小" width="100" align="center">
|
|
|
|
|
|
<template #default="{ row }">{{ sizeText(row.fileSize) }}</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column prop="uploadedBy" label="上传人" width="100" align="center">
|
|
|
|
|
|
<template #default="{ row }">{{ row.uploadedBy || '-' }}</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column label="上传时间" width="160" align="center">
|
|
|
|
|
|
<template #default="{ row }">{{ fmtTime(row.createdAt) }}</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column label="状态" width="90" align="center">
|
|
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
|
<el-tag v-if="row.deleted" type="danger" size="small">已删除</el-tag>
|
|
|
|
|
|
<el-tag v-else type="success" size="small">正常</el-tag>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
2026-10-17 17:49:47 +08:00
|
|
|
|
<el-table-column label="操作" width="130" align="center" fixed="right">
|
2026-09-19 10:54:15 +08:00
|
|
|
|
<template #default="{ row }">
|
2026-10-10 18:09:17 +08:00
|
|
|
|
<el-button type="primary" size="small" :disabled="row.deleted" @click="download(row)">下载</el-button>
|
|
|
|
|
|
<el-popconfirm v-if="can('attachment:manage')" title="确认删除该附件?" @confirm="remove(row)">
|
|
|
|
|
|
<template #reference>
|
|
|
|
|
|
<el-button link type="danger" size="small" :disabled="row.deleted">删除</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-popconfirm>
|
2026-09-19 10:54:15 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
</el-table>
|
|
|
|
|
|
<div class="pager">
|
|
|
|
|
|
<el-pagination background layout="total, sizes, prev, pager, next" :total="total"
|
|
|
|
|
|
:current-page="page.current" :page-size="page.size" :page-sizes="[20, 50, 100]"
|
|
|
|
|
|
@current-change="(p) => { page.current = p; load() }"
|
|
|
|
|
|
@size-change="(s) => { page.size = s; page.current = 1; load() }" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
|
|
|
|
|
|
<PageHelp :data="helpAttachment" page="Attachment" />
|
2026-09-20 14:52:36 +08:00
|
|
|
|
|
2026-10-28 10:10:17 +08:00
|
|
|
|
<!-- 已删除附件抽屉:物理清理已删附件(仅管理员) -->
|
|
|
|
|
|
<el-drawer v-model="cleaner.show" title="已删除附件" size="520px">
|
2026-09-20 14:52:36 +08:00
|
|
|
|
<el-alert type="info" :closable="false" show-icon class="mb12"
|
2026-10-28 10:10:17 +08:00
|
|
|
|
title="清理前先「预检」查看影响范围,确认后再「执行」。物理清理保留索引可追溯。" />
|
2026-09-20 14:52:36 +08:00
|
|
|
|
|
|
|
|
|
|
<el-card shadow="never" class="mb12">
|
2026-10-28 10:10:17 +08:00
|
|
|
|
<template #header><b>物理清理已删附件</b></template>
|
|
|
|
|
|
<p class="tip">扫描索引中已标记「已删除」的附件,物理删除对应磁盘文件释放空间(索引保留)。删除的附件仍占用磁盘空间,需彻底删除才释放。</p>
|
2026-09-20 14:52:36 +08:00
|
|
|
|
<el-space>
|
|
|
|
|
|
<el-button :loading="cleaner.busy === 'purge'" @click="purgePreview">预检</el-button>
|
|
|
|
|
|
<el-button type="danger" :disabled="!cleaner.purgePreview" :loading="cleaner.busy === 'purge'" @click="purgeRun">执行清理</el-button>
|
|
|
|
|
|
</el-space>
|
|
|
|
|
|
<div v-if="cleaner.purgePreview" class="preview">
|
|
|
|
|
|
将删除 <b>{{ cleaner.purgePreview.removed }}</b> 个文件,预计释放
|
|
|
|
|
|
<b>{{ ((cleaner.purgePreview.freed || 0) / 1024 / 1024).toFixed(2) }} MB</b>(缺失 {{ cleaner.purgePreview.missing }}、失败 {{ cleaner.purgePreview.failed }})
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</el-drawer>
|
2026-09-19 10:54:15 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.mb12 { margin-bottom: 12px; }
|
|
|
|
|
|
.pager { display: flex; justify-content: flex-end; margin-top: 10px; }
|
2026-09-20 14:52:36 +08:00
|
|
|
|
.tip { color: #909399; font-size: 12px; line-height: 1.6; margin: 0 0 10px; }
|
2026-10-28 10:10:17 +08:00
|
|
|
|
.del-hint { margin-left: 8px; color: #909399; font-size: 12px; }
|
2026-09-20 14:52:36 +08:00
|
|
|
|
.preview { margin-top: 10px; font-size: 13px; color: #e6a23c; }
|
2026-09-19 10:54:15 +08:00
|
|
|
|
</style>
|