{"remainingRequest":"D:\\data\\hanguodoushan\\acs2\\nladmin-ui\\node_modules\\vue-loader\\lib\\index.js??vue-loader-options!D:\\data\\hanguodoushan\\acs2\\nladmin-ui\\src\\components\\UploadExcel\\index.vue?vue&type=script&lang=js","dependencies":[{"path":"D:\\data\\hanguodoushan\\acs2\\nladmin-ui\\src\\components\\UploadExcel\\index.vue","mtime":1732871026484},{"path":"D:\\data\\hanguodoushan\\acs2\\nladmin-ui\\node_modules\\cache-loader\\dist\\cjs.js","mtime":1732872824662},{"path":"D:\\data\\hanguodoushan\\acs2\\nladmin-ui\\node_modules\\babel-loader\\lib\\index.js","mtime":1732872825017},{"path":"D:\\data\\hanguodoushan\\acs2\\nladmin-ui\\node_modules\\cache-loader\\dist\\cjs.js","mtime":1732872824662},{"path":"D:\\data\\hanguodoushan\\acs2\\nladmin-ui\\node_modules\\vue-loader\\lib\\index.js","mtime":1732872825835}],"contextDependencies":[],"result":["//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\r\nimport XLSX from 'xlsx'\r\n\r\nexport default {\r\n props: {\r\n beforeUpload: Function, // eslint-disable-line\r\n onSuccess: Function// eslint-disable-line\r\n },\r\n data() {\r\n return {\r\n loading: false,\r\n excelData: {\r\n header: null,\r\n results: null\r\n }\r\n }\r\n },\r\n methods: {\r\n generateData({ header, results }) {\r\n this.excelData.header = header\r\n this.excelData.results = results\r\n this.onSuccess && this.onSuccess(this.excelData)\r\n },\r\n handleDrop(e) {\r\n e.stopPropagation()\r\n e.preventDefault()\r\n if (this.loading) return\r\n const files = e.dataTransfer.files\r\n if (files.length !== 1) {\r\n this.$message.error('只支持单个文件上传!')\r\n return\r\n }\r\n const rawFile = files[0]\r\n\r\n if (!this.isExcel(rawFile)) {\r\n this.$message.error('只支持.xlsx, .xls, .csv 格式文件')\r\n return false\r\n }\r\n this.upload(rawFile)\r\n e.stopPropagation()\r\n e.preventDefault()\r\n },\r\n handleDragover(e) {\r\n e.stopPropagation()\r\n e.preventDefault()\r\n e.dataTransfer.dropEffect = 'copy'\r\n },\r\n handleUpload() {\r\n this.$refs['excel-upload-input'].click()\r\n },\r\n handleClick(e) {\r\n const files = e.target.files\r\n const rawFile = files[0] // only use files[0]\r\n if (!rawFile) return\r\n this.upload(rawFile)\r\n },\r\n upload(rawFile) {\r\n this.$refs['excel-upload-input'].value = null // fix can't select the same excel\r\n\r\n if (!this.beforeUpload) {\r\n this.readerData(rawFile)\r\n return\r\n }\r\n const before = this.beforeUpload(rawFile)\r\n if (before) {\r\n this.readerData(rawFile)\r\n }\r\n },\r\n readerData(rawFile) {\r\n this.loading = true\r\n return new Promise((resolve, reject) => {\r\n const reader = new FileReader()\r\n reader.onload = e => {\r\n const data = e.target.result\r\n const workbook = XLSX.read(data, { type: 'array' })\r\n const firstSheetName = workbook.SheetNames[0]\r\n const worksheet = workbook.Sheets[firstSheetName]\r\n const header = this.getHeaderRow(worksheet)\r\n const results = XLSX.utils.sheet_to_json(worksheet)\r\n this.generateData({ header, results })\r\n this.loading = false\r\n resolve()\r\n }\r\n reader.readAsArrayBuffer(rawFile)\r\n })\r\n },\r\n getHeaderRow(sheet) {\r\n const headers = []\r\n const range = XLSX.utils.decode_range(sheet['!ref'])\r\n let C\r\n const R = range.s.r\r\n /* start in the first row */\r\n for (C = range.s.c; C <= range.e.c; ++C) { /* walk every column in the range */\r\n const cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })]\r\n /* find the cell in the first row */\r\n let hdr = 'UNKNOWN ' + C // <-- replace with your desired default\r\n if (cell && cell.t) hdr = XLSX.utils.format_cell(cell)\r\n headers.push(hdr)\r\n }\r\n return headers\r\n },\r\n isExcel(file) {\r\n return /\\.(xlsx|xls|csv)$/.test(file.name)\r\n }\r\n }\r\n}\r\n",null]}