ModalSearchPicker

ModalSearchPicker 带搜索、分页的 Picker

代码示例

import { BfModalSearchPicker } from '@bud-fe/react-taro-ui';
import { Button, View } from '@tarojs/components';
import React, { useState } from 'react';
export default () => {
const [isOpened, setIsOpened] = useState(false);
const [isStaticOpened, setIsStaticOpened] = useState(false);
const [isCustomHeaderOpened, setIsCustomHeaderOpened] = useState(false);
return (
<>
<Button className="group-title" onClick={() => setIsOpened(true)}>
基础用法
</Button>
<Button className="group-title" onClick={() => setIsStaticOpened(true)}>
options + confirmDisable=true
</Button>
<Button className="group-title" onClick={() => setIsCustomHeaderOpened(true)}>
自定义头部(会替换掉默认的searchBar)
</Button>
<BfModalSearchPicker
isOpened={isOpened}
searchBarProps={{ searchBtn: true }}
tapConfirmToSearch
searchHistoryKey="a"
// multiple
// value={[1, 3, 4]}
value={1}
title="选择商品"
placeholder="请输入商品名称"
params={{ test: 'a' }}
request={async (params) => {
console.log('request params', params);
return Array.from({ length: 20 }, (_, index) => ({
label: `百威纯生 500ml 大听(${index})`,
value: index,
}));
}}
onCancel={() => {
console.log('onCancel');
setIsOpened(false);
}}
onConfirm={(v) => {
console.log('onConfirm', v);
setIsOpened(false);
}}
/>
<BfModalSearchPicker
isOpened={isStaticOpened}
title="选择商品"
placeholder="请输入商品名称"
value={3}
options={[
{ name: '111', id: 1 },
{ name: '222', id: 2 },
{ name: '333', id: 3 },
]}
fieldNames={{ label: 'name', value: 'id' }}
confirmDisable
onCancel={() => {
console.log('onCancel');
setIsStaticOpened(false);
}}
onConfirm={(v) => {
console.log('onConfirm', v);
setIsStaticOpened(false);
}}
/>
<BfModalSearchPicker
isOpened={isCustomHeaderOpened}
title="选择商品"
placeholder="请输入商品名称"
value={2}
header={<View>以下为完美门店联系人列表,可选择一位成为BEES项目关键人</View>}
request={async (params) => {
console.log('request params', params);
return Array.from({ length: 20 }, (_, index) => ({
label: `百威纯生 500ml 大听(${index})`,
value: index,
}));
}}
onCancel={() => {
console.log('onCancel');
setIsCustomHeaderOpened(false);
}}
onConfirm={(v) => {
console.log('onConfirm', v);
setIsCustomHeaderOpened(false);
}}
/>
</>
);
};

API

属性名描述类型默认值
options静态选项数据。若传入此prop,会忽略requestTOptions[]--
params请求数据时其余的参数。此字段更新时会重新触发requestRecord<string, any>--
idid,多组数据共用一个Picker时,可通过该属性进行区分string--
fieldNames自定义节点 label、value 的字段{ label: string; value: string; }--
placeholder搜索框的 placeholderstring--
header自定义头部(会替换掉默认的searchBar)any--
debounceTime防抖时间number500
request获取选项数据的 promise(params: TRequestParams) => Promise<TOptions[]>--
searchHistoryKey存储搜索历史的localStorage的keystring--
searchHistoryMaxCount搜索历史存储的最大数量number5
tapConfirmToSearch点击软键盘右下角的确认按钮时是否触发搜索booleanfalse
searchBarProps内部 BfSearchBar 的 propsIBfSearchBarProps & InputProps--
value当前值any--
multiple是否多选booleanfalse false
onConfirm确认按钮回调((value: TOptions, id?: string) => void) | ((value: TOptions[], id?: string) => void)--
isOpened是否打开booleanfalse
title标题any--
onClose元素被关闭时候触发的事件,比如点击蒙层时。同 AtFloatLayout 的 onClose() => void--
dumi10:24