/*
 * @Description:
 * @Version:
 * @Author: kangjinrui
 * @Date: 2022-10-26 10:03:40
 * @LastEditors: kangjinrui
 * @LastEditTime: 2024-04-26 16:57:21
 */

/**
 * 获取uuid
 *
 * @returns
 */
export function uuid() {
  const s = [];
  const hexDigits = '0123456789abcdef';
  for (let i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  s[8] = s[13] = s[18] = s[23] = '-';

  const uuid = s.join('');
  return uuid;
}
/**
 * 获取uuidc纯数字
 *
 * @returns
 */
export function uuidNum() {
  const value = Math.floor(Math.random() * (9999 - 1000)) + 1000;

  // var charactors = "1234567890";
  // var value = '', i;
  // for (var j = 1; j <= 4; j++) {
  // 	i = parseInt(10 * Math.random());
  // 	value = value + charactors.charAt(i);
  // }

  return value;
}

/**
 * 获取uuid
 *
 * @returns
 */
export function simpleUuid() {
  const s = [];
  const hexDigits = '0123456789abcdef';
  for (let i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  // s[8] = s[13] = s[18] = s[23] = "-";

  const uuid = s.join('');
  return uuid;
}

/**
 * 获取uuid
 *
 * @returns
 */
export function uuidOnlyStr() {
  const s = [];
  const hexDigits = 'abcdefghijklmn';
  for (let i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  // s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
  // s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  // s[8] = s[13] = s[18] = s[23] = "-";

  const uuid = s.join('');
  return uuid;
}
