Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit cb5ecf4a
authored
Dec 26, 2024
by
Netfan
Committed by
GitHub
Dec 26, 2024
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
chore: add apiSelect remote search demo (#5246)
1 parent
68a7e790
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
2 deletions
playground/src/views/examples/form/basic.vue
playground/src/views/examples/form/basic.vue
View file @
cb5ecf4
<
script
lang=
"ts"
setup
>
<
script
lang=
"ts"
setup
>
import
{
ref
}
from
'vue'
;
import
{
h
,
ref
}
from
'vue'
;
import
{
Page
}
from
'@vben/common-ui'
;
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
dayjs
from
'dayjs'
;
import
{
useVbenForm
}
from
'#/adapter/form'
;
import
{
useVbenForm
}
from
'#/adapter/form'
;
...
@@ -12,6 +13,22 @@ import { getAllMenusApi } from '#/api';
...
@@ -12,6 +13,22 @@ import { getAllMenusApi } from '#/api';
import
DocButton
from
'../doc-button.vue'
;
import
DocButton
from
'../doc-button.vue'
;
const
activeTab
=
ref
(
'basic'
);
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
({
const
[
BaseForm
,
baseFormApi
]
=
useVbenForm
({
// 所有表单项共用,可单独在表单内覆盖
// 所有表单项共用,可单独在表单内覆盖
...
@@ -65,6 +82,37 @@ const [BaseForm, baseFormApi] = useVbenForm({
...
@@ -65,6 +82,37 @@ const [BaseForm, baseFormApi] = useVbenForm({
label
:
'ApiSelect'
,
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'
,
component
:
'ApiTreeSelect'
,
// 对应组件的参数
// 对应组件的参数
componentProps
:
{
componentProps
:
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment