-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
399e90d
commit b6af119
Showing
4 changed files
with
164 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
--- | ||
order: 1 | ||
title: 级联选择器 | ||
desc: 全选 | ||
--- | ||
|
||
```jsx | ||
|
||
import React, { useState } from 'react'; | ||
import { CCascader, Input } from 'cloud-react'; | ||
const LABEL_KEY = { | ||
fj: '贵州 - 黔西南布依族苗族自治州', | ||
fuzhou: '福州', | ||
mawei: '马尾', | ||
mawei1: '马尾1', | ||
quanzhou: '泉州', | ||
zj: '浙江', | ||
hangzhou: '杭州', | ||
yuhang: '余杭', | ||
bj: '北京', | ||
chaoyang: '朝阳区', | ||
haidian: '海淀区' | ||
} | ||
const addressOptions = [{ | ||
label: '贵州 - 黔西南布依族苗族自治州', | ||
value: 'fj', | ||
children: [{ | ||
label: '福州', | ||
value: 'fuzhou', | ||
children: [{ | ||
label: '马尾', | ||
value: 'mawei', | ||
},{ | ||
label: '马尾1', | ||
value: 'mawei1', | ||
}], | ||
}, { | ||
label: '泉州', | ||
value: 'quanzhou', | ||
}], | ||
}, { | ||
label: '浙江', | ||
value: 'zj', | ||
children: [{ | ||
label: '杭州', | ||
value: 'hangzhou', | ||
children: [{ | ||
label: '余杭', | ||
value: 'yuhang', | ||
}], | ||
}], | ||
}, { | ||
label: '北京', | ||
value: 'bj', | ||
children: [{ | ||
label: '朝阳区', | ||
value: 'chaoyang', | ||
}, { | ||
label: '海淀区', | ||
value: 'haidian', | ||
}], | ||
}]; | ||
|
||
export default function Demo() { | ||
const [ value, setValue ] = useState([['zj']]); | ||
const [ inputValue, setInputValue] =useState(''); | ||
const maxTagCount = addressOptions.reduce((acc, item) => { | ||
if (item.children && item.children.length){ | ||
acc = acc + item.children.length; | ||
} else { | ||
acc += 1; | ||
} | ||
return acc; | ||
}, 0) | ||
|
||
const onChange = (value, selectedOptions, isSelectedAll) => { | ||
setValue(value); | ||
setInputValue(isSelectedAll ? '全部' : value.map(x => x[x.length - 1]).map(x => LABEL_KEY[x]).join(',')); | ||
} | ||
|
||
const filter = (inputValue, path) => { | ||
return path.some(option => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1); | ||
} | ||
|
||
return ( | ||
<div> | ||
<div style={{ marginBottom: 24 }}>多选级联组件</div> | ||
<CCascader | ||
hasSelectAll | ||
options={addressOptions} | ||
onChange={onChange} | ||
placeholder="Please select" | ||
value={value} | ||
multiple | ||
allowClear | ||
showSearch={{ filter: filter }} | ||
maxTagCount={1}> | ||
<Input | ||
placeholder={'请选择'} | ||
value={inputValue} | ||
style={{ width: 170 }} | ||
/> | ||
</CCascader> | ||
</div> | ||
); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters