@@ -116,16 +87,8 @@ import {
printHistoryInfo,
} from '../../services/Index/index'
import HistoryMessage from './components/History/HistoryMessage.vue'
-interface TableItem {
- id: number
- sampleUserid: string
- projName: string
- sampleBloodType: string
- result: string
- creatDate: string | number | Date
- lotId: string
- // 其他字段...
-}
+import type { TableItem } from '../../types/Index'
+
//选中弹出框
const isVisible = ref
(false)
@@ -209,6 +172,7 @@ const handleSelectRow = (item: TableItem) => {
isVisible.value = true
console.log('选中的行', item)
}
+
// 根据操作类型显示不同的确认弹框或通知
const showActionConfirm = (actionType: string) => {
// 判断是否有选中的项目
@@ -223,19 +187,65 @@ const showActionConfirm = (actionType: string) => {
currentAction.value = actions[actionType]
showModal.value = true
}
-
+//控制骨架屏
+const loading = ref(false)
// 获取表格数据
const tableData = ref([])
+const currentPage = ref(1)
+const pageSize = ref(20)
+const total = ref(0)
+const totalPage = ref(0)
+const tableKey = ref(0)//控制重新渲染
+const tableContainer = ref(null as HTMLElement | null)
+const hasMore = ref(true)
+const loadingText = ref("加载中...")
const getTableData = async () => {
+ hasMore.value = true
+ if (loading.value || !hasMore.value) return
+ loading.value = true
try {
- const res = await getHistoryInfo()
- console.log(res.data.list)
- tableData.value = res.data.list as TableItem[]
+ const res = await getHistoryInfoApi()
+ if (currentPage.value > totalPage.value) {
+ hasMore.value = false
+ loadingText.value = "没有更多数据了"
+ } else {
+
+ tableData.value = [...tableData.value, ...res.data.list]
+ currentPage.value++;
+ loadingText.value = "加载中..."
+ }
} catch (error) {
console.error('获取数据失败', error)
+ loadingText.value = "加载失败,请重试"
+ } finally {
+ setTimeout(() => {
+ loading.value = false
+ }, 1000)
+ }
+}
+const getHistoryInfoApi = async () => {
+ const params = {
+ pageNum: currentPage.value,
+ pageSize: pageSize.value,
+ }
+ try {
+ const res = await getHistoryInfo(params)
+ total.value = res.data.total
+ totalPage.value = res.data.totalPage
+ return res
+ } catch (error) {
+ console.log("获取数据失败", error)
+ }
+}
+const onScroll = (event: any) => {
+ const container = event.target;
+ const isNearBottom = container.scrollHeight - container.scrollTop <= container.clientHeight + 100;
+ if (isNearBottom && !loading.value) {
+ getTableData()
}
}
+
// 搜索功能
const handleSearch = async () => {
// 这里根据 inputValue 进行搜索,更新 tableData
@@ -263,7 +273,6 @@ const handleConfirm = async () => {
const actionType = currentAction.value.type
if (actionType === 'delete') {
console.log('调用删除接口')
- // 调用删除接口
await handleDelete()
} else if (actionType === 'print') {
// 执行打印操作
@@ -287,16 +296,21 @@ const handleCancel = () => {
const handleDelete = async () => {
try {
// 调用删除接口,传入要删除的ID数组
- const res = await deleteHistoryInfo(selectedIds.value)
- if (res.success) {
- getTableData()
- // 清空选中的项
- selectedItems.value = []
- // 提示删除成功
- warnMessage.value = '删除成功'
- showWarn.value = true
- } else {
- throw new Error(res.message || '删除失败')
+ if (selectedIds.value.length > 0) {
+ selectedIds.value.forEach(async item => {
+ const res = await deleteHistoryInfo(item)
+ if (res.success) {
+ tableKey.value++
+ getTableData()
+ // 清空选中的项
+ selectedItems.value = []
+ // 提示删除成功
+ warnMessage.value = '删除成功'
+ showWarn.value = true
+ } else {
+ throw new Error(res.message || '删除失败')
+ }
+ })
}
} catch (error) {
console.error('删除失败', error)
@@ -522,6 +536,7 @@ onMounted(() => {
}
}
}
+
.page-container {
width: 100%;
max-width: 600px;
@@ -530,6 +545,7 @@ onMounted(() => {
display: flex;
flex-direction: column;
justify-content: space-between;
+
header {
text-align: center;
margin-bottom: 20px;
@@ -539,19 +555,23 @@ onMounted(() => {
color: #333;
}
}
+
.list-container {
.divider {
height: 40px;
}
+
ul {
li {
font-size: 32px;
}
}
}
+
footer {
text-align: center;
margin-top: 20px;
+
.close-btn {
width: 90%;
background-color: #528dfe;
diff --git a/src/pages/Index/Index.vue b/src/pages/Index/Index.vue
index c7adb41..b2bd121 100644
--- a/src/pages/Index/Index.vue
+++ b/src/pages/Index/Index.vue
@@ -79,7 +79,7 @@
@@ -267,10 +245,12 @@ const handleSelectedSamples = ({