Commit eaf8f9a8 by zhaochengxiang

支持多选

parent c17aca7b
......@@ -732,17 +732,21 @@ const AssetAction = (props) => {
)
}
if (element.selectMode==='单选') {
if (element.selectMode==='单选' || element.selectMode==='多选') {
const tmp = (element.optional??'').split(',')
if ((tmp??[]).indexOf('部门列表')!==-1) {
return <DepartmentItem loading={loadingDepartments} departments={departments} />
return <DepartmentItem loading={loadingDepartments} departments={departments} multiple={element.selectMode==='多选'} />
}
if ((tmp??[]).indexOf('用户列表')!==-1) {
return <UserItem loading={loadingUsers} users={users} />
return <UserItem loading={loadingUsers} users={users} multiple={element.selectMode==='多选'} />
}
}
if (element.selectMode==='单选') {
const tmp = (element.optional??'').split(',')
return (
<Select
allowClear
......@@ -1189,7 +1193,7 @@ const CascaderItem = ({ value = null, data, onChange, ...restProps }) => {
)
}
const DepartmentItem = ({ loading, departments, value, onChange }) => {
const DepartmentItem = ({ loading, departments, value, onChange, multiple = false }) => {
const [searchValue, setSearchValue] = React.useState()
const [options, setOptions] = React.useState()
......@@ -1204,10 +1208,25 @@ const DepartmentItem = ({ loading, departments, value, onChange }) => {
)
}, [searchValue, departments], { wait: 300 })
const currentValue = useMemo(() => {
if (!value) return undefined
if ((options??[]).length>0) {
if (multiple) {
return (value??'').split(',')
} else {
return value
}
}
return undefined
}, [value])
return (
<Select loading={loading} showSearch allowClear
mode={multiple?'multiple':null}
placeholder='请选择部门'
value={(options??[]).length>0?value:undefined}
value={currentValue}
searchValue={searchValue}
onSearch={(val) => {
setSearchValue(val)
......@@ -1218,13 +1237,17 @@ const DepartmentItem = ({ loading, departments, value, onChange }) => {
filterOption={false}
options={options}
onChange={(val) => {
if (multiple) {
onChange?.((val??[]).toString())
} else {
onChange?.(val)
}
}}
/>
)
}
const UserItem = ({ loading, users, value, onChange, readonly=false, terms = [] }) => {
const UserItem = ({ loading, users, value, onChange, readonly=false, terms = [], multiple = false }) => {
const [searchValue, setSearchValue] = React.useState()
const [options, setOptions] = React.useState()
......@@ -1251,6 +1274,20 @@ const UserItem = ({ loading, users, value, onChange, readonly=false, terms = []
)
}, [searchValue, users], { wait: 300 })
const currentValue = useMemo(() => {
if (!value) return undefined
if ((options??[]).length>0) {
if (multiple) {
return (value??'').split(',')
} else {
return value
}
}
return undefined
}, [value])
return (
<React.Fragment>
{
......@@ -1258,7 +1295,8 @@ const UserItem = ({ loading, users, value, onChange, readonly=false, terms = []
{highlightSearchContentByTerms(userInfo, terms)}
</Typography.Text> : <Select loading={loading} showSearch allowClear
placeholder='请选择用户'
value={(options??[]).length>0?value:undefined}
mode={multiple?'multiple':null}
value={currentValue}
searchValue={searchValue}
onSearch={(val) => {
setSearchValue(val)
......@@ -1269,7 +1307,11 @@ const UserItem = ({ loading, users, value, onChange, readonly=false, terms = []
filterOption={false}
options={options}
onChange={(val) => {
if (multiple) {
onChange?.((val??[]).toString())
} else {
onChange?.(val)
}
}}
/>
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment