diff --git a/src/assets/del-icon copy.svg b/src/assets/del-icon copy.svg
new file mode 100644
index 0000000..587d7f2
--- /dev/null
+++ b/src/assets/del-icon copy.svg
@@ -0,0 +1,4 @@
+
diff --git a/src/pages/Index/History.vue b/src/pages/Index/History.vue
index cf9dc02..f95806d 100644
--- a/src/pages/Index/History.vue
+++ b/src/pages/Index/History.vue
@@ -140,6 +140,7 @@ import {
} from '../../services/Index/index'
import HistoryMessage from './components/History/HistoryMessage.vue'
import type { TableItem } from '../../types/Index'
+import { ElMessage } from 'element-plus'
// 添加表格引用
const historyTableRef = ref()
@@ -217,15 +218,12 @@ const selectedIds = ref([])
// 处理表格选中的项目
const handleSelection = (items: TableItem[]) => {
selectedItems.value = items
- console.log('选中的项目', items)
}
const handleSelectIds = (ids: number[]) => {
- console.log('选中的id', ids)
selectedIds.value = ids
}
-const handleSelectRow = (item: TableItem) => {
+const handleSelectRow = () => {
isVisible.value = true
- console.log('选中的行', item)
}
// 根据操作类型显示不同的确认弹框或通知
@@ -238,8 +236,16 @@ const showActionConfirm = (actionType: string) => {
return
}
- // 如果有选中的项目,显示确认弹框
- currentAction.value = actions[actionType]
+ // 如果是删除操作,确认删除的数量
+ if (actionType === 'delete') {
+ currentAction.value = {
+ ...actions[actionType],
+ message: `是否删除选中的 ${selectedItems.value.length} 条记录?`
+ }
+ } else {
+ currentAction.value = actions[actionType]
+ }
+
showModal.value = true
}
//控制骨架屏
@@ -335,7 +341,7 @@ const handleConfirm = async () => {
showWarn.value = false
const actionType = currentAction.value.type
if (actionType === 'delete') {
- await handleDelete()
+ await handleConfirmDelete()
} else if (actionType === 'print') {
// 执行打印操作
handlePrint()
@@ -355,35 +361,41 @@ const handleCancel = () => {
showWarn.value = false
}
-// 删除功能
-const handleDelete = async () => {
+// 自定义 ElMessage 样式
+const showCustomMessage = (message: string, type: 'success' | 'error' = 'success') => {
+ ElMessage({
+ message,
+ type,
+ customClass: 'custom-message',
+ duration: 2000,
+ })
+}
+
+// 处理删除确认
+const handleConfirmDelete = async () => {
try {
- if (selectedIds.value.length > 0) {
- for (const item of selectedIds.value) {
- const res = await deleteHistoryInfo(item)
- if (res.success) {
- tableKey.value++
- // 清空选中状态
- selectedItems.value = []
- selectedIds.value = []
- // 手动清除表格的选中状态
- if (historyTableRef.value?.clearSelection) {
- historyTableRef.value.clearSelection()
- }
- // 重新获取数据,传入 true 表示需要重置
- await getTableData(true)
- // 提示删除成功
- warnMessage.value = '删除成功'
- showWarn.value = true
- } else {
- throw new Error(res.message || '删除失败')
- }
+ // 一次删除一条记录
+ for (const item of selectedItems.value) {
+ const res = await deleteHistoryInfo(item.id)
+ if (!res.success) {
+ throw new Error('删除失败')
}
}
+
+ // 从表格数据中移除被删除的项目
+ const deleteIds = selectedItems.value.map(item => item.id)
+ tableData.value = tableData.value.filter(item => !deleteIds.includes(item.id))
+
+ // 通过表格组件清空选择状态
+ if (historyTableRef.value) {
+ historyTableRef.value.clearSelection()
+ }
+
+ showCustomMessage('删除成功')
} catch (error) {
- console.error('删除失败', error)
- warnMessage.value = '删除失败,请重试'
- showWarn.value = true
+ showCustomMessage('删除失败', 'error')
+ } finally {
+ showModal.value = false
}
}
@@ -401,7 +413,7 @@ const handlePrint = async () => {
for (const item of idsToPrint) {
const res = await printHistoryInfo(item)
if (res.success && res.ecode === "SUC") {
- warnMessage.value = '打印成功'
+ warnMessage.value = '打���成功'
warnIcon = new URL('@/assets/Index/History/success.svg', import.meta.url).href
showWarn.value = true
@@ -423,71 +435,6 @@ const handlePrint = async () => {
showWarn.value = true
}
}
-// 执行打印的方法
-// const executePrint = async (data: any) => {
-// // 创建打印内容的模板
-// const printContent = createPrintTemplate(data)
-
-// // 创建一个新窗口用于打印
-// const printWindow = window.open('', '_blank')
-// if (printWindow) {
-// printWindow.document.write(printContent)
-// printWindow.document.close()
-// printWindow.focus()
-// printWindow.print()
-// printWindow.close()
-// } else {
-// throw new Error('无法打开打印窗口')
-// }
-// }
-// 创建打印模���
-// const createPrintTemplate = (data: any) => {
-// // 根据数据生成打印内容的HTML符串
-// let content = `
-//
-//
-// 打印
-//
-//
-//
-// 打印内容
-//
-//
-//
-// ID |
-// 用户ID |
-// 项目名称 |
-//
-//
-//
-//
-// `
-
-// data.forEach((item: any) => {
-// content += `
-//
-// ${item.id} |
-// ${item.sampleUserid} |
-// ${item.projName} |
-//
-//
-// `
-// })
-
-// content += `
-//
-//
-//
-//
-// `
-
-// return content
-// }
// 导出功能
const handleExport = () => {
// 执行导出操作
@@ -503,6 +450,21 @@ onMounted(() => {