Bläddra i källkod

优化table滚动

lighter 3 år sedan
förälder
incheckning
c5b69972fd

+ 18 - 15
src/utils/el-table-scroll.js

@@ -1,19 +1,22 @@
 export const setScrollTop = (tableRef, index) => {
-    try {
-        const targetTop = tableRef.$el.querySelectorAll('.el-table__body tr')[index].getBoundingClientRect().top //该行的位置
-        const containerTop = tableRef.$el.querySelector('.el-table__body').getBoundingClientRect().top //body的位置
-        tableRef.setScrollTop(targetTop - containerTop)
-    } catch (e) {
-
-    }
+  tableRef.setScrollTop(getScrollTop(tableRef, index))
 }
 
 export const getScrollTop = (tableRef, index) => {
-    try {
-        const targetTop = tableRef.$el.querySelectorAll('.el-table__body tr')[index].getBoundingClientRect().top //该行的位置
-        const containerTop = tableRef.$el.querySelector('.el-table__body').getBoundingClientRect().top //body的位置
-        return targetTop - containerTop
-    } catch (e) {
-        return 0
-    }
-}
+  try {
+    const targetTop = tableRef.$el.querySelectorAll('.el-table__body tr')[index].getBoundingClientRect().top //该行的位置
+    const containerTop = tableRef.$el.querySelector('.el-table__body').getBoundingClientRect().top //body的位置
+    return targetTop - containerTop
+  } catch (e) {
+    return 0
+  }
+}
+
+export function smoothScrollTableColumn(tableRef, columnIndex, columnData) {
+  tableRef.setCurrentRow(columnData)
+  tableRef.scrollTo({
+    top: getScrollTop(tableRef, columnIndex),
+    left: 0,
+    behavior: 'smooth',
+  })
+}

+ 10 - 12
src/views/hospitalization/case-front-sheet/FillCaseFrontSheet.vue

@@ -794,6 +794,7 @@ import HeadPage from '../../../components/inpatient/frontsheet-printpage/HeadPag
 import TailPage from '../../../components/inpatient/frontsheet-printpage/TailPage.vue'
 import router from '@/router/index'
 import Sleep from '@/utils/sleep'
+import { smoothScrollTableColumn } from '@/utils/el-table-scroll'
 
 const userWards = ref([])
 const currentWard = ref('')
@@ -830,24 +831,21 @@ const searchPatient = () => {
     })
     return
   }
-  let found = false
-  for (let i = 0; i < overview.value.length; i++) {
-    const item = overview.value[i]
-    if (item.bah === inpatientNo.value.trim()) {
-      fetchSheetInfo(item)
-      found = true
-      asideTable.value.setCurrentRow(item)
-      asideTable.value.$refs.bodyWrapper.scrollTop = 36 * i
-      break
-    }
-  }
-  if (!found) {
+
+  const patientIndex = overview.value.findIndex((item) => {
+    return item.bah === inpatientNo.value.trim()
+  })
+  if (patientIndex === -1) {
     ElMessage({
       message: '未找到住院号【' + inpatientNo.value.trim() + '】的患者信息',
       type: 'warning',
       duration: 2500,
       showClose: true,
     })
+  } else {
+    const currentPatient = overview.value[patientIndex]
+    fetchSheetInfo(currentPatient)
+    smoothScrollTableColumn(asideTable.value, patientIndex, currentPatient)
   }
 }