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

优化代码

上级 36fd0b78
import React, { useMemo } from 'react';
import moment from 'moment';
import { TimePicker } from 'antd';
export default function TimePickerDiy(props) {
const { value, onChange, json } = props;
const otherProps = useMemo(
() => {
if (json?.otherProps) {
let v = json?.otherProps;
try {
return new Function(v)();
} catch (e) {
return {};
}
}
return {};
},
[json],
);
const changeValue = useMemo(
() => {
if (value) {
return moment(value);
} else {
return null;
}
},
[value],
);
const handleChange = (v) => {
if (v) {
onChange(v.format('HH:mm:ss'));
} else {
onChange(null);
}
};
return <TimePicker value={changeValue} onChange={handleChange} {...otherProps} />;
}
...@@ -98,7 +98,6 @@ import { ...@@ -98,7 +98,6 @@ import {
getOptionsApi, getOptionsApi,
} from '../Services/apiConfig'; } from '../Services/apiConfig';
import UploadComReadOnly from '@/webPublic/one_stop_public/libs/Split/UploadComReadOnly'; import UploadComReadOnly from '@/webPublic/one_stop_public/libs/Split/UploadComReadOnly';
import TimePickerDiy from "@/webPublic/one_stop_public/tableCompon/Split_Index/TimePickerDiy";
/** /**
* 日期组件antd3.x有bug 详情见禅道 27152 毕业跟踪调查管理 毕业时间改为年级筛选 * 日期组件antd3.x有bug 详情见禅道 27152 毕业跟踪调查管理 毕业时间改为年级筛选
*/ */
...@@ -1881,17 +1880,6 @@ export default class TableCom extends Component { ...@@ -1881,17 +1880,6 @@ export default class TableCom extends Component {
</span> </span>
); );
break;
case 'TimePicker':
cm = value ? (
<span>
{moment(parseInt(value)).format('HH:mm:ss')}
{get === 'mobile' ? <br /> : ''}
</span>
) : (
''
);
break; break;
case 'DatePicker': case 'DatePicker':
cm = value ? ( cm = value ? (
...@@ -2422,21 +2410,6 @@ ${obj[dataColumn.base52]} ...@@ -2422,21 +2410,6 @@ ${obj[dataColumn.base52]}
} }
title = title ? title : '起止时间'; title = title ? title : '起止时间';
break; break;
case 'TimePicker':
const vTimePicker = obj[dataColumn.base52];
if (vTimePicker && typeof vTimePicker === 'string' ) {
cm = (
<span>
{vTimePicker}
</span>
);
} else {
cm = (
<span></span>
);
}
break;
case 'DatePicker': case 'DatePicker':
const vTime = obj[dataColumn.base52]; const vTime = obj[dataColumn.base52];
if (vTime && typeof vTime === 'string' && vTime.indexOf('-') <= -1) { if (vTime && typeof vTime === 'string' && vTime.indexOf('-') <= -1) {
...@@ -3538,8 +3511,6 @@ ${obj[dataColumn.base52]} ...@@ -3538,8 +3511,6 @@ ${obj[dataColumn.base52]}
} }
break; break;
} }
// console.table('rangePicker', this.props?.form?.getFieldsValue()[begin.base52 + '$' + end.base52]);
console.log(required);
cm = getFieldDecorator(begin.base52 + '$' + end.base52, { cm = getFieldDecorator(begin.base52 + '$' + end.base52, {
initialValue: ivs, initialValue: ivs,
rules: rules:
...@@ -3555,26 +3526,6 @@ ${obj[dataColumn.base52]} ...@@ -3555,26 +3526,6 @@ ${obj[dataColumn.base52]}
} }
if (json.label == null) title = '起止时间'; if (json.label == null) title = '起止时间';
break; break;
case 'TimePicker':
var iv = null;
if (initValue != null) {
iv = initValue;
}
cm = getFieldDecorator(dataColumn.base52, {
initialValue: iv,
rules:
json.vlds && json.vlds.length > 0
? json.vlds
: [
{
required: required,
message: '请选择时间',
},
],
})(
<TimePickerDiy json={json}/>
);
break;
case 'DatePicker': case 'DatePicker':
if (json?.otherProps) { if (json?.otherProps) {
otherProps = json?.otherProps; otherProps = json?.otherProps;
...@@ -3584,7 +3535,7 @@ ${obj[dataColumn.base52]} ...@@ -3584,7 +3535,7 @@ ${obj[dataColumn.base52]}
otherProps = {}; otherProps = {};
} }
} }
const Component = otherProps.mode === 'time' ? TimePicker : DatePicker;
var iv = null; var iv = null;
if (initValue != null) { if (initValue != null) {
iv = moment(typeof initValue === 'string' ? +initValue : initValue); iv = moment(typeof initValue === 'string' ? +initValue : initValue);
...@@ -3602,7 +3553,7 @@ ${obj[dataColumn.base52]} ...@@ -3602,7 +3553,7 @@ ${obj[dataColumn.base52]}
}, },
], ],
})( })(
<DatePicker <Component
disabled={disabled} disabled={disabled}
showTime={json.showTime != null ? json.showTime : true} showTime={json.showTime != null ? json.showTime : true}
getCalendarContainer={getPopupContainer(false, uuid)} getCalendarContainer={getPopupContainer(false, uuid)}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论