Commit 3b86435766bc19902b934d4e7c17bf4cf609354e

Authored by JinMao
1 parent e3637e7a

feat: ApiTree add afterFetch props,add ApiTree demo

src/components/Form/src/components/ApiTree.vue
... ... @@ -24,6 +24,7 @@
24 24 params: { type: Object },
25 25 immediate: { type: Boolean, default: true },
26 26 resultField: propTypes.string.def(''),
  27 + afterFetch: { type: Function as PropType<Fn> },
27 28 },
28 29 emits: ['options-change', 'change'],
29 30 setup(props, { attrs, emit }) {
... ... @@ -61,7 +62,7 @@
61 62 });
62 63  
63 64 async function fetch() {
64   - const { api } = props;
  65 + const { api, afterFetch } = props;
65 66 if (!api || !isFunction(api)) return;
66 67 loading.value = true;
67 68 treeData.value = [];
... ... @@ -71,6 +72,9 @@
71 72 } catch (e) {
72 73 console.error(e);
73 74 }
  75 + if (afterFetch && isFunction(afterFetch)) {
  76 + result = afterFetch(result);
  77 + }
74 78 loading.value = false;
75 79 if (!result) return;
76 80 if (!isArray(result)) {
... ...
src/views/demo/form/index.vue
... ... @@ -461,6 +461,27 @@
461 461 },
462 462 },
463 463 {
  464 + field: 'field36',
  465 + component: 'ApiTree',
  466 + label: '远程Tree',
  467 + helpMessage: ['ApiTree组件', '使用接口提供的数据生成选项'],
  468 + required: true,
  469 + componentProps: {
  470 + api: treeOptionsListApi,
  471 + params: {
  472 + count: 2,
  473 + },
  474 + afterFetch: (v) => {
  475 + //do something
  476 + return v;
  477 + },
  478 + resultField: 'list',
  479 + },
  480 + colProps: {
  481 + span: 8,
  482 + },
  483 + },
  484 + {
464 485 field: 'divider-linked',
465 486 component: 'Divider',
466 487 label: '字段联动',
... ...