表格组件

This commit is contained in:
yanran200730
2023-03-15 15:18:19 +08:00
parent 106535fc01
commit 529e0ddccf
7 changed files with 87 additions and 55 deletions

View File

@@ -396,6 +396,7 @@ export default {
})
},
clone(e) {
console.log(this.deepClone(e))
this.componentList.push(this.deepClone(e))
},
@@ -405,31 +406,42 @@ export default {
}
},
deepClone(data, hash = new WeakMap()) {
if (typeof data !== 'object' || data === null) {
throw new TypeError('传入参数不是对象')
}
if (hash.has(data)) {
return hash.get(data)
}
let newData = {}
const dataKeys = Object.keys(data)
dataKeys.forEach(value => {
const currentDataValue = data[value]
if (typeof currentDataValue !== "object" || currentDataValue === null) {
newData[value] = currentDataValue
} else if (Array.isArray(currentDataValue)) {
newData[value] = [...currentDataValue]
} else if (currentDataValue instanceof Set) {
newData[value] = new Set([...currentDataValue])
} else if (currentDataValue instanceof Map) {
newData[value] = new Map([...currentDataValue])
deepClone(obj) {
if (obj instanceof Object) {
let newObj = {}
if (Array.isArray(obj)) {
let arr = []
obj.forEach(item => {
arr.push(this.deepClone(item))
})
return arr
} else if (typeof obj == 'function') {
newObj = obj.bind(newObj)
} else {
hash.set(data, data)
newData[value] = this.deepClone(currentDataValue, hash)
for (let key in obj) {
let value = obj[key]
if (typeof value == 'function') {
newObj[key] = value.bind(newObj)
} else if (typeof value == 'object') {
if (Array.isArray(value)) {
newObj[key] = []
value.forEach(item => {
newObj[key].push(this.deepClone(item))
})
} else {
newObj[key] = this.deepClone(value)
}
} else {
newObj[key] = value
}
}
}
})
return newData
return newObj
} else {
return obj
}
},
onContextmenu(e, index) {