You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.7 KiB
74 lines
1.7 KiB
import moment from 'moment';
|
|
var dateFormatterMap = {
|
|
time: 'HH:mm:ss',
|
|
timeRange: 'HH:mm:ss',
|
|
date: 'YYYY-MM-DD',
|
|
dateRange: 'YYYY-MM-DD',
|
|
dateTime: 'YYYY-MM-DD HH:mm:ss',
|
|
dateTimeRange: 'YYYY-MM-DD HH:mm:ss'
|
|
};
|
|
/**
|
|
* 根据不同的格式转化 moment
|
|
* @param value
|
|
* @param dateFormatter
|
|
* @param valueType
|
|
*/
|
|
|
|
var conversionMoment = function conversionMoment(value, dateFormatter) {
|
|
var valueType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'dateTime';
|
|
|
|
if (!dateFormatter) {
|
|
return value;
|
|
}
|
|
|
|
if (moment.isMoment(value) && !Array.isArray(value)) {
|
|
if (dateFormatter === 'number') {
|
|
return value.valueOf();
|
|
}
|
|
|
|
return value.format(dateFormatterMap[valueType] || 'YYYY-MM-DD HH:mm:ss');
|
|
}
|
|
|
|
if (Array.isArray(value)) {
|
|
return value.map(function (item) {
|
|
if (moment.isMoment(item)) {
|
|
if (dateFormatter === 'number') {
|
|
return item.valueOf();
|
|
}
|
|
|
|
return item.format(dateFormatterMap[valueType] || 'YYYY-MM-DD HH:mm:ss');
|
|
}
|
|
|
|
return item;
|
|
});
|
|
}
|
|
|
|
return value;
|
|
};
|
|
/**
|
|
* 这里主要是来转化一下数据
|
|
* 将 moment 转化为 string
|
|
* 将 all 默认删除
|
|
* @param value
|
|
* @param dateFormatter
|
|
* @param proColumnsMap
|
|
*/
|
|
|
|
|
|
var conversionSubmitValue = function conversionSubmitValue(value, dateFormatter, valueTypeMap) {
|
|
var tmpValue = {};
|
|
Object.keys(value).forEach(function (key) {
|
|
var valueType = valueTypeMap[key] || 'text';
|
|
var itemValue = value[key];
|
|
|
|
if (!itemValue) {
|
|
return;
|
|
} // 都没命中,原样返回
|
|
|
|
|
|
tmpValue[key] = conversionMoment(itemValue, dateFormatter, valueType);
|
|
});
|
|
return tmpValue;
|
|
};
|
|
|
|
export default conversionSubmitValue; |