浏览代码

Merge branch 'master' of http://120.26.64.82:3000/BFFE/SZYGM1.0

chenrui  2 年之前
父节点
当前提交
e2fe181550

+ 2 - 2
src/views/baggageManagement/departure/flight/index.vue

@@ -210,9 +210,9 @@ const domeTable = ref(null)
 const { exportToExcel } = useTableExport()
 //点击下载按钮
 const downLoad=(data) =>{
-  const tableRef = ref(domeTable.value.table)
+  const table = ref(domeTable.value.table)
   exportToExcel({
-    tableRef
+    table
   })
 }
 

+ 6 - 6
src/views/baggageManagement/hooks/useTableExport.ts

@@ -3,26 +3,26 @@ import { ElMessage, ElTable } from 'element-plus'
 import * as XLSX from 'xlsx'
 import FileSaver from 'file-saver'
 
+type ElTableType = InstanceType<typeof ElTable>
 interface ExportOptions {
-  tableRef: Ref<InstanceType<typeof ElTable>>
+  table: ElTableType | Ref<ElTableType>
   sheetName?: string
   fileName?: string
   headerRowNumber?: number
 }
-
 type ExportHandler = (option: ExportOptions) => void
 
 export default function useTableExport() {
   const exportToExcel: ExportHandler = ({
-    tableRef,
+    table,
     sheetName = 'sheet1',
     fileName = '导出表格.xlsx',
     headerRowNumber = 1,
   }) => {
     try {
-      const tableNode = (tableRef.value.$el as HTMLElement).cloneNode(
-        true
-      ) as HTMLElement
+      const tableNode = (('$el' in table
+        ? table.$el
+        : table.value.$el) as HTMLElement).cloneNode(true) as HTMLElement
       // 设置了列的fixed属性后会有两个table元素,导出数据会重复,需要去掉一个table
       const fixedTable = tableNode.querySelector('.el-table__fixed')
       fixedTable && tableNode.removeChild(fixedTable)