| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { Form, Row, Col, Input, Select, Icon, Radio, notification, InputNumber } from 'antd' |
| | | import { Form, Row, Col, Input, Select, Icon, Radio, notification, InputNumber, Tooltip } from 'antd' |
| | | import { formRule } from '@/utils/option.js' |
| | | import { dateOptions } from '@/utils/option.js' |
| | | import EditTable from '../editable' |
| | |
| | | |
| | | let type = formlist.filter(cell => cell.key === 'type')[0].initVal |
| | | let resourceType = formlist.filter(cell => cell.key === 'resourceType')[0].initVal |
| | | let _options = ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden'] // 默认显示项 |
| | | let _options = ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden', 'readin'] // 默认显示项 |
| | | |
| | | if ((type === 'multiselect' || type === 'select' || type === 'link') && resourceType === '0') { // 选择类型、自定义资源 |
| | | _options = [..._options, 'resourceType', 'options'] |
| | | } else if ((type === 'multiselect' || type === 'select' || type === 'link') && resourceType === '1') { // 选择类型、数据源 |
| | | _options = [..._options, 'resourceType', 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'database'] |
| | | } else if (type === 'number') { |
| | | _options = ['label', 'field', 'initval', 'type', 'readonly', 'hidden', 'decimal', 'min', 'max'] |
| | | _options = ['label', 'field', 'initval', 'type', 'readonly', 'hidden', 'decimal', 'min', 'max', 'readin'] |
| | | } else if (type === 'fileupload') { |
| | | _options = ['label', 'field', 'type', 'readonly', 'required'] |
| | | _options = ['label', 'field', 'type', 'readonly', 'required', 'readin', 'fieldlength'] |
| | | } else if (type === 'text' || type === 'textarea') { |
| | | _options = [..._options, 'fieldlength'] |
| | | } |
| | | |
| | | if (type === 'select') { |
| | | _options = [..._options, 'setAll'] |
| | | if (resourceType === '1') { |
| | | _options.push('linkSubField') |
| | | } |
| | | _options = [..._options, 'setAll', 'linkSubField'] |
| | | } else if (type === 'multiselect') { |
| | | _options = [..._options, 'fieldlength'] |
| | | } else if (type === 'link') { // 关联类型、增加关联字段 |
| | | _options = [..._options, 'setAll', 'linkField'] |
| | | } else if (type === 'funcvar') { // 设置为函数变量时,不需要其他信息 |
| | | _options = ['label', 'field', 'type'] |
| | | } else if (type === 'linkMain') { |
| | | _options = ['label', 'field', 'type', 'readonly', 'required', 'hidden'] |
| | | _options = ['label', 'field', 'type', 'readonly', 'required', 'hidden', 'fieldlength'] |
| | | } |
| | | |
| | | this.setState({ |
| | |
| | | form.type = 'select' |
| | | } else if (type === 'number' && form.key === 'initval') { |
| | | form.type = 'number' |
| | | form.initVal = form.initVal || 0 |
| | | form.required = true |
| | | } |
| | | form.show = _options.includes(form.key) |
| | |
| | | |
| | | openTypeChange = (key, value) => { |
| | | if (key === 'type') { |
| | | let _options = ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden'] |
| | | let _options = ['label', 'field', 'initval', 'type', 'readonly', 'required', 'hidden', 'readin'] |
| | | |
| | | if ((value === 'multiselect' || value === 'select' || value === 'link') && this.state.resourceType === '0') { // 选择类型、自定义资源 |
| | | _options = [..._options, 'resourceType', 'options'] |
| | | } else if ((value === 'multiselect' || value === 'select' || value === 'link') && this.state.resourceType === '1') { // 选择类型、数据源 |
| | | _options = [..._options, 'resourceType', 'dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'database'] |
| | | } else if (value === 'number') { |
| | | _options = ['label', 'field', 'initval', 'type', 'readonly', 'hidden', 'decimal', 'min', 'max'] |
| | | _options = ['label', 'field', 'initval', 'type', 'readonly', 'hidden', 'decimal', 'min', 'max', 'readin'] |
| | | } else if (value === 'fileupload') { |
| | | _options = ['label', 'field', 'type', 'readonly', 'required'] |
| | | _options = ['label', 'field', 'type', 'readonly', 'required', 'readin', 'fieldlength'] |
| | | } else if (value === 'text' || value === 'textarea') { |
| | | _options = [..._options, 'fieldlength'] |
| | | } |
| | | |
| | | if (value === 'select') { |
| | | _options = [..._options, 'setAll'] |
| | | if (this.state.resourceType === '1') { |
| | | _options.push('linkSubField') |
| | | } |
| | | _options = [..._options, 'setAll', 'linkSubField'] |
| | | } else if (value === 'multiselect') { |
| | | _options = [..._options, 'fieldlength'] |
| | | } else if (value === 'link') { |
| | | _options = [..._options, 'setAll', 'linkField'] |
| | | } else if (value === 'funcvar') { |
| | | _options = ['label', 'field', 'type'] |
| | | } else if (value === 'linkMain') { |
| | | _options = ['label', 'field', 'type', 'readonly', 'required', 'hidden'] |
| | | _options = ['label', 'field', 'type', 'readonly', 'required', 'hidden', 'fieldlength'] |
| | | } |
| | | |
| | | this.setState({ |
| | |
| | | form.show = _options.includes(form.key) |
| | | if (form.key === 'initval') { |
| | | form.required = false |
| | | form.initVal = '' |
| | | if (dateOptions.hasOwnProperty(value)) { |
| | | form.options = dateOptions[value] |
| | | form.type = 'select' |
| | | } else if (value === 'number') { |
| | | form.type = 'number' |
| | | form.required = true |
| | | form.initVal = 0 |
| | | } else { |
| | | form.type = 'text' |
| | | } |
| | | form.initVal = '' |
| | | form.show = false |
| | | } else if (form.key === 'fieldlength') { |
| | | form.initVal = 50 |
| | | if (value === 'textarea' || value === 'fileupload') { |
| | | form.initVal = 512 |
| | | } |
| | | form.show = false |
| | | } else if (form.key === 'resourceType') { |
| | | form.initVal = this.state.resourceType |
| | | } |
| | | return form |
| | | }) |
| | |
| | | this.setState({ |
| | | formlist: this.state.formlist.map(form => { |
| | | if (form.key === 'initval' && value !== 'fileupload' && value !== 'funcvar' && value !== 'linkMain') { |
| | | form.show = true |
| | | } else if (form.key === 'fieldlength' && (value === 'fileupload' || value === 'multiselect' || value === 'text' || value === 'textarea' || value === 'linkMain')) { |
| | | form.show = true |
| | | } |
| | | return form |
| | |
| | | } |
| | | } |
| | | |
| | | multiselectChange = (key, value, options) => { |
| | | if (key === 'linkSubField') { |
| | | |
| | | } |
| | | console.log(key) |
| | | console.log(value) |
| | | console.log(options) |
| | | } |
| | | |
| | | onChange = (e, key) => { |
| | | const { openType } = this.state |
| | | let value = e.target.value |
| | | if (key === 'resourceType') { |
| | | let _options = ['label', 'field', 'initval', 'type', 'resourceType', 'readonly', 'required', 'hidden'] |
| | | let _options = ['label', 'field', 'initval', 'type', 'resourceType', 'readonly', 'required', 'hidden', 'readin'] |
| | | if (value === '0') { |
| | | _options = [..._options, 'options'] |
| | | } else if (value === '1') { |
| | |
| | | } |
| | | |
| | | if (openType === 'select') { |
| | | _options = [..._options, 'setAll'] |
| | | if (value === '1') { |
| | | _options.push('linkSubField') |
| | | } |
| | | _options = [..._options, 'setAll', 'linkSubField'] |
| | | } else if (openType === 'link') { |
| | | _options = [..._options, 'setAll', 'linkField'] |
| | | } else if (openType === 'multiselect') { |
| | | _options = [..._options, 'fieldlength'] |
| | | } |
| | | |
| | | this.setState({ |
| | |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.key === 'fieldlength') { |
| | | fields.push( |
| | | <Col span={12} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initVal, |
| | | rules: [ |
| | | { |
| | | required: !!item.required, |
| | | message: this.props.dict['form.required.input'] + item.label + '!' |
| | | } |
| | | ] |
| | | })(<InputNumber min={1} precision={0} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else { |
| | | fields.push( |
| | | <Col span={12} key={index}> |
| | |
| | | showSearch |
| | | mode="multiple" |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | onChange={(value) => this.multiselectChange(item.key, value, item.options)} |
| | | > |
| | | {item.options.map(option => |
| | | <Select.Option id={option.uuid} key={option.uuid} value={option.field}>{option.label}</Select.Option> |
| | |
| | | } else if (item.type === 'radio') { |
| | | fields.push( |
| | | <Col span={12} key={index}> |
| | | <Form.Item label={item.label}> |
| | | <Form.Item label={item.tooltip ? |
| | | <Tooltip placement="topLeft" overlayClassName={item.tooltipClass} title={item.tooltip}> |
| | | <Icon type="question-circle" /> |
| | | {item.label} |
| | | </Tooltip> : item.label |
| | | }> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initVal, |
| | | rules: [ |