## Global

### Members

#### constant formatConfig

  UnitFormat默认配置项 decimal：2 保留小数两位 isMinUintFloor：true 是否最小单位向下取整

#### constant 单位_Units

  对外公开单位常量，包含单位名称以及单位体量 同类型单位标记为x_units:[a,b,...],数组对象为对应单位对象名称，按单位体量从小到大排序 单位对象标记为x:{key:'x',name:'X',carryIndex:i,decimal:j,type:'x_units'}其中： key:单位标示符，和单位对象同名 name:单位显示值 carryIndex:同组单位体量指数固有系数，应为连续整数 carry:单位体量指数常量，可理解为单位进制转换为10的decimal次幂 type：单位所属同类单位组对象名称

#### constant 常量_RANGE_TYPE :object

  时间段标识

  - 配合getServerCurrentTime方法使用
  1. RANGE_TYPE.LAST_ONE_HOUR 最近一个小时
  2. RANGE_TYPE.LAST_HALF_HOUR 最近半小时
  3. RANGE_TYPE.LAST_SIX_HOUR 最近六个小时
  4. RANGE_TYPE.LAST_FOUR_HOUR 最近四个小时
  5. RANGE_TYPE.LAST_ONE_DAY 最近1天
  6. RANGE_TYPE.LAST_SEVEN_DAY 最近七天

### Methods

#### static arrayGroupBy(key, data) → {object}

  对数组进行分组，分组后的对象

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `key` | string | 分组属性.
  `data` | array | 数组数据。

  ##### Returns:

  object -

  {"fieldName":[{...}],...}

  Author:
    - hht

  ##### Examples

      example 01
      --------------------------------------------------------------------------
      import { arrayGroupBy } from "@riil-frontend/utils";
      const array =  [
       {
         type: 'assets',
         name: 'zhangsan',
         age: '33',
       },
       {
         type: 'config',
         name: 'a',
         age: '13',
       },
       {
         type: 'run',
         name: 'lisi',
         age: '3',
       },
       {
         type: 'xx',
         name: 'timo',
         age: '4',
       },
      ];
      arrayGroupBy(array,'type',);

      result:{
         assets: [{ age: '33', name: 'zhangsan', type: 'assets' }],
         config: [{ age: '13', name: 'a', type: 'config' }],
         run: [{ age: '3', name: 'lisi', type: 'run' }],
         xx: [{ age: '4', name: 'timo', type: 'xx' }],
       };

      example 02 null
      --------------------------------------------------------------------------
      const array = null;
      arrayGroupBy(array,"type");

      result:{}

      example 03 key undefind
      --------------------------------------------------------------------------
      const array =  [
       {
         type: 'assets',
         name: 'zhangsan',
         age: '33',
       },
       {
         type: 'config',
         name: 'a',
         age: '13',
       },
       {
         type: 'run',
         name: 'lisi',
         age: '3',
       },
       {
         type: 'xx',
         name: 'timo',
         age: '4',
       },
      ];
      arrayGroupBy(array,"xx");

      result:{}

#### static arrayToTree(array, option) → {object}

  将平行数组转换为树形结构

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `array` |  | 数据集合

  `option`

  Object

  参数配置.

  ###### Properties

  Name | Type | Description
  --- | --- | ---
  `parentFiled` | string | 父级指向字段标识，默认值'parent'。
  `keyFiled` | string | 唯一标识字段标识,默认值'id'。
  `childFiled` | string | 树形结构的子字段，默认值'children'。
  `returnType` | string | 返回数据类型 支持tree和object，默认值'tree'。
  `isDeep` | string | 是否深拷贝，默认值false。 等价 'parent'

  ##### Returns:

  object -

  树形结构

  Author:
    - libo

  ##### Examples

      example 01 默认使用
      --------------------------------------------------------------------------
      import { arrayToTree } from "@riil-frontend/utils";
      const array = [
          { id: 1, value: 1, parent: null },
          { id: 2, value: 2, parent: 1 }
      ];
      arrayToTree(array);
      // result
      [
        {
          "id": 1,
          "value": 1,
          "parent": null,
          "children": [
            {
              "id": 2,
              "value": 2,
              "parent": 1,
              "children": []
            }
          ]
        }
      ]

      example 02 返回对象格式 便捷获取某个节点数据的及所有子数据
      --------------------------------------------------------------------------
      const array = [
          { id: 1, value: 1, parent: null },
          { id: 2, value: 2, parent: 1 }
      ];
      arrayToTree(array,{returnType:'object'});

      // result
      {
        "1": {
          "id": 1,
          "value": 1,
          "parent": null,
          "children": [
            {
              "id": 2,
              "value": 2,
              "parent": 1,
              "children": []
            }
          ]
        },
        "2": {
          "id": 2,
          "value": 2,
          "parent": 1,
          "children": []
        }
      }

#### createObj(key, value) → {object}

  [createObj 创建对象]

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `key` | string | [对象的属性名] 嵌套属性key用'.'来间隔
  `value` | string | [对应属性值]

  ##### Returns:

  object -

  [创建新对象]

#### static debounce(func, delay, immediate) → {func}

  函数防抖：将几次操作合并为一次操作进行。原理是维护一个计时器，规定在delay时间后触发函数， 但是在delay时间内再次触发的话，就会取消之前的计时器而重新设置。这样一来，只有最后一次操作能被触发。

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `func` | * | 被防抖函数
  `delay` | * | 等待的时间(ms)
  `immediate` | * | true表示立即执行然后再等待，false表示进入等待，达到条件再触发

  ##### Returns:

  func -

  func's result

  ##### Example

      --------------------------------------------------------------------------
      import {debounce} from '@riil-frontend/utils';
      debounce(func, 1000，true);
      debounce(func, 1000);

#### static deep(obj) → {object}

  深度拷贝对象

  - 在JS中对应引用在很多场景下会出现问题，因为引用对象改变值后，所有使用该对象处都发生了变化(这往往不是想要的)。
  - 深度拷贝后的对象，与原来的对象不存在引用同一个地址情况。

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `obj` | object | 需要深度拷贝的对象

  ##### Returns:

  object -

  深度拷贝后的新对象

  ##### Example

      01 深度拷贝
      --------------------------------------------------------------------------
      import { deep } from '@riil-frontend/utils';
      let obj = {name:'name'};
      let objA = obj;
      objA.age = '18';
      console.log(obj.age) // 18    // 不希望改变原来对象的值
      console.log(objA.age) // 18

      let deepObj = deep(obj);
      deepObj.address = 'beijing';
      console.log(obj.address) // undefined
      console.log(deepObj.address) // "beijing"

#### static dynamicSort(property, sortOrder) → {boolean}

  对象数组动态排序

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `property` | * | 对象key值
  `sortOrder` |  | 1正序，-1倒序

  ##### Returns:

  boolean
  Author:
    - libo

  ##### Example

      01 对象数组排序
      --------------------------------------------------------------------------
       import { dynamicSort } from "@riil-frontend/utils";
       var People = [
           {Name: "Name", Surname: "Surname"},
           {Name:"AAA", Surname:"ZZZ"},
           {Name: "Name", Surname: "AAA"}
       ];

       People.sort(dynamicSort("Name"));
       People.sort(dynamicSort("Surname"));
       People.sort(dynamicSort("Surname",-1));//倒序

#### static encryption(string, typeopt) → {null}

  字符串加密

  - 'ASC' 加密 当前只有一种加密 后续会增加

  ##### Parameters:

  Name | Type | Attributes | Default | Description
  --- | --- | --- | --- | ---
  `string` | string |  |  | 需要加密的字符
  `type` | string | <optional> | "ASC" | 加密类型

  ##### Returns:

  null -

  加密后的字符串

  ##### Example

      01 asc 加密
      --------------------------------------------------------------------------
      import {encryption} from '@riil-frontend/utils';
      let string = 'riil猎豹';
      encryption(string);
      // result
      "uoLPE3xmBdjHLXMudacZAg=="

#### static fromatRuleOperator(operator, threshold, value) → {object}

  格式化后台规则表达式

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `operator` | String | 规则中阈值表达式,后端规则配置中子规则中的operator值
  `threshold` | Number | 规则阈值,后端规则配置中子规则中的threshold值
  `value` | Number | 指标的值

  ##### Returns:

  object -

  {label：{des,ope},result:boolean}

  ##### Examples

      01 获取阈值文本显示
      --------------------------------------------------------------------------
       import {fromatRuleOperator} from '@riil-frontend/utils';
       fromatRuleOperator({'equals',threshold:0.7});// return {label:{des:'等于0.7',ope:'=0.7'},result:null}

      02 获取阈值文本显示以及比较后结果
      --------------------------------------------------------------------------
       import {fromatRuleOperator} from '@riil-frontend/utils';
       fromatRuleOperator({'equals',threshold:0.7,value:1});// return {label:{des:'等于0.7',ope:'=0.7'},result:false}

#### static get(obj, key, splitopt) → {*}

  获取对象或数组的属性对应值

  - 主要用于深度获取未知对象的值.

  ##### Parameters:

  Name | Type | Attributes | Default | Description
  --- | --- | --- | --- | ---
  `obj` | array | object |  |  | 对象或者数组
  `key` | string |  |  | 对象的key值
  `split` | string | <optional> | "." | 分隔符

  ##### Returns:

  * -

  返回key对应的任何数据格式的值

  ##### Examples

      01 常见获取值
      --------------------------------------------------------------------------
      import { get } from '@riil-frontend/utils';
      const obj = { a: { b: { c: [{'.f.m':'age'}, { d: 'name' }] } } };
      get(obj, 'a.b.c.1.d');  // "name"

      02 未知深度
      --------------------------------------------------------------------------
      get(obj, 'm.b.c.1.d');  // undefined

      03 自定义分割
      --------------------------------------------------------------------------
      get(obj, 'a@b@c@0@.f.m', '@') //age

#### getNumberLength(n) → {number}

  求数字整数位数

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `n` |  |

  ##### Returns:

  number

#### static getURLParam() → {array}

  获取 URL 传递所有参数

  ##### Returns:

  array -

  返回全部参数组装的对象

  Author:
    - libo

  ##### Example

      example 01 缺省key值
      --------------------------------------------------------------------------

       import { getURLParam } from '@riil-frontend/utils';
       getURLParam();

       eg: url = http://localhost/riil-biz-frontend/dist/#/module/function?id=123&name=appbir&ts=1571105560850
       // result
       {
         "id": "123",
         "name": "appbir",
         "ts": "1571105560850"
       }

#### static getURLParamByKey(keyopt) → {string|object}

  获取 URL 传递指定参数

  ##### Parameters:

  Name | Type | Attributes | Description
  --- | --- | --- | ---
  `key` | string | undefined | <optional> | 参数key键

  ##### Returns:

  string | object -

  key键对应的值 默认返回全部的参数值

  Author:
    - libo

  ##### Examples

      example 01 缺省key值
      --------------------------------------------------------------------------

       import { getURLParamByKey } from '@riil-frontend/utils';
       getURLParamByKey();

       eg: url = http://localhost/riil-biz-frontend/dist/#/module/function?id=123&name=appbir&ts=1571105560850
       // result
       {
         "id": "123",
         "name": "appbir",
         "ts": "1571105560850"
       }

      example 02 指定key
      --------------------------------------------------------------------------
      getURLParamByKey('id');

      // result
      "123"

#### static getUUID() → {string}

  生成UUID

  ##### Returns:

  string

  ##### Example

      01 生成UUID
      --------------------------------------------------------------------------
      import {getUUID} from '@riil-frontend/utils';
      getUUID() result // 94ddda53-e67d-1b92-6e12-295ed71b246d

#### HMSformat(value, unit) → {string|string}

  将时间转换成时分秒显示格式文字 不足1分钟显示秒，超过1分钟只显示小时分钟，向下舍去秒数据

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `value` | number |
  `unit` | 'ms' | 's' | 'm' | 'h' | 'd' | 'w' | 'M' | 'y' | (ms/s/m/h/d/w/M/y)

  ##### Returns:

  - string
  - string

  ##### Example

      将时间转换成时分秒。显示格式文字不足1分钟显示秒，超过1分钟只显示小时分钟，向下舍去秒数据。
      let result = DateFormat(63,'s').HMSformat();
      // result 1分钟
      let result = DateFormat(59,'s').HMSformat();
      // result 59秒
      let result = DateFormat(61,'m').HMSformat();
      // result 1小时1分钟
      --------------------------------------------------------------------------

#### static httpsValidate(rule, value, callback) → {*}

  https Urls验证

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `rule` |  |
  `value` |  |
  `callback` |  |

  ##### Returns:

  *

#### static httpValidate(rule, value, callback) → {*}

  http Urls验证

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `rule` |  |
  `value` |  |
  `callback` |  |

  ##### Returns:

  *

#### static isAvailableArray(arr) → {boolean}

  是否为可用的数组

  - 可用数组检查规则

  > 1. 数据类型是数组
  > 2. 数组至少有一个数据

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `arr` | * | 需要判断的数组

  ##### Returns:

  boolean -

  是否为可用的数组 true： 表示可用 false ：表示不可用

  ##### Example

      01 非数组类型
      --------------------------------------------------------------------------
      import {isAvailableArray} from '@riil-frontend';
      isAvailableArray(null)      // false
      isAvailableArray(undefined) // false
      isAvailableArray({})        // false
      isAvailableArray([])        // false
      isAvailableArray(() => { }) // false
      isAvailableArray([1])       // true

#### static isNull(arg) → {boolean}

  为空值判断

  - undefined null NaN '' 返回为true
  - 其外都为false (包含 0 , false ,Infinity,-Infinity)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `arg` | * | 判断值是否为空

  ##### Returns:

  boolean -

  true : 为空 ; false：不为空

  Author:
    - libo

  ##### Example

      01 空值判断
      --------------------------------------------------------------------------
       isNull(null);// true
       isNull(undefined); // true
       isNull(NaN); // true
       isNull(''); // true

       isNull(0);  // false
       isNull(false); // false
       isNull(Infinity); // false

#### static isPassForSpecification() → {boolean}

  数字类校验，系统限制小数点前9位，小数点后两位，正数
  详单功能Table高级过滤器-比较过滤输入框校验 isPassForSpecification *

  ##### Returns:

  - -

    boolean 校验结果

  - boolean

  ##### Examples

      01 校验通过
      --------------------------------------------------------------------------
      import { validator } from '@riil-frontend/utils';
      validator.isPassForSpecification('1564.33');

      // result

      02 校验不通过
      --------------------------------------------------------------------------
      import { validator } from '@riil-frontend/utils';
      validator.isPassForSpecification('aaaa');

      // result
      false

#### static recursionGet(}, data) → {array}

  递归函数，返回符合集合

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `}` | string | value 查找的值.
  `data` | array | 所有树节点数据。

  ##### Returns:

  array -

  符合条件的数组

  Author:
    - hht

  ##### Examples

      example 01 匹配子节点
      --------------------------------------------------------------------------
      import { recursionGet } from "@riil-frontend/utils";
      const array = [
       {
         label: '网络设备',
         id: 'network',
         icon: 'network',
         children: [
           {
             label: '交换机',
             id: 'switch',
             icon: 'switch',
             children: null,
           },
           {
             label: '锐捷交换机',
             id: 'ruijieSwitch',
             icon: 'ruijieSwitch',
             children: null,
           },
           {
             label: '路由器',
             id: 'router',
             icon: 'router',
             children: null,
           },
           {
             label: '锐捷路由器',
             id: 'ruijieRouter',
             icon: 'ruijieRouter',
             children: null,
           },
         ],
       },
       {
         label: '操作系统',
         id: 'system',
         icon: 'system',
         children: [
           {
             label: 'Linux',
             id: 'Linux',
             icon: 'Linux',
             children: null,
           },
           {
             label: 'Windows',
             id: 'Windows',
             icon: 'Windows',
             children: null,
           },
         ],
       },
      ];
      recursionGet('Linux',array);
      // result
      ['Linux']

      example 02 无匹配
      --------------------------------------------------------------------------
      const array = [
          { id: 1, label: 1, children: null },
          { id: 2, label: 2, children: 1 }
      ];
      recursionGet("Linux",array);

      // result
      []

#### static removeUrlSpace(value) → {*|void|string}

  去除url中的空格

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `value` |  | url

  ##### Returns:

  * | void | string

#### static set(object, key, val) → {object}

  设置对象或数组属性对应的值

  - 主要用于深度获取未知对象的值.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `object` |  | 需要呗设置的对象
  `key` | string | 设置的key属性
  `val` | * | key对应的value值

  ##### Returns:

  object -

  设置后的对象值

  To Do:
    - 后续继续扩展split和array

  ##### Examples

      01 设置属性值
      --------------------------------------------------------------------------
      import { set } from '@riil-frontend/utils';
      const obj = { a: { b: { c: [{ }, { d: 'name' }] } } };
      set(obj, 'a.b.c.1.d','newName');
      // result
      { a: { b: { c: [{ }, { d: 'newName' }] } } };

      01 设置不存在属性的值
      --------------------------------------------------------------------------
      set(obj, 'm.b.c.d','noProp');
      // result
       { a: { b: { c: [{ }, { d: 'newName' }] } },
         m: { b: { c: { d: 'noProp' } } }
       };

#### static successContentValidate(rule, value, callback) → {*}

  录像文本关键字验证

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `rule` |  |
  `value` |  |
  `callback` |  |

  ##### Returns:

  *

#### static tcpValidate(rule, value, callback) → {*}

  ip+端口验证

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `rule` |  |
  `value` |  |
  `callback` |  |

  ##### Returns:

  *

#### toDecimal(x, n) → {number}

  数字格式化，保留N位小数

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `x` |  | 数值
  `n` |  | 保留位数

  ##### Returns:

  number

#### static validatePort(rule, value, callback, source, options) → {*}

  端口验证

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `rule` |  | ant form rule
  `value` |  | 端口值可以为数组，将分别校验
  `callback` |  | ant form callback
  `source` |  | 要验证的对象（必填）。
  `options` |  | 一个对象，描述验证的处理选项（可选）。

  ##### Returns:

  *

### Type Definitions

#### unit