chore: add apiSelect remote search demo (#5246)

This commit is contained in:
Netfan 2024-12-26 19:23:59 +08:00 committed by GitHub
parent 68a7e790d8
commit cb5ecf4a8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,9 +1,10 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { h, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, Card, message, TabPane, Tabs } from 'ant-design-vue';
import { useDebounceFn } from '@vueuse/core';
import { Button, Card, message, Spin, TabPane, Tabs } from 'ant-design-vue';
import dayjs from 'dayjs';
import { useVbenForm } from '#/adapter/form';
@ -12,6 +13,22 @@ import { getAllMenusApi } from '#/api';
import DocButton from '../doc-button.vue';
const activeTab = ref('basic');
const keyword = ref('');
const fetching = ref(false);
//
function fetchRemoteOptions({ keyword = '选项' }: Record<string, any>) {
fetching.value = true;
return new Promise((resolve) => {
setTimeout(() => {
const options = Array.from({ length: 10 }).map((_, index) => ({
label: `${keyword}-${index}`,
value: `${keyword}-${index}`,
}));
resolve(options);
fetching.value = false;
}, 1000);
});
}
const [BaseForm, baseFormApi] = useVbenForm({
//
@ -64,6 +81,37 @@ const [BaseForm, baseFormApi] = useVbenForm({
// label
label: 'ApiSelect',
},
{
component: 'ApiSelect',
//
componentProps: () => {
return {
api: fetchRemoteOptions,
//
filterOption: false,
// 使loading
notFoundContent: fetching.value ? undefined : null,
// 使useDebounceFn
onSearch: useDebounceFn((value: string) => {
keyword.value = value;
}, 300),
// params
params: {
keyword: keyword.value || undefined,
},
showSearch: true,
};
},
//
fieldName: 'remoteSearch',
// label
label: '远程搜索',
renderComponentContent: () => {
return {
notFoundContent: fetching.value ? h(Spin) : undefined,
};
},
},
{
component: 'ApiTreeSelect',
//