Skip to content

Commit

Permalink
feat(ApiTree): 完善ApiTree组件的重置回显功能. close #2307
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjue666 committed Oct 14, 2023
1 parent d4f2641 commit a0d4b10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/components/Form/src/components/ApiTree.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<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)">
<slot :name="item" v-bind="data || {}"></slot>
</template>
Expand All @@ -14,6 +14,7 @@
import { get } from 'lodash-es';
import { propTypes } from '/@/utils/propTypes';
import { DataNode } from 'ant-design-vue/es/tree';
import { useRuleFormItem } from '/@/hooks/component/useFormItem';
export default defineComponent({
name: 'ApiTree',
Expand All @@ -24,12 +25,16 @@
immediate: { type: Boolean, default: true },
resultField: propTypes.string.def(''),
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 }) {
const treeData = ref<DataNode[]>([]);
const isFirstLoaded = ref<Boolean>(false);
const loading = ref(false);
const emitData = ref<any[]>([]);
const [state] = useRuleFormItem(props, 'value', 'change', emitData);
const getAttrs = computed(() => {
return {
...(props.api ? { treeData: unref(treeData) } : {}),
Expand All @@ -40,6 +45,13 @@
emit('change', ...args);
}
watch(
() => state.value,
(v) => {
emit('update:value', v);
},
);
watch(
() => props.params,
() => {
Expand Down Expand Up @@ -82,7 +94,7 @@
isFirstLoaded.value = true;
emit('options-change', treeData.value);
}
return { getAttrs, loading, handleChange };
return { getAttrs, loading, handleChange, state };
},
});
</script>
3 changes: 3 additions & 0 deletions src/components/Form/src/hooks/useFormEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ function getDefaultValue(
if (!defaultValue && schema && checkIsRangeSlider(schema)) {
defaultValue = [0, 0];
}
if (!defaultValue && schema && schema.component === 'ApiTree') {
defaultValue = [];
}
return defaultValue;
}

Expand Down

0 comments on commit a0d4b10

Please sign in to comment.