mirror of
https://github.com/Ssl1S/json-schema-editor-vue.git
synced 2025-12-30 01:37:55 +08:00
fix: 修复属性名称修改后顺序被重置的问题
This commit is contained in:
@@ -115,7 +115,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import { isNull } from './util'
|
import { isNull, renamePropertyAndKeepKeyPrecedence } from './util'
|
||||||
import {TYPE_NAME, TYPE} from './type/type'
|
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 { Row,Col,Button,Input,InputNumber, Icon,Checkbox,Select,Tooltip,Modal,Form,Switch} from 'ant-design-vue'
|
||||||
import LocalProvider from './LocalProvider'
|
import LocalProvider from './LocalProvider'
|
||||||
@@ -242,11 +242,13 @@ export default {
|
|||||||
const newKey = e.target.value
|
const newKey = e.target.value
|
||||||
if(oldKey === newKey) return
|
if(oldKey === newKey) return
|
||||||
|
|
||||||
const nodeValue = this.parent.properties[oldKey]
|
// const nodeValue = this.parent.properties[oldKey]
|
||||||
|
|
||||||
// 替换key名
|
// // 替换key名
|
||||||
this.$delete(this.parent.properties, oldKey)
|
// this.$delete(this.parent.properties, oldKey)
|
||||||
this.$set(this.parent.properties, newKey, nodeValue)
|
// this.$set(this.parent.properties, newKey, nodeValue)
|
||||||
|
const _this = this
|
||||||
|
renamePropertyAndKeepKeyPrecedence(_this, this.parent.properties,[ oldKey, newKey ])
|
||||||
|
|
||||||
// required重新设置
|
// required重新设置
|
||||||
const requireds = this.parent.required || []
|
const requireds = this.parent.required || []
|
||||||
@@ -324,7 +326,7 @@ export default {
|
|||||||
const node = this.pickValue
|
const node = this.pickValue
|
||||||
node.properties || this.$set(node,'properties',{})
|
node.properties || this.$set(node,'properties',{})
|
||||||
const props = node.properties
|
const props = node.properties
|
||||||
this.$set(props,name,{type: type})
|
this.$set(props,name,{type: type, title: ''})
|
||||||
},
|
},
|
||||||
parseCustomProps () {
|
parseCustomProps () {
|
||||||
const ownProps = this.ownProps
|
const ownProps = this.ownProps
|
||||||
|
|||||||
@@ -21,4 +21,23 @@ export function isNull(ele){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user