utils.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //所有自然数
  2. export const natural = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
  3. //所有英文字母
  4. export const chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  5. 'v', 'w', 'x', 'y', 'z'
  6. ];
  7. //顺序排序全键盘
  8. export const order = [
  9. ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
  10. ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
  11. ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'],
  12. ['z', 'x', 'c', 'v', 'b', 'n', 'm']
  13. ];
  14. //随机排序全键盘
  15. export const disorder = () => {
  16. let lines = [10, 9, 7];
  17. let array = [];
  18. array.push(digits());
  19. let [...temp] = chars;
  20. const random = (length) => {
  21. let randoms = [];
  22. for (let i = 0; i < length; i++) {
  23. let index = Math.floor(Math.random() * temp.length);
  24. randoms.push(temp[index]);
  25. temp.splice(index, 1);
  26. }
  27. return randoms;
  28. };
  29. for (let i = 0; i < lines.length; i++) {
  30. array.push(random(lines[i]));
  31. }
  32. return array;
  33. };
  34. //所有符号
  35. export const symbols = [
  36. ['~', '`', '!', '@', '#', '$', '%', '^', '&', '*'],
  37. ['(', ')', '-', '+', '=', '{', '}', '[', ']'],
  38. ['_', '|', '\\', ':', ';', '\'', '<', ',', '>'],
  39. ['"', '?', '.', '/', '€', '£', '¥']
  40. ];
  41. //所有数字
  42. export const digits = () => {
  43. let [...temp] = natural;
  44. return temp.sort(function() {
  45. return Math.random() > 0.5 ? -1 : 1; //用Math.random()函数生成0~1之间的随机数与0.5比较,返回-1或1
  46. });
  47. };
  48. //键盘模式
  49. export const KEYBOARD_MODE = {
  50. SYMBOL: 'symbol', //符号键盘
  51. DIGIT: 'digit', //数字键盘
  52. LETTER: 'letter' //字母键盘
  53. };