declare const _default: "import * as React from 'react';\nimport ReactDOM from 'react-dom';\nimport Select from '@/components/select';\nimport { useState } from 'react';\nimport { CheckOutlined } from '@ant-design/icons';\nconst { Option } = Select;\nimport { Select as AntdSelect } from 'antd';\n\ninterface IProps {}\n\ninterface IState {\n value: string[];\n allChoosed: boolean;\n list: any;\n}\n\nclass Example extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n value: ['a10', 'c12'],\n allChoosed: false,\n list: [],\n };\n }\n\n componentDidMount() {\n this.getList();\n }\n\n handleChange = (value: string | string[]) => {\n // console.log(`selected ${value}`);\n };\n\n getList = () => {\n const list: any = [];\n for (let i = 10; i < 36; i = i + 1) {\n list.push({\n key: i.toString(36) + i,\n value: i.toString(36) + i,\n checked:\n this.state.value.indexOf(i.toString(36) + i) > -1 ? true : false,\n });\n }\n this.setState({\n list,\n });\n };\n\n chooseAll = () => {\n this.setState(\n {\n allChoosed: true,\n value: ['全部选项'],\n },\n () => {\n const { list } = this.state;\n list.map((l: any) => {\n l.checked = true;\n });\n }\n );\n };\n\n // 只有点击右侧的叉号可以触发\n handleMultiChange = (value: string[]) => {\n const { list } = this.state;\n if (value.length === 0) {\n list.map((l: any) => {\n l.checked = false;\n });\n this.setState({\n list,\n allChoosed: false,\n });\n }\n this.setState({\n value,\n });\n };\n\n chooseDrop(l: any) {\n const { value, list } = this.state;\n // 当前全部选中\n const val: any =\n value[0] === '全部选项' ? list.map((_l: any) => _l.key) : value;\n if (val.indexOf(l.key) > -1) {\n val.splice(val.indexOf(l.key), 1);\n l.checked = false;\n } else {\n val.push(l.key);\n l.checked = true;\n }\n const allChoosed: boolean = val.length === this.state.list.length;\n this.setState({\n value: allChoosed ? ['全部选项'] : val,\n allChoosed,\n });\n }\n private andSelectRef = React.createRef();\n\n render() {\n const { value, allChoosed, list } = this.state;\n return (\n
\n

基本用法

\n \n \n \n \n \n \n \n

多选

\n (this.andSelectRef = res)}\n onChange={() => (this.andSelectRef.current as any).blur()}\n mode=\"multiple\"\n defaultValue={['a10']}\n placeholder=\"请选择一个选项\">\n {list.map((option: any) => (\n \n ))}\n \n

带选择全部的多选

\n (\n
\n
\n {list.length > 0 &&\n list.map((l: any) => (\n this.chooseDrop(l)}>\n
\n {l.value}\n
\n {l.checked && (\n \n \n \n )}\n
\n ))}\n {list.length === 0 && (\n
\n 无匹配选项\n
\n )}\n
\n
\n )}\n onChange={this.handleMultiChange}>\n {list.map((option: any) => (\n \n ))}\n \n \n );\n }\n}\n\nexport default Example;\n"; export default _default;