feat: add parentFiled
parent
6ffd1b516b
commit
20dca104bb
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<Tree v-bind="getAttrs" @change="handleChange">
|
<Tree v-bind="(getAttrs as any)" @change="handleChange">
|
||||||
<template #[item]="data" v-for="item in Object.keys(slots)">
|
<template #[item]="data" v-for="item in Object.keys(slots)">
|
||||||
<slot :name="item" v-bind="data || {}"></slot>
|
<slot :name="item" v-bind="data || {}"></slot>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
import { computed, watch, ref, onMounted, unref, useAttrs } from 'vue'
|
import { computed, watch, ref, onMounted, unref, useAttrs } from 'vue'
|
||||||
import { TreeSelect } from 'ant-design-vue'
|
import { TreeSelect } from 'ant-design-vue'
|
||||||
import { isArray, isFunction } from '@/utils/is'
|
import { isArray, isFunction } from '@/utils/is'
|
||||||
import { get } from 'lodash-es'
|
import { get, set } from 'lodash-es'
|
||||||
import { propTypes } from '@/utils/propTypes'
|
import { propTypes } from '@/utils/propTypes'
|
||||||
import { LoadingOutlined } from '@ant-design/icons-vue'
|
import { LoadingOutlined } from '@ant-design/icons-vue'
|
||||||
import { handleTree } from '@/utils/tree'
|
import { handleTree } from '@/utils/tree'
|
||||||
|
|
@ -24,7 +24,8 @@ const props = defineProps({
|
||||||
resultField: propTypes.string.def(''),
|
resultField: propTypes.string.def(''),
|
||||||
handleTree: { type: String, default: '' },
|
handleTree: { type: String, default: '' },
|
||||||
parent: { type: String, default: '' },
|
parent: { type: String, default: '' },
|
||||||
parentId: { type: Number, default: 0 }
|
parentId: { type: Number, default: 0 },
|
||||||
|
parentFiled: { type: String, default: 'name' }
|
||||||
})
|
})
|
||||||
const emit = defineEmits(['options-change', 'change'])
|
const emit = defineEmits(['options-change', 'change'])
|
||||||
const attrs = useAttrs()
|
const attrs = useAttrs()
|
||||||
|
|
@ -82,7 +83,8 @@ async function fetch() {
|
||||||
result = handleTree(result, props.handleTree)
|
result = handleTree(result, props.handleTree)
|
||||||
}
|
}
|
||||||
if (props.parent) {
|
if (props.parent) {
|
||||||
let tree: any = { id: props.parentId, name: props.parent, children: [] }
|
let tree: Recordable = { id: props.parentId, children: [] }
|
||||||
|
tree = set(tree, props.parentFiled, props.parent)
|
||||||
tree.children = (result as Recordable[]) || []
|
tree.children = (result as Recordable[]) || []
|
||||||
treeData.value.push(tree)
|
treeData.value.push(tree)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue