1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import { NumberKeyboardDefaultProps } from './props';
- import '../_util/assert-component2';
- var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
- Component({
- props: NumberKeyboardDefaultProps,
- data: {
- numArr: [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
- randomArr: [],
- },
- didMount: function () {
- this.setRandom();
- },
- methods: {
- catchAppearModal: function () {
- this.setRandom();
- },
- setRandom: function () {
- if (this.props.random) {
- var newArr = arr.sort(function () {
- return Math.random() - 0.5;
- });
- this.setData({
- randomArr: [newArr.slice(0, 3), newArr.slice(3, 6), newArr.slice(6, 9)]
- });
- }
- },
- tapButton: function (e) {
- var _a = this.props, value = _a.value, onChange = _a.onChange, confirmDisabled = _a.confirmDisabled, onClose = _a.onClose;
- this.vibrate();
- var _key = e.target.dataset.key;
- var _val = "".concat(value);
- // 回退
- if (_key === 'del') {
- onChange("".concat(_val.substr(0, _val.length - 1)));
- return;
- }
- if (_key !== 'del' && _key !== 'enter') {
- onChange("".concat(_val).concat(_key));
- }
- if (_key === 'enter' && !confirmDisabled) {
- this.onClickEnter();
- onClose();
- }
- },
- // 隐藏键盘,失去焦点
- onHide: function () {
- var onClose = this.props.onClose;
- onClose();
- },
- onClickEnter: function () {
- var _a = this.props, confirmDisabled = _a.confirmDisabled, onConfirm = _a.onConfirm;
- if (confirmDisabled)
- return;
- this.onHide();
- onConfirm();
- },
- // 振动反馈
- vibrate: function () {
- my.canIUse('vibrateShort') && this.props.vibrate && my.vibrateShort();
- },
- },
- });
|