| | |
| | | |
| | | import { getColumnForm } from './formconfig' |
| | | import { formRule } from '@/utils/option.js' |
| | | import CodeMirror from '@/templates/zshare/codemirror' |
| | | import EditTable from '@/templates/zshare/modalform/modaleditable' |
| | | import './index.scss' |
| | | |
| | | |
| | | const { TextArea } = Input |
| | | const columnTypeOptions = { |
| | |
| | | |
| | | state = { |
| | | visible: false, |
| | | formlist: null |
| | | formlist: null, |
| | | transfield: {} |
| | | } |
| | | |
| | | column = null |
| | | |
| | | UNSAFE_componentWillMount() { |
| | | let transfield = {} |
| | | this.props.columns.forEach(item => { |
| | | transfield[item.field] = item.label |
| | | }) |
| | | |
| | | this.setState({transfield}) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | |
| | | } |
| | | } |
| | | |
| | | editColumn = (column) => { |
| | | let formlist = getColumnForm(column, this.props.fields, this.props.columns) |
| | | let _options = fromJS(columnTypeOptions[column.type]).toJS() |
| | | getOptions = () => { |
| | | let _options = fromJS(columnTypeOptions[this.column.type]).toJS() |
| | | |
| | | if (column.editable === 'true') { |
| | | if (column.type === 'text') { |
| | | _options.push('required', 'enter', 'footEnter') |
| | | } else if (column.type === 'number') { |
| | | _options.push('max', 'min', 'enter', 'footEnter') |
| | | if (this.column.editable === 'true') { |
| | | if (this.column.type === 'text') { |
| | | _options.push('editType') |
| | | |
| | | if (this.column.editType === 'switch') { |
| | | _options.push('enter', 'openVal', 'closeVal', 'openText', 'closeText', 'editField') |
| | | } else if (this.column.editType === 'select') { |
| | | _options.push('required', 'enter', 'resourceType', 'linkSubField', 'editField', 'dropdown') |
| | | |
| | | if (this.column.resourceType === '0') { |
| | | _options.push('options') |
| | | } else { |
| | | _options.push('dataSource', 'valueField', 'valueText', 'orderBy', 'orderType', 'disableField', 'database') |
| | | } |
| | | } else { |
| | | _options.push('required', 'enter') |
| | | } |
| | | } else if (this.column.type === 'number') { |
| | | _options.push('max', 'min', 'enter') |
| | | } |
| | | } |
| | | |
| | | return _options |
| | | } |
| | | |
| | | editColumn = (column) => { |
| | | let formlist = getColumnForm(column, this.props.fields, this.props.columns) |
| | | |
| | | this.column = fromJS(column).toJS() |
| | | this.column.editType = this.column.editType || 'text' |
| | | this.column.resourceType = this.column.resourceType || '0' |
| | | |
| | | let _options = this.getOptions() |
| | | |
| | | this.setState({ |
| | | visible: true, |
| | | editable: column.editable || 'false', |
| | | type: column.type, |
| | | formlist: formlist.map(item => { |
| | | item.hidden = !_options.includes(item.key) |
| | | |
| | |
| | | } |
| | | |
| | | typeChange = (key, value, option) => { |
| | | const { editable, type } = this.state |
| | | if (key === 'type') { |
| | | let _options = fromJS(columnTypeOptions[value]).toJS() |
| | | this.column[key] = value |
| | | |
| | | if (editable === 'true') { |
| | | if (value === 'text') { |
| | | _options.push('required', 'enter', 'footEnter') |
| | | } else if (value === 'number') { |
| | | _options.push('max', 'min', 'enter', 'footEnter') |
| | | } |
| | | } |
| | | if (key === 'type') { |
| | | let _options = this.getOptions() |
| | | |
| | | this.setState({ |
| | | type: value, |
| | | formlist: this.state.formlist.map(item => { |
| | | if (item.key === 'editable') { |
| | | item.initVal = editable |
| | | } |
| | | item.initVal = this.column[item.key] || item.initVal |
| | | item.hidden = !_options.includes(item.key) |
| | | |
| | | return item |
| | |
| | | values.type = 'text' |
| | | } |
| | | |
| | | if (values.type !== this.state.type) { |
| | | let _options = fromJS(columnTypeOptions[values.type]).toJS() |
| | | let _type = this.column.type |
| | | this.column.type = values.type |
| | | |
| | | if (editable === 'true') { |
| | | if (values.type === 'text') { |
| | | _options.push('required', 'enter', 'footEnter') |
| | | } else if (values.type === 'number') { |
| | | _options.push('max', 'min', 'enter', 'footEnter') |
| | | } |
| | | } |
| | | if (values.type !== _type) { |
| | | let _options = this.getOptions() |
| | | |
| | | this.setState({ |
| | | type: values.type, |
| | | formlist: this.state.formlist.map(item => { |
| | | if (item.key === 'editable') { |
| | | item.initVal = editable |
| | | } |
| | | item.initVal = this.column[item.key] || item.initVal |
| | | item.hidden = !_options.includes(item.key) |
| | | |
| | | return item |
| | |
| | | } |
| | | } else if (key === 'format' && value === 'percent') { |
| | | this.props.form.setFieldsValue({postfix: '%'}) |
| | | } else if (key === 'editable') { |
| | | let _options = fromJS(columnTypeOptions[type]).toJS() |
| | | |
| | | if (value === 'true') { |
| | | if (type === 'text') { |
| | | _options.push('required', 'enter', 'footEnter') |
| | | } else if (type === 'number') { |
| | | _options.push('max', 'min', 'enter', 'footEnter') |
| | | } |
| | | } |
| | | } else if (key === 'editable' || key === 'editType' || key === 'resourceType') { |
| | | let _options = this.getOptions() |
| | | |
| | | this.setState({ |
| | | editable: value, |
| | | formlist: this.state.formlist.map(item => { |
| | | item.initVal = this.column[item.key] || item.initVal |
| | | item.hidden = !_options.includes(item.key) |
| | | |
| | | return item |
| | |
| | | } |
| | | } |
| | | |
| | | multiselectChange = (key, value) => { |
| | | if (key !== 'linkSubField') return |
| | | |
| | | this.column[key] = value |
| | | } |
| | | |
| | | handleEmpty = () => { |
| | | let field = this.props.form.getFieldValue('valueField') |
| | | |
| | | if (!field) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请填写值·字段。', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let text = this.props.form.getFieldValue('valueText') |
| | | |
| | | if (!text) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请填写文本·字段。', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let resource = this.props.form.getFieldValue('dataSource') || '' |
| | | |
| | | resource = `select '' as ${field},'全部' as ${text} union all \n${resource}` |
| | | |
| | | this.props.form.setFieldsValue({dataSource: resource}) |
| | | } |
| | | |
| | | changeOptions = (data) => { |
| | | this.column.options = data || [] |
| | | } |
| | | |
| | | getFields() { |
| | | const { dict } = this.props |
| | | const { getFieldDecorator } = this.props.form |
| | | const { formlist } = this.state |
| | | const { formlist, transfield } = this.state |
| | | const fields = [] |
| | | |
| | | if (!formlist) return null |
| | |
| | | formlist.forEach((item, index) => { |
| | | if (item.hidden || item.forbidden) return |
| | | |
| | | if (item.type === 'text') { // 文本搜索 |
| | | let rules = [] |
| | | if (item.key !== 'linkurl') { |
| | | rules = [{ |
| | | let span = 12 |
| | | let rules = [] |
| | | let className = '' |
| | | let content = null |
| | | let extra = null |
| | | let initVal = item.initVal || '' |
| | | |
| | | if (item.type === 'text') { |
| | | rules = [ |
| | | { required: item.required, message: dict['form.required.input'] + item.label + '!' }, |
| | | { |
| | | max: formRule.input.max, |
| | | message: formRule.input.message |
| | | }] |
| | | } |
| | | fields.push( |
| | | <Col span={12} key={index}> |
| | | <Form.Item label={item.tooltip ? |
| | | <Tooltip placement="topLeft" title={item.tooltip}> |
| | | <QuestionCircleOutlined className="mk-form-tip" /> |
| | | {item.label} |
| | | </Tooltip> : item.label |
| | | }> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initVal || '', |
| | | rules: [ |
| | | { |
| | | required: !!item.required, |
| | | message: this.props.dict['form.required.input'] + item.label + '!' |
| | | }, |
| | | ...rules |
| | | ] |
| | | })(<Input placeholder="" autoComplete="off" disabled={item.readonly} onPressEnter={this.handleSubmit} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } |
| | | ] |
| | | |
| | | content = <Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} /> |
| | | } else if (item.type === 'number') { |
| | | fields.push( |
| | | <Col span={12} key={index}> |
| | | <Form.Item label={item.tooltip ? |
| | | <Tooltip placement="topLeft" title={item.tooltip}> |
| | | <QuestionCircleOutlined className="mk-form-tip" /> |
| | | {item.label} |
| | | </Tooltip> : item.label |
| | | }> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initVal, |
| | | rules: [ |
| | | { |
| | | required: !!item.required, |
| | | message: this.props.dict['form.required.input'] + item.label + '!' |
| | | } |
| | | ] |
| | | })(item.unlimit ? <InputNumber onPressEnter={this.handleSubmit}/> : |
| | | <InputNumber min={item.min} max={item.max} precision={item.decimal} onPressEnter={this.handleSubmit}/>)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | rules = [ |
| | | { required: item.required, message: dict['form.required.input'] + item.label + '!' } |
| | | ] |
| | | initVal = item.initVal |
| | | |
| | | if (!item.unlimit) { |
| | | content = <InputNumber min={item.min} max={item.max} precision={item.precision} onPressEnter={this.handleSubmit}/> |
| | | } else { |
| | | content = <InputNumber onPressEnter={this.handleSubmit}/> |
| | | } |
| | | } else if (item.type === 'select') { |
| | | 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.select'] + item.label + '!' |
| | | } |
| | | ] |
| | | })( |
| | | <Select |
| | | showSearch |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | onChange={(value, option) => {this.typeChange(item.key, value, option)}} |
| | | getPopupContainer={() => document.getElementById('columnwinter')} |
| | | > |
| | | {item.options.map((option, index) => |
| | | <Select.Option key={index} datatype={option.datatype || ''} value={(option.value || option.field || option.MenuID)}> |
| | | {(option.text || option.label || option.MenuName)} |
| | | </Select.Option> |
| | | )} |
| | | </Select> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | rules = [ |
| | | { required: item.required, message: dict['form.required.select'] + item.label + '!' } |
| | | ] |
| | | content = <Select |
| | | showSearch |
| | | allowClear={item.allowClear === true} |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | onChange={(value, option) => {this.typeChange(item.key, value, option)}} |
| | | getPopupContainer={() => document.getElementById('edit-table-column-winter')} |
| | | > |
| | | {item.options.map((option, i) => |
| | | <Select.Option key={i} datatype={option.datatype || ''} value={(option.value || option.field || option.MenuID)}> |
| | | {(option.text || option.label || option.MenuName)} |
| | | </Select.Option> |
| | | )} |
| | | </Select> |
| | | } else if (item.type === 'radio') { |
| | | fields.push( |
| | | <Col span={12} key={index}> |
| | | <Form.Item label={item.tooltip ? |
| | | <Tooltip placement="topLeft" title={item.tooltip}> |
| | | <QuestionCircleOutlined className="mk-form-tip" /> |
| | | {item.label} |
| | | </Tooltip> : item.label |
| | | }> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initVal, |
| | | rules: [ |
| | | { |
| | | required: !!item.required, |
| | | message: this.props.dict['form.required.select'] + item.label + '!' |
| | | } |
| | | ] |
| | | })( |
| | | <Radio.Group onChange={(e) => {this.typeChange(item.key, e.target.value)}}> |
| | | { |
| | | item.options.map(option => { |
| | | return ( |
| | | <Radio key={option.value} value={option.value}>{option.text}</Radio> |
| | | ) |
| | | }) |
| | | } |
| | | </Radio.Group> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | rules = [ |
| | | { required: item.required, message: dict['form.required.select'] + item.label + '!' } |
| | | ] |
| | | initVal = item.initVal |
| | | |
| | | content = <Radio.Group onChange={(e) => {this.typeChange(item.key, e.target.value)}}> |
| | | {item.options.map(option => <Radio key={option.value} value={option.value}>{option.text}</Radio>)} |
| | | </Radio.Group> |
| | | } else if (item.type === 'multiselect') { // 多选 |
| | | fields.push( |
| | | <Col span={12} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initVal || [] |
| | | })( |
| | | <Select |
| | | showSearch |
| | | mode="multiple" |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | > |
| | | {item.options.map((option, i) => |
| | | <Select.Option id={i} key={i} value={option.value || option.field}>{option.text || option.label}</Select.Option> |
| | | )} |
| | | </Select> |
| | | )} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'textarea') { // 文本搜索 |
| | | fields.push( |
| | | <Col span={24} key={index} className="textarea"> |
| | | <Form.Item label={item.tooltip ? |
| | | <Tooltip placement="topLeft" title={item.tooltip}> |
| | | <QuestionCircleOutlined className="mk-form-tip" /> |
| | | {item.label} |
| | | </Tooltip> : item.label |
| | | }> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: item.initVal || '', |
| | | rules: [ |
| | | { |
| | | required: !!item.required, |
| | | message: this.props.dict['form.required.input'] + item.label + '!' |
| | | } |
| | | ] |
| | | })(<TextArea rows={2} disabled={item.readonly} placeholder={item.placeholder || ''} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | content = <Select |
| | | showSearch |
| | | mode="multiple" |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | onChange={(value) => this.multiselectChange(item.key, value)} |
| | | > |
| | | {item.options.map((option, i) => |
| | | <Select.Option key={i} value={option.value || option.field}>{option.text || option.label}</Select.Option> |
| | | )} |
| | | </Select> |
| | | } else if (item.type === 'textarea') { |
| | | span = 24 |
| | | className = 'text-area' |
| | | rules = [ |
| | | { required: item.required, message: dict['form.required.input'] + item.label + '!' } |
| | | ] |
| | | |
| | | content = <TextArea rows={item.rows || 2}/> |
| | | } else if (item.type === 'codemirror') { |
| | | rules = [ |
| | | { required: item.required, message: dict['form.required.input'] + item.label + '!' } |
| | | ] |
| | | span = 24 |
| | | className = 'text-area' |
| | | |
| | | extra = <span className="add-resource-empty" onClick={this.handleEmpty}>空</span> |
| | | |
| | | content = <CodeMirror /> |
| | | } else if (item.type === 'options') { |
| | | span = 24 |
| | | className = 'text-area' |
| | | |
| | | let linkSubFields = this.column.linkSubField || [] |
| | | |
| | | content = <EditTable type={'select'} module="form" transfield={transfield} linkSubFields={linkSubFields} onChange={this.changeOptions}/> |
| | | } |
| | | |
| | | fields.push( |
| | | <Col span={span} key={index}> |
| | | <Form.Item className={className} extra={extra} label={item.tooltip ? |
| | | <Tooltip placement="topLeft" title={item.tooltip}> |
| | | <QuestionCircleOutlined className="mk-form-tip" /> |
| | | {item.label} |
| | | </Tooltip> : item.label |
| | | }> |
| | | {getFieldDecorator(item.key, { |
| | | initialValue: initVal, |
| | | rules: rules |
| | | })(content)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | }) |
| | | return fields |
| | | } |
| | |
| | | } |
| | | this.setState({visible: false, formlist: null}) |
| | | this.props.submitCol(values) |
| | | |
| | | this.column = null |
| | | } |
| | | }) |
| | | } |
| | |
| | | <Modal |
| | | title="显示列编辑" |
| | | visible={visible} |
| | | width={800} |
| | | width={900} |
| | | maskClosable={false} |
| | | onOk={this.handleSubmit} |
| | | onCancel={this.editModalCancel} |
| | | destroyOnClose |
| | | > |
| | | <Form {...formItemLayout} className="commontable-column-form" id="columnwinter"> |
| | | <Form {...formItemLayout} className="commontable-column-form" id="edit-table-column-winter"> |
| | | <Row gutter={24}>{this.getFields()}</Row> |
| | | </Form> |
| | | </Modal> |