Commit fb43e548472c7e3dd7dbdeaa27889733a61258db

Authored by zuihou
1 parent 1e0ede09

feat(BasicTree): 支持设置加载中

src/components/Tree/src/Tree.vue
... ... @@ -14,7 +14,7 @@
14 14 onMounted,
15 15 } from 'vue';
16 16 import TreeHeader from './TreeHeader.vue';
17   - import { Tree, Empty } from 'ant-design-vue';
  17 + import { Tree, Spin, Empty } from 'ant-design-vue';
18 18 import { TreeIcon } from './TreeIcon';
19 19 import { ScrollContainer } from '/@/components/Container';
20 20 import { omit, get, difference, cloneDeep } from 'lodash-es';
... ... @@ -426,10 +426,16 @@
426 426 {extendSlots(slots)}
427 427 </TreeHeader>
428 428 )}
429   - <ScrollContainer style={scrollStyle} v-show={!unref(getNotFound)}>
430   - <Tree {...unref(getBindValues)} showIcon={false} treeData={treeData.value} />
431   - </ScrollContainer>
432   - <Empty v-show={unref(getNotFound)} image={Empty.PRESENTED_IMAGE_SIMPLE} class="!mt-4" />
  429 + <Spin spinning={unref(props.loading)} tip="加载中...">
  430 + <ScrollContainer style={scrollStyle} v-show={!unref(getNotFound)}>
  431 + <Tree {...unref(getBindValues)} showIcon={false} treeData={treeData.value} />
  432 + </ScrollContainer>
  433 + <Empty
  434 + v-show={unref(getNotFound)}
  435 + image={Empty.PRESENTED_IMAGE_SIMPLE}
  436 + class="!mt-4"
  437 + />
  438 + </Spin>
433 439 </div>
434 440 );
435 441 };
... ...
src/components/Tree/src/tree.ts
... ... @@ -130,6 +130,10 @@ export const treeProps = buildProps({
130 130 checkOnSearch: Boolean,
131 131 // 搜索完成自动select所有结果
132 132 selectedOnSearch: Boolean,
  133 + loading: {
  134 + type: Boolean,
  135 + default: false,
  136 + },
133 137 });
134 138  
135 139 export type TreeProps = ExtractPropTypes<typeof treeProps>;
... ...
src/views/demo/tree/index.vue
... ... @@ -32,7 +32,7 @@
32 32 :load-data="onLoadData"
33 33 />
34 34 </Col>
35   - <Col :span="16">
  35 + <Col :span="8">
36 36 <Card title="异步数据,默认展开">
37 37 <template #extra>
38 38 <a-button @click="loadTreeData" :loading="treeLoading">加载数据</a-button>
... ... @@ -42,6 +42,14 @@
42 42 </Spin>
43 43 </Card>
44 44 </Col>
  45 + <Col :span="8">
  46 + <Card title="BasicTree内置加载">
  47 + <template #extra>
  48 + <a-button @click="loadTreeData2" :loading="treeLoading">请求数据</a-button>
  49 + </template>
  50 + <BasicTree ref="loadTreeRef" :treeData="tree2" :loading="treeLoading" />
  51 + </Card>
  52 + </Col>
45 53 </Row>
46 54 </PageWrapper>
47 55 </template>
... ... @@ -58,6 +66,7 @@
58 66 setup() {
59 67 const asyncTreeRef = ref<Nullable<TreeActionType>>(null);
60 68 const asyncExpandTreeRef = ref<Nullable<TreeActionType>>(null);
  69 + const loadTreeRef = ref<Nullable<TreeActionType>>(null);
61 70 const tree2 = ref<TreeItem[]>([]);
62 71 const treeLoading = ref(false);
63 72  
... ... @@ -79,6 +88,15 @@
79 88 });
80 89 }, 2000);
81 90 }
  91 + function loadTreeData2() {
  92 + treeLoading.value = true;
  93 + // 以下是模拟异步获取数据
  94 + setTimeout(() => {
  95 + // 设置数据源
  96 + tree2.value = cloneDeep(treeData);
  97 + treeLoading.value = false;
  98 + }, 2000);
  99 + }
82 100  
83 101 const tree = ref([
84 102 {
... ... @@ -119,9 +137,11 @@
119 137 onLoadData,
120 138 asyncTreeRef,
121 139 asyncExpandTreeRef,
  140 + loadTreeRef,
122 141 tree2,
123 142 loadTreeData,
124 143 treeLoading,
  144 + loadTreeData2,
125 145 };
126 146 },
127 147 });
... ...