task-278(验收反馈): 生成记录加清理数据功能(DELETE /api/admin/history 二次确认+条数提示;含工作区在途的 imagehistory 分页优化)

This commit is contained in:
2026-09-06 02:25:44 +08:00
parent 6d9b4a13ee
commit 648935e757
5 changed files with 140 additions and 15 deletions
@@ -2,11 +2,12 @@
/** 历史生成记录页(module 13 task 259 对齐 admin panel-history):指定用户下拉 + 起止时间筛选、类型中文、≤3 缩略图、大图预览、空态。 */
import { formatDateTime } from '@/utils/datetime'
import { computed, onMounted, reactive, ref } from 'vue'
import { fetchHistoryList, fetchHistoryUserOptions } from './history-api.ts'
import { fetchHistoryList, fetchHistoryUserOptions, clearHistory } from './history-api.ts'
import type { HistoryUserOption } from './history-user-option.ts'
import type { HistoryRecordItem } from './history-dto.ts'
import { historyEmptyText, historyErrorText } from './history-feedback.ts'
import { historyPanelTypeLabel } from './history-type.ts'
import { ElMessage, ElMessageBox } from 'element-plus'
const loading = ref(false)
const userLoading = ref(false)
@@ -98,6 +99,32 @@ function openPreview(item: HistoryRecordItem) {
previewVisible.value = true
}
const clearing = ref(false)
/** 清空全部生成记录:二次确认后调后端 DELETE /api/admin/history。 */
async function clearAll() {
try {
await ElMessageBox.confirm('确定清空全部生成记录吗?该操作会删除所有历史数据,无法恢复。', '清理生成记录', {
confirmButtonText: '确认清空',
cancelButtonText: '取消',
type: 'warning',
})
} catch {
return
}
clearing.value = true
try {
const removed = await clearHistory()
ElMessage.success(`已清空 ${removed} 条生成记录`)
page.value = 1
await load()
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '清理失败')
} finally {
clearing.value = false
}
}
onMounted(() => {
load()
loadUserOptions()
@@ -111,6 +138,9 @@ onMounted(() => {
<h2>生成记录</h2>
<p>查看各用户在后台生成的历史记录与结果图</p>
</div>
<div class="heading-actions">
<el-button type="danger" plain :loading="clearing" @click="clearAll">清理数据</el-button>
</div>
</div>
<el-card shadow="never" class="filter-card">
@@ -17,3 +17,11 @@ export async function fetchHistoryUserOptions(): Promise<HistoryUserOption[]> {
const { data } = await http.get<unknown>('/api/admin/users', { params: { page: 1, page_size: 999 } })
return parseHistoryUserOptions(data)
}
/** 清空全部生成记录(验收反馈:生成记录数据要可清理)。返回清理条数。 */
export async function clearHistory(): Promise<number> {
const { data } = await http.delete<unknown>(HISTORY_ENDPOINT)
const record = data && typeof data === 'object' ? (data as Record<string, unknown>) : null
const removed = record?.data
return typeof removed === 'number' ? removed : 0
}