index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { Component, triggerEvent, triggerEventOnly, getValueFromProps, } from '../_util/simply';
  2. import { NumberKeyboardDefaultProps } from './props';
  3. var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
  4. Component(NumberKeyboardDefaultProps, {
  5. catchAppearModal: function () {
  6. this.setRandom();
  7. },
  8. setRandom: function () {
  9. if (getValueFromProps(this, 'random')) {
  10. var newArr = arr.sort(function () {
  11. return Math.random() - 0.5;
  12. });
  13. this.setData({
  14. randomArr: [
  15. newArr.slice(0, 3),
  16. newArr.slice(3, 6),
  17. newArr.slice(6, 9),
  18. ],
  19. });
  20. }
  21. },
  22. tapButton: function (e) {
  23. var _a = getValueFromProps(this, [
  24. 'value',
  25. 'confirmDisabled',
  26. ]), value = _a[0], confirmDisabled = _a[1];
  27. this.vibrate();
  28. var _key = e.currentTarget.dataset.key;
  29. var _val = "".concat(value);
  30. // 回退
  31. if (_key === 'del') {
  32. triggerEvent(this, 'change', "".concat(_val.substr(0, _val.length - 1)), e);
  33. return;
  34. }
  35. if (_key !== 'del' && _key !== 'enter') {
  36. triggerEvent(this, 'change', "".concat(_val).concat(_key), e);
  37. }
  38. if (_key === 'enter' && !confirmDisabled) {
  39. this.onClickEnter();
  40. triggerEventOnly(this, 'close');
  41. }
  42. },
  43. // 隐藏键盘,失去焦点
  44. handleHide: function () {
  45. triggerEventOnly(this, 'close');
  46. },
  47. onClickEnter: function () {
  48. var confirmDisabled = getValueFromProps(this, 'confirmDisabled');
  49. if (confirmDisabled)
  50. return;
  51. this.handleHide();
  52. triggerEventOnly(this, 'confirm');
  53. },
  54. // 振动反馈
  55. vibrate: function () {
  56. if (getValueFromProps(this, 'vibrate') && typeof my !== 'undefined') {
  57. my.canIUse('vibrateShort') && my.vibrateShort();
  58. }
  59. },
  60. }, {
  61. numArr: [
  62. [1, 2, 3],
  63. [4, 5, 6],
  64. [7, 8, 9],
  65. ],
  66. randomArr: [],
  67. }, undefined, {
  68. didMount: function () {
  69. this.setRandom();
  70. },
  71. });