|
|
@@ -0,0 +1,32 @@
|
|
|
+<!-- 我的库存-批量导入 -->
|
|
|
+<template>
|
|
|
+ <app-drawer title="批量导入" :width="960" v-model:show="show">
|
|
|
+ <el-upload accept=".xlsx,.xls" :show-file-list="false" :auto-upload="false" @change="handleExcel">
|
|
|
+ <el-button size="small">导入</el-button>
|
|
|
+ </el-upload>
|
|
|
+ </app-drawer>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts" setup>
|
|
|
+import { shallowRef } from 'vue'
|
|
|
+import { UploadFile } from 'element-plus'
|
|
|
+import { read, utils } from 'xlsx'
|
|
|
+import AppDrawer from '@pc/components/base/drawer/index.vue'
|
|
|
+
|
|
|
+const show = shallowRef(true)
|
|
|
+
|
|
|
+// 处理导入的excel表格
|
|
|
+const handleExcel = (uploadFile: UploadFile) => {
|
|
|
+ const fileReader = new FileReader()
|
|
|
+ fileReader.readAsBinaryString(uploadFile.raw as Blob)
|
|
|
+ fileReader.onload = (ev) => {
|
|
|
+ const data = ev.target?.result
|
|
|
+ if (data) {
|
|
|
+ const workbook = read(data, { type: 'binary' })
|
|
|
+ const page1 = workbook.SheetNames[0]
|
|
|
+ const page2 = workbook.SheetNames[1]
|
|
|
+ console.log(workbook)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|