Skip to content

Commit

Permalink
docs: update ApiComponent docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mynetfan committed Dec 11, 2024
1 parent 5e5f64c commit 1a170c2
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 142 deletions.
111 changes: 107 additions & 4 deletions docs/src/components/common-ui/vben-api-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,112 @@ outline: deep

通过 `component` 传入其它组件的定义,并配置相关的其它属性(主要是一些名称映射)。包装组件将通过`api`获取数据(`beforerFetch``afterFetch`将分别在`api`运行前、运行后被调用),使用`resultField`从中提取数组,使用`valueField``labelField`等来从数据中提取value和label(如果提供了`childrenField`,会将其作为树形结构递归处理每一级数据),之后将处理好的数据通过`optionsPropName`指定的属性传递给目标组件。

级联选择器包装:
::: details 包装级联选择器,点击下拉时开始加载远程数据

<DemoPreview dir="demos/vben-api-component/cascader" />
```vue
<script lang="ts" setup>
import { ApiComponent } from '@vben/common-ui';
分段控制器包装:
import { Cascader } from 'ant-design-vue';
<DemoPreview dir="demos/vben-api-component/segmented" />
const treeData: Record<string, any> = [
{
label: '浙江',
value: 'zhejiang',
children: [
{
value: 'hangzhou',
label: '杭州',
children: [
{
value: 'xihu',
label: '西湖',
},
{
value: 'sudi',
label: '苏堤',
},
],
},
{
value: 'jiaxing',
label: '嘉兴',
children: [
{
value: 'wuzhen',
label: '乌镇',
},
{
value: 'meihuazhou',
label: '梅花洲',
},
],
},
{
value: 'zhoushan',
label: '舟山',
children: [
{
value: 'putuoshan',
label: '普陀山',
},
{
value: 'taohuadao',
label: '桃花岛',
},
],
},
],
},
{
label: '江苏',
value: 'jiangsu',
children: [
{
value: 'nanjing',
label: '南京',
children: [
{
value: 'zhonghuamen',
label: '中华门',
},
{
value: 'zijinshan',
label: '紫金山',
},
{
value: 'yuhuatai',
label: '雨花台',
},
],
},
],
},
];
/**
* 模拟请求接口
*/
function fetchApi(): Promise<Record<string, any>> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(treeData);
}, 1000);
});
}
</script>
<template>
<ApiComponent
:api="fetchApi"
:component="Cascader"
:immediate="false"
children-field="children"
loading-slot="suffixIcon"
visible-event="onDropdownVisibleChange"
/>
</template>
```

:::

### Props

Expand All @@ -45,3 +144,7 @@ outline: deep
| options | 直接传入选项数据,也作为api返回空数据时的后备数据 | `OptionsItem[]` | - |
| visibleEvent | 触发重新请求数据的事件名 | `string` | - |
| loadingSlot | 组件的插槽名称,用来显示一个"加载中"的图标 | `string` | - |

```
```
74 changes: 0 additions & 74 deletions docs/src/demos/vben-api-component/cascader/data.ts

This file was deleted.

94 changes: 82 additions & 12 deletions docs/src/demos/vben-api-component/cascader/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,80 @@ import { ApiComponent } from '@vben/common-ui';
import { Cascader } from 'ant-design-vue';
import { treeData } from './data';
const treeData: Record<string, any> = [
{
label: '浙江',
value: 'zhejiang',
children: [
{
value: 'hangzhou',
label: '杭州',
children: [
{
value: 'xihu',
label: '西湖',
},
{
value: 'sudi',
label: '苏堤',
},
],
},
{
value: 'jiaxing',
label: '嘉兴',
children: [
{
value: 'wuzhen',
label: '乌镇',
},
{
value: 'meihuazhou',
label: '梅花洲',
},
],
},
{
value: 'zhoushan',
label: '舟山',
children: [
{
value: 'putuoshan',
label: '普陀山',
},
{
value: 'taohuadao',
label: '桃花岛',
},
],
},
],
},
{
label: '江苏',
value: 'jiangsu',
children: [
{
value: 'nanjing',
label: '南京',
children: [
{
value: 'zhonghuamen',
label: '中华门',
},
{
value: 'zijinshan',
label: '紫金山',
},
{
value: 'yuhuatai',
label: '雨花台',
},
],
},
],
},
];
/**
* 模拟请求接口
*/
Expand All @@ -16,15 +89,12 @@ function fetchApi(): Promise<Record<string, any>> {
}
</script>
<template>
<div class="flex items-center gap-3">
<span>点击下拉时开始加载远程数据</span>
<ApiComponent
:api="fetchApi"
:component="Cascader"
:immediate="false"
children-field="children"
loading-slot="suffixIcon"
visible-event="onDropdownVisibleChange"
/>
</div>
<ApiComponent
:api="fetchApi"
:component="Cascader"
:immediate="false"
children-field="children"
loading-slot="suffixIcon"
visible-event="onDropdownVisibleChange"
/>
</template>
31 changes: 0 additions & 31 deletions docs/src/demos/vben-api-component/segmented/data.ts

This file was deleted.

21 changes: 0 additions & 21 deletions docs/src/demos/vben-api-component/segmented/index.vue

This file was deleted.

0 comments on commit 1a170c2

Please sign in to comment.