| | |
| | | fieldlen: null, |
| | | groups: null, |
| | | formlist: [], |
| | | encrypts: [], // 加密字段 |
| | | intercepts: [], // 截取字段 |
| | | record: {} |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | const { datatype } = this.state |
| | | const { datatype, encrypts } = this.state |
| | | if (nextProps.data && !is(fromJS(this.props.data), fromJS(nextProps.data))) { |
| | | |
| | | let _fieldsvalue = {} |
| | |
| | | } |
| | | |
| | | _fieldsvalue[key] = _val |
| | | } else if (datatype[key] === 'text' || datatype[key] === 'textarea') { |
| | | let _value = nextProps.data[key] |
| | | if (encrypts.includes(key)) { // 加密字段 |
| | | try { |
| | | _value = window.btoa(window.encodeURIComponent(_value)) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |
| | | } |
| | | |
| | | _fieldsvalue[key] = _value |
| | | } else { |
| | | _fieldsvalue[key] = nextProps.data[key] |
| | | } |
| | | } else { |
| | | _record[key] = nextProps.data[key] |
| | | let _value = nextProps.data[key] |
| | | if (encrypts.includes(key)) { // 加密字段 |
| | | try { |
| | | _value = window.btoa(window.encodeURIComponent(_value)) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |
| | | } |
| | | |
| | | _record[key] = _value |
| | | } |
| | | }) |
| | | |
| | |
| | | let readin = {} |
| | | let fieldlen = {} |
| | | let _formlist = [] |
| | | let encrypts = [] |
| | | let intercepts = [] |
| | | |
| | | let _groups = groups.map(group => { |
| | | group.sublist = group.sublist.map(item => { |
| | | let _readin = item.readin !== 'false' |
| | | if (item.type === 'funcvar') { |
| | | _readin = false |
| | | item.initval = '' // 初始化为空 |
| | | } |
| | | |
| | | if (item.type === 'textarea' && item.encryption === 'true') { |
| | | encrypts.push(item.field) |
| | | } |
| | | if (item.interception === 'true') { |
| | | intercepts.push(item.field) |
| | | } |
| | | |
| | | item.initVal = item.initval ? JSON.parse(JSON.stringify(item.initval)) : '' |
| | | |
| | | let _fieldlen = item.fieldlength || 50 |
| | | if (item.type === 'textarea' || item.type === 'fileupload') { |
| | | if (item.type === 'textarea' || item.type === 'fileupload' || item.type === 'multiselect') { |
| | | _fieldlen = item.fieldlength || 512 |
| | | } else if (item.type === 'number') { |
| | | _fieldlen = item.decimal ? item.decimal : 0 |
| | |
| | | fieldlen[item.field] = _fieldlen |
| | | |
| | | if (_readin && !/^date/.test(item.type) && data && data.hasOwnProperty(item.field)) { |
| | | item.initval = data[item.field] |
| | | let newval = data[item.field] |
| | | |
| | | if (encrypts.includes(item.field) && newval) { |
| | | try { |
| | | newval = window.decodeURIComponent(window.atob(newval)) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |
| | | } |
| | | |
| | | item.initval = newval |
| | | } |
| | | |
| | | if (item.supvalue) { |
| | |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未查询到表单《' + item.label + '》关联字段!', |
| | | duration: 10 |
| | | duration: 5 |
| | | }) |
| | | } else { |
| | | item.options = item.oriOptions.filter(option => option.parentId === supItem.initval) |
| | |
| | | let cols = 2 |
| | | if (this.props.setting && this.props.setting.cols) { |
| | | cols = parseInt(this.props.setting.cols) |
| | | if (cols > 3 || cols < 1) { |
| | | if (cols > 4 || cols < 1) { |
| | | cols = 2 |
| | | } |
| | | } |
| | |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'funcvar') { |
| | | |
| | | fields.push( |
| | | <Col span={24 / cols} key={index}> |
| | | <Form.Item label={item.label}> |
| | | {getFieldDecorator(item.field, { |
| | | initialValue: '系统自动生成', |
| | | })(<Input placeholder="" autoComplete="off" disabled={true} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'textarea') { |
| | | let _labelcol = cols !== 3 ? 8 / cols : 3 |
| | | let _wrapcol = cols !== 3 ? 16 + (cols - 1) * 4 : 21 |
| | | let _style = {} |
| | | if (cols === 2) { |
| | | if (cols === 2 || cols === 4) { |
| | | _style.paddingLeft = '7px' |
| | | } |
| | | fields.push( |
| | |
| | | } |
| | | |
| | | handleConfirm = () => { |
| | | const { record } = this.state |
| | | const { record, encrypts, intercepts } = this.state |
| | | // 表单提交时检查输入值是否正确 |
| | | return new Promise((resolve, reject) => { |
| | | this.props.form.validateFieldsAndScroll((err, values) => { |
| | |
| | | if (!item.field) return |
| | | |
| | | if (item.type === 'funcvar') { |
| | | let _val = item.initval |
| | | if (values.hasOwnProperty(item.field)) { |
| | | _val = values[item.field] === '系统自动生成' ? '' : values[item.field] |
| | | } else if (record.hasOwnProperty(item.field)) { |
| | | _val = record[item.field] |
| | | } |
| | | search.push({ |
| | | type: 'funcvar', |
| | | readonly: 'true', |
| | | readin: false, |
| | | fieldlen: this.state.fieldlen[item.field], |
| | | key: item.field, |
| | | value: '' |
| | | value: _val |
| | | }) |
| | | } else if (item.hidden === 'true' && item.field !== this.props.setting.primaryKey) { |
| | | let _val = item.initval |
| | | if (record.hasOwnProperty(item.field)) { |
| | | _val = record[item.field] |
| | | } |
| | | |
| | | search.push({ |
| | | type: this.state.datatype[item.field], |
| | | readonly: this.state.readtype[item.field], |
| | |
| | | key: item.field, |
| | | value: _val |
| | | }) |
| | | } else if (item.supField && !item.supvalue.includes(this.props.form.getFieldValue(item.supField))) { |
| | | search.push({ |
| | | type: this.state.datatype[item.field], |
| | | readonly: this.state.readtype[item.field], |
| | | readin: this.state.readin[item.field], |
| | | fieldlen: this.state.fieldlen[item.field], |
| | | key: item.field, |
| | | value: item.initVal |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | Object.keys(values).forEach(key => { |
| | | if (this.state.datatype[key] === 'funcvar') return |
| | | |
| | | let _value = '' |
| | | if (this.state.datatype[key] === 'datetime') { |
| | | if (values[key]) { |
| | |
| | | } |
| | | |
| | | _value = vals.join(',') |
| | | } else if (this.state.datatype[key] === 'text') { |
| | | _value = values[key].replace(/(^\s*|\s*$) | \t* | \v*/ig, '') |
| | | } else if (this.state.datatype[key] === 'text' || this.state.datatype[key] === 'textarea') { |
| | | _value = values[key].replace(/\t*|\v*/g, '') // 去除制表符 |
| | | |
| | | if (intercepts.includes(key)) { // 去除首尾空格 |
| | | _value = _value.replace(/(^\s*|\s*$)/g, '') |
| | | } |
| | | } else { |
| | | _value = values[key] |
| | | |
| | |
| | | value: _value |
| | | }) |
| | | }) |
| | | |
| | | if (encrypts && encrypts.length > 0) { |
| | | search = search.map(item => { |
| | | let _value = item.value |
| | | if (encrypts.includes(item.key)) { |
| | | try { |
| | | _value = window.btoa(window.encodeURIComponent(_value)) |
| | | } catch (e) { |
| | | console.warn(e) |
| | | } |
| | | } |
| | | item.value = _value |
| | | |
| | | return item |
| | | }) |
| | | } |
| | | resolve(search) |
| | | } else { |
| | | reject(err) |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { groups, setting } = this.props |
| | | const { setting } = this.props |
| | | const { groups } = this.state |
| | | const formItemLayout = { |
| | | labelCol: { |
| | | xs: { span: 24 }, |
| | |
| | | let _width = (setting && setting.width) || 100 |
| | | |
| | | let keys = groups.map(group => group.uuid) |
| | | |
| | | |
| | | return ( |
| | | <Form {...formItemLayout} className="form-tab-form-field"> |
| | | <Collapse |