123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //时间格式化
- var formatTime = function (date) {
- var date = getDate(date)
- var year = date.getFullYear()
- var month = date.getMonth() + 1
- var day = date.getDate()
- var hour = date.getHours()
- var minute = date.getMinutes()
- var second = date.getSeconds()
- return [year, month, day].map(formatNumber).join('-')
- }
- var formatNumber = function (n) {
- n = n.toString()
- return n[1] ? n : '0' + n
- }
- // + ' ' + [hour, minute, second].map(formatNumber).join(':')
- //年月日时分
- var formatDate = function (date) {
- var date = getDate(date)
- var year = date.getFullYear()
- var month = date.getMonth() + 1
- var day = date.getDate()
- var hour = date.getHours()
- var minute = date.getMinutes()
- var second = date.getSeconds()
- return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
- }
- //时分格式化
- var formatDateSF = function (date) {
- var date = getDate(date)
- var year = date.getFullYear()
- var month = date.getMonth() + 1
- var day = date.getDate()
- var hour = date.getHours()
- var minute = date.getMinutes()
- var second = date.getSeconds()
- return [hour, minute].map(formatNumber).join(':')
- }
- var numToReg = function (val) {
- return val.replace(getRegExp('[0-9]', 'g'), '*')
- }
- //截取返回时间到分钟
- var sliceFun = function (val) {
- return val.slice(0, 5)
- }
- //正则-逗号
- var regD = function (val) {
- return val.replace(getRegExp('[,]', 'g'), ' ')
- }
- var interceptStart = function (text) {
- var str = text.substr(1, 3).replace(str, "**");
- return str
- }
- function defineIndexOf(str, val) {
- return str.indexOf(val);
- }
- function includeItem(arr, week, val) {
- // let arrItem=arr.filter(item=>{return item.week==week});
- // let isInclude=arrItem.some(item=>{return item.time==val});
- // return isInclude;
- var length = arr.length;
- var timeList = [];
- for (var i = 0; i < length; i++) {
- if (arr[i].week == week) {
- timeList.push(arr[i]);
- }
- }
- var len2 = timeList.length;
- var isInclude = false;
- for (var j = 0; j < len2; j++) {
- if (timeList[j].time == val) {
- isInclude = true;
- break;
- }
- }
- return isInclude;
- }
- function serviceModel(type) {
- var modelText = '';
- switch (type) {
- case '1':
- modelText = '钟点工';
- break;
- case '2':
- modelText = '白班保姆';
- break;
- case '3':
- modelText = '住家保姆';
- break;
- case '4':
- modelText = '月嫂';
- break;
- case '5':
- modelText = '代班保姆-钟点工';
- break;
- case '6':
- modelText = '代班保姆-保姆';
- break;
- default:
- modelText = '';
- }
- return modelText;
- }
- module.exports = {
- formatTime: formatTime,
- formatNumber: formatNumber,
- formatDate: formatDate,
- sliceFun: sliceFun,
- numToReg: numToReg,
- regD: regD,
- defineIndexOf: defineIndexOf,
- includeItem: includeItem,
- serviceModel:serviceModel
- }
- // 截取文字*号代替
|