fix: 修复属性名称修改后顺序被重置的问题

This commit is contained in:
albert
2022-12-21 11:13:57 +08:00
parent 78ab7fddcf
commit be8a175584
2 changed files with 27 additions and 6 deletions

View File

@@ -115,7 +115,7 @@
</template>
<script>
import Vue from 'vue'
import { isNull } from './util'
import { isNull, renamePropertyAndKeepKeyPrecedence } from './util'
import {TYPE_NAME, TYPE} from './type/type'
import { Row,Col,Button,Input,InputNumber, Icon,Checkbox,Select,Tooltip,Modal,Form,Switch} from 'ant-design-vue'
import LocalProvider from './LocalProvider'
@@ -242,11 +242,13 @@ export default {
const newKey = e.target.value
if(oldKey === newKey) return
const nodeValue = this.parent.properties[oldKey]
// const nodeValue = this.parent.properties[oldKey]
// 替换key名
this.$delete(this.parent.properties, oldKey)
this.$set(this.parent.properties, newKey, nodeValue)
// // 替换key名
// this.$delete(this.parent.properties, oldKey)
// this.$set(this.parent.properties, newKey, nodeValue)
const _this = this
renamePropertyAndKeepKeyPrecedence(_this, this.parent.properties,[ oldKey, newKey ])
// required重新设置
const requireds = this.parent.required || []
@@ -324,7 +326,7 @@ export default {
const node = this.pickValue
node.properties || this.$set(node,'properties',{})
const props = node.properties
this.$set(props,name,{type: type})
this.$set(props,name,{type: type, title: ''})
},
parseCustomProps () {
const ownProps = this.ownProps

View File

@@ -21,4 +21,23 @@ export function isNull(ele){
return true;
}
return false;
}
export function renamePropertyAndKeepKeyPrecedence(_this, obj, [oldKey, newKey]) {
const descriptors = Object.getOwnPropertyDescriptors(obj)
if (Object.prototype.hasOwnProperty.call(descriptors, oldKey)) {
Object.entries(descriptors)
.reduce((target, [key, descriptor]) => {
if(key === '__ob__') return target
// Reflect.deleteProperty(target, key)
console.info('TTT', target, key ,descriptor)
_this.$delete(target, key)
if (key === oldKey) {
key = newKey
}
// // Reflect.defineProperty(target, key, descriptor)
_this.$set(target, key, descriptor.get())
return target;
}, obj)
}
return obj
}