Vue (utils.js) is the encapsulation of common methods. The following is the collection of some public methods that I think may be used in VUE. I will continue to add the methods ENCOUNTERED in the later development process or browse the better methods:

/* * Verify whether the mobile phone number is qualified */
export function isPhone(phoneStr) {
  let myreg = ,4,5,7,8,9 / ^ [1] [3] [0-9] {9} $/;
  if(! myreg.test(phoneStr)) {return false;
  } else {
    return true; }}/* * Verify that the id number is qualified * true-- indicates that the id number is qualified */
export function isIdCard(idCardStr) {
  let idcardReg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0 -9]|X)$/;
  if (idcardReg.test(idCardStr)) {
    return true;
  } else {
    return false; }}/** * Verify whether the license plate number is qualified * true-- indicate qualified */
export function isVehicleNumber(vehicleNumber) {
  let xreg = / ^ [beijing-tianjin Shanghai yu ji yu cloud liao black xiang anhui new GuiGan of hubei province can Sue your yue jin meng shan ji min qinghai-tibet plain NingQiong that brought A - Z] {1} {1} [a-z] ([[0-9] {5} [DF] $) | ([DF] [A - HJ - NP - Z0-9] [0-9] {4} $)) /;
  let creg = / ^ [beijing-tianjin Shanghai yu ji yu cloud liao black xiang anhui new GuiGan of hubei province can Sue your yue jin meng shan ji min qinghai-tibet plain NingQiong that brought A - Z] {1} {1} [a-z] [A - HJ - NP - Z0-9] {4} [A - HJ - NP - Z0-9 hang cop Hong Kong and Macao] {1} $/;
  if (vehicleNumber.length == 7) {
    return creg.test(vehicleNumber);
  } else if (vehicleNumber.length == 8) {
    return xreg.test(vehicleNumber);
  } else {
    return false; }}/* * Verify that the string is empty (also cannot be blank) * true-- indicates that it is empty, false-- indicates that it is not empty */
export function isEmptyString(string) {
  if (
    string= =undefined ||
    typeof string= ='undefined' ||
    !string ||
    string= =null ||
    string= =' ' ||
    /^\s+$/gi.test(string)) {return true;
  } else {
    return false; }}/* * Birthday to age (exact month) */
export function birsdayToAge(birsday) {
  let aDate = new Date(a);let thisYear = aDate.getFullYear();
  let bDate = new Date(birsday);
  let brith = bDate.getFullYear();
  let age = thisYear - brith;
  if (aDate.getMonth() == bDate.getMonth()) {
    if (aDate.getDate() < bDate.getDate()) {
      age = age - 1; }}else {
    if (aDate.getMonth() < bDate.getMonth()) {
      age = age - 1; }}return age;
}

/** * Determine the data type *@param {any} val- Basic or reference type data *@return {string} - The possible results are all lowercase characters * number, Boolean, string, NULL, undefined, array, object, and function */
export function getType(val){
  // Determine if the data is null or undefined
  if (val == null) {
    return val + "";
  }
  return typeof(val) === "object" ?
      Object.prototype.toString.call(val).slice(8, -1).toLowerCase() :
      typeof(val);
}

/* * Verify whether the number is */
export function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

/* * Whether it is an array */
export function isArray(obj) {
  return Object.prototype.toString.call(obj) === '[object Array]';
}

/* * Is an empty array */
export function isArrayEmpty(val) {
  if (val && val instanceof Array && val.length > 0) {
    return false;
  } else {
    return true; }}/* * Get the URL parameter string * Does not return null */
export function getQueryString(name) {
  let reg = new RegExp('(^ | &)' + name + '= (/ ^ & *) (& | $)'.'i');
  let r = window.location.search.substr(1).match(reg);
  if(r ! =null) {
    return unescape(r[2]);
  }
  return null;
}

/* * Recursive deep copy */
export function deepCopy(obj) {
  let result = Array.isArray(obj) ? [] : {};
  for (let 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;
}

/** * Remove parameter null data (used when passing parameters to background) *@param {Object} Obj [Parameter object] */
export function filterEmptyData(obj) {
  for (let prop in obj) {
    obj[prop] === ' ' ? delete obj[prop] : obj[prop];
  }
  return obj;
}

/ * * *@desc  Function to change multiple executions to the last *@param {function} func- The executed function that requires function stabilization. Will pass *@param {Number} wait- How many milliseconds to trigger, only the first time to execute, default 1000ms. You don't have to send */
export function debounce(fn, delay) {
  delay = delay || 1000; // The default value is 1s
  let timer = null;
  return function () {
    let context = this;
    let arg = arguments;
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(() = > {
      fn.apply(context, arg);
    }, delay);
  };
}

/** * Throttling function, used to change multiple executions into periodic executions@param Action * triggered by the fn event@param Delay Specifies the number of milliseconds between which an event is triggered */
export function throttle2(fn, delay) {
  let timer = null;
  return function () {
    let context = this;
    let args = arguments;
    if(! timer) { timer =setTimeout(function () {
        fn.apply(context, args);
        clearTimeout(timer); }, delay); }}; }// Round (n decimal places)
  export function round (number, n) {
    n = n ? parseInt(n) : 0
    if (n <= 0) return Math.round(number)
    number = Math.round(number * Math.pow(10, n)) / Math.pow(10, n)
    return number
}

/** * Digital amount to text function **@export
 * @param {*} money
 * @returns* /
export function convertCurrency(money) {
  // The number of Chinese characters
  var cnNums = new Array('zero'.'one'.'. '.'叁'.'boss'.'wu'.'land'.'pure'.'捌'.'nine');
  // Basic units
  var cnIntRadice = new Array(' '.'pick up'.'or'.'仟');
  // The corresponding integer part extends the unit
  var cnIntUnits = new Array(' '.'万'.'亿'.'兆');
  // Corresponds to decimal units
  var cnDecUnits = new Array('Angle'.'points'.'nano'.'li');
  // The character following the integer amount
  var cnInteger = 'the whole';
  // The unit after the integer
  var cnIntLast = '元';
  // The number of maximum processing
  var maxNum = 999999999999999.9999;
  // The value is an integer
  var integerNum;
  // The amount is the decimal part
  var decimalNum;
  // The output value string in Chinese
  var chineseStr = ' ';
  // Separate the amount after the array used, predefined
  var parts;
  if (money == ' ') {
    return ' ';
  }
  money = parseFloat(money);
  if (money >= maxNum) {
    // Exceed maximum processing number
    return ' ';
  }
  if (money == 0) {
    chineseStr = cnNums[0] + cnIntLast + cnInteger;
    return chineseStr;
  }
  // Convert to a string
  money = money.toString();
  if (money.indexOf('. ') = = -1) {
    integerNum = money;
    decimalNum = ' ';
  } else {
    parts = money.split('. ');
    integerNum = parts[0];
    decimalNum = parts[1].substr(0.4);
  }
  // Get the integral part of the conversion
  if (parseInt(integerNum, 10) > 0) {
    var zeroCount = 0;
    var IntLen = integerNum.length;
    for (var i = 0; i < IntLen; i++) {
      var n = integerNum.substr(i, 1);
      var p = IntLen - i - 1;
      var q = p / 4;
      var m = p % 4;
      if (n == '0') {
        zeroCount++;
      } else {
        if (zeroCount > 0) {
          chineseStr += cnNums[0];
        }
        / / to zero
        zeroCount = 0;
        chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
      }
      if (m == 0 && zeroCount < 4) {
        chineseStr += cnIntUnits[q];
      }
    }
    chineseStr += cnIntLast;
  }
  // The fractional part
  if(decimalNum ! =' ') {
    var decLen = decimalNum.length;
    for (var i = 0; i < decLen; i++) {
      var n = decimalNum.substr(i, 1);
      if(n ! ='0') {
        chineseStr += cnNums[Number(n)] + cnDecUnits[i]; }}}if (chineseStr == ' ') {
    chineseStr += cnNums[0] + cnIntLast + cnInteger;
  } else if (decimalNum == ' ') {
    chineseStr += cnInteger;
  }
  return chineseStr;
}


Example: 2020-06-10 * days Indicates the number of days to be added. Example: 30 * return Indicates the number of days to be added */
export function addDate(date, days) {
  var d = new Date(date);
  d.setDate(d.getDate() + days);
  var month = d.getMonth() + 1;
  var day = d.getDate();
  if (month < 10) {
    month = "0" + month;
  }
  if (day < 10) {
    day = "0" + day;
  }
  var val = d.getFullYear() + "-" + month + "-" + day;
  return val;
}

/* * Add a comma (* */) to every thousand digits
export function commafy(num) {
  return num && num.toString()
    .replace(/\d+/.function(s){
         return s.replace(/(\d)(? =(\d{3})+$)/g.'$1')})}/* * Number complement * numberPad The number complement is 0. The default value is 2 */
export function numberPad(source, length = 2) {
  let pre = ' '
  const negative = source < 0
  const string = String(Math.abs(source))
  if (string.length < length) {
    pre = (new Array(length - string.length + 1)).join('0')}return (negative ? The '-' : ' ') + pre + string
}

/* * random number * */
export function numberRandom (min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min)
}
/* * The middle four digits of the mobile phone number hide the flower number (*) and display * */
export function hideMobile(mobile) {
  return mobile.replace(/^(\d{3})\d{4}(\d{4})$/."$1 * * * * $2")}/** * Removes the string space *@param The string * to be processed by STR@param Type 1: all Spaces 2: Spaces before and after 3: Spaces before 4: Spaces after */
export function strTrim(str, type) {
        switch (type) {
            case 1:
                return str.replace(/\s+/g."");
            case 2:
                return str.replace(/(^\s*)|(\s*$)/g."");
            case 3:
                return str.replace(/(^\s*)/g."");
            case 4:
                return str.replace(/(\s*$)/g."");
            default:
                returnstr; }},/** * Case switch *@param The string * to be processed by STR@param Type 1: uppercase first letter 2: Lowercase first letter 3: case conversion 4: all uppercase 5: all lowercase */
export function strChangeCase(str, type) {
        function ToggleCase(str) {
            var itemText = ""
            str.split("").forEach(
                function (item) {
                    if (/^([a-z]+)/.test(item)) {
                        itemText += item.toUpperCase();
                    } else if (/^([A-Z]+)/.test(item)) {
                        itemText += item.toLowerCase();
                    } else{ itemText += item; }});return itemText;
        }

        switch (type) {
            case 1:
                return str.replace(/^(\w)(\w+)/.function (v, v1, v2) {
                    return v1.toUpperCase() + v2.toLowerCase();
                });
            case 2:
                return str.replace(/^(\w)(\w+)/.function (v, v1, v2) {
                    return v1.toLowerCase() + v2.toUpperCase();
                });
            case 3:
                return ToggleCase(str);
            case 4:
                return str.toUpperCase();
            case 5:
                return str.toLowerCase();
            default:
                returnstr; }},/** * Check password strength *@param STR string *@returns 1: weak password 2: medium password 3: strong password 4: strong password */
   export function checkPwd(str) {
        var nowLv = 0;
        if (str.length < 6) {
            return nowLv
        };
        if (/ [0-9].test(str)) {
            nowLv++
        };
        if (/[a-z]/.test(str)) {
            nowLv++
        };
        if (/[A-Z]/.test(str)) {
            nowLv++
        };
        return nowLv;
    },

        /** * return a number in a range of values. You can pass only one, returning some value between 0 and the number passed in@param N1 Start interval Example: 5 x@param N2 End interval example: 10 x@returns Returns a random value */ for this interval
    export const randomNumber(n1, n2) {
        if (arguments.length === 2) {
            return Math.round(n1 + Math.random() * (n2 - n1));
        } else if (arguments.length === 1) {
            return Math.round(Math.random() * n1)
        } else {
            return Math.round(Math.random() * 255)}},/** * randomly generate a color *@returns {String} Color example: RGB (250,82,49) */
        //randomNumber is the function defined above
export function randomColor() {
    return 'rgb(' + this.randomNumber(255) + ', ' this.randomNumber(255) + ', ' + this.randomNumber(255) + ') ';
    },

        /** * Simple array sort, for array of numbers *@param Type 1: descending, 0: ascending */
export function sortArr(arr, type) {
        if (type= =1) {
            / / descending
            arr.sort(function (a, b) {
                return b - a;
            });
        } else {
            arr.sort(function (a, b) {
                return a - b;
            });
        }
        return arr;
    },


/** * Full-screen browser */

export function reqFullScreen(){

if (document.documentElement.requestFullScreen) {

document.documentElement.requestFullScreen();

} else if (document.documentElement.webkitRequestFullScreen) {

document.documentElement.webkitRequestFullScreen();

} else if (document.documentElement.mozRequestFullScreen) {

document.documentElement.mozRequestFullScreen(); }};/** * Exit full screen */

export function exitFullScreen = () = >{

if (document.documentElement.requestFullScreen) {

document.exitFullScreen();

} else if (document.documentElement.webkitRequestFullScreen) {

document.webkitCancelFullScreen();

} else if (document.documentElement.mozRequestFullScreen) {

document.mozCancelFullScreen(); }};Encryption / * * * /
  export function encrypt (word) {
    let encrypted = CryptoJS.AES.encrypt(word.toString(), key,/ / AES encryption
      {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7   Pkcs5 is used in the background and Pkcs7 is used in the foreground
      })
    return encrypted.toString()
  },
  Decryption / * * * /
  export function decrypt (word) {
    let decrypted = CryptoJS.AES.decrypt(word, key,/ / AES decryption
      {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
      })
    return CryptoJS.enc.Utf8.stringify(decrypted)
  },
  /** Parameter encryption */
  export function paramsEncrypt (params = {}) {
    for (let prop in params) {
      if(params[prop] ! =null) {
        params[prop] = this.encrypt(params[prop])
      }
    }
  },
  /** File download */
  export function downLoad(way,url,name,type){
    var token = sessionStorage.getItem("account.token") | |"";
    var xhr = new XMLHttpRequest();
    xhr.open(way, url, true);
    xhr.responseType = "blob";
    xhr.setRequestHeader("Authorization"."Bearer " + token);
    xhr.onload = function () {
      if (this.status === 200) {
        var blob = this.response;
        var reader = new FileReader();
        reader.readAsDataURL(blob); // Convert to base64, which can be directly inserted into the a tag href
        reader.onload = function (e) {
          var a = document.createElement("a"); // When the conversion is complete, create an A tag for download
          a.download = name + type;
          a.href = e.target.result;
          $("body").append(a); // Fix an inability to trigger click in Firefoxa.click(); $(a).remove(); }; }}; xhr.send();// Send the Ajax request
  }

  / / id name
  findOrgIdToName(arr,orgid,_name){
    arr.forEach(item= > {
      if (item.orgid == orgid) {
        _name = item.orgname;
      } else{
        if (item.children && item.children.length) {
          const p = this.findOrgIdToName(item.children, orgid);
          if(p) _name = p; }}});return _name;
  },
Copy the code