Browse Source

更改读取文件方式为url读取

liuyu 5 years ago
parent
commit
6a87e01fd1
2 changed files with 6 additions and 4 deletions
  1. 6 2
      app/service/excelimport.js
  2. 0 2
      config/config.default.js

+ 6 - 2
app/service/excelimport.js

@@ -12,9 +12,13 @@ class ExcelimportService extends Service {
 
   // 获取导入的XLSX文件中的数据
   async getImportXLSXData(elem) {
-    const filepath = this.ctx.app.config.fileDirImp + elem.content;
+    // 导入学籍的情况
     if (elem.type === '0') {
-      const workbook = XLSX.readFile(filepath);
+      const filepath = this.ctx.app.config.baseDirImp + elem.content;
+      const file = await this.ctx.curl(filepath);
+      console.log(11111);
+      console.log(file.data);
+      const workbook = XLSX.read(file.data);
       // 读取内容
       const sheetNames = workbook.SheetNames; // 获取所有sheet页
       const sheet = workbook.Sheets[sheetNames[0]]; // 通过取得当前sheet页

+ 0 - 2
config/config.default.js

@@ -57,8 +57,6 @@ module.exports = appInfo => {
   //   },
   // };
   // base路径
-  config.fileDirImp = 'D:\\tmp\\';
-  // base路径
   config.baseDirImp = 'http://smart.cc-lotus.info';
   // 学生信息url
   config.stusDirImp = '/stud/enrollments';