ソースを参照

手工数据录入再优化

hbchen 8 ヶ月 前
コミット
f32cff54bd
1 ファイル変更35 行追加19 行削除
  1. 35 19
      src/views/dataEntry_manage/onlineExcelCopy.vue

+ 35 - 19
src/views/dataEntry_manage/onlineExcelCopy.vue

@@ -242,15 +242,19 @@ created() {
         this.haveSaveProtected=true
       }
       this.options.hook.cellUpdateBefore=(r,c)=>{
+        let edbNameEle = luckysheet.getSheetData()[3][c]
         // 禁止更新的单元格 已经有的指标名称和单位不允许更新
-        if(([0,1,2].includes(r) && c==0) || ([3,4].includes(r) && c<=dataList.length)){
+        if(([0,1,2].includes(r) && c==0) 
+          || ([3,4].includes(r) && edbNameEle && this.protectedData[3].some(data => data.v == edbNameEle.v))){
           return false
         }
       }
 
       this.options.hook.cellMousedownBefore=(e,position)=>{
+        let edbNameEle = luckysheet.getSheetData()[3][position.c]
         // 禁止鼠标选中的单元格
-        if([0,1,2].includes(position.r) || ([3,4].includes(position.r) && position.c<=dataList.length)){
+        if([0,1,2].includes(position.r) 
+          || ([3,4].includes(position.r) && edbNameEle && this.protectedData[3].some(data => data.v == edbNameEle.v))){
           return false
         }
       }
@@ -274,12 +278,18 @@ created() {
         
         // 是否更改了受保护的数据
         let haveUpdatedProtectedData=false
-        if([3,4].includes(position.r) && position.c>=0 && position.c<=dataList.length){
+        if([3,4].includes(position.r)){
           if(!cell) return 
-          Object.keys(this.protectedData[position.r][position.c]).forEach(key => {
-            if(!_.isEqual(cell[key], this.protectedData[position.r][position.c][key])){
+          // 经实践发现……在表格render之前 celldata为之前的数据,但是data已经是之后的数据了
+          let edbNameEle = sheet.celldata.find(cd => cd.r==3 && cd.c==position.c)
+          let index = this.protectedData[3].findIndex(data => {
+            return edbNameEle && edbNameEle.v && (data.v == edbNameEle.v.v)
+          })
+          if(index ==-1) return 
+          Object.keys(this.protectedData[position.r][index]).forEach(key => {
+            if(!_.isEqual(cell[key], this.protectedData[position.r][index][key])){
               haveUpdatedProtectedData=true
-              cell[key] = this.protectedData[position.r][position.c][key]
+              cell[key] = this.protectedData[position.r][index][key]
             }
           }); 
         }else if([0,1,2].includes(position.r)){
@@ -288,7 +298,7 @@ created() {
             if(cindex<1){
               return 
             }
-            luckysheet.getSheet().data[position.r][position.c] = this.protectedData[position.r][cindex]
+            sheet.data[position.r][position.c] = this.protectedData[position.r][1]
           }else{
             Object.keys(this.protectedData[position.r][cindex]).forEach(key => {
               if(!_.isEqual(cell[key], this.protectedData[position.r][cindex][key])){
@@ -296,7 +306,7 @@ created() {
                 cell[key] = this.protectedData[position.r][cindex][key]
               }
             });
-            if([0,1,2].includes(position.r) && position.c>0){
+            if(position.c>0){
               if(position.r==0){
                 if(cell.m !==this.firstClassName || cell.v !== this.firstClassName){
                   haveUpdatedProtectedData=true
@@ -323,21 +333,28 @@ created() {
       }
 
       this.options.hook.updated=(operation)=>{
-        // console.log(operation);
         if(operation.type == 'delRC'){
           // 删除行或者列
           if(operation.ctrlValue.rc == 'c'){
-            console.log('删除列',`第${operation.ctrlValue.index+1}列开始`,`删除了${operation.ctrlValue.len}列`);
-            let deleteColIndexs = []
-            for (let i = operation.ctrlValue.index; i < operation.ctrlValue.index+operation.ctrlValue.len; i++) {
-              if(i > dataList.length){
-                break;
+            // console.log('删除列',`第${operation.ctrlValue.index+1}列开始`,`删除了${operation.ctrlValue.len}列`);
+            if(!operation.data){
+              // 没有data为撤销 恢复他
+              for (let i = operation.ctrlValue.index; i < operation.ctrlValue.index+operation.ctrlValue.len; i++) {
+                if(i > this.protectedData[3].length){
+                  break;
+                }
+                this.protectedData[3].splice(i,0,operation.curdata[3][i])
+                this.protectedData[4].splice(i,0,operation.curdata[4][i])
+              }
+            }else{
+              for (let i = operation.ctrlValue.index; i < operation.ctrlValue.index+operation.ctrlValue.len; i++) {
+                if(i > this.protectedData[3].length){
+                  break;
+                }
+                this.protectedData[3].splice(i,1)
+                this.protectedData[4].splice(i,1)
               }
-              this.protectedData[3].splice(i,1)
-              this.protectedData[4].splice(i,1)
-              deleteColIndexs.push(i-1)
             }
-            dataList = dataList.filter((item,index) => !deleteColIndexs.includes(index))
           }
         }
       }
@@ -391,7 +408,6 @@ created() {
         })
       })
       for (let i = 0; i < col; i++) {
-        // let item =dataList[0]
         this.options.data[0].celldata.push(
         {
           "r":0,