A8000
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

704 lines
17 KiB

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
  1. <template>
  2. <!-- 历史页面-->
  3. <div id="history-container">
  4. <!-- 筛选 -->
  5. <div class="history-filter">
  6. <div class="filter-input">
  7. <el-input v-model="inputValue" placeholder="输入信息">
  8. <template #prefix>
  9. <el-icon class="el-input__icon">
  10. <search />
  11. </el-icon>
  12. </template>
  13. </el-input>
  14. </div>
  15. <div class="filter-button">
  16. <el-button type="primary" class="search-button" @click="handleSearch" disabled>搜索</el-button>
  17. <el-button class="reload-button" @click="handleReset">重置</el-button>
  18. </div>
  19. </div>
  20. <!-- 表格 -->
  21. <div class="history-table" @scroll="onScroll" ref="tableContainer">
  22. <HistoryTable ref="historyTableRef" @selectItems="handleSelection" @selectIds="handleSelectIds"
  23. @select-row="handleSelectRow" :tableData="tableData" :loading="loading" :key="tableKey"
  24. :loadingText="loadingText" />
  25. </div>
  26. <!-- 功能 -->
  27. <div class="history-function">
  28. <el-button type="primary" plain @click="showActionConfirm('delete')">删除</el-button>
  29. <el-button type="primary" plain @click="showActionConfirm('print')">打印</el-button>
  30. <el-button type="primary" plain @click="showActionConfirm('export')">导出</el-button>
  31. </div>
  32. <!-- 确认操作弹框 -->
  33. <HistoryWarn v-if="showModal" :icon="currentAction.icon" :message="currentAction.message"
  34. :confirmText="currentAction.confirmText" :cancelText="currentAction.cancelText" @confirm="handleConfirm"
  35. @cancel="handleCancel" />
  36. <!-- 通知提示框 -->
  37. <HistoryWarn v-if="showWarn" :message="warnMessage" :icon="warnIcon" @close="showWarn = false" />
  38. <!-- 通用通知组件 -->
  39. <HistoryWarn v-if="showWarn" :message="warnMessage" :icon="warnIcon" :confirmText="'关闭'" :showButtons="false"
  40. @confirm="handleWarnClose" />
  41. </div>
  42. <HistoryMessage :isVisible="isVisible" @update:isVisible="isVisible = $event">
  43. <div class="detail-container">
  44. <div class="detail-section">
  45. <div class="detail-item">
  46. <span class="label">日期:</span>
  47. <span class="value">2024-01-01</span>
  48. </div>
  49. <div class="divider"></div>
  50. <div class="detail-item">
  51. <span class="label">SampleID:</span>
  52. <span class="value">12345</span>
  53. </div>
  54. <div class="divider"></div>
  55. <div class="detail-item">
  56. <span class="label">ProjectShortName:</span>
  57. <span class="value">Test Project</span>
  58. </div>
  59. <div class="detail-item">
  60. <span class="label">subResult1:</span>
  61. <span class="value">Result 1</span>
  62. </div>
  63. <div class="detail-item">
  64. <span class="label">subResult2:</span>
  65. <span class="value">Result 2</span>
  66. </div>
  67. <div class="detail-item">
  68. <span class="label">subResult3:</span>
  69. <span class="value">Result 3</span>
  70. </div>
  71. </div>
  72. <div class="detail-section">
  73. <div class="detail-item">
  74. <span class="label">样本种类:</span>
  75. <span class="value">Type A</span>
  76. </div>
  77. <div class="detail-item">
  78. <span class="label">操次:</span>
  79. <span class="value">1</span>
  80. </div>
  81. <div class="detail-item">
  82. <span class="label">Rec:</span>
  83. <span class="value">Record 1</span>
  84. </div>
  85. <div class="detail-item">
  86. <span class="label">有效期:</span>
  87. <span class="value">2024-12-31</span>
  88. </div>
  89. <div class="divider"></div>
  90. <div class="detail-item">
  91. <span class="label">操作人:</span>
  92. <span class="value">John Doe</span>
  93. </div>
  94. <div class="detail-item">
  95. <span class="label">序列号:</span>
  96. <span class="value">SN12345</span>
  97. </div>
  98. <div class="detail-item">
  99. <span class="label">App Ver:</span>
  100. <span class="value">1.0.0</span>
  101. </div>
  102. <div class="detail-item">
  103. <span class="label">F/W Ver:</span>
  104. <span class="value">2.0.0</span>
  105. </div>
  106. </div>
  107. <div class="detail-footer">
  108. <button class="confirm-btn" @click="handleClose">确认</button>
  109. </div>
  110. </div>
  111. </HistoryMessage>
  112. </template>
  113. <script setup lang="ts">
  114. import { onMounted, ref } from 'vue'
  115. import { HistoryTable, HistoryWarn } from './components/index'
  116. import {
  117. getHistoryInfo,
  118. deleteHistoryInfo,
  119. searchHistoryInfo,
  120. printHistoryInfo,
  121. } from '../../services/Index/index'
  122. import HistoryMessage from './components/History/HistoryMessage.vue'
  123. import type { TableItem } from '../../types/Index'
  124. import { ElMessage } from 'element-plus'
  125. // 添加表格引用
  126. const historyTableRef = ref()
  127. //选中弹出框
  128. const isVisible = ref<boolean>(false)
  129. const handleClose = () => {
  130. isVisible.value = false
  131. }
  132. // 绑定输入框的值
  133. const inputValue = ref<string>('')
  134. // 选中的项目
  135. const selectedItems = ref<TableItem[]>([])
  136. // 控制弹框和通知的显示
  137. const showModal = ref<boolean>(false)
  138. const showWarn = ref<boolean>(false)
  139. // 当前操作的图标和提示信息
  140. const currentAction = ref<{
  141. type: string
  142. icon: string
  143. message: string
  144. confirmText: string
  145. cancelText: string
  146. }>({
  147. type: '',
  148. icon: '',
  149. message: '',
  150. confirmText: '',
  151. cancelText: '',
  152. })
  153. // 通知消息
  154. const warnMessage = ref<string>('')
  155. // 未选择项目通知的图标
  156. let warnIcon = new URL('@/assets/Index/History/warn.svg', import.meta.url).href
  157. // 定义不同操作的图标和提示信息
  158. const actions: Record<
  159. string,
  160. {
  161. type: string
  162. icon: string
  163. message: string
  164. confirmText: string
  165. cancelText: string
  166. }
  167. > = {
  168. delete: {
  169. type: 'delete',
  170. icon: new URL('@/assets/Index/History/warn.svg', import.meta.url).href,
  171. message: '请确认是否删除所选项目',
  172. confirmText: '确认删除',
  173. cancelText: '取消',
  174. },
  175. print: {
  176. type: 'print',
  177. icon: new URL('@/assets/Index/History/print.svg', import.meta.url).href,
  178. message: '请确认是否打印所选项目',
  179. confirmText: '确认打印',
  180. cancelText: '取消',
  181. },
  182. export: {
  183. type: 'export',
  184. icon: new URL('@/assets/Index/History/warn.svg', import.meta.url).href,
  185. message: '请确认是否导出所选项目',
  186. confirmText: '确认导出',
  187. cancelText: '取消',
  188. },
  189. }
  190. const selectedIds = ref<number[]>([])
  191. // 处理表格选中的项目
  192. const handleSelection = (items: TableItem[]) => {
  193. selectedItems.value = items
  194. }
  195. const handleSelectIds = (ids: number[]) => {
  196. selectedIds.value = ids
  197. }
  198. const handleSelectRow = () => {
  199. isVisible.value = true
  200. }
  201. // 根据操作类型显示不同的确认弹框或通知
  202. const showActionConfirm = (actionType: string) => {
  203. // 判断是否有选中的项目
  204. if (selectedItems.value.length === 0) {
  205. // 如果没有选中项目,弹出通知框
  206. warnMessage.value = '请先选择项目'
  207. showWarn.value = true
  208. return
  209. }
  210. // 如果是删除操作,确认删除的数量
  211. if (actionType === 'delete') {
  212. currentAction.value = {
  213. ...actions[actionType],
  214. message: `是否删除选中的 ${selectedItems.value.length} 条记录?`
  215. }
  216. } else {
  217. currentAction.value = actions[actionType]
  218. }
  219. showModal.value = true
  220. }
  221. //控制骨架屏
  222. const loading = ref(false)
  223. // 获取表格数据
  224. const tableData = ref<TableItem[]>([])
  225. const currentPage = ref(1)
  226. const pageSize = ref(20)
  227. const total = ref(0)
  228. const totalPage = ref(0)
  229. const tableKey = ref(0)//控制重新渲染
  230. const tableContainer = ref(null as HTMLElement | null)
  231. const hasMore = ref(true)
  232. const loadingText = ref("加载中...")
  233. const getTableData = async (isReset: boolean = false) => {
  234. if (isReset) {
  235. // 重置数据和页码
  236. tableData.value = []
  237. currentPage.value = 1
  238. hasMore.value = true
  239. }
  240. if (loading.value || !hasMore.value) return
  241. loading.value = true
  242. try {
  243. const res = await getHistoryInfoApi()
  244. if (currentPage.value > totalPage.value) {
  245. hasMore.value = false
  246. loadingText.value = "没有更多数据了"
  247. } else {
  248. tableData.value = [...tableData.value, ...res.data.list]
  249. currentPage.value++;
  250. loadingText.value = "加载中..."
  251. }
  252. } catch (error) {
  253. console.error('获取数据失败', error)
  254. loadingText.value = "加载失败,请重试"
  255. } finally {
  256. setTimeout(() => {
  257. loading.value = false
  258. }, 1000)
  259. }
  260. }
  261. const getHistoryInfoApi = async () => {
  262. const params = {
  263. pageNum: currentPage.value,
  264. pageSize: pageSize.value,
  265. }
  266. try {
  267. const res = await getHistoryInfo(params)
  268. total.value = res.data.total
  269. totalPage.value = res.data.totalPage
  270. return res
  271. } catch (error) {
  272. console.log("获取数据失败", error)
  273. }
  274. }
  275. const onScroll = (event: any) => {
  276. const container = event.target;
  277. const isNearBottom = container.scrollHeight - container.scrollTop <= container.clientHeight + 100;
  278. if (isNearBottom && !loading.value) {
  279. getTableData()
  280. }
  281. }
  282. // 搜索功能
  283. const handleSearch = async () => {
  284. console.log('搜索内容:', inputValue.value)
  285. try {
  286. const res = await searchHistoryInfo(inputValue.value)
  287. console.log(res.data.list)
  288. // 直接替换数据,不进行累加
  289. tableData.value = res.data.list as TableItem[]
  290. // 重置分页相关状态
  291. currentPage.value = 1
  292. hasMore.value = false
  293. } catch (error) {
  294. console.error('搜索失败', error)
  295. }
  296. }
  297. // 重置功能
  298. const handleReset = () => {
  299. inputValue.value = ''
  300. getTableData(true) // 传入 true 表示需要重置
  301. }
  302. // 确认操作时的回调函数
  303. const handleConfirm = async () => {
  304. showModal.value = false
  305. showWarn.value = false
  306. const actionType = currentAction.value.type
  307. if (actionType === 'delete') {
  308. await handleConfirmDelete()
  309. } else if (actionType === 'print') {
  310. // 执行打印操作
  311. handlePrint()
  312. } else if (actionType === 'export') {
  313. // 执行导出操作
  314. handleExport()
  315. }
  316. }
  317. const handleWarnClose = () => {
  318. getTableData()
  319. showWarn.value = false
  320. }
  321. // 取消操作时的回调函数
  322. const handleCancel = () => {
  323. showModal.value = false
  324. showWarn.value = false
  325. }
  326. // 自定义 ElMessage 样式
  327. const showCustomMessage = (message: string, type: 'success' | 'error' = 'success') => {
  328. ElMessage({
  329. message,
  330. type,
  331. customClass: 'custom-message',
  332. duration: 2000,
  333. })
  334. }
  335. // 处理删除确认
  336. const handleConfirmDelete = async () => {
  337. try {
  338. // 一次删除一条记录
  339. for (const item of selectedItems.value) {
  340. const res = await deleteHistoryInfo(item.id)
  341. if (!res.success) {
  342. throw new Error('删除失败')
  343. }
  344. }
  345. // 从表格数据中移除被删除的项目
  346. const deleteIds = selectedItems.value.map(item => item.id)
  347. tableData.value = tableData.value.filter(item => !deleteIds.includes(item.id))
  348. // 通过表格组件清空选择状态
  349. if (historyTableRef.value) {
  350. historyTableRef.value.clearSelection()
  351. }
  352. showCustomMessage('删除成功')
  353. } catch (error) {
  354. showCustomMessage('删除失败', 'error')
  355. } finally {
  356. showModal.value = false
  357. }
  358. }
  359. // 打印功能
  360. const handlePrint = async () => {
  361. try {
  362. if (selectedItems.value.length > 10) {
  363. warnMessage.value = '一次最多只能打印 10 条记录'
  364. warnIcon = new URL('@/assets/Index/History/warn.svg', import.meta.url).href
  365. showWarn.value = true
  366. return
  367. }
  368. const idsToPrint = selectedItems.value.map((item) => item.id)
  369. for (const item of idsToPrint) {
  370. const res = await printHistoryInfo(item)
  371. if (res.success && res.ecode === "SUC") {
  372. warnMessage.value = '打���成功'
  373. warnIcon = new URL('@/assets/Index/History/success.svg', import.meta.url).href
  374. showWarn.value = true
  375. // 清空选中状态
  376. selectedItems.value = []
  377. selectedIds.value = []
  378. // 手动清除表格的选中状态
  379. if (historyTableRef.value?.clearSelection) {
  380. historyTableRef.value.clearSelection()
  381. }
  382. } else {
  383. throw new Error(res.message || '打印失败')
  384. }
  385. }
  386. } catch (error) {
  387. console.error('打印失败', error)
  388. warnMessage.value = '打印失败,请重试'
  389. warnIcon = new URL('@/assets/Index/History/error.svg', import.meta.url).href
  390. showWarn.value = true
  391. }
  392. }
  393. // 导出功能
  394. const handleExport = () => {
  395. // 执行导出操作
  396. // 根据实际需求实现导出功能
  397. console.log('导出项目:', selectedItems.value)
  398. warnMessage.value = '导出成功'
  399. showWarn.value = true
  400. }
  401. onMounted(() => {
  402. getTableData()
  403. })
  404. </script>
  405. <style scoped lang="less">
  406. :global(.custom-message) {
  407. min-width: 380px !important;
  408. padding: 16px 24px !important;
  409. .el-message__content {
  410. font-size: 24px !important;
  411. line-height: 1.5 !important;
  412. }
  413. .el-message__icon {
  414. font-size: 24px !important;
  415. margin-right: 12px !important;
  416. }
  417. }
  418. #history-container {
  419. width: 100%;
  420. height: 90vh;
  421. display: flex;
  422. flex-direction: column;
  423. background-color: #f5f7fa;
  424. box-sizing: border-box;
  425. .history-filter {
  426. width: 100%;
  427. height: 70px;
  428. margin-bottom: 20px;
  429. display: flex;
  430. justify-content: space-between;
  431. align-items: center;
  432. background-color: #fff;
  433. border-radius: 10px;
  434. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  435. .filter-input {
  436. flex: 1;
  437. max-width: 800px;
  438. .el-input {
  439. height: 50px;
  440. font-size: 26px;
  441. .el-input__wrapper {
  442. border-radius: 25px;
  443. padding: 0 20px;
  444. box-shadow: 0 0 0 1px #dcdfe6;
  445. &:hover {
  446. box-shadow: 0 0 0 1px #409eff;
  447. }
  448. &.is-focus {
  449. box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  450. }
  451. }
  452. .el-input__icon {
  453. font-size: 26px;
  454. color: #909399;
  455. }
  456. }
  457. }
  458. .filter-button {
  459. display: flex;
  460. .search-button,
  461. .reload-button {
  462. height: 50px;
  463. border-radius: 25px;
  464. font-size: 26px;
  465. font-weight: 500;
  466. transition: all 0.3s;
  467. &:hover {
  468. transform: translateY(-2px);
  469. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  470. }
  471. }
  472. .search-button {
  473. width: 200px;
  474. &:disabled {
  475. background-color: #a0cfff;
  476. border-color: #a0cfff;
  477. &:hover {
  478. transform: none;
  479. box-shadow: none;
  480. }
  481. }
  482. }
  483. .reload-button {
  484. width: 90px;
  485. color: #606266;
  486. border: 1px solid #dcdfe6;
  487. &:hover {
  488. color: #409eff;
  489. border-color: #c6e2ff;
  490. background-color: #ecf5ff;
  491. }
  492. }
  493. }
  494. }
  495. .history-table {
  496. flex: 1;
  497. overflow-y: auto; // 只允许垂直滚动
  498. overflow-x: hidden; // 禁止水平滚动
  499. background-color: #fff;
  500. border-radius: 10px;
  501. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  502. margin: 0 20px;
  503. padding: 20px;
  504. position: relative;
  505. // 优化滚动条样式
  506. &::-webkit-scrollbar {
  507. width: 6px;
  508. height: 6px;
  509. }
  510. &::-webkit-scrollbar-thumb {
  511. background: #c0c4cc;
  512. border-radius: 3px;
  513. &:hover {
  514. background: #909399;
  515. }
  516. }
  517. &::-webkit-scrollbar-track {
  518. background: #f5f7fa;
  519. }
  520. // 添加表格容器阴影效果
  521. &::after {
  522. content: '';
  523. position: absolute;
  524. left: 0;
  525. right: 0;
  526. bottom: 0;
  527. height: 30px;
  528. background: linear-gradient(to top, rgba(255, 255, 255, 0.9), transparent);
  529. pointer-events: none;
  530. }
  531. }
  532. .history-function {
  533. width: 100%;
  534. height: 84px;
  535. margin-top: 20px;
  536. background-color: #fff;
  537. box-shadow: 0 -2px 12px 0 rgba(0, 0, 0, 0.05);
  538. display: flex;
  539. justify-content: center;
  540. align-items: center;
  541. gap: 20px;
  542. .el-button {
  543. height: 50px;
  544. border-radius: 25px;
  545. font-size: 26px;
  546. font-weight: 500;
  547. transition: all 0.3s;
  548. &:hover {
  549. transform: translateY(-2px);
  550. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  551. }
  552. &:nth-child(1) {
  553. width: 215px;
  554. }
  555. &:nth-child(2),
  556. &:nth-child(3) {
  557. width: 392px;
  558. }
  559. &.is-plain {
  560. background-color: #fff;
  561. &:hover {
  562. background-color: #ecf5ff;
  563. }
  564. }
  565. }
  566. }
  567. }
  568. .detail-container {
  569. .detail-section {
  570. margin-bottom: 24px;
  571. }
  572. .detail-item {
  573. display: flex;
  574. align-items: center;
  575. padding: 16px 0;
  576. font-size: 28px;
  577. .label {
  578. color: #606266;
  579. min-width: 200px;
  580. font-weight: 500;
  581. }
  582. .value {
  583. color: #303133;
  584. flex: 1;
  585. }
  586. }
  587. .divider {
  588. height: 1px;
  589. background-color: #ebeef5;
  590. margin: 16px 0;
  591. }
  592. .detail-footer {
  593. margin-top: 40px;
  594. text-align: center;
  595. .confirm-btn {
  596. width: 90%;
  597. height: 88px;
  598. background-color: #409eff;
  599. border: none;
  600. border-radius: 44px;
  601. color: white;
  602. font-size: 32px;
  603. font-weight: 500;
  604. cursor: pointer;
  605. transition: all 0.3s;
  606. &:hover {
  607. background-color: #66b1ff;
  608. transform: translateY(-2px);
  609. box-shadow: 0 4px 12px rgba(64, 158, 255, 0.4);
  610. }
  611. &:active {
  612. transform: translateY(0);
  613. }
  614. }
  615. }
  616. }
  617. </style>