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><BfModalSearchPickerisOpened={isOpened}searchBarProps={{ searchBtn: true }}tapConfirmToSearchsearchHistoryKey="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);}}/><BfModalSearchPickerisOpened={isStaticOpened}title="选择商品"placeholder="请输入商品名称"value={3}options={[{ name: '111', id: 1 },{ name: '222', id: 2 },{ name: '333', id: 3 },]}fieldNames={{ label: 'name', value: 'id' }}confirmDisableonCancel={() => {console.log('onCancel');setIsStaticOpened(false);}}onConfirm={(v) => {console.log('onConfirm', v);setIsStaticOpened(false);}}/><BfModalSearchPickerisOpened={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,会忽略request | TOptions[] | -- |
params | 请求数据时其余的参数。此字段更新时会重新触发request | Record<string, any> | -- |
id | id,多组数据共用一个Picker时,可通过该属性进行区分 | string | -- |
fieldNames | 自定义节点 label、value 的字段 | { label: string; value: string; } | -- |
placeholder | 搜索框的 placeholder | string | -- |
header | 自定义头部(会替换掉默认的searchBar) | any | -- |
debounceTime | 防抖时间 | number | 500 |
request | 获取选项数据的 promise | (params: TRequestParams) => Promise<TOptions[]> | -- |
searchHistoryKey | 存储搜索历史的localStorage的key | string | -- |
searchHistoryMaxCount | 搜索历史存储的最大数量 | number | 5 |
tapConfirmToSearch | 点击软键盘右下角的确认按钮时是否触发搜索 | boolean | false |
searchBarProps | 内部 BfSearchBar 的 props | IBfSearchBarProps & InputProps | -- |
value | 当前值 | any | -- |
multiple | 是否多选 | boolean | false
false |
onConfirm | 确认按钮回调 | ((value: TOptions, id?: string) => void) | ((value: TOptions[], id?: string) => void) | -- |
isOpened | 是否打开 | boolean | false |
title | 标题 | any | -- |
onClose | 元素被关闭时候触发的事件,比如点击蒙层时。同 AtFloatLayout 的 onClose | () => void | -- |