Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChenSun1
vue-vben-admin
提交
41e6d94b
V
vue-vben-admin
项目概览
ChenSun1
/
vue-vben-admin
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vue-vben-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
41e6d94b
编写于
7月 08, 2021
作者:
无
无木
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(demo): add search demo for apiSelect
添加ApiSelect的本地搜索和远程搜索例子
上级
17e47e07
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
81 addition
and
27 deletion
+81
-27
mock/demo/select-demo.ts
mock/demo/select-demo.ts
+8
-8
src/api/demo/select.ts
src/api/demo/select.ts
+1
-1
src/views/demo/form/index.vue
src/views/demo/form/index.vue
+72
-18
未找到文件。
mock/demo/select-demo.ts
浏览文件 @
41e6d94b
import
{
MockMethod
}
from
'
vite-plugin-mock
'
;
import
{
resultSuccess
}
from
'
../_util
'
;
const
list
:
any
[]
=
[];
const
demoList
=
(()
=>
{
const
demoList
=
(
keyword
)
=>
{
const
result
=
{
list
:
list
,
list
:
[]
,
};
for
(
let
index
=
0
;
index
<
20
;
index
++
)
{
result
.
list
.
push
({
name
:
`选项
${
index
}
`
,
name
:
`
${
keyword
??
''
}
选项
${
index
}
`
,
id
:
`
${
index
}
`
,
});
}
return
result
;
}
)()
;
};
export
default
[
{
url
:
'
/basic-api/select/getDemoOptions
'
,
timeout
:
1000
,
method
:
'
pos
t
'
,
method
:
'
ge
t
'
,
response
:
({
query
})
=>
{
console
.
log
(
query
);
return
resultSuccess
(
demoList
);
const
{
keyword
}
=
query
;
console
.
log
(
keyword
);
return
resultSuccess
(
demoList
(
keyword
));
},
},
]
as
MockMethod
[];
src/api/demo/select.ts
浏览文件 @
41e6d94b
...
...
@@ -8,4 +8,4 @@ enum Api {
* @description: Get sample options value
*/
export
const
optionsListApi
=
(
params
?:
selectParams
)
=>
defHttp
.
pos
t
<
DemoOptionsItem
[]
>
({
url
:
Api
.
OPTIONS_LIST
,
params
});
defHttp
.
ge
t
<
DemoOptionsItem
[]
>
({
url
:
Api
.
OPTIONS_LIST
,
params
});
src/views/demo/form/index.vue
浏览文件 @
41e6d94b
...
...
@@ -3,22 +3,49 @@
<CollapseContainer
title=
"基础示例"
>
<BasicForm
autoFocusFirstItem
:labelWidth=
"
1
00"
:labelWidth=
"
2
00"
:schemas=
"schemas"
:actionColOptions=
"
{ span: 24 }"
@submit="handleSubmit"
/>
@reset="handleReset"
>
<template
#localSearch
="
{ model, field }">
<ApiSelect
:api=
"optionsListApi"
showSearch
v-model:value=
"model[field]"
optionFilterProp=
"label"
resultField=
"list"
labelField=
"name"
valueField=
"id"
/>
</
template
>
<
template
#remoteSearch=
"{ model, field }"
>
<ApiSelect
:api=
"optionsListApi"
showSearch
v-model:value=
"model[field]"
:filterOption=
"false"
resultField=
"list"
labelField=
"name"
valueField=
"id"
:params=
"searchParams"
@
search=
"onSearch"
/>
</
template
>
</BasicForm>
</CollapseContainer>
</PageWrapper>
</template>
<
script
lang=
"ts"
>
import
{
defineComponent
,
ref
}
from
'
vue
'
;
import
{
BasicForm
,
FormSchema
}
from
'
/@/components/Form/index
'
;
import
{
CollapseContainer
}
from
'
/@/components/Container
/index
'
;
import
{
computed
,
defineComponent
,
unref
,
ref
}
from
'
vue
'
;
import
{
BasicForm
,
FormSchema
,
ApiSelect
}
from
'
/@/components/Form/index
'
;
import
{
CollapseContainer
}
from
'
/@/components/Container
'
;
import
{
useMessage
}
from
'
/@/hooks/web/useMessage
'
;
import
{
PageWrapper
}
from
'
/@/components/Page
'
;
import
{
optionsListApi
}
from
'
/@/api/demo/select
'
;
import
{
useDebounceFn
}
from
'
@vueuse/core
'
;
const
provincesOptions
=
[
{
...
...
@@ -265,11 +292,10 @@
],
},
},
{
field
:
'
field30
'
,
component
:
'
ApiSelect
'
,
label
:
'
远程下拉
'
,
label
:
'
懒加载
远程下拉
'
,
required
:
true
,
componentProps
:
{
// more details see /src/components/Form/src/components/ApiSelect.vue
...
...
@@ -277,15 +303,6 @@
params
:
{
id
:
1
,
},
// use [res.data.result.list] (no res.data.result) as options datas
// result: {
// list: [
// {
// name: "选项0",
// id: "0"
// },
// ]
// }
resultField
:
'
list
'
,
// use name as label
labelField
:
'
name
'
,
...
...
@@ -304,7 +321,30 @@
colProps
:
{
span
:
8
,
},
// set default value
defaultValue
:
'
0
'
,
},
{
field
:
'
field31
'
,
component
:
'
Input
'
,
label
:
'
下拉本地搜索
'
,
helpMessage
:
[
'
ApiSelect组件
'
,
'
远程数据源本地搜索
'
,
'
只发起一次请求获取所有选项
'
],
required
:
true
,
slot
:
'
localSearch
'
,
colProps
:
{
span
:
8
,
},
defaultValue
:
'
0
'
,
},
{
field
:
'
field32
'
,
component
:
'
Input
'
,
label
:
'
下拉远程搜索
'
,
helpMessage
:
[
'
ApiSelect组件
'
,
'
将关键词发送到接口进行远程搜索
'
],
required
:
true
,
slot
:
'
remoteSearch
'
,
colProps
:
{
span
:
8
,
},
defaultValue
:
'
0
'
,
},
{
...
...
@@ -394,12 +434,26 @@
];
export
default
defineComponent
({
components
:
{
BasicForm
,
CollapseContainer
,
PageWrapper
},
components
:
{
BasicForm
,
CollapseContainer
,
PageWrapper
,
ApiSelect
},
setup
()
{
const
check
=
ref
(
null
);
const
{
createMessage
}
=
useMessage
();
const
keyword
=
ref
<
string
>
(
''
);
const
searchParams
=
computed
<
Recordable
>
(()
=>
{
return
{
keyword
:
unref
(
keyword
)
};
});
function
onSearch
(
value
:
string
)
{
keyword
.
value
=
value
;
}
return
{
schemas
,
optionsListApi
,
onSearch
:
useDebounceFn
(
onSearch
,
300
),
searchParams
,
handleReset
:
()
=>
{
keyword
.
value
=
''
;
},
handleSubmit
:
(
values
:
any
)
=>
{
createMessage
.
success
(
'
click search,values:
'
+
JSON
.
stringify
(
values
));
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录