Commit fb43e548472c7e3dd7dbdeaa27889733a61258db

Authored by zuihou
1 parent 1e0ede09

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

src/components/Tree/src/Tree.vue
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 onMounted, 14 onMounted,
15 } from 'vue'; 15 } from 'vue';
16 import TreeHeader from './TreeHeader.vue'; 16 import TreeHeader from './TreeHeader.vue';
17 - import { Tree, Empty } from 'ant-design-vue'; 17 + import { Tree, Spin, Empty } from 'ant-design-vue';
18 import { TreeIcon } from './TreeIcon'; 18 import { TreeIcon } from './TreeIcon';
19 import { ScrollContainer } from '/@/components/Container'; 19 import { ScrollContainer } from '/@/components/Container';
20 import { omit, get, difference, cloneDeep } from 'lodash-es'; 20 import { omit, get, difference, cloneDeep } from 'lodash-es';
@@ -426,10 +426,16 @@ @@ -426,10 +426,16 @@
426 {extendSlots(slots)} 426 {extendSlots(slots)}
427 </TreeHeader> 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 </div> 439 </div>
434 ); 440 );
435 }; 441 };
src/components/Tree/src/tree.ts
@@ -130,6 +130,10 @@ export const treeProps = buildProps({ @@ -130,6 +130,10 @@ export const treeProps = buildProps({
130 checkOnSearch: Boolean, 130 checkOnSearch: Boolean,
131 // 搜索完成自动select所有结果 131 // 搜索完成自动select所有结果
132 selectedOnSearch: Boolean, 132 selectedOnSearch: Boolean,
  133 + loading: {
  134 + type: Boolean,
  135 + default: false,
  136 + },
133 }); 137 });
134 138
135 export type TreeProps = ExtractPropTypes<typeof treeProps>; 139 export type TreeProps = ExtractPropTypes<typeof treeProps>;
src/views/demo/tree/index.vue
@@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
32 :load-data="onLoadData" 32 :load-data="onLoadData"
33 /> 33 />
34 </Col> 34 </Col>
35 - <Col :span="16"> 35 + <Col :span="8">
36 <Card title="异步数据,默认展开"> 36 <Card title="异步数据,默认展开">
37 <template #extra> 37 <template #extra>
38 <a-button @click="loadTreeData" :loading="treeLoading">加载数据</a-button> 38 <a-button @click="loadTreeData" :loading="treeLoading">加载数据</a-button>
@@ -42,6 +42,14 @@ @@ -42,6 +42,14 @@
42 </Spin> 42 </Spin>
43 </Card> 43 </Card>
44 </Col> 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 </Row> 53 </Row>
46 </PageWrapper> 54 </PageWrapper>
47 </template> 55 </template>
@@ -58,6 +66,7 @@ @@ -58,6 +66,7 @@
58 setup() { 66 setup() {
59 const asyncTreeRef = ref<Nullable<TreeActionType>>(null); 67 const asyncTreeRef = ref<Nullable<TreeActionType>>(null);
60 const asyncExpandTreeRef = ref<Nullable<TreeActionType>>(null); 68 const asyncExpandTreeRef = ref<Nullable<TreeActionType>>(null);
  69 + const loadTreeRef = ref<Nullable<TreeActionType>>(null);
61 const tree2 = ref<TreeItem[]>([]); 70 const tree2 = ref<TreeItem[]>([]);
62 const treeLoading = ref(false); 71 const treeLoading = ref(false);
63 72
@@ -79,6 +88,15 @@ @@ -79,6 +88,15 @@
79 }); 88 });
80 }, 2000); 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 const tree = ref([ 101 const tree = ref([
84 { 102 {
@@ -119,9 +137,11 @@ @@ -119,9 +137,11 @@
119 onLoadData, 137 onLoadData,
120 asyncTreeRef, 138 asyncTreeRef,
121 asyncExpandTreeRef, 139 asyncExpandTreeRef,
  140 + loadTreeRef,
122 tree2, 141 tree2,
123 loadTreeData, 142 loadTreeData,
124 treeLoading, 143 treeLoading,
  144 + loadTreeData2,
125 }; 145 };
126 }, 146 },
127 }); 147 });