mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-24 18:40:22 +08:00
feat(ApiTree): 完善ApiTree组件的重置回显功能. close #2307
This commit is contained in:
parent
d4f2641b9a
commit
a0d4b10a1f
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<a-tree v-bind="getAttrs" @select="handleChange">
|
<a-tree v-bind="getAttrs" @select="handleChange" v-model:selectedKeys="state">
|
||||||
<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>
|
||||||
@ -14,6 +14,7 @@
|
|||||||
import { get } from 'lodash-es';
|
import { get } from 'lodash-es';
|
||||||
import { propTypes } from '/@/utils/propTypes';
|
import { propTypes } from '/@/utils/propTypes';
|
||||||
import { DataNode } from 'ant-design-vue/es/tree';
|
import { DataNode } from 'ant-design-vue/es/tree';
|
||||||
|
import { useRuleFormItem } from '/@/hooks/component/useFormItem';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'ApiTree',
|
name: 'ApiTree',
|
||||||
@ -24,12 +25,16 @@
|
|||||||
immediate: { type: Boolean, default: true },
|
immediate: { type: Boolean, default: true },
|
||||||
resultField: propTypes.string.def(''),
|
resultField: propTypes.string.def(''),
|
||||||
afterFetch: { type: Function as PropType<AnyFunction> },
|
afterFetch: { type: Function as PropType<AnyFunction> },
|
||||||
|
value: [Array, Object, String, Number],
|
||||||
},
|
},
|
||||||
emits: ['options-change', 'change'],
|
emits: ['options-change', 'change', 'update:value'],
|
||||||
setup(props, { attrs, emit }) {
|
setup(props, { attrs, emit }) {
|
||||||
const treeData = ref<DataNode[]>([]);
|
const treeData = ref<DataNode[]>([]);
|
||||||
const isFirstLoaded = ref<Boolean>(false);
|
const isFirstLoaded = ref<Boolean>(false);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
const emitData = ref<any[]>([]);
|
||||||
|
|
||||||
|
const [state] = useRuleFormItem(props, 'value', 'change', emitData);
|
||||||
const getAttrs = computed(() => {
|
const getAttrs = computed(() => {
|
||||||
return {
|
return {
|
||||||
...(props.api ? { treeData: unref(treeData) } : {}),
|
...(props.api ? { treeData: unref(treeData) } : {}),
|
||||||
@ -40,6 +45,13 @@
|
|||||||
emit('change', ...args);
|
emit('change', ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => state.value,
|
||||||
|
(v) => {
|
||||||
|
emit('update:value', v);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.params,
|
() => props.params,
|
||||||
() => {
|
() => {
|
||||||
@ -82,7 +94,7 @@
|
|||||||
isFirstLoaded.value = true;
|
isFirstLoaded.value = true;
|
||||||
emit('options-change', treeData.value);
|
emit('options-change', treeData.value);
|
||||||
}
|
}
|
||||||
return { getAttrs, loading, handleChange };
|
return { getAttrs, loading, handleChange, state };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -415,6 +415,9 @@ function getDefaultValue(
|
|||||||
if (!defaultValue && schema && checkIsRangeSlider(schema)) {
|
if (!defaultValue && schema && checkIsRangeSlider(schema)) {
|
||||||
defaultValue = [0, 0];
|
defaultValue = [0, 0];
|
||||||
}
|
}
|
||||||
|
if (!defaultValue && schema && schema.component === 'ApiTree') {
|
||||||
|
defaultValue = [];
|
||||||
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user