Project development process, some of the commonly used methods

Some of the commonly used method of packaging in the development process, by reference 
// get the current time instant
// type = 1 date, type = 2 minutes and seconds, fommatter = "-" indicates date daily - separated, or by a "/" spaced 
Export function curTimeFun (type, fommatter) { 
  const = new new myDate a Date (); 
  ? = const year myDate.getFullYear ()>. 9 myDate.getFullYear (): '0' + myDate.getFullYear (); 
  ? = const month The (myDate.getMonth () +. 1)> myDate.getMonth. 9 () . 1 +: '0' + (myDate.getMonth () +. 1); 
  const = myDate.getDate DATE ()>. 9 myDate.getDate ():? '0' + myDate.getDate (); 
  const = H myDate.getHours ? ()> 9 myDate.getHours () : '0' + myDate.getHours (); // get the current number (0-23) hours 
  const m = myDate.getMinutes ()> 9 myDate.getMinutes (): '? 0 '+ myDate.getMinutes (); // get the current number (0-59) minutes 
  const s = myDate.getSeconds ()> 9 myDate.getSeconds ():?' 0 '+ myDate.getSeconds ();
  let nowTime = "";
  if(type == '1'){
    if(fommatter == '-') {
      nowTime = year + '-' + month + "-" + date;
    } else {
      nowTime = year + '/' + month + "/" + date;
    }
  } else if(type == '2'){
    nowTime = h + ':' + m + ":" + s;
  } else {
    if(fommatter == '-') {
      nowTime = year + '-' + month + "-" + date + " " + h + ':' + m + ":" + s;
    } else {
      nowTime = year + '/' + month + "/" + date + " " + h + ':' + m + ":" + s;
    }
  }
  return nowTime;
}

  

// I Get What day am today
getWeekFun function Export () { 
  const WEEKDAY = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] 
  the let Week = new new a Date (). getDay () ; 
  return WEEKDAY [Week]; 
}

  

// Query n recent years, n represents the number of years before the meaning 
// example query nearly 5 years, n = 4, not including this year's first four years
export function getLastNYear(n) {
  const myDate = new Date;
  const curYear = myDate.getFullYear();
  if(n =='' || n==undefined || n == null){
    n =0;
  }
  let rstYear = curYear*1 - n*1;
  return rstYear;
}

  

// Query n recent months, n represents the number of months before the meaning of
getLastNMonth function Export (n-) { 
  const = new new myDate a Date; 
  const curYear myDate.getFullYear = (); 
  const myDate.getMonth curmonth = () +. 1; // January counting from zero. Need to add. 1 
  IF (n-== '' || || n-n-== undefined == null) {n-= 0;} 
  the let rstYear = ''; 
  the let rstMonth = ''; 
  IF (n-> curmonth) {// to represent the last month, year to year need to 
    rstYear 1-1 of * * = curYear. 1; 
    rstMonth = 12- (n--curmonth) + 1'd; 
  } the else { 
    rstYear = curYear; 
    rstMonth = -n curmonth; 
  } 
  = rstMonth (rstMonth)> rstMonth. 9: '0' + (rstMonth);? 
  the let rstYearMonth = rstYear + '-' + rstMonth; 
  return rstYearMonth; 
}

 

 

// Get the most recent n days, n represents the number of days before the mean. 
// example query nearly seven days, n = 6, not including the day before the six days
export function getLastNDate(n,fommatter) {
  const d = new Date();
  var myDate=new Date(d.getTime()-86400000*n);  // 获取前n天的日期
  const year = myDate.getFullYear()>9?myDate.getFullYear():'0'+myDate.getFullYear();
  const month = (myDate.getMonth() + 1)>9?myDate.getMonth() + 1:'0'+(myDate.getMonth() + 1);
  const date = myDate.getDate()>9?myDate.getDate():'0'+myDate.getDate();
  let last7Date = '';
  if(fommatter == '-') {
    last7Date = year + '-' + month + "-" + date;
  } else {
    last7Date = year + '/' + month + "/" + date;
  }
  return last7Date;
}

  

// Get the most recent n hours, n represents the number of hours before the mean.
export function getLastNHour(n,fommatter) {
  const d = new Date();
  var myDate=new Date(d.getTime()-86400000*n);  // 获取前n天的日期
  const year = myDate.getFullYear()>9?myDate.getFullYear():'0'+myDate.getFullYear();
  const month = (myDate.getMonth() + 1)>9?myDate.getMonth() + 1:'0'+(myDate.getMonth() + 1);
  const date = myDate.getDate()>9?myDate.getDate():'0'+myDate.getDate();
  const h = myDate.getHours()>9?myDate.getHours():'0'+myDate.getHours();       //获取当前小时数(0-23)
  const m = myDate.getMinutes()>9?myDate.getMinutes():'0'+myDate.getMinutes();     //获取当前分钟数(0-59)
  const s = myDate.getSeconds()>9?myDate.getSeconds():'0'+myDate.getSeconds();
  let nowTime = "";
  if(fommatter == '-') {
    nowTime = year + '-' + month + "-" + date + " " + h + ':' + m + ":" + s;
  } else {
    nowTime = year + '/' + month + "/" + date + " " + h + ':' + m + ":" + s;
  }
  return nowTime;
}

  

/ * Menu tree drop prohibit choose the current item and its children, in order to prevent infinite loop * /
export function diGuiTreeEdit(item,compID) {  // 编辑情况下,禁止选择当前节点及其子节点
  let data = item;
  let treeAry = [];
  for (let i in data) {
    let v = data[i];
    let node = {};
    if (v === null || v === undefined) {}
    else {
      if (v.children && v.children.length > 0) {
        if (v.id == compID) {
          node.isDisabled = true;
        } else {
          node.isDisabled = false;
        }
        node.id = v.id;
        node.label = v.label;
        node.name = v.name;
        node.children = diGuiTreeEdit(v.children, compID);
        treeAry.push(node);
      } else {
        if (v.id == compID) {
          node.isDisabled = true;
        } else {
          node.isDisabled = false;
        }
        node.id = v.id;
        node.label = v.label;
        node.name = v.name;
        treeAry.push(node);
      }
    }
  }
  return treeAry;
};

  

// determines whether the data is empty, return the value specified is empty, the
export function isNullORFalse(checkVal,rstVal) {
  if(checkVal == '' || checkVal == null || checkVal == undefined || typeof(checkVal) == undefined){
    if(rstVal == null || rstVal == ''){
      rstVal = "";
    }
    return rstVal;
  } else {
    return checkVal;
  }
}

  

// Replace All
// str represents the original string, s represents the contents to be replaced, replaceStr alternative content for 
Export function repalceAll (STR, s, replaceStr = '') { 
  var the RegExp new new REG = (S, "G") // g, represents replace all 
  return str.replace (REG, ReplaceStr) 
}

  

// number of days difference between two dates function, general time format of yyyy-MM-dd format
export function dateDiff (sDate1, sDate2) {// sDate1 are sDate2 and yyyy-MM-dd format 
  the let aDATE, oDate1, oDate2, iDays 
  aDATE = sDate1.split ( "-") 
  oDate1 new new = a Date (aDATE [. 1] + ' - '+ aDate [2] + ' - '+ aDate [0]) // convert yyyy-MM-dd format 
  aDATE = sDate2.split ( "-") 
  oDate2 new new = a Date (aDATE [. 1] +' - ' aDATE + [2] + '-' + aDATE [0]) 
  iDays = the parseInt (the Math.abs (oDate1 - oDate2) / 1000/60/60/24) // converts the difference between the number of milliseconds to several days 
  return iDays; / / returns the number of days difference 
}

  

// when the value is too large is that more than 9 digits (million) million Units into show
rspHundredMill function Export (Val, Unit = 'HM') { 
  IF (Unit == 'HM') { 
    IF (Val> 100000000) {// is greater than 100 million 
      return (val / 100000000) .toFixed ( 3) + ' one hundred million' 
    the else {} 
      return Val 
    } 
  } 
}

  

// According to id, and the value of the id, the object traversing the list, drawn label
export function rstLabelFormID(list, id, label, idVal) {
  let rsp = ''
  for (let i = 0; i < list.length; i++) {
    if (list[i][id] === idVal) {
      rsp = list[i][label]
      break
    }
  }
  return rsp
}

  

// The id, and the id value, traversal list set corresponding object obtained
export function rstListFormID(list, id, idVal) {
  let rsp = undefined
  for (let i = 0; i < list.length; i++) {
    if (list[i][id] === idVal) {
      rsp = list[i]
      break
    }
  }
  return rsp
}

  

// Object deep copy
export function deepCopy(obj) {
  var result = Array.isArray(obj) ? [] : {}
  for (var key in obj) {
    if (obj.hasOwnProperty(key)) {
      if (typeof obj[key] === 'object' && obj[key] !== null) {
        result[key] = deepCopy(obj[key])
      } else {
        result[key] = obj[key]
      }
    }
  }
  return result
}

  

// div drag to adjust the width of the left and right sides
// resizeName expressed drag the toolbar className 
// className left represents the area on the left. leftWid represents a minimum width of the left 
// midName className represents the right region. rightWid represents a minimum width of the right 
// boxName represents className parent element of 
export function dragControllerDiv (resizeName = 'resize ', leftName = 'left', midName = 'mid', boxName = 'box', leftWid = 250, rightWid = 800 ) { 
  var = a resize document.getElementsByClassName (resizeName); 
  var left = document.getElementsByClassName (leftName); 
  var = MID document.getElementsByClassName (midName); 
  var = document.getElementsByClassName Box (boxName); 
  for (the let I = 0; I <resize.length; I ++) { 
    // mouse down event 
    a resize [I] .onmousedown = function (E) { 
      var startX = e.clientX;
      a resize [I] .left = a resize [I] .offsetLeft; 
      // mouse drag event 
      document.onmousemove = function (E) { 
        var = endX, e.clientX; 
        var = a resize moveLen [I] .left + (endX, - startX ); // (endx-startx) = distance moved. resize [i] .left + Final width = distance moved left area 
        var maxT = box [i] .clientWidth - resize [i] .offsetWidth; // container Width - width of the left area of the right area = 

        if (moveLen < leftWid) moveLen = leftWid; // minimum width of the left region is by 150px 
        IF (moveLen> maxT - rightWid) moveLen = maxT - rightWid; // minimum width of the right area 800px 

        a resize [I] = .style.left moveLen; // the width of the left area provided 

        for (the let J = 0; J <left.length; J ++) { 
          left [J] = moveLen through .style.width, + 'PX';
          MID [J] through .style.width, = (Box [I] .clientWidth - moveLen - 10) + 'PX'; 
        } 
      } 
      // mouse release event 
      document.onmouseup = function (EVT) { 
        document.onmousemove = null; 
        Document = null .onmouseup; 
        of a resize [i] && .releaseCapture of a resize [i] .releaseCapture (); // when you do not need to continue to get the mouse message and it should call ReleaseCapture () freed 
      } 
      of a resize [i] && .setCapture of a resize [ i] .setCapture (); // this function sets the mouse capture the specified window belonging to the current thread's 
      return to false; 
    } 
  } 
}

  






Guess you like

Origin www.cnblogs.com/luoxuemei/p/11646108.html