|
|
@@ -2,11 +2,19 @@ import React, { forwardRef, useState } from 'react'
|
|
|
import { Select } from 'antd'
|
|
|
|
|
|
const ChangeSelect = props => {
|
|
|
- const { defaultValue, refinstance, options, onSave, ...resetProps } = props
|
|
|
- const extraDefaultValue =
|
|
|
- options.findIndex(item => item.value === defaultValue || item.key === defaultValue) !== -1
|
|
|
- ? defaultValue
|
|
|
- : null
|
|
|
+ const { defaultValue, refinstance, options, onSave } = props
|
|
|
+ let extraDefaultValue
|
|
|
+ let mode = null
|
|
|
+ if (Array.isArray(defaultValue)) {
|
|
|
+ extraDefaultValue = defaultValue
|
|
|
+ mode = 'multiple'
|
|
|
+ } else {
|
|
|
+ extraDefaultValue =
|
|
|
+ options.findIndex(item => item.value === defaultValue || item.key === defaultValue) !== -1
|
|
|
+ ? defaultValue
|
|
|
+ : null
|
|
|
+ }
|
|
|
+
|
|
|
const [selectedObj, setSelectedObj] = useState({ value: extraDefaultValue, label: '' })
|
|
|
|
|
|
const handleOnChange = (value, option) => {
|
|
|
@@ -27,13 +35,12 @@ const ChangeSelect = props => {
|
|
|
|
|
|
return (
|
|
|
<Select
|
|
|
- {...resetProps}
|
|
|
defaultValue={extraDefaultValue}
|
|
|
ref={refinstance}
|
|
|
onBlur={() => onSave({ currentTarget: { ...selectedObj } })}
|
|
|
options={options}
|
|
|
defaultOpen={true}
|
|
|
- // mode={Array.isArray(selectedObj.value) ? 'multiple' : null}
|
|
|
+ mode={mode}
|
|
|
onChange={handleOnChange}
|
|
|
className="w-full"
|
|
|
/>
|