Browse Source

改成支持单文件上传

Karsa 1 year ago
parent
commit
9c6213826b

+ 1 - 1
index.html

@@ -22,7 +22,6 @@
 	<link rel='stylesheet' href='https://hzstatic.hzinsights.com/static/cdn/Luckysheet@2.1.13/dist/plugins/plugins.css' />
 	<link rel='stylesheet' href='https://hzstatic.hzinsights.com/static/cdn/Luckysheet@2.1.13/dist/css/luckysheet.css' />
 	<link rel='stylesheet' href='https://hzstatic.hzinsights.com/static/cdn/Luckysheet@2.1.13/dist/assets/iconfont/iconfont.css' />
-	<script src="https://cdn.jsdelivr.net/npm/luckyexcel/dist/luckyexcel.umd.js"></script>
 	
 	<!-- dataTables -->
 	<link rel="stylesheet" type="text/css" href="./static/css/jquery.dataTables.css"/>
@@ -65,6 +64,7 @@
 	<script type="text/javascript" src="./static/js/jquery.min.js"></script>
 	<script src="https://hzstatic.hzinsights.com/static/cdn/Luckysheet@2.1.13/dist/plugins/js/plugin.js"></script>
 	<script src="https://hzstatic.hzinsights.com/static/cdn/Luckysheet@2.1.13/dist/luckysheet.umd.js"></script>
+	<script src="https://hzstatic.hzinsights.com/static/cdn/luckyexcel.umd.js"></script>
 	<script type="text/javascript" src="./static/js/jquery.dataTables.js"></script>
 </body>
 </html>

+ 13 - 16
src/views/datasheet_manage/customAnalysis/addAnalysisSheet.vue

@@ -4,8 +4,7 @@
       <div class="left-section">
         <el-tabs 
           v-model="selectIndex" 
-          type="card" 
-          closable
+          type="card"
           @tab-remove="handleRemoveSheet"
           @tab-click="handleSwitchSheet"
         >
@@ -97,7 +96,7 @@ export default {
 
       if (this.currentPage<this.maxPage) {
         this.currentPage++
-        setTimeout(this.loadDataSync(), 1000); // 1秒后加载下一页数据
+        requestAnimationFrame(this.loadDataSync());
       }else {
         this.isLoadOver = true;
       }
@@ -105,28 +104,26 @@ export default {
 
     /* 分割数据 */
     splitSheetData(sheets) {
-      this.allSheetData = sheets.map(_ => ({
-        index: _.index, //工作表索引
-        order: _.order, //工作表的下标
-        name: _.name,
-        calcChain: _.calcChain,
-        celldata: _.celldata,
-        config: _.config
-      }));
+      // this.allSheetData = sheets.map(_ => ({
+      //   index: _.index, //工作表索引
+      //   order: _.order, //工作表的下标
+      //   name: _.name,
+      //   calcChain: _.calcChain,
+      //   celldata: _.celldata,
+      //   config: _.config
+      // }));
+      // this.maxPage = Math.max(...sheets.map(_ =>  Math.ceil(_.celldata.length / this.pageSize)))
 
-      this.maxPage = Math.max(...sheets.map(_ =>  Math.ceil(_.celldata.length / this.pageSize)))
-
-      this.sheetConfig.data = this.allSheetData.map(_ => ({
+      this.sheetConfig.data = sheets.map(_ => ({
         index: _.index, //工作表索引
         order: _.order, //工作表的下标
         name: _.name,
         calcChain: _.calcChain,
         config: _.config,
-        celldata: _.celldata
+        celldata: _.celldata,
       }));
       
       // this.loadDataSync();
-      // console.log(this.sheetConfig.data)
       this.isLoading = false;
     },
 

+ 7 - 13
src/views/datasheet_manage/customAnalysis/list.vue

@@ -18,7 +18,7 @@
             :loading="isUploadLoading"
             @click="clickUpload"
           >上传文件</el-button>
-          <input type="file" multiple @change="fileSelected" id="file"  style="display: none;">
+          <input type="file" @change="fileSelected" id="file"  style="display: none;">
           
           <el-button>
             <el-checkbox v-model="isShowMe"  @change="() => { getTreeData();getPublicList() }">只看我的</el-checkbox>
@@ -817,19 +817,13 @@ export default {
 
     //选择文件上传
     fileSelected(){ 
-      let files = document.getElementById('file').files;
-      console.log(files)
-      if(files.length){
+      let file = document.getElementById('file').files[0];
+      if(file){
+        if(!file.name.includes('.xlsx')) return this.$message.warning("上传失败,格式不符合xlsx");
+        if(file.size > 1.1*1024*1024) return this.$message.warning("上传文件最大不能超过1M");
 
-        for(let i = 0;i<files.length;i++) {
-          if(!files[i].name.includes('.xlsx')) return this.$message.warning("上传失败,格式不符合xlsx");
-          if(files[i].size > 10*1024*1024) return this.$message.warning("上传文件最大不能超过10M");
-
-          if(i === files.length - 1) {
-            this.$store.commit('sheet/SET_UPLOADFIlES',files)
-            this.$router.push({ path: '/addAnalysisSheet' });
-          }
-        }
+        this.$store.commit('sheet/SET_UPLOADFIlES',[file])
+        this.$router.push({ path: '/addAnalysisSheet' });
 
 
       }