index.js 2.0 KB

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