task-278(验收反馈): 生成记录加清理数据功能(DELETE /api/admin/history 二次确认+条数提示;含工作区在途的 imagehistory 分页优化)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readSource } from './helpers.ts'
|
||||
|
||||
// 验收反馈:生成记录的数据要可清理。
|
||||
// 契约:页面有「清理数据」入口(二次确认)、前端 DELETE /api/admin/history、后端清空端点与日志。
|
||||
|
||||
test('align_history_clear_normal_primary_path', () => {
|
||||
const page = readSource('src/pages/records/RecordsHistoryPage.vue')
|
||||
assert.match(page, /清理数据/, '页头有清理数据按钮')
|
||||
assert.match(page, /确定清空全部生成记录吗/, '清理前需二次确认')
|
||||
assert.match(page, /clearHistory\(\)/, '页面调用清理 API')
|
||||
})
|
||||
|
||||
test('align_history_clear_normal_variant_input', () => {
|
||||
const api = readSource('src/pages/records/history-api.ts')
|
||||
assert.match(api, /http\.delete<unknown>\(HISTORY_ENDPOINT\)/, '清理走 DELETE /api/admin/history')
|
||||
assert.match(api, /clearHistory/, '暴露 clearHistory 适配函数')
|
||||
})
|
||||
|
||||
test('align_history_clear_boundary_empty_input', () => {
|
||||
const page = readSource('src/pages/records/RecordsHistoryPage.vue')
|
||||
assert.match(page, /已清空 \$\{removed\} 条生成记录/, '成功提示含清理条数')
|
||||
})
|
||||
|
||||
test('align_history_clear_dependency_failure_returns_actionable_message', () => {
|
||||
// 后端契约:DELETE /history 端点 + service 清空 + 中文排查日志。
|
||||
const ctrl = readSource('../backend-java/src/main/java/com/nanri/aiimage/modules/imagehistory/controller/ImageHistoryController.java')
|
||||
assert.match(ctrl, /@DeleteMapping\("\/history"\)/, '后端有 DELETE /api/admin/history 端点')
|
||||
assert.match(ctrl, /admin_history/, '清理端点沿用生成记录模块权限')
|
||||
const service = readSource('../backend-java/src/main/java/com/nanri/aiimage/modules/imagehistory/service/ImageHistoryService.java')
|
||||
assert.match(service, /clearAllHistory/, 'service 有清空方法')
|
||||
assert.match(service, /清空生成记录,共清理/, '清空操作留中文排查日志')
|
||||
})
|
||||
Reference in New Issue
Block a user