902 lines
46 KiB
Vue
902 lines
46 KiB
Vue
<template>
|
||
<div>
|
||
<el-alert type="warning" :closable="false" show-icon style="margin-bottom:12px"
|
||
title="数据归档 = 备份到外部存储 + 按时间窗物理清理"
|
||
description="① 先把历史数据备份到 U 盘 / 移动硬盘(不可逆操作的前置保护);② 确认备份完整后,再按时间窗物理删除本地数据以释放空间。清理不可恢复,请务必先备份。" />
|
||
<el-row :gutter="12">
|
||
<el-col :xs="24" :lg="14">
|
||
<el-card shadow="never" header="一、备份到外部存储(U 盘 / 移动硬盘)">
|
||
<el-form label-width="120px" style="max-width:680px">
|
||
<el-form-item label="目标路径" required>
|
||
<div style="display:flex;gap:8px;width:100%;align-items:center">
|
||
<el-input :model-value="targetPath" readonly placeholder="请选择 U 盘/移动硬盘挂载路径" style="flex:1" />
|
||
<el-button @click="openPicker">选择路径</el-button>
|
||
</div>
|
||
<div class="tip">备份包(zip,含 manifest.json + index.html 清单/目录说明/使用与恢复指引)将直接流式写入该路径,不在本机留临时文件。默认回填上次成功备份路径。</div>
|
||
</el-form-item>
|
||
<el-form-item label="时间窗" required>
|
||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap">
|
||
<el-date-picker v-model="startDate" type="date" value-format="YYYY-MM-DD" placeholder="开始日期"
|
||
:disabled-date="d => d > today" style="width:160px" />
|
||
<span>至</span>
|
||
<el-date-picker v-model="endDate" type="date" value-format="YYYY-MM-DD" placeholder="结束日期"
|
||
:disabled-date="d => d >= tomorrow" style="width:160px" />
|
||
<el-button :loading="checking" @click="checkCoverage">覆盖预检</el-button>
|
||
</div>
|
||
<div class="tip">结束日期须 ≤ 昨天(不可备份当天及之后的数据)。建议先选时间窗做覆盖预检,确认历史已有完整备份。</div>
|
||
<el-alert v-if="coverage" :type="coverage.ok ? 'success' : 'error'" :closable="false" style="margin-top:8px"
|
||
:title="coverage.ok ? '该时间窗已被完整备份' : '该时间窗存在未备份的缺失段'" />
|
||
<div v-if="coverage && !coverage.ok" class="seg-line">
|
||
已覆盖:<el-tag v-for="s in coverage.covered" :key="'c' + s.start" type="success" size="small" class="seg">{{ fmtDay(s.start) }} ~ {{ fmtDay(s.end) }}</el-tag>
|
||
<el-tag v-if="!coverage.covered.length" type="info" size="small">无</el-tag>
|
||
</div>
|
||
<div v-if="coverage && !coverage.ok" class="seg-line">
|
||
缺失:<el-tag v-for="s in coverage.missing" :key="'m' + s.start" type="danger" size="small" class="seg">{{ fmtDay(s.start) }} ~ {{ fmtDay(s.end) }}</el-tag>
|
||
</div>
|
||
</el-form-item>
|
||
<el-form-item label="数据项" required>
|
||
<el-checkbox-group v-model="selItems">
|
||
<el-checkbox v-for="it in items" :key="it.key" :value="it.key">
|
||
<el-tooltip :content="it.desc" placement="top">{{ it.name }}</el-tooltip>
|
||
</el-checkbox>
|
||
</el-checkbox-group>
|
||
<div class="tip">质量相关 4 表(过程检/完工检/巡检/在制品流转)不在此列表,不参与归档清理。</div>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" :loading="backing" :disabled="!canStartBackup" @click="startBackup">开始备份</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
<el-progress v-if="backupProg" :percentage="backupProg.percent" :status="backupProg.failed ? 'exception' : (backupProg.done ? 'success' : '')"
|
||
:text-inside="true" :stroke-width="18" style="margin-top:8px" />
|
||
<div v-if="backupProg" class="tip">{{ backupProg.message }}</div>
|
||
<el-alert v-if="backupResult" type="success" :closable="false" style="margin-top:10px"
|
||
:title="'备份完成:' + backupResult.backupPath">
|
||
<div>共 {{ backupResult.items.length }} 项,总量 {{ fmtBytes(backupResult.totalSize) }},校验和(sha256) {{ backupResult.checksum }}</div>
|
||
</el-alert>
|
||
</el-card>
|
||
</el-col>
|
||
|
||
<el-col :xs="24" :lg="10">
|
||
<el-card shadow="never" header="二、按时间窗清理(腾空间,物理删除)">
|
||
<el-alert v-if="!lastSuccessAt" type="info" :closable="false"
|
||
title="尚无成功备份记录,清理入口未开放" style="margin-bottom:10px" />
|
||
<template v-else>
|
||
<el-form label-width="120px" style="max-width:560px">
|
||
<el-form-item label="时间窗" required>
|
||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap">
|
||
<el-date-picker v-model="cleanStart" type="date" value-format="YYYY-MM-DD" placeholder="开始" :disabled-date="d => d > today" style="width:140px" />
|
||
<span>至</span>
|
||
<el-date-picker v-model="cleanEnd" type="date" value-format="YYYY-MM-DD" placeholder="结束" :disabled-date="d => d >= tomorrow" style="width:140px" />
|
||
<el-button :loading="checkingClean" @click="checkCleanCoverage">检查覆盖</el-button>
|
||
</div>
|
||
<div class="tip">清理窗口受数据保护期限制:仅允许删除 180 天前的数据(可在基础设置调整 archive.protect.days)。</div>
|
||
</el-form-item>
|
||
|
||
<!-- 覆盖地图 -->
|
||
<template v-if="cov">
|
||
<el-form-item label="覆盖情况">
|
||
<div style="width:100%">
|
||
<el-alert :type="cov.ok ? 'success' : 'error'" :closable="false" style="margin-bottom:6px"
|
||
:title="cov.ok ? '该时间窗已被完整备份,可以清理' : '该时间窗存在未备份的数据段'" />
|
||
<div class="seg-line">已覆盖:
|
||
<el-tag v-for="s in cov.covered" :key="'cc' + s.start" type="success" size="small" class="seg">{{ fmtDay(s.start) }} ~ {{ fmtDay(s.end) }}</el-tag>
|
||
<el-tag v-if="!cov.covered.length" type="info" size="small">无</el-tag>
|
||
</div>
|
||
<div v-if="!cov.ok" class="seg-line">缺失:
|
||
<el-tag v-for="s in cov.missing" :key="'mm' + s.start" type="danger" size="small" class="seg">{{ fmtDay(s.start) }} ~ {{ fmtDay(s.end) }}</el-tag>
|
||
</div>
|
||
<el-table v-if="cov.records && cov.records.length" :data="cov.records" size="small" style="margin-top:6px" max-height="180">
|
||
<el-table-column label="备份执行时间" width="140">
|
||
<template #default="{ row }">{{ fmtTime(row.executedAt) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="覆盖范围" min-width="170">
|
||
<template #default="{ row }">{{ fmtDay(row.rangeStart) }} ~ {{ fmtDay(row.rangeEnd) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作人" width="80" prop="operator" />
|
||
<el-table-column label="大小" width="80">
|
||
<template #default="{ row }">{{ fmtBytes(row.totalSize) }}</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</div>
|
||
</el-form-item>
|
||
<el-form-item v-if="!cov.ok" label="缺失段处置">
|
||
<div style="display:flex;gap:8px;flex-wrap:wrap">
|
||
<el-button type="primary" :loading="filling" @click="fillMissing">① 一键补备份缺失段</el-button>
|
||
<el-button :disabled="!cov.covered.length" @click="cleanCovered">② 仅清理已覆盖部分</el-button>
|
||
<el-button type="danger" plain @click="forceOpen = true">③ 强制清理(不备份)</el-button>
|
||
</div>
|
||
<div class="tip">① 需已选择上方备份目标路径,自动对缺失段逐一备份;② 未备份段数据将保留不删;③ 风险自担,需实名留痕。</div>
|
||
</el-form-item>
|
||
</template>
|
||
|
||
<el-form-item label="数据项">
|
||
<el-checkbox-group v-model="cleanItems">
|
||
<el-checkbox v-for="it in items" :key="it.key" :value="it.key">{{ it.name }}</el-checkbox>
|
||
</el-checkbox-group>
|
||
</el-form-item>
|
||
<el-form-item label="二次确认" required>
|
||
<div>
|
||
<el-checkbox v-model="ack1">① 我确认已将对应时间窗的数据完整备份到 U 盘 / 移动硬盘</el-checkbox><br />
|
||
<el-checkbox v-model="ack2">② 我知晓此操作将物理删除本地数据,不可恢复</el-checkbox>
|
||
</div>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button :loading="previewing" @click="previewClean">预览将删除内容</el-button>
|
||
<el-button type="danger" :loading="cleaning" :disabled="!canStartClean" @click="startCleanup()" style="margin-left:8px">开始清理</el-button>
|
||
</el-form-item>
|
||
<el-alert v-if="preview" type="warning" :closable="false" style="margin-top:6px"
|
||
:title="'清理预览:将删除合计 ' + preview.totalRows + ' 行 / ' + fmtBytes(preview.totalBytes)">
|
||
<div v-for="p in preview.items" :key="p.key" style="line-height:1.8">
|
||
{{ p.name }}:{{ p.rows }} 行 / {{ fmtBytes(p.bytes) }}
|
||
</div>
|
||
<template v-if="cov && cov.records && cov.records.length">
|
||
<div style="margin-top:6px;font-weight:bold">以上数据对应备份记录(可在「备份/清理历史」核对):</div>
|
||
<div v-for="r in cov.records" :key="r.id" style="line-height:1.8">
|
||
#{{ r.id }}({{ fmtDay(r.rangeStart) }} ~ {{ fmtDay(r.rangeEnd) }},{{ r.operator }} 备份于 {{ fmtTime(r.executedAt) }},{{ fmtBytes(r.totalSize) }})
|
||
</div>
|
||
</template>
|
||
</el-alert>
|
||
</el-form>
|
||
<el-progress v-if="cleanProg" :percentage="cleanProg.percent" :status="cleanProg.failed ? 'exception' : (cleanProg.done ? 'success' : '')"
|
||
:text-inside="true" :stroke-width="18" style="margin-top:8px" />
|
||
<div v-if="cleanProg" class="tip">{{ cleanProg.message }}</div>
|
||
</template>
|
||
|
||
<el-divider>定时清理提醒</el-divider>
|
||
<div class="tip">清理提醒周期在「基础设置」页配置(默认 7 天)。距上次成功备份超过该天数时,登录后弹出强提醒,每天一次;仅提醒,不自动删除。</div>
|
||
</el-card>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<el-card shadow="never" style="margin-top:12px" header="三、备份 / 清理历史">
|
||
<el-table :data="records.list" v-loading="recordsLoading" stripe size="small">
|
||
<el-table-column label="类型" width="90">
|
||
<template #default="{ row }">
|
||
<el-tag v-if="row.status === 'cleanup'" type="warning" size="small">清理</el-tag>
|
||
<el-tag v-else-if="row.status === 'cleanup_forced'" type="danger" size="small">强制清理</el-tag>
|
||
<el-tag v-else type="primary" size="small">备份</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="执行时间" width="170">
|
||
<template #default="{ row }">{{ fmtTime(row.executedAt) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="时间窗" min-width="220">
|
||
<template #default="{ row }">{{ fmtTime(row.rangeStart) }} ~ {{ fmtTime(row.rangeEnd) }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="backupPath" label="路径" min-width="200" show-overflow-tooltip />
|
||
<el-table-column label="大小" width="120">
|
||
<template #default="{ row }">{{ row.backupPath ? fmtBytes(row.totalSize) : '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="状态" width="90">
|
||
<template #default="{ row }">
|
||
<el-tag :type="statusType(row.status)" size="small">{{ statusText(row.status) }}</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="operator" label="操作人" width="110" />
|
||
<el-table-column label="操作" width="80" fixed="right">
|
||
<template #default="{ row }">
|
||
<el-button link type="primary" size="small" @click="openDetail(row)">详情</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<el-pagination style="margin-top:10px;justify-content:flex-end" layout="total, prev, pager, next"
|
||
:total="records.total" :page-size="records.size" :current-page="records.page"
|
||
@current-change="loadRecords" />
|
||
</el-card>
|
||
|
||
<!-- 记录详情 -->
|
||
<el-dialog title="备份 / 清理记录详情" v-model="detailOpen" width="720px">
|
||
<el-descriptions :column="2" border size="small" v-if="detail">
|
||
<el-descriptions-item label="类型">{{ typeText(detail) }}</el-descriptions-item>
|
||
<el-descriptions-item label="状态">
|
||
<el-tag :type="statusType(detail.status)" size="small">{{ statusText(detail.status) }}</el-tag>
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="执行时间">{{ fmtTime(detail.executedAt) }}</el-descriptions-item>
|
||
<el-descriptions-item label="操作人(登录人)">{{ detail.operator || '—' }}</el-descriptions-item>
|
||
<el-descriptions-item label="时间窗" :span="2">{{ fmtTime(detail.rangeStart) }} ~ {{ fmtTime(detail.rangeEnd) }}</el-descriptions-item>
|
||
<el-descriptions-item label="当时备份情况" :span="2">{{ backupStateText(detail) }}</el-descriptions-item>
|
||
<el-descriptions-item v-if="detail.ackName || detail.ackPhone" label="强制清理确认人">{{ detail.ackName }}</el-descriptions-item>
|
||
<el-descriptions-item v-if="detail.ackName || detail.ackPhone" label="确认人手机号">{{ detail.ackPhone }}</el-descriptions-item>
|
||
<el-descriptions-item label="备份包路径" :span="2">
|
||
<span v-if="detail.backupPath">{{ detail.backupPath }}</span>
|
||
<span v-else class="tip">(清理记录,无备份包)</span>
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="大小">{{ detail.backupPath ? fmtBytes(detail.totalSize) : '—' }}</el-descriptions-item>
|
||
<el-descriptions-item label="校验和(sha256)">
|
||
<span style="word-break:break-all">{{ detail.checksum || '—' }}</span>
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
<div style="margin-top:12px;font-weight:bold">数据项明细</div>
|
||
<el-table :data="detailItems" size="small" max-height="260" style="margin-top:6px">
|
||
<el-table-column prop="name" label="数据项" min-width="120" />
|
||
<el-table-column prop="rows" label="行数 / 文件数" width="110" />
|
||
<el-table-column label="大小" width="110">
|
||
<template #default="{ row }">{{ fmtBytes(row.bytes || 0) }}</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<template #footer>
|
||
<el-button @click="detailOpen = false">关闭</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 强制清理(不备份)实名留痕 -->
|
||
<el-dialog title="强制清理(未备份直接删除,风险自担)" v-model="forceOpen" width="560px">
|
||
<el-alert type="error" :closable="false" show-icon style="margin-bottom:10px"
|
||
title="未备份的数据删除后永久丢失,无法恢复!"
|
||
:description="'以下时间段的数据尚未备份,将被直接物理删除:' + forceMissingText" />
|
||
<el-form label-width="120px">
|
||
<el-form-item label="确认人姓名" required>
|
||
<el-input v-model="forceName" placeholder="请填写本人真实姓名(留痕)" maxlength="20" />
|
||
</el-form-item>
|
||
<el-form-item label="手机号" required>
|
||
<el-input v-model="forcePhone" placeholder="请填写 11 位手机号(留痕)" maxlength="11" />
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="forceOpen = false">取消</el-button>
|
||
<el-button type="danger" :loading="cleaning" @click="startCleanup({ force: true })">我已知晓风险,强制清理</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 四、磁盘空间回收(附件清理):删除/恢复/彻底清除唯一入口(attachment:manage) -->
|
||
<el-card v-if="can('attachment:manage')" shadow="never" style="margin-top:12px" header="四、磁盘空间回收(附件清理)">
|
||
<el-alert type="info" :closable="false" show-icon style="margin-bottom:10px"
|
||
title="附件的删除、恢复与磁盘释放统一在此操作(附件中心为纯查阅)。所有删除均需实名留痕;仅允许清理保护期(默认 180 天)之前的数据。"
|
||
description="① 先逻辑删除(可恢复);② 确认无误后彻底清除释放磁盘(仅删文件,索引保留可追溯)。彻底清除前请确认已备份。" />
|
||
<el-space style="margin-bottom:10px" wrap>
|
||
<el-button :loading="attStatsLoading" @click="loadAttStats">刷新预检</el-button>
|
||
<span v-if="attStats">已删除未清除:<b>{{ attStats.removed }}</b> 个 / <b>{{ fmtBytes(attStats.freed) }}</b>
|
||
(缺失 {{ attStats.missing }}、保护期/禁删跳过 {{ attStats.protected }})</span>
|
||
<el-button type="danger" plain :disabled="!attStats || !attStats.removed" @click="openBatchPurge">批量清除已删除附件</el-button>
|
||
<el-button type="warning" plain @click="openOrphans">扫描无引用附件(孤儿)</el-button>
|
||
</el-space>
|
||
|
||
<el-form inline style="margin-bottom:8px" @submit.prevent="loadAttList(1)">
|
||
<el-form-item label="文件名"><el-input v-model="attFilter.fileName" clearable style="width:150px" @keyup.enter="loadAttList(1)" /></el-form-item>
|
||
<el-form-item label="业务标识"><el-input v-model="attFilter.bizId" clearable style="width:140px" @keyup.enter="loadAttList(1)" /></el-form-item>
|
||
<el-form-item label="状态">
|
||
<el-select v-model="attFilter.state" style="width:110px" @change="loadAttList(1)">
|
||
<el-option label="全部" value="all" />
|
||
<el-option label="正常" value="normal" />
|
||
<el-option label="已删除" value="deleted" />
|
||
<el-option label="已清除" value="purged" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button :loading="attListLoading" @click="loadAttList(1)">查询</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
<el-table :data="attList" size="small" border v-loading="attListLoading" max-height="320">
|
||
<el-table-column prop="fileName" label="文件名" min-width="180" show-overflow-tooltip />
|
||
<el-table-column prop="bizId" label="业务标识" min-width="120" show-overflow-tooltip />
|
||
<el-table-column label="大小" width="90" align="center">
|
||
<template #default="{ row }">{{ fmtBytes(row.fileSize) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="上传时间" width="150" 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.purgedAt" type="info" size="small">已清除</el-tag>
|
||
<el-tag v-else-if="row.deleted" type="danger" size="small">已删除</el-tag>
|
||
<el-tag v-else type="success" size="small">正常</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" width="150" align="center" fixed="right">
|
||
<template #default="{ row }">
|
||
<template v-if="!row.deleted && !row.purgedAt">
|
||
<el-button link type="danger" size="small" @click="openAttDialog('delete', row)">删除</el-button>
|
||
</template>
|
||
<template v-else-if="row.deleted && !row.purgedAt">
|
||
<el-button link type="primary" size="small" @click="restoreAtt(row)">恢复</el-button>
|
||
<el-button link type="danger" size="small" @click="openAttDialog('purge', row)">彻底清除</el-button>
|
||
</template>
|
||
<span v-else class="tip">—</span>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<el-pagination style="margin-top:8px;justify-content:flex-end" layout="total, prev, pager, next"
|
||
:total="attTotal" :page-size="attPage.size" :current-page="attPage.current" @current-change="loadAttList" />
|
||
</el-card>
|
||
|
||
<!-- 一步式删除/清除弹窗:删除前提示清楚(保护期/引用/备份覆盖),实名留痕 -->
|
||
<el-dialog :title="attDialog.mode === 'delete' ? '删除附件(逻辑删除,可恢复)' : '彻底清除附件(不可恢复)'"
|
||
v-model="attDialog.open" width="620px">
|
||
<template v-if="attPre">
|
||
<el-descriptions :column="2" border size="small" style="margin-bottom:10px">
|
||
<el-descriptions-item label="文件">{{ attPre.fileName }}</el-descriptions-item>
|
||
<el-descriptions-item label="大小">{{ fmtBytes(attPre.fileSize) }}</el-descriptions-item>
|
||
<el-descriptions-item label="上传时间">{{ fmtTime(attPre.createdAt) }}</el-descriptions-item>
|
||
<el-descriptions-item label="业务归属">{{ attPre.bizType }} / {{ attPre.bizId || '—' }}</el-descriptions-item>
|
||
</el-descriptions>
|
||
<el-alert v-if="attPre.protectBlocked" type="error" :closable="false" show-icon style="margin-bottom:8px"
|
||
:title="'禁止删除:' + attPre.protectBlocked" />
|
||
<el-alert v-else-if="attPre.refCount > 0" type="error" :closable="false" show-icon style="margin-bottom:8px"
|
||
:title="'该附件仍被业务数据引用,禁止删除:' + (attPre.refs || []).join('、')" />
|
||
<template v-else>
|
||
<el-alert type="warning" :closable="false" style="margin-bottom:8px"
|
||
:title="'保护期校验通过(保护期 ' + attPre.protectDays + ' 天)'"
|
||
:description="attPre.backupInfo + '。备份介质由保管人自行核对可读性;删除后彻底清除前仍可恢复。'" />
|
||
<el-form label-width="110px">
|
||
<el-form-item :label="attDialog.mode === 'delete' ? '删除说明' : '清除说明'">
|
||
<el-input v-model="attDialog.reason" type="textarea" :rows="2" maxlength="200" placeholder="选填:为什么删除/清除该附件(留痕)" />
|
||
</el-form-item>
|
||
<el-form-item label="确认人姓名" required>
|
||
<el-input v-model="attDialog.ackName" placeholder="本人真实姓名(留痕)" maxlength="20" style="width:220px" />
|
||
</el-form-item>
|
||
<el-form-item label="手机号" required>
|
||
<el-input v-model="attDialog.ackPhone" placeholder="11 位手机号(留痕)" maxlength="11" style="width:220px" />
|
||
</el-form-item>
|
||
</el-form>
|
||
<div v-if="attDialog.mode === 'purge'" class="tip" style="margin-bottom:6px">
|
||
彻底清除将物理删除磁盘文件、不可恢复(索引保留可追溯);如需找回只能依赖备份包(系统不保证介质可读)。
|
||
</div>
|
||
</template>
|
||
</template>
|
||
<template #footer>
|
||
<el-button @click="attDialog.open = false">取消</el-button>
|
||
<el-button v-if="attPre && !attPre.protectBlocked && attPre.refCount === 0" type="danger"
|
||
:loading="attDialog.busy" @click="confirmAttDialog">
|
||
{{ attDialog.mode === 'delete' ? '确认删除' : '确认彻底清除' }}
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 批量清除已删除附件 -->
|
||
<el-dialog title="批量清除已删除附件" v-model="batchPurge.open" width="560px">
|
||
<el-alert type="warning" :closable="false" show-icon style="margin-bottom:10px"
|
||
:title="'将物理删除 ' + (attStats?.removed || 0) + ' 个已删除附件,释放 ' + fmtBytes(attStats?.freed || 0)"
|
||
description="保护期/禁删保护的附件将自动跳过;文件缺失的仅补登记。索引保留可追溯。" />
|
||
<el-form label-width="110px">
|
||
<el-form-item label="确认人姓名" required><el-input v-model="batchPurge.ackName" maxlength="20" style="width:220px" /></el-form-item>
|
||
<el-form-item label="手机号" required><el-input v-model="batchPurge.ackPhone" maxlength="11" style="width:220px" /></el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="batchPurge.open = false">取消</el-button>
|
||
<el-button type="danger" :loading="batchPurge.busy" @click="runBatchPurge">确认批量清除</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 孤儿扫描与批量清除 -->
|
||
<el-dialog title="无引用附件(孤儿)扫描" v-model="orphans.open" width="680px">
|
||
<el-alert type="info" :closable="false" show-icon style="margin-bottom:10px"
|
||
title="孤儿 = 附件正常但业务单据已不存在(未保存即取消/单据已删除)。无引用数据无保留价值,可批量物理清除(文件+记录)。" />
|
||
<div style="margin-bottom:8px">
|
||
<el-button :loading="orphans.loading" @click="scanOrphans">重新扫描</el-button>
|
||
<span v-if="orphans.list.length" style="margin-left:10px">
|
||
共 <b>{{ orphans.list.length }}</b> 个 / <b>{{ fmtBytes(orphans.totalSize) }}</b>
|
||
</span>
|
||
<span v-else-if="!orphans.loading" class="tip">(未发现孤儿附件)</span>
|
||
</div>
|
||
<el-table :data="orphans.list" size="small" border max-height="260">
|
||
<el-table-column prop="fileName" label="文件名" min-width="180" show-overflow-tooltip />
|
||
<el-table-column prop="bizType" label="业务类型" width="100" align="center" />
|
||
<el-table-column prop="bizId" label="业务标识" min-width="110" show-overflow-tooltip />
|
||
<el-table-column label="大小" width="90" align="center">
|
||
<template #default="{ row }">{{ fmtBytes(row.fileSize) }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="reason" label="判定原因" min-width="160" show-overflow-tooltip />
|
||
</el-table>
|
||
<el-form label-width="110px" style="margin-top:10px">
|
||
<el-form-item label="确认人姓名" required><el-input v-model="orphans.ackName" maxlength="20" style="width:220px" /></el-form-item>
|
||
<el-form-item label="手机号" required><el-input v-model="orphans.ackPhone" maxlength="11" style="width:220px" /></el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="orphans.open = false">取消</el-button>
|
||
<el-button type="danger" :disabled="!orphans.list.length" :loading="orphans.purging" @click="purgeOrphans">确认批量清除</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 服务端目录选择器 -->
|
||
<el-dialog title="选择备份目标路径" v-model="pickerOpen" width="560px">
|
||
<el-form label-width="60px">
|
||
<el-form-item label="盘符">
|
||
<el-select v-model="browseDrive" @change="onDriveChange" style="width:200px">
|
||
<el-option v-for="d in drives" :key="d.path" :label="d.letter + ':\\'" :value="d.path" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="当前路径">
|
||
<div style="display:flex;gap:8px;width:100%;align-items:center">
|
||
<el-input :model-value="browsePath" readonly style="flex:1" />
|
||
<el-button @click="goUp">上一级</el-button>
|
||
</div>
|
||
</el-form-item>
|
||
<el-form-item label="子目录">
|
||
<div v-loading="dirLoading" class="dir-list">
|
||
<div v-if="!dirs.length" class="tip">该目录下无子目录</div>
|
||
<div v-for="d in dirs" :key="d.path" class="dir-item" @click="enterDir(d)">
|
||
<el-icon><Folder /></el-icon><span>{{ d.name }}</span>
|
||
</div>
|
||
</div>
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="pickerOpen = false">取消</el-button>
|
||
<el-button type="primary" @click="confirmPath">确定</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, reactive, computed, onMounted, onBeforeUnmount } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { Folder } from '@element-plus/icons-vue'
|
||
import request from '../utils/request'
|
||
import { can } from '../utils/perm'
|
||
|
||
const items = ref([])
|
||
const targetPath = ref('')
|
||
const startDate = ref('')
|
||
const endDate = ref('')
|
||
const selItems = ref([])
|
||
const checking = ref(false)
|
||
const coverage = ref(null)
|
||
|
||
const backing = ref(false)
|
||
const backupProg = ref(null)
|
||
const backupResult = ref(null)
|
||
|
||
const cleanStart = ref('')
|
||
const cleanEnd = ref('')
|
||
const cleanItems = ref([])
|
||
const ack1 = ref(false)
|
||
const ack2 = ref(false)
|
||
const cleaning = ref(false)
|
||
const cleanProg = ref(null)
|
||
|
||
const checkingClean = ref(false)
|
||
const cov = ref(null)
|
||
const filling = ref(false)
|
||
|
||
const forceOpen = ref(false)
|
||
const forceName = ref('')
|
||
const forcePhone = ref('')
|
||
|
||
const previewing = ref(false)
|
||
const preview = ref(null)
|
||
|
||
const lastSuccessAt = ref(Number(localStorage.getItem('wms_last_backup_at') || 0))
|
||
|
||
const records = reactive({ list: [], total: 0, page: 1, size: 50 })
|
||
const recordsLoading = ref(false)
|
||
|
||
const detailOpen = ref(false)
|
||
const detail = ref(null)
|
||
const detailItems = ref([])
|
||
|
||
const today = new Date()
|
||
const tomorrow = new Date(); tomorrow.setDate(today.getDate() + 1)
|
||
|
||
// ===== 四、磁盘空间回收(附件清理) =====
|
||
const attStats = ref(null)
|
||
const attStatsLoading = ref(false)
|
||
const attList = ref([])
|
||
const attTotal = ref(0)
|
||
const attListLoading = ref(false)
|
||
const attPage = reactive({ current: 1, size: 20 })
|
||
const attFilter = reactive({ fileName: '', bizId: '', state: 'all' })
|
||
|
||
const attDialog = reactive({ open: false, mode: 'delete', row: null, pre: null, reason: '', ackName: '', ackPhone: '', busy: false })
|
||
const attPre = computed(() => attDialog.pre)
|
||
const batchPurge = reactive({ open: false, busy: false, ackName: '', ackPhone: '' })
|
||
const orphans = reactive({ open: false, loading: false, purging: false, list: [], totalSize: 0, ackName: '', ackPhone: '' })
|
||
|
||
function attState(row) {
|
||
if (row.purgedAt) return 'purged'
|
||
if (row.deleted) return 'deleted'
|
||
return 'normal'
|
||
}
|
||
|
||
async function loadAttStats() {
|
||
attStatsLoading.value = true
|
||
try {
|
||
attStats.value = await request.post('/attachments/purge-deleted', { dryRun: true })
|
||
} finally { attStatsLoading.value = false }
|
||
}
|
||
|
||
async function loadAttList(pageNo = 1) {
|
||
attPage.current = pageNo
|
||
attListLoading.value = true
|
||
try {
|
||
const params = {
|
||
includeDeleted: 'true', page: attPage.current, pageSize: attPage.size,
|
||
fileName: attFilter.fileName.trim(), bizId: attFilter.bizId.trim()
|
||
}
|
||
const d = await request.get('/attachments/all', { params })
|
||
let rows = d?.list || []
|
||
if (attFilter.state !== 'all') rows = rows.filter(r => attState(r) === attFilter.state)
|
||
attList.value = rows
|
||
attTotal.value = d?.total || 0
|
||
} finally { attListLoading.value = false }
|
||
}
|
||
|
||
function openAttDialog(mode, row) {
|
||
attDialog.mode = mode
|
||
attDialog.row = row
|
||
attDialog.reason = ''
|
||
attDialog.ackName = ''
|
||
attDialog.ackPhone = ''
|
||
attDialog.open = true
|
||
attDialog.pre = null
|
||
// 删除前提示清楚:拉取预检(保护期/禁删/引用/备份覆盖)
|
||
request.post('/attachments/delete-precheck', { id: row.id })
|
||
.then(p => { attDialog.pre = p })
|
||
.catch(e => { ElMessage.error(e?.response?.data?.message || e?.message || '预检失败'); attDialog.open = false })
|
||
}
|
||
|
||
async function confirmAttDialog() {
|
||
if (!attDialog.ackName.trim()) { ElMessage.warning('请填写确认人姓名(留痕)'); return }
|
||
if (!/^1\d{10}$/.test(attDialog.ackPhone.trim())) { ElMessage.warning('请填写有效的 11 位手机号(留痕)'); return }
|
||
attDialog.busy = true
|
||
try {
|
||
if (attDialog.mode === 'delete') {
|
||
await request.post('/attachments/delete', {
|
||
id: attDialog.row.id, reason: attDialog.reason.trim(),
|
||
ackName: attDialog.ackName.trim(), ackPhone: attDialog.ackPhone.trim()
|
||
})
|
||
ElMessage.success('已删除(逻辑删除,彻底清除前可恢复)')
|
||
} else {
|
||
await request.post('/attachments/purge', {
|
||
id: attDialog.row.id,
|
||
ackName: attDialog.ackName.trim(), ackPhone: attDialog.ackPhone.trim()
|
||
})
|
||
ElMessage.success('已彻底清除(索引保留可追溯)')
|
||
}
|
||
attDialog.open = false
|
||
await Promise.all([loadAttList(attPage.current), loadAttStats(), loadRecords(1)])
|
||
} catch (e) {
|
||
ElMessage.error(e?.response?.data?.message || e?.message || '操作失败')
|
||
} finally { attDialog.busy = false }
|
||
}
|
||
|
||
async function restoreAtt(row) {
|
||
try {
|
||
await ElMessageBox.confirm(`确认恢复附件「${row.fileName}」?恢复后回到正常状态。`, '恢复确认', { type: 'info' })
|
||
} catch { return }
|
||
try {
|
||
await request.post('/attachments/restore', { id: row.id })
|
||
ElMessage.success('已恢复')
|
||
await Promise.all([loadAttList(attPage.current), loadAttStats()])
|
||
} catch (e) {
|
||
ElMessage.error(e?.response?.data?.message || e?.message || '恢复失败')
|
||
}
|
||
}
|
||
|
||
function openBatchPurge() {
|
||
batchPurge.ackName = ''
|
||
batchPurge.ackPhone = ''
|
||
batchPurge.open = true
|
||
}
|
||
async function runBatchPurge() {
|
||
if (!batchPurge.ackName.trim()) { ElMessage.warning('请填写确认人姓名(留痕)'); return }
|
||
if (!/^1\d{10}$/.test(batchPurge.ackPhone.trim())) { ElMessage.warning('请填写有效的 11 位手机号(留痕)'); return }
|
||
batchPurge.busy = true
|
||
try {
|
||
const d = await request.post('/attachments/purge-deleted', {
|
||
dryRun: false, ackName: batchPurge.ackName.trim(), ackPhone: batchPurge.ackPhone.trim()
|
||
})
|
||
ElMessage.success(`批量清除完成:删除 ${d?.removed || 0}、释放 ${fmtBytes(d?.freed || 0)}、跳过 ${d?.protected || 0}、失败 ${d?.failed || 0}`)
|
||
batchPurge.open = false
|
||
await Promise.all([loadAttStats(), loadAttList(attPage.current), loadRecords(1)])
|
||
} catch (e) {
|
||
ElMessage.error(e?.response?.data?.message || e?.message || '批量清除失败')
|
||
} finally { batchPurge.busy = false }
|
||
}
|
||
|
||
async function openOrphans() {
|
||
orphans.open = true
|
||
orphans.ackName = ''
|
||
orphans.ackPhone = ''
|
||
await scanOrphans()
|
||
}
|
||
async function scanOrphans() {
|
||
orphans.loading = true
|
||
try {
|
||
const d = await request.get('/attachments/orphans')
|
||
orphans.list = d?.list || []
|
||
orphans.totalSize = d?.totalSize || 0
|
||
} finally { orphans.loading = false }
|
||
}
|
||
async function purgeOrphans() {
|
||
if (!orphans.ackName.trim()) { ElMessage.warning('请填写确认人姓名(留痕)'); return }
|
||
if (!/^1\d{10}$/.test(orphans.ackPhone.trim())) { ElMessage.warning('请填写有效的 11 位手机号(留痕)'); return }
|
||
orphans.purging = true
|
||
try {
|
||
const d = await request.post('/attachments/orphans/purge', {
|
||
ackName: orphans.ackName.trim(), ackPhone: orphans.ackPhone.trim()
|
||
})
|
||
ElMessage.success(`孤儿清除完成:删除 ${d?.removed || 0}、释放 ${fmtBytes(d?.freed || 0)}、失败 ${d?.failed || 0}`)
|
||
await scanOrphans()
|
||
await Promise.all([loadAttStats(), loadAttList(attPage.current), loadRecords(1)])
|
||
} catch (e) {
|
||
ElMessage.error(e?.response?.data?.message || e?.message || '孤儿清除失败')
|
||
} finally { orphans.purging = false }
|
||
}
|
||
|
||
// ===== 目录选择器 =====
|
||
const pickerOpen = ref(false)
|
||
const drives = ref([])
|
||
const browseDrive = ref('')
|
||
const browsePath = ref('')
|
||
const dirs = ref([])
|
||
const dirLoading = ref(false)
|
||
|
||
function toUnixEnd(dateStr) {
|
||
const d = new Date(dateStr + 'T23:59:59')
|
||
return Math.floor(d.getTime() / 1000)
|
||
}
|
||
function toUnixStart(dateStr) {
|
||
const d = new Date(dateStr + 'T00:00:00')
|
||
return Math.floor(d.getTime() / 1000)
|
||
}
|
||
function fmtBytes(n) {
|
||
if (!n) return '0 B'
|
||
const u = ['B', 'KB', 'MB', 'GB', 'TB']
|
||
let i = 0; let x = n
|
||
while (x >= 1024 && i < u.length - 1) { x /= 1024; i++ }
|
||
return (i === 0 ? x : x.toFixed(2)) + ' ' + u[i]
|
||
}
|
||
function fmtTime(unix) {
|
||
if (!unix) return '—'
|
||
const d = new Date(unix * 1000)
|
||
const p = (n) => String(n).padStart(2, '0')
|
||
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`
|
||
}
|
||
function fmtDay(unix) {
|
||
const d = new Date(unix * 1000)
|
||
const p = (n) => String(n).padStart(2, '0')
|
||
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`
|
||
}
|
||
function statusText(s) {
|
||
return { success: '成功', failed: '失败', partial: '部分', cleanup: '清理完成', cleanup_forced: '强制清理' }[s] || s
|
||
}
|
||
function statusType(s) {
|
||
return { success: 'success', failed: 'danger', partial: 'warning', cleanup: 'warning', cleanup_forced: 'danger' }[s] || 'info'
|
||
}
|
||
function typeText(r) {
|
||
if (r.status === 'cleanup') return '按时间窗清理'
|
||
if (r.status === 'cleanup_forced') return '强制清理(未完整备份)'
|
||
return '备份到外部存储'
|
||
}
|
||
function backupStateText(r) {
|
||
if (r.status === 'cleanup') return '清理前已完成完整备份(覆盖校验通过)'
|
||
if (r.status === 'cleanup_forced') return '未完整备份,强制清理(见下方留痕)'
|
||
return r.status === 'success' ? '备份成功' : (r.status === 'failed' ? '备份失败,未产生备份包' : '部分成功,存在缺失')
|
||
}
|
||
const forceMissingText = computed(() =>
|
||
(cov.value ? cov.value.missing : []).map(s => `${fmtDay(s.start)} ~ ${fmtDay(s.end)}`).join('、'))
|
||
|
||
// ===== 通用任务轮询(返回 Promise)=====
|
||
const activeTimers = new Set()
|
||
function pollJob(base, jobId, progRef) {
|
||
return new Promise((resolve, reject) => {
|
||
const t = setInterval(async () => {
|
||
try {
|
||
const p = await request.get(base + '/progress', { params: { jobId } })
|
||
progRef.value = p
|
||
if (p.done) {
|
||
clearInterval(t)
|
||
activeTimers.delete(t)
|
||
p.failed ? reject(new Error(p.message || '任务失败')) : resolve(p.result)
|
||
}
|
||
} catch { /* 轮询异常忽略,继续等待 */ }
|
||
}, 1000)
|
||
activeTimers.add(t)
|
||
})
|
||
}
|
||
|
||
const canStartBackup = computed(() =>
|
||
targetPath.value.trim() !== '' && startDate.value && endDate.value &&
|
||
toUnixStart(startDate.value) < toUnixEnd(endDate.value) && selItems.value.length > 0 && !backing.value)
|
||
|
||
const canStartClean = computed(() =>
|
||
lastSuccessAt.value && cleanStart.value && cleanEnd.value &&
|
||
toUnixStart(cleanStart.value) < toUnixEnd(cleanEnd.value) && cleanItems.value.length > 0 &&
|
||
ack1.value && ack2.value && preview.value && cov.value && cov.value.ok && !cleaning.value)
|
||
|
||
async function loadItems() {
|
||
try { items.value = await request.get('/backup/items') } catch { items.value = [] }
|
||
}
|
||
|
||
async function checkCoverage() {
|
||
if (!startDate.value || !endDate.value) { ElMessage.warning('请选择时间窗'); return }
|
||
checking.value = true
|
||
try {
|
||
coverage.value = await request.post('/cleanup/check', { start: toUnixStart(startDate.value), end: toUnixEnd(endDate.value) })
|
||
} finally { checking.value = false }
|
||
}
|
||
|
||
async function checkCleanCoverage() {
|
||
if (!cleanStart.value || !cleanEnd.value) { ElMessage.warning('请先选择清理时间窗'); return }
|
||
checkingClean.value = true
|
||
cov.value = null
|
||
try {
|
||
cov.value = await request.post('/cleanup/check', { start: toUnixStart(cleanStart.value), end: toUnixEnd(cleanEnd.value) })
|
||
} finally { checkingClean.value = false }
|
||
}
|
||
|
||
// ===== 一键补备份缺失段 =====
|
||
async function fillMissing() {
|
||
if (!targetPath.value.trim()) { ElMessage.warning('请先在「一、备份到外部存储」中选择目标路径'); return }
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
'将对缺失时间段 ' + forceMissingText.value + ' 逐一执行备份(目标:' + targetPath.value.trim() + '),完成后自动刷新覆盖情况。是否继续?',
|
||
'一键补备份', { type: 'info' })
|
||
} catch { return }
|
||
filling.value = true
|
||
backupResult.value = null
|
||
try {
|
||
for (const seg of cov.value.missing) {
|
||
const r = await request.post('/backup/start', {
|
||
targetPath: targetPath.value.trim(),
|
||
start: seg.start,
|
||
end: seg.end,
|
||
items: items.value.map(i => i.key)
|
||
})
|
||
await pollJob('/backup', r.jobId, backupProg)
|
||
lastSuccessAt.value = Math.floor(Date.now() / 1000)
|
||
localStorage.setItem('wms_last_backup_at', String(lastSuccessAt.value))
|
||
}
|
||
ElMessage.success('缺失段已全部补齐备份')
|
||
await checkCleanCoverage()
|
||
loadRecords(1)
|
||
} catch (e) {
|
||
ElMessage.error(e.message || '补备份失败')
|
||
} finally {
|
||
filling.value = false
|
||
}
|
||
}
|
||
|
||
async function startBackup() {
|
||
backupResult.value = null
|
||
backupProg.value = { jobId: '', percent: 0, message: '准备中…' }
|
||
backing.value = true
|
||
try {
|
||
const r = await request.post('/backup/start', {
|
||
targetPath: targetPath.value.trim(),
|
||
start: toUnixStart(startDate.value),
|
||
end: toUnixEnd(endDate.value),
|
||
items: selItems.value
|
||
})
|
||
await pollJob('/backup', r.jobId, backupProg)
|
||
backupResult.value = null
|
||
const p = backupProg.value
|
||
if (p && p.result) backupResult.value = p.result
|
||
lastSuccessAt.value = Math.floor(Date.now() / 1000)
|
||
localStorage.setItem('wms_last_backup_at', String(lastSuccessAt.value))
|
||
ElMessage.success('备份完成')
|
||
loadRecords(1)
|
||
} catch (e) {
|
||
ElMessage.error(e.message || '备份失败')
|
||
} finally {
|
||
backing.value = false
|
||
}
|
||
}
|
||
|
||
async function previewClean() {
|
||
if (!cleanStart.value || !cleanEnd.value) { ElMessage.warning('请先选择清理时间窗'); return }
|
||
if (!cleanItems.value.length) { ElMessage.warning('请至少选择一个数据项'); return }
|
||
previewing.value = true
|
||
preview.value = null
|
||
try {
|
||
const [r] = await Promise.all([
|
||
request.post('/cleanup/preview', {
|
||
start: toUnixStart(cleanStart.value), end: toUnixEnd(cleanEnd.value), items: cleanItems.value
|
||
}),
|
||
checkCleanCoverage()
|
||
])
|
||
preview.value = r
|
||
} finally { previewing.value = false }
|
||
}
|
||
|
||
// opts: { mode?: 'covered', force?: true }(强制清理的姓名/手机号取弹窗表单)
|
||
async function startCleanup(opts = {}) {
|
||
const force = !!opts.force
|
||
if (force) {
|
||
if (!forceName.value.trim()) { ElMessage.warning('请填写确认人姓名(留痕)'); return }
|
||
if (!/^1\d{10}$/.test(forcePhone.value.trim())) { ElMessage.warning('请填写有效的 11 位手机号(留痕)'); return }
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
'未备份数据将被永久删除且无法恢复!确认人:' + forceName.value.trim() + '(' + forcePhone.value.trim() + ')。确定强制清理?',
|
||
'最终确认', { type: 'error', confirmButtonText: '确定强制清理' })
|
||
} catch { return }
|
||
} else {
|
||
try {
|
||
await ElMessageBox.confirm('即将物理删除本地数据(不可恢复),且已确认 U 盘备份完整。是否继续?', '二次确认', { type: 'warning' })
|
||
} catch { return }
|
||
}
|
||
cleanProg.value = { percent: 0, message: '准备中…' }
|
||
cleaning.value = true
|
||
try {
|
||
const r = await request.post('/cleanup/start', {
|
||
start: toUnixStart(cleanStart.value),
|
||
end: toUnixEnd(cleanEnd.value),
|
||
items: cleanItems.value,
|
||
mode: opts.mode || '',
|
||
force,
|
||
ackName: forceName.value.trim(),
|
||
ackPhone: forcePhone.value.trim()
|
||
})
|
||
await pollJob('/cleanup', r.jobId, cleanProg)
|
||
ElMessage.success(force ? '强制清理完成(已留痕)' : '清理完成')
|
||
preview.value = null
|
||
forceOpen.value = false
|
||
forceName.value = ''; forcePhone.value = ''
|
||
loadRecords(1)
|
||
checkCleanCoverage()
|
||
} catch (e) {
|
||
ElMessage.error(e.message || '清理被拒/失败')
|
||
} finally {
|
||
cleaning.value = false
|
||
}
|
||
}
|
||
|
||
// 仅清理已覆盖部分(mode=covered)
|
||
function cleanCovered() {
|
||
if (!ack1.value || !ack2.value) { ElMessage.warning('请先勾选下方二次确认'); return }
|
||
if (!cleanItems.value.length) { ElMessage.warning('请至少选择一个数据项'); return }
|
||
startCleanup({ mode: 'covered' })
|
||
}
|
||
|
||
async function loadRecords(page = 1) {
|
||
recordsLoading.value = true
|
||
try {
|
||
const r = await request.get('/backup/records', { params: { page, size: records.size } })
|
||
records.list = r.list || []
|
||
records.total = r.total || 0
|
||
records.page = r.page || page
|
||
} catch { /* ignore */ } finally { recordsLoading.value = false }
|
||
}
|
||
|
||
function openDetail(row) {
|
||
detail.value = row
|
||
try { detailItems.value = JSON.parse(row.itemsJson || '[]') } catch { detailItems.value = [] }
|
||
detailOpen.value = true
|
||
}
|
||
|
||
// ===== 目录选择器逻辑 =====
|
||
async function openPicker() {
|
||
pickerOpen.value = true
|
||
dirLoading.value = true
|
||
try {
|
||
drives.value = await request.get('/backup/drives')
|
||
const def = targetPath.value || (drives.value[0] && drives.value[0].path) || ''
|
||
browsePath.value = def
|
||
browseDrive.value = (drives.value.find(d => def.startsWith(d.path)) || drives.value[0] || {}).path || ''
|
||
await loadDirs()
|
||
} finally { dirLoading.value = false }
|
||
}
|
||
function onDriveChange(p) { browsePath.value = p; loadDirs() }
|
||
function goUp() {
|
||
const i = Math.max(browsePath.value.lastIndexOf('\\'), browsePath.value.lastIndexOf('/'))
|
||
if (i > 0) { browsePath.value = browsePath.value.slice(0, i); loadDirs() }
|
||
}
|
||
function enterDir(d) { browsePath.value = d.path; loadDirs() }
|
||
async function loadDirs() {
|
||
dirLoading.value = true
|
||
try { dirs.value = await request.get('/backup/listdir', { params: { path: browsePath.value } }) } catch { dirs.value = [] }
|
||
finally { dirLoading.value = false }
|
||
}
|
||
function confirmPath() { targetPath.value = browsePath.value; pickerOpen.value = false }
|
||
|
||
onMounted(async () => {
|
||
await loadItems()
|
||
try {
|
||
const r = await request.get('/backup/reminder')
|
||
if (r.lastBackupPath) targetPath.value = r.lastBackupPath
|
||
} catch { /* ignore */ }
|
||
await loadRecords(1)
|
||
})
|
||
onBeforeUnmount(() => { activeTimers.forEach(t => clearInterval(t)); activeTimers.clear() })
|
||
</script>
|
||
|
||
<style scoped>
|
||
.tip { color: #909399; font-size: 12px; line-height: 1.6; width: 100%; }
|
||
.dir-list { border: 1px solid #ebeef5; border-radius: 4px; padding: 6px; max-height: 240px; overflow: auto; }
|
||
.dir-item { display: flex; align-items: center; gap: 6px; padding: 4px 8px; cursor: pointer; border-radius: 4px; }
|
||
.dir-item:hover { background: #f2f6fc; color: #1668dc; }
|
||
.seg-line { margin-top: 4px; font-size: 12px; color: #909399; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
|
||
.seg { font-size: 12px; }
|
||
</style>
|