admin
2020-12-08 7f2d1daf6af6ecebad84d80de46a0e5024bbf5da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
Component({
  props: {
    className: '',
    placeholder: '',
    focus: false,
    showVoice: false,
    borderColor: '#1677ff',
    controlled: true,
    enableNative: undefined // false 处理 fixed 定位后输入框内容闪动的问题
 
  },
  data: {
    _value: '',
    focus: false
  },
  didMount: function didMount() {
    this.setData({
      _value: 'value' in this.props ? this.props.value : '',
      focus: this.props.focus
    });
  },
  didUpdate: function didUpdate() {
    if ('value' in this.props && this.props.value !== this.data._value) {
      this.setData({
        _value: this.props.value
      });
    }
  },
  methods: {
    handleInput: function handleInput(e) {
      var value = e.detail.value;
 
      if (!('value' in this.props)) {
        this.setData({
          _value: value
        });
      }
 
      if (this.props.onInput) {
        this.props.onInput(value);
      }
    },
    handleClear: function handleClear() {
      var _this = this;
 
      // this.setData({
      //   focus: true,
      // });
      setTimeout(function () {
        _this.handleFocus();
      }, 100);
 
      if (!('value' in this.props)) {
        this.setData({
          _value: ''
        });
      }
 
      this.doClear();
    },
    doClear: function doClear() {
      if (this.props.onClear) {
        this.props.onClear('');
      }
 
      if (this.props.onChange) {
        this.props.onChange('');
      }
    },
    handleFocus: function handleFocus() {
      this.setData({
        focus: true
      });
 
      if (this.props.onFocus) {
        this.props.onFocus();
      }
    },
    handleBlur: function handleBlur() {
      this.setData({
        focus: false
      });
 
      if (this.props.onBlur) {
        this.props.onBlur();
      }
    },
    handleCancel: function handleCancel() {
      if (!('value' in this.props)) {
        this.setData({
          _value: ''
        });
      }
 
      if (this.props.onCancel) {
        this.props.onCancel();
      } else {
        this.doClear();
      }
    },
    handleConfirm: function handleConfirm(e) {
      var value = e.detail.value;
 
      if (this.props.onSubmit) {
        this.props.onSubmit(value);
      }
    },
    handleVoice: function handleVoice() {
      if (this.props.onVoiceClick) {
        this.props.onVoiceClick();
      }
    }
  }
});