@bos-alpha/data
Version:
数据管理
170 lines (169 loc) • 6.63 kB
JavaScript
import moment from 'moment';
var weekTable = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
/**
* 获取计划执行时间
* 一次:年:月:日:时:分:秒
每天:时:分:秒
每周:周一,周二:时:分:秒
每月:日,日:时:分:秒 最后一天L
每年:月,月:日,日:时:分:秒
*/
export var getScheduleParams = function (vals, scheduleType) {
switch (scheduleType) {
case 'once':
return vals.date.format('YYYY:MM:DD:HH:mm:ss');
case 'daily':
return vals.time.format('HH:mm:ss');
case 'weekly':
var weeks = vals.week.sort().join(',');
var weektime = vals.time.format('HH:mm:ss');
return "".concat(weeks, ":").concat(weektime);
case 'monthly':
var days = vals.day.sort().join(',');
var monthtime = vals.time.format('HH:mm:ss');
return "".concat(days, ":").concat(monthtime);
case 'yearly':
var yeardays = vals.day.sort().join(',');
var months = vals.month.sort().join(',');
var yeartime = vals.time.format('HH:mm:ss');
return "".concat(months, ":").concat(yeardays, ":").concat(yeartime);
case 'cycle':
return "".concat(vals.cycleTime);
case 'manual':
return '';
}
};
export var parseScheduleParams = function (scheduleType, scheduleValue) {
switch (scheduleType) {
case 'once':
var dateArr = scheduleValue.split(':').map(function (item, index) {
// 月份 js中需要减1
if (index === 1) {
return Number(item) - 1;
}
return item;
});
return { date: moment(dateArr) };
case 'daily':
return { time: moment(scheduleValue, 'HH:mm:ss') };
case 'weekly':
var week = scheduleValue.split(':').slice(0, 1);
var time = scheduleValue.split(':').slice(1).join(':');
return {
week: week[0].split(',').map(function (item) { return Number(item); }),
time: moment(time, 'HH:mm:ss')
};
case 'monthly':
var day = scheduleValue.split(':').slice(0, 1);
var time2 = scheduleValue.split(':').slice(1).join(':');
return {
day: day[0]
.split(',')
.map(function (item) { return (item === 'L' ? item : Number(item)); }),
time: moment(time2, 'HH:mm:ss')
};
case 'yearly':
var month = scheduleValue.split(':').slice(0, 1);
var day2 = scheduleValue.split(':').slice(1, 2);
var time3 = scheduleValue.split(':').slice(2).join(':');
return {
month: month[0].split(',').map(function (item) { return Number(item); }),
day: day2[0]
.split(',')
.map(function (item) { return (item === 'L' ? item : Number(item)); }),
time: moment(time3, 'HH:mm:ss')
};
case 'minutes':
case 'hours':
return {
cycleTime: scheduleValue,
cycleType: scheduleType
};
case 'manual':
return {};
}
};
export var parseScheduleText = function (scheduleType, scheduleValue) {
switch (scheduleType) {
case 'once':
var dateArr = scheduleValue.split(':').map(function (item, index) {
// 月份 js中需要减1
if (index === 1) {
return Number(item) - 1;
}
return item;
});
return "\u4E00\u6B21 ".concat(moment(dateArr).format('YYYY-MM-DD HH:mm:ss'));
case 'daily':
return "\u6BCF\u5929 ".concat(scheduleValue);
case 'weekly':
var week = scheduleValue
.split(':')
.slice(0, 1)[0]
.split(',')
.map(function (day) { return "".concat(weekTable[day] || day); })
.join('、');
var time = scheduleValue.split(':').slice(1).join(':');
return " \u6BCF\u5468 ".concat(week, " ").concat(time);
case 'monthly':
var day = scheduleValue
.split(':')
.slice(0, 1)[0]
.split(',')
.map(function (item) { return (item === 'L' ? '最后一天' : "".concat(item, "\u53F7")); })
.join('、');
var time2 = scheduleValue.split(':').slice(1).join(':');
return "\u6BCF\u6708 ".concat(day, " ").concat(time2);
case 'yearly':
var month = scheduleValue
.split(':')
.slice(0, 1)[0]
.split(',')
.map(function (item) { return "".concat(item, "\u6708"); })
.join('、');
var day2 = scheduleValue
.split(':')
.slice(1, 2)[0]
.split(',')
.map(function (item) { return (item === 'L' ? '最后一天' : "".concat(item, "\u53F7")); })
.join('、');
var time3 = scheduleValue.split(':').slice(2).join(':');
return "\u6BCF\u5E74 ".concat(month, " ").concat(day2, " ").concat(time3);
case 'minutes':
return "\u6BCF\u9694 ".concat(scheduleValue, " \u5206\u949F");
case 'hours':
return "\u6BCF\u9694 ".concat(scheduleValue, " \u5C0F\u65F6");
case 'manual':
return '';
}
};
export var parseScheduleType = function (scheduleType) {
switch (scheduleType) {
case 'once':
return "\u4E00\u6B21";
case 'daily':
return "\u6BCF\u5929";
case 'weekly':
return " \u6BCF\u5468";
case 'monthly':
return "\u6BCF\u6708";
case 'yearly':
return "\u6BCF\u5E74";
case 'minutes':
return "\u5206\u949F";
case 'hours':
return "\u5C0F\u65F6";
case 'manual':
return '仅手动';
}
};
export var parseSchedule = function (scheduleType, scheduleValue, executor) {
// 执行者为 非系统周期执行 就是用户手动点击执行
// 触发条件为仅手动
if (executor !== '系统' || scheduleType === 'manual') {
return '手动执行';
}
else {
return "\u81EA\u52A8\u89E6\u53D1\uFF08".concat(parseScheduleText(scheduleType, scheduleValue), "\uFF09");
}
};