index.js 805 Bytes
Newer Older
田翔's avatar
田翔 committed
1
import React, { useEffect } from 'react'
田翔's avatar
田翔 committed
2 3 4 5
import { Switch } from 'antd'

const BooleanSwitch = (props) => {

田翔's avatar
田翔 committed
6
  const { value, onChange, addons, schema, disabled } = props
田翔's avatar
田翔 committed
7
  const { widget } = addons.formData
田翔's avatar
田翔 committed
8 9 10 11 12 13

  const switchChange = (checked) => {
    onChange(checked)
  }

  useEffect(() => {
田翔's avatar
田翔 committed
14
    if (widget === 'ComboBox') {
田翔's avatar
田翔 committed
15
      if (value) {
16
        addons.setValue('isMultiple', false)
田翔's avatar
田翔 committed
17 18
      }
    }
田翔's avatar
田翔 committed
19 20 21 22 23 24 25
    // if (widget === 'TextInput') {
    //   if (schema.$id === 'isStoreID') {
    //     if (value) {
    //       addons.setValue('disabled', true)
    //     }
    //   }
    // }
田翔's avatar
田翔 committed
26
  }, [value])
田翔's avatar
田翔 committed
27 28 29

  return (
    <Switch
30
      disabled={disabled}
田翔's avatar
田翔 committed
31
      checked={value}
田翔's avatar
田翔 committed
32 33
      checkedChildren='是'
      unCheckedChildren='否'
田翔's avatar
田翔 committed
34
      onChange={switchChange}
田翔's avatar
田翔 committed
35 36 37 38 39 40
    />
  )

}

export default BooleanSwitch