提交 8055ab38 authored 作者: 钟是志's avatar 钟是志

bug修改

上级 c211fd1c
...@@ -14,7 +14,7 @@ const FieldList = (props) => { ...@@ -14,7 +14,7 @@ const FieldList = (props) => {
{ {
config.map((x) =>{ config.map((x) =>{
return ( return (
<p className={styles.detailInfo}> <p className={styles.detailInfo} key={x.key}>
<span>{x.name}</span> <span>{x.name}</span>
<span>{data[x.key] || ''}</span> <span>{data[x.key] || ''}</span>
</p> </p>
......
import React, {Fragment, Component} from 'react'; import React, { Fragment, Component } from 'react';
import {DatePicker, Picker, TextareaItem, InputItem, List} from 'antd-mobile'; import { DatePicker, Picker, TextareaItem, InputItem, List } from 'antd-mobile';
import moment from 'moment'; import moment from 'moment';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import FieldList from '@/H5Public/baseComponents/FieldList'; import FieldList from '@/H5Public/baseComponents/FieldList';
const DiyInput = (props) => { const DiyInput = (props) => {
let {config, formValue, changeValue, otherProps} = props; let { config, formValue, changeValue, otherProps } = props;
if (config.readOnly) {
config.placeholder = '';
} else {
config.placeholder = config.placeholder || '点击输入';
}
return ( return (
<InputItem <InputItem
key={config.key} key={config.key}
type={config.dataType} type={config.dataType}
editable={!config.readOnly} editable={!config.readOnly}
value={formValue[config.key]} value={formValue[config.key]}
placeholder={config.placeholder || '点击输入'} placeholder={config.placeholder}
onChange={(e) => { onChange={(e) => {
changeValue(e, config.key) changeValue(e, config.key);
}} }}
{...config.otherProps} {...config.otherProps}
> >
{giveRequiredName(config)} {giveRequiredName(config)}
</InputItem> </InputItem>
) );
}; };
const DiyTextarea = (props) => { const DiyTextarea = (props) => {
let {config, formValue, changeValue} = props; let { config, formValue, changeValue } = props;
if (config.readOnly) {
config.placeholder = '';
} else {
config.placeholder = config.placeholder || '点击输入';
}
return ( return (
<TextareaItem <TextareaItem
key={config.key} key={config.key}
title={giveRequiredName(config)} title={giveRequiredName(config)}
maxLength={200} maxLength={200}
autoHeight={true} autoHeight={true}
placeholder={config.placeholder || '点击输入'} placeholder={config.placeholder}
editable={!config.readOnly} editable={!config.readOnly}
value={formValue[config.key]} value={formValue[config.key]}
onChange={(e) => { onChange={(e) => {
changeValue(e, config.key) changeValue(e, config.key);
}} }}
{...config.otherProps} {...config.otherProps}
> >
</TextareaItem> </TextareaItem>
) );
}; };
const DiyPicker = (props) => { const DiyPicker = (props) => {
let {config, formValue, changeValue} = props; let { config, formValue, changeValue } = props;
if (config.readOnly) {
config.placeholder = ' ';
} else {
config.placeholder = config.placeholder || '点击输入';
}
let opt = config.options.map((x) => { let opt = config.options.map((x) => {
return { return {
label: x.name, label: x.name,
value: x.key, value: x.key,
} };
}); });
return ( return (
<Picker <Picker
data={opt} data={opt}
cols={1} cols={1}
extra={config.placeholder || '请选择'} extra={' '}
key={config.key} key={config.key}
value={[formValue[config.key]]} value={[formValue[config.key]]}
disabled={config.readOnly} disabled={config.readOnly}
...@@ -65,9 +80,8 @@ const DiyPicker = (props) => { ...@@ -65,9 +80,8 @@ const DiyPicker = (props) => {
changeValue(val[0], config.key); changeValue(val[0], config.key);
}} }}
{...config.otherProps} {...config.otherProps}
> >
<List.Item arrow="horizontal"> <List.Item arrow={config.readOnly ? '' : 'horizontal' }>
{giveRequiredName(config)} {giveRequiredName(config)}
</List.Item> </List.Item>
</Picker> </Picker>
...@@ -76,20 +90,25 @@ const DiyPicker = (props) => { ...@@ -76,20 +90,25 @@ const DiyPicker = (props) => {
}; };
const DiyDatePicker = (props) => { const DiyDatePicker = (props) => {
let {config, formValue, changeValue} = props; let { config, formValue, changeValue } = props;
let value = formValue[config.key] ? new Date(formValue[config.key].replace(/-/g, '/')) : null; let value = formValue[config.key] ? new Date(formValue[config.key].replace(/-/g, '/')) : null;
const change = (date) => { const change = (date) => {
let v = moment(date.valueOf()).format('YYYY-MM-DD'); let v = moment(date.valueOf()).format('YYYY-MM-DD');
changeValue(v,config.key); changeValue(v, config.key);
}; };
if (config.readOnly) {
config.placeholder = '';
} else {
config.placeholder = config.placeholder || '点击输入';
}
return ( return (
<DatePicker <DatePicker
value={value} value={value}
extra={config.placeholder || '请选择'} extra={config.placeholder}
mode={'date'} mode={'date'}
key={config.key} key={config.key}
disabled={config.readOnly} disabled={config.readOnly}
onChange={ (date) => change(date)} onChange={(date) => change(date)}
{...otherProps} {...otherProps}
> >
...@@ -105,20 +124,20 @@ const DiyDatePicker = (props) => { ...@@ -105,20 +124,20 @@ const DiyDatePicker = (props) => {
const giveRequiredName = (config) => { const giveRequiredName = (config) => {
if(config.required){ if (config.required) {
return ( return (
<Fragment> <Fragment>
<i style={{color: 'red'}}>*&nbsp;</i> <i style={{ color: 'red' }}>*&nbsp;</i>
{config.name} {config.name}
</Fragment> </Fragment>
) );
}else{ } else {
return ( return (
<Fragment> <Fragment>
<i style={{color: 'red'}}>&nbsp;&nbsp;</i> <i style={{ color: 'red' }}>&nbsp;&nbsp;</i>
{config.name} {config.name}
</Fragment> </Fragment>
) );
} }
}; };
...@@ -130,10 +149,8 @@ class FormArray extends Component { ...@@ -130,10 +149,8 @@ class FormArray extends Component {
detailDom = () => { detailDom = () => {
const { config, formValues, readOnly } = this.props; const { config, formValues, readOnly } = this.props;
if(readOnly){
config.readOnly = true;
}
return config.map((x) => { return config.map((x) => {
x.readOnly = readOnly || false;
switch (x.type) { switch (x.type) {
case 'InputItem': case 'InputItem':
return ( return (
...@@ -184,7 +201,7 @@ class FormArray extends Component { ...@@ -184,7 +201,7 @@ class FormArray extends Component {
<List> <List>
{this.detailDom()} {this.detailDom()}
</List> </List>
) );
} }
} }
...@@ -199,8 +216,8 @@ FormArray.defaultProps = { ...@@ -199,8 +216,8 @@ FormArray.defaultProps = {
formValues: {}, formValues: {},
config: [ config: [
{ {
type: 'input' type: 'input',
} },
], ],
changeValue: (value, key) => { changeValue: (value, key) => {
console.log(value, key); console.log(value, key);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论