heyujie
2021-11-04 50b919f5c8c49573ab3314976434afb01ed79fd6
src/scripts/util.js
@@ -3,10 +3,23 @@
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
}
const guid = () => {
  return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4())
  return (
    S4() +
    S4() +
    '-' +
    S4() +
    '-' +
    S4() +
    '-' +
    S4() +
    '-' +
    S4() +
    S4() +
    S4()
  )
}
/* http 传参方法json2url, json2path, json2formData, */
const json2url = (json) => {
const json2url = json => {
  if (!json) {
    return false
  }
@@ -17,7 +30,7 @@
  var str = arr.join('&')
  return str
}
const json2path = (json) => {
const json2path = json => {
  if (!json) {
    return false
  }
@@ -28,7 +41,8 @@
  var str = arr.join('/')
  return str
}
const json2formData = (json) => { // Content-Type: multipart/form-data;boundary=${bound}  //代表分割符号
const json2formData = json => {
  // Content-Type: multipart/form-data;boundary=${bound}  //代表分割符号
  if (!json) {
    return false
  }
@@ -50,12 +64,14 @@
  return false
}
/* 获取当前路由信息 */
const thisRouterObjFn = (routesArr) => {
const thisRouterObjFn = routesArr => {
  if (!routesArr && !Array.isArray(routesArr)) {
    return false
  }
  let pathArr = []
  let MenuInfo = sessionStorage.getItem('fSDoorwayManagementMenuInfo') && JSON.parse(sessionStorage.getItem('fSDoorwayManagementMenuInfo'))
  let MenuInfo =
    sessionStorage.getItem('fSDoorwayManagementMenuInfo') &&
    JSON.parse(sessionStorage.getItem('fSDoorwayManagementMenuInfo'))
  if (MenuInfo) {
    for (let i = 0; i < routesArr.length; i++) {
      const element = routesArr[i]
@@ -73,7 +89,7 @@
}
// 判断图片是否存在
const isHasImg = (pathImg) => {
const isHasImg = pathImg => {
  var ImgObj = new Image()
  ImgObj.src = pathImg
  if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
@@ -89,7 +105,7 @@
 ***/
const findButtonAuthoritys = (arr, fn) => {
  fn = fn || function () {}
  fn = fn || function() {}
  if (Array.isArray(arr)) {
    for (let iteam of arr) {
      if (iteam.type === 2 && iteam.permission !== '') {
@@ -136,7 +152,7 @@
  return arr
}
// json 是否为空
const isJsonNull = (jsonStr) => {
const isJsonNull = jsonStr => {
  if (typeof jsonStr === 'object' && jsonStr != null) {
    for (let key in jsonStr) {
      if (jsonStr[key]) {
@@ -146,10 +162,10 @@
  }
  return false
}
const cloneDeep = (node) => {
const cloneDeep = node => {
  if (!node) return node
  var newNode = {}
  Object.keys(node).forEach(function (key) {
  Object.keys(node).forEach(function(key) {
    if (key[0] === '_') return
    var val = node[key]
@@ -165,7 +181,7 @@
  })
  return newNode
}
var Week = (function () {
var Week = (function() {
  var ONE_DAY = 24 * 3600 * 1000
  var ONE_WEEK = 7 * ONE_DAY
@@ -183,7 +199,19 @@
    var nextWeekday = formatNumber(nextWeek.getDate() - 1)
    /* 只截取当前年份时间 */
    if (year === nextWeekYear) {
      return year + '-' + month + '-' + day + '~' + nextWeekYear + '-' + nextWeekMonth + '-' + nextWeekday
      return (
        year +
        '-' +
        month +
        '-' +
        day +
        '~' +
        nextWeekYear +
        '-' +
        nextWeekMonth +
        '-' +
        nextWeekday
      )
    } else {
      return year + '-' + month + '-' + day + '~' + year + '-' + month + '-31'
    }
@@ -199,18 +227,18 @@
    this.days = 0
    this.weeks = 0
  }
  Week.prototype.getDays = function () {
  Week.prototype.getDays = function() {
    this.days = Math.ceil((this.nextYear - this.year) / ONE_DAY)
    return Math.ceil((this.nextYear - this.year) / ONE_DAY)
  }
  Week.prototype.getWeeks = function () {
  Week.prototype.getWeeks = function() {
    this.weeks = Math.ceil(this.days || this.getDays() / 7)
    return Math.ceil(this.days || this.getDays() / 7)
  }
  Week.prototype.getSomeWeek = function (num) {
  Week.prototype.getSomeWeek = function(num) {
    return formatDate(new Date(+this.year + ONE_WEEK * num), num)
  }
  Week.prototype.showWeek = function (num) {
  Week.prototype.showWeek = function(num) {
    num = parseInt(num - 1) || 0
    if (!this.weeks) {
      this.getWeeks()
@@ -222,8 +250,7 @@
      return this.getSomeWeek(num)
    } else {
      var arr = []
      while (num <
        this.weeks) {
      while (num < this.weeks) {
        arr.push(this.getSomeWeek(num))
        num++
      }
@@ -250,20 +277,46 @@
}
//拆分二维数组
const chunkArr = (arr, size = 1)=>{
  if (arr.length == 0) return;
  const tempContainer = [];
  let innerArr = [];
const chunkArr = (arr, size = 1) => {
  if (arr.length == 0) return
  const tempContainer = []
  let innerArr = []
  arr.forEach(item => {
    if (innerArr.length == 0) {
      tempContainer.push(innerArr);
      tempContainer.push(innerArr)
    }
    innerArr.push(item);
    innerArr.push(item)
    if (innerArr.length == size) {
      innerArr = [];
      innerArr = []
    }
  });
  return tempContainer;
  })
  return tempContainer
}
const numberFormat = (nums, retain) => {
  var num
  var result = ''
  var dot = ''
  var minus = ''
  if (nums || Number(nums) === 0) {
    num = (nums * 1).toFixed(retain).toString()
    if (num.indexOf('-') > -1) {
      minus = '-'
      num = num.split('-')[1]
    }
    if (num.indexOf('.') > -1) {
      var newnum = num.split('.')
      num = newnum[0]
      dot = newnum[1]
    }
    while (num.length > 3) {
      result = ',' + num.slice(-3) + result
      num = num.slice(0, num.length - 3)
    }
    if (num) {
      result = retain ? minus + num + result + '.' + dot : minus + num + result
    }
  }
  return result
}
export {
  thisRouterObjFn,
@@ -281,5 +334,6 @@
  cloneDeep,
  getYearWeek,
  getContainerRect,
  chunkArr
  chunkArr,
  numberFormat
}