223 lines
9.3 KiB
Vue
223 lines
9.3 KiB
Vue
<script setup>
|
||||
|
|
defineOptions({ name: 'AttachmentCenter' })
|
|||
|
|
import { onActivated, onMounted, reactive, ref } from 'vue'
|
|||
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|||
|
|
import request from '../utils/request'
|
|||
|
|
import { fmtTime } from '../utils/format'
|
|||
|
|
import { can } from '../utils/perm'
|
|||
|
|
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导入' },
|
|||
|
|
{ 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 preview(row) {
|
|||
|
|
window.open(row.url, '_blank')
|
|||
|
|
}
|
|||
|
|
function download(row) {
|
|||
|
|
window.open(row.url + '?dl=1', '_blank')
|
|||
|
|
}
|
|||
|
|
async function remove(row) {
|
|||
|
|
try {
|
|||
|
|
await ElMessageBox.confirm(`确认删除附件「${row.fileName}」?删除后索引标记为已删除(文件由归档任务统一清理)。`, '删除确认', { type: 'warning' })
|
|||
|
|
} catch {
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
await request.post('/attachments/delete', { id: row.id })
|
|||
|
|
ElMessage.success('已删除')
|
|||
|
|
await load()
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 归档:把早于本地保留年数的附件备份到外部目录并标记归档
|
|||
|
|
const archiving = ref(false)
|
|||
|
|
async function archive() {
|
|||
|
|
try {
|
|||
|
|
await ElMessageBox.confirm('将把早于「本地保留年数」的附件归档(备份到外部目录并标记),是否继续?', '归档确认', { type: 'warning' })
|
|||
|
|
} catch {
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
archiving.value = true
|
|||
|
|
try {
|
|||
|
|
const d = await request.post('/attachments/archive', { dryRun: false })
|
|||
|
|
ElMessage.success(`归档完成:移动 ${d?.moved || 0}、标记 ${d?.marked || 0}、失败 ${d?.failed || 0}`)
|
|||
|
|
await load()
|
|||
|
|
} finally {
|
|||
|
|
archiving.value = false
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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>
|
|||
|
|
<el-button v-if="can('attachment:manage')" type="warning" :loading="archiving" @click="archive">归档清理</el-button>
|
|||
|
|
</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-if="row.archived" type="warning" size="small">已归档</el-tag>
|
|||
|
|
<el-tag v-else type="success" size="small">正常</el-tag>
|
|||
|
|
</template>
|
|||
|
|
</el-table-column>
|
|||
|
|
<el-table-column label="操作" width="180" align="center" fixed="right">
|
|||
|
|
<template #default="{ row }">
|
|||
|
|
<el-button link type="primary" size="small" :disabled="row.deleted" @click="preview(row)">查看</el-button>
|
|||
|
|
<el-button link type="primary" size="small" :disabled="row.deleted" @click="download(row)">下载</el-button>
|
|||
|
|
<el-button v-if="can('attachment:manage')" link type="danger" size="small" :disabled="row.deleted" @click="remove(row)">删除</el-button>
|
|||
|
|
</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" />
|
|||
|
|
</div>
|
|||
|
|
</template>
|
|||
|
|
|
|||
|
|
<style scoped>
|
|||
|
|
.mb12 { margin-bottom: 12px; }
|
|||
|
|
.pager { display: flex; justify-content: flex-end; margin-top: 10px; }
|
|||
|
|
</style>
|