feat: ApiTree add afterFetch props,add ApiTree demo

This commit is contained in:
JinMao 2022-04-18 08:21:04 +08:00
parent e3637e7af4
commit 3b86435766
2 changed files with 26 additions and 1 deletions

View File

@ -24,6 +24,7 @@
params: { type: Object }, params: { type: Object },
immediate: { type: Boolean, default: true }, immediate: { type: Boolean, default: true },
resultField: propTypes.string.def(''), resultField: propTypes.string.def(''),
afterFetch: { type: Function as PropType<Fn> },
}, },
emits: ['options-change', 'change'], emits: ['options-change', 'change'],
setup(props, { attrs, emit }) { setup(props, { attrs, emit }) {
@ -61,7 +62,7 @@
}); });
async function fetch() { async function fetch() {
const { api } = props; const { api, afterFetch } = props;
if (!api || !isFunction(api)) return; if (!api || !isFunction(api)) return;
loading.value = true; loading.value = true;
treeData.value = []; treeData.value = [];
@ -71,6 +72,9 @@
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
if (afterFetch && isFunction(afterFetch)) {
result = afterFetch(result);
}
loading.value = false; loading.value = false;
if (!result) return; if (!result) return;
if (!isArray(result)) { if (!isArray(result)) {

View File

@ -460,6 +460,27 @@
span: 8, span: 8,
}, },
}, },
{
field: 'field36',
component: 'ApiTree',
label: '远程Tree',
helpMessage: ['ApiTree组件', '使用接口提供的数据生成选项'],
required: true,
componentProps: {
api: treeOptionsListApi,
params: {
count: 2,
},
afterFetch: (v) => {
//do something
return v;
},
resultField: 'list',
},
colProps: {
span: 8,
},
},
{ {
field: 'divider-linked', field: 'divider-linked',
component: 'Divider', component: 'Divider',