|
@@ -280,11 +280,7 @@ created() {
|
|
let haveUpdatedProtectedData=false
|
|
let haveUpdatedProtectedData=false
|
|
if([3,4].includes(position.r)){
|
|
if([3,4].includes(position.r)){
|
|
if(!cell) return
|
|
if(!cell) return
|
|
- // 经实践发现……在表格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)
|
|
|
|
- })
|
|
|
|
|
|
+ let index = this.protectedData[3].findIndex((pd,ind) => pd && ind==position.c)
|
|
if(index ==-1) return
|
|
if(index ==-1) return
|
|
Object.keys(this.protectedData[position.r][index]).forEach(key => {
|
|
Object.keys(this.protectedData[position.r][index]).forEach(key => {
|
|
if(!_.isEqual(cell[key], this.protectedData[position.r][index][key])){
|
|
if(!_.isEqual(cell[key], this.protectedData[position.r][index][key])){
|
|
@@ -333,29 +329,56 @@ created() {
|
|
}
|
|
}
|
|
|
|
|
|
this.options.hook.updated=(operation)=>{
|
|
this.options.hook.updated=(operation)=>{
|
|
|
|
+ // 维护 protectedData数据
|
|
if(operation.type == 'delRC'){
|
|
if(operation.type == 'delRC'){
|
|
- // 删除行或者列
|
|
|
|
|
|
+ // 删除列
|
|
if(operation.ctrlValue.rc == 'c'){
|
|
if(operation.ctrlValue.rc == 'c'){
|
|
// console.log('删除列',`第${operation.ctrlValue.index+1}列开始`,`删除了${operation.ctrlValue.len}列`);
|
|
// console.log('删除列',`第${operation.ctrlValue.index+1}列开始`,`删除了${operation.ctrlValue.len}列`);
|
|
if(!operation.data){
|
|
if(!operation.data){
|
|
// 没有data为撤销 恢复他
|
|
// 没有data为撤销 恢复他
|
|
for (let i = operation.ctrlValue.index; i < operation.ctrlValue.index+operation.ctrlValue.len; i++) {
|
|
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])
|
|
|
|
|
|
+ // 在celldata初始数据里面找,有找到说明不是新加的
|
|
|
|
+ let isFind = luckysheet.getSheet().celldata.some(cd => {
|
|
|
|
+ return cd.r==3 && cd.c < operation.ctrlValue.index+operation.ctrlValue.len+1 &&
|
|
|
|
+ cd.v && cd.v.v == operation.curdata[3][i].v
|
|
|
|
+ })
|
|
|
|
+ this.protectedData[3].splice(i,0,isFind?operation.curdata[3][i]:false)
|
|
|
|
+ this.protectedData[4].splice(i,0,isFind?operation.curdata[4][i]:false)
|
|
}
|
|
}
|
|
}else{
|
|
}else{
|
|
for (let i = operation.ctrlValue.index; i < operation.ctrlValue.index+operation.ctrlValue.len; i++) {
|
|
for (let i = operation.ctrlValue.index; i < operation.ctrlValue.index+operation.ctrlValue.len; i++) {
|
|
- if(i > this.protectedData[3].length){
|
|
|
|
|
|
+ if(operation.ctrlValue.index > this.protectedData[3].length){
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- this.protectedData[3].splice(i,1)
|
|
|
|
- this.protectedData[4].splice(i,1)
|
|
|
|
|
|
+ this.protectedData[3].splice(operation.ctrlValue.index,1)
|
|
|
|
+ this.protectedData[4].splice(operation.ctrlValue.index,1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ }else if(operation.type == 'addRC' && operation.ctrlValue.rc == 'c'){
|
|
|
|
+ // 增加列
|
|
|
|
+ let addIndex = operation.ctrlValue.index
|
|
|
|
+ if(operation.ctrlValue.direction=='lefttop'){
|
|
|
|
+ // 向左加
|
|
|
|
+ addIndex--
|
|
|
|
+ }
|
|
|
|
+ // 比原本的protectedData数组长度大,就不会对protectedData造成形象 就return
|
|
|
|
+ if(!(addIndex < this.protectedData[3].length)) return
|
|
|
|
+ // console.log('增加列',`第${addIndex+1}列开始向右`,`增加了${operation.ctrlValue.len}列,${operation.data?"正向操作":"撤销"}`);
|
|
|
|
+
|
|
|
|
+ if(!operation.data){
|
|
|
|
+ // 没有data为撤销 删除它
|
|
|
|
+ for (let i = addIndex; i < addIndex+operation.ctrlValue.len; i++) {
|
|
|
|
+ this.protectedData[3].splice(addIndex+1,1)
|
|
|
|
+ this.protectedData[4].splice(addIndex+1,1)
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ for (let i = addIndex; i < addIndex+operation.ctrlValue.len; i++) {
|
|
|
|
+ // 新加的列,只占个位置,保持索引相对,不需要保护,置为false
|
|
|
|
+ this.protectedData[3].splice(i+1,0,false)
|
|
|
|
+ this.protectedData[4].splice(i+1,0,false)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|