zuiidea / antd-admin

An excellent front-end solution for enterprise applications built upon Ant Design and UmiJS
https://antd-admin.zuiidea.com
MIT License
9.64k stars 2.53k forks source link

这个也是结构赋值的写法,把form对象的方法解构出来。?传到UI组件里面。。。。很少见到这样的写法,一般都在UI组件内部结构。。。。 #801

Closed martinwithyou closed 6 years ago

martinwithyou commented 6 years ago

form: { getFieldDecorator, getFieldsValue, setFieldsValue, },

请酌情提供细节,并保持issue精简便于查阅

  1. 功能需求 => 详细说明
  2. Bug反馈
    2.1 简单描述下报错
    2.2 你期望什么结果
    2.3 如何操作导致的
    2.4 可提供运行环境信息
  3. 代码求助 => 可以提,未必及时答复
superlbr commented 6 years ago

见很少。。。

martinwithyou commented 6 years ago

const Filter = ({ onAdd, isMotion, switchIsMotion, onFilterChange, filter, form: { getFieldDecorator, getFieldsValue, setFieldsValue, }, }) => {

console.log(getFieldDecorator);
console.log(getFieldsValue);
console.log(setFieldsValue);

const handleFields = (fields) => { const { createTime } = fields if (createTime.length) { fields.createTime = [createTime[0].format('YYYY-MM-DD'), createTime[1].format('YYYY-MM-DD')] } return fields }

const handleSubmit = () => { let fields = getFieldsValue() fields = handleFields(fields) onFilterChange(fields) }

const handleReset = () => { const fields = getFieldsValue() for (let item in fields) { if ({}.hasOwnProperty.call(fields, item)) { if (fields[item] instanceof Array) { fields[item] = [] } else { fields[item] = undefined } } } setFieldsValue(fields) handleSubmit() }

const handleChange = (key, values) => { let fields = getFieldsValue() fields[key] = values fields = handleFields(fields) onFilterChange(fields) }

const { name, address } = filter

let initialCreateTime = [] if (filter.createTime && filter.createTime[0]) { initialCreateTime[0] = moment(filter.createTime[0]) } if (filter.createTime && filter.createTime[1]) { initialCreateTime[1] = moment(filter.createTime[1]) }

return (

{getFieldDecorator('name', { initialValue: name })()} {getFieldDecorator('address', { initialValue: address })( document.getElementById('addressCascader')} />)} {getFieldDecorator('createTime', { initialValue: initialCreateTime })( { return document.getElementById('createTimeRangePicker') }} />)}

) }

Filter.propTypes = { onAdd: PropTypes.func, isMotion: PropTypes.bool, switchIsMotion: PropTypes.func, form: PropTypes.object, filter: PropTypes.object, onFilterChange: PropTypes.func, }

export default Form.create()(Filter)

martinwithyou commented 6 years ago

这个就是你 user 文件夹 下面的 filter.js这么写的啊、、、、、

martinwithyou commented 6 years ago

const Filter = ({ onAdd, isMotion, switchIsMotion, onFilterChange, filter, form: { getFieldDecorator, getFieldsValue, setFieldsValue, }, }) => {

it belongs to you.

superlbr commented 6 years ago
  1. 不用大段贴代码的,github有很优雅的方式。。。
  2. 纠结写法这种细枝末节的方式很无趣
martinwithyou commented 6 years ago

。。。。。。 可能我对于函数参数的理解,是 “”父组件的传的值“” 得结构赋值。

superlbr commented 6 years ago

难道不是?