Blame view

pages/component/input/input.nvue 9.51 KB
4b045f7c   刘淇   江阴初始化项目
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
  <template>
      <view class="nvue-page-root">
          <view class="page-title">
              <view class="page-title__wrapper">
                  <text class="page-title__text">{{title}}</text>
              </view>
          </view>
          <view class="uni-common-mt">
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">可自动聚焦的 input</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" focus placeholder="自动获得焦点" />
                  </view>
              </view>
              <!-- #ifdef APP-PLUS -->
              <view v-if="platform==='ios'&&!isNvue" class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">隐藏 iOS 软键盘上的导航条</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" placeholder="触摸其他地方收起键盘" @focus="onFocus" @blur="onBlur" />
                  </view>
              </view>
              <!-- #endif -->
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">键盘右下角按钮显示为搜索</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" confirm-type="search" placeholder="键盘右下角按钮显示为搜索" />
                  </view>
              </view>
              <!-- #ifndef H5 -->
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">键盘右下角按钮显示为发送</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" confirm-type="send" placeholder="键盘右下角按钮显示为发送" />
                  </view>
              </view>
              <!-- #endif -->
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">控制最大输入长度的 input</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" maxlength="10" placeholder="最大输入长度为10" />
                  </view>
              </view>
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">实时获取输入值:{{inputValue}}</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" @input="onKeyInput" placeholder="输入同步到view中" />
                  </view>
              </view>
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">控制输入的 input</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" @input="replaceInput" v-model="changeValue" placeholder="连续的两个1会变成2" />
                  </view>
              </view>
              <!-- #ifndef MP-BAIDU -->
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">控制键盘的 input</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" ref="input1" @input="hideKeyboard" placeholder="输入123自动收起键盘" />
                  </view>
              </view>
              <!-- #endif -->
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">数字输入的 input</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" type="number" placeholder="这是一个数字输入框" />
                  </view>
              </view>
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">密码输入的 input</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" password type="text" placeholder="这是一个密码输入框" />
                  </view>
              </view>
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">带小数点的 input</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" type="digit" placeholder="带小数点的数字键盘" /> </view>
              </view>
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">身份证输入的 input</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" type="idcard" placeholder="身份证输入键盘" /> </view>
              </view>
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">控制占位符颜色的 input</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" placeholder-style="color:#F76260" placeholder="占位符字体是红色的" />
                  </view>
              </view>
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">带清除按钮的输入框</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" placeholder="带清除按钮的输入框" :value="inputClearValue" @input="clearInput" />
                      <text class="uni-icon" v-if="showClearIcon" @click="clearIcon">&#xe434;</text>
                  </view>
              </view> 
              <view class="uni-form-item uni-column">
                  <view class="title"><text class="uni-form-item__title">可查看密码的输入框</text></view>
                  <view class="uni-input-wrapper">
                      <input class="uni-input" placeholder="请输入密码" :password="showPassword" />
                      <text class="uni-icon" :class="[!showPassword ? 'uni-eye-active' : '']" @click="changePassword">&#xe568;</text>
                  </view>
              </view>
          </view>
      </view>
  </template>
  <script>
      export default {
          data() {
              return {
                  title: 'input',
                  focus: false,
                  inputValue: '',
                  showClearIcon: false,
                  inputClearValue: '',
                  changeValue: '',
                  showPassword: true,
                  src: '../../../static/eye-1.png',
                  platform: '',
                  isNvue: false,
              }
          },
          methods: {
              onKeyInput: function(event) {
                  this.inputValue = event.detail.value
              },
              replaceInput: function(event) {
                  var value = event.detail.value;
                  if (value === '11') {
                      this.changeValue = '2';
                  }
              },
              hideKeyboard: function(event) {
                  if (event.detail.value === '123') {
                      uni.hideKeyboard();
                  }
              },
              clearInput: function(event) {
                  this.inputClearValue = event.detail.value;
                  if (event.detail.value.length > 0) {
                      this.showClearIcon = true;
                  } else {
                      this.showClearIcon = false;
                  }
              },
              clearIcon: function() {
                  this.inputClearValue = '';
                  this.showClearIcon = false;
              },
              changePassword: function() {
                  this.showPassword = !this.showPassword;
              },
              onFocus() {
                  this.$mp.page.$getAppWebview().setStyle({
                      softinputNavBar: 'none'
                  })
              },
              onBlur() {
                  this.$mp.page.$getAppWebview().setStyle({
                      softinputNavBar: 'auto'
                  })
              }
          },
          onLoad() {
              this.platform = uni.getSystemInfoSync().platform
              // #ifdef APP-PLUS-NVUE
              this.isNvue = true
              // #endif
          }
      }
  </script>
  
  <style scoped>
      .nvue-page-root {
          background-color: #F8F8F8;
          padding-bottom: 20px;
      }
  
      .page-title {
          /* #ifndef APP-NVUE */
          display: flex;
          /* #endif */
          flex-direction: row;
          justify-content: center;
          align-items: center;
          padding: 35rpx;
      }
  
      .page-title__wrapper {
          padding: 0px 20px;
          border-bottom-color: #D8D8D8;
          border-bottom-width: 1px;
      }
  
      .page-title__text {
          font-size: 16px;
          height: 48px;
          line-height: 48px;
          color: #BEBEBE;
      }
  
      .title {
          padding: 5px 13px;
      }
  
      .uni-form-item__title {
          font-size: 16px;
          line-height: 24px;
      }
  
      .uni-input-wrapper {
          /* #ifndef APP-NVUE */
          display: flex;
          /* #endif */
          padding: 8px 13px;
          flex-direction: row;
          flex-wrap: nowrap;
          background-color: #FFFFFF;
      }
  
      .uni-input {
          height: 28px;
          line-height: 28px;
          font-size: 15px;
          padding: 0px;
          flex: 1;
          background-color: #FFFFFF;
      }
  
      .uni-icon {
          font-family: uniicons;
          font-size: 24px;
          font-weight: normal;
          font-style: normal;
          width: 24px;
          height: 24px;
          line-height: 24px;
          color: #999999;
      }
  
      .uni-eye-active {
          color: #007AFF;
      }
  </style>