sadais-piui 1.2.7-beta113 → 1.2.7-beta115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/.prettierrc +7 -7
  2. package/CHANGELOG.md +545 -545
  3. package/LICENSE +20 -20
  4. package/README.md +166 -166
  5. package/components/pi-action-sheet/index.vue +247 -247
  6. package/components/pi-badge/index.vue +146 -146
  7. package/components/pi-bottom-bar/index.vue +139 -139
  8. package/components/pi-bubble/index.vue +174 -174
  9. package/components/pi-button/index.vue +492 -492
  10. package/components/pi-calendar-input/index.vue +230 -230
  11. package/components/pi-calendar-panel/components/calendar-days/index.vue +410 -410
  12. package/components/pi-calendar-panel/index.vue +473 -473
  13. package/components/pi-canvas/index.vue +407 -407
  14. package/components/pi-card/index.vue +127 -127
  15. package/components/pi-cascader/index.vue +601 -601
  16. package/components/pi-checkbox/index.vue +363 -363
  17. package/components/pi-checkbox-group/index.vue +222 -222
  18. package/components/pi-circle-progress/index.vue +311 -311
  19. package/components/pi-code-input/index.vue +270 -270
  20. package/components/pi-collapse/index.vue +124 -124
  21. package/components/pi-collapse-item/index.vue +352 -352
  22. package/components/pi-count-down/index.vue +245 -245
  23. package/components/pi-count-up/index.vue +209 -209
  24. package/components/pi-date-picker-input/index.vue +219 -219
  25. package/components/pi-divider/index.vue +112 -112
  26. package/components/pi-dropdown/components/dropdown-tab.vue +71 -71
  27. package/components/pi-dropdown/index.vue +356 -356
  28. package/components/pi-dropdown-item/index.vue +252 -252
  29. package/components/pi-form/index.vue +273 -273
  30. package/components/pi-form-item/index.vue +603 -590
  31. package/components/pi-gap/index.vue +72 -72
  32. package/components/pi-grid/index.vue +92 -92
  33. package/components/pi-grid-item/index.vue +220 -220
  34. package/components/pi-icon/index.vue +147 -147
  35. package/components/pi-img/index.vue +266 -266
  36. package/components/pi-img-cropper/canvas.js +106 -106
  37. package/components/pi-img-cropper/index.vue +357 -357
  38. package/components/pi-img-cropper/touch.js +163 -163
  39. package/components/pi-img-cropper/vector.js +34 -34
  40. package/components/pi-input/index.vue +409 -401
  41. package/components/pi-line/index.vue +78 -78
  42. package/components/pi-line-progress/index.vue +198 -198
  43. package/components/pi-list/index.vue +115 -115
  44. package/components/pi-list-item/index.vue +335 -335
  45. package/components/pi-loading/index.vue +188 -188
  46. package/components/pi-marquee/index.vue +310 -310
  47. package/components/pi-marquee-item/index.vue +47 -47
  48. package/components/pi-mask/index.vue +198 -198
  49. package/components/pi-modal/index.vue +303 -303
  50. package/components/pi-navbar/index.vue +421 -421
  51. package/components/pi-notify/index.vue +239 -239
  52. package/components/pi-number-keyboard/index.vue +189 -189
  53. package/components/pi-opentype-button/index.vue +501 -501
  54. package/components/pi-pagination/index.vue +290 -290
  55. package/components/pi-picker/index.vue +317 -317
  56. package/components/pi-popup/index.vue +356 -356
  57. package/components/pi-popup-select/index.vue +300 -300
  58. package/components/pi-radio/index.vue +403 -403
  59. package/components/pi-radio-group/index.vue +300 -300
  60. package/components/pi-rate/index.vue +212 -212
  61. package/components/pi-regions-select/index.vue +349 -349
  62. package/components/pi-regions-select-input/index.vue +230 -230
  63. package/components/pi-search/index.vue +386 -386
  64. package/components/pi-section/index.vue +218 -218
  65. package/components/pi-select/index.vue +678 -678
  66. package/components/pi-select-input/index.vue +273 -273
  67. package/components/pi-skeleton/index.vue +280 -280
  68. package/components/pi-status-bar/index.vue +56 -56
  69. package/components/pi-stepper/index.vue +408 -408
  70. package/components/pi-steps/index.vue +378 -378
  71. package/components/pi-subsection/index.vue +403 -403
  72. package/components/pi-swiper/index.vue +344 -344
  73. package/components/pi-switch/index.vue +231 -231
  74. package/components/pi-table/index.vue +351 -351
  75. package/components/pi-tabs/index.vue +435 -435
  76. package/components/pi-tag/index.vue +488 -488
  77. package/components/pi-upload-img/index.vue +980 -980
  78. package/components/pi-waterfall/index.vue +130 -130
  79. package/config/actionSheet.js +24 -24
  80. package/config/badge.js +9 -9
  81. package/config/bottomBar.js +11 -11
  82. package/config/bubble.js +6 -6
  83. package/config/button.js +29 -29
  84. package/config/calendar.js +19 -19
  85. package/config/calendarInput.js +19 -19
  86. package/config/calendarPanel.js +27 -27
  87. package/config/card.js +8 -8
  88. package/config/cascader.js +22 -22
  89. package/config/checkbox.js +15 -15
  90. package/config/checkboxGroup.js +15 -15
  91. package/config/circleProgress.js +20 -20
  92. package/config/codeInput.js +13 -13
  93. package/config/collapse.js +7 -7
  94. package/config/collapseItem.js +11 -11
  95. package/config/countDown.js +12 -12
  96. package/config/countUp.js +13 -13
  97. package/config/datePickerInput.js +18 -18
  98. package/config/divider.js +10 -10
  99. package/config/dropdown.js +25 -25
  100. package/config/dropdownItem.js +26 -26
  101. package/config/form.js +29 -29
  102. package/config/formItem.js +27 -27
  103. package/config/gap.js +8 -8
  104. package/config/grid.js +9 -9
  105. package/config/gridItem.js +12 -12
  106. package/config/icon.js +11 -11
  107. package/config/img.js +21 -21
  108. package/config/imgCropper.js +26 -26
  109. package/config/index.js +28 -28
  110. package/config/input.js +37 -36
  111. package/config/line.js +8 -8
  112. package/config/lineProgress.js +14 -14
  113. package/config/list.js +12 -12
  114. package/config/listItem.js +25 -25
  115. package/config/loading.js +10 -10
  116. package/config/marquee.js +10 -10
  117. package/config/mask.js +12 -12
  118. package/config/modal.js +36 -36
  119. package/config/navbar.js +32 -32
  120. package/config/notify.js +13 -13
  121. package/config/numberKeyboard.js +21 -21
  122. package/config/pagination.js +10 -10
  123. package/config/picker.js +19 -19
  124. package/config/popup.js +23 -23
  125. package/config/popupSelect.js +35 -35
  126. package/config/radio.js +16 -16
  127. package/config/radioGroup.js +17 -17
  128. package/config/rate.js +15 -15
  129. package/config/regionsData.js +58 -58
  130. package/config/regionsSelect.js +19 -19
  131. package/config/regionsSelectInput.js +29 -29
  132. package/config/search.js +27 -27
  133. package/config/section.js +23 -23
  134. package/config/select.js +41 -41
  135. package/config/selectInput.js +29 -29
  136. package/config/skeleton.js +13 -13
  137. package/config/statusBar.js +5 -5
  138. package/config/stepper.js +19 -19
  139. package/config/steps.js +19 -19
  140. package/config/subsection.js +14 -14
  141. package/config/swiper.js +22 -22
  142. package/config/switch.js +13 -13
  143. package/config/table.js +8 -8
  144. package/config/tabs.js +23 -23
  145. package/config/tag.js +21 -21
  146. package/config/uploadImg.js +81 -81
  147. package/config/waterfall.js +6 -6
  148. package/index.js +41 -41
  149. package/mixin/component-custom.js +24 -24
  150. package/mixin/emitter.js +45 -45
  151. package/mixin/props-sync.js +65 -65
  152. package/mixin/value-sync.js +32 -32
  153. package/mixin/wx-code.js +30 -30
  154. package/package.json +28 -28
  155. package/plugins/async-validator.js +1511 -1511
  156. package/scss/animation.scss +260 -260
  157. package/scss/icon/icon.scss +595 -595
  158. package/scss/index.scss +5 -5
  159. package/scss/mixin.scss +47 -47
  160. package/tools/index.js +19 -19
@@ -1,401 +1,409 @@
1
- <template>
2
- <view
3
- class="pi-input-wrap"
4
- :style="[getInputWrapStyle]"
5
- :class="[{ disabled: getDisabled }]"
6
- >
7
- <!-- 当disabled,增加一个abso的蒙层,为了触发click事件 -->
8
- <view
9
- v-if="getDisabled"
10
- class="pi-input-mask"
11
- :style="{ width: `calc(100% - ${closeIconWidth}px)` }"
12
- @tap="handleItemClick"
13
- />
14
-
15
- <textarea
16
- v-if="type === 'textarea'"
17
- class="pi-input-textarea"
18
- :style="[customStyle]"
19
- :class="[customClass]"
20
- :value="val"
21
- :password="password"
22
- :placeholder="placeholder"
23
- :placeholder-style="placeholderStyle"
24
- :placeholder-class="placeholderClass"
25
- :maxlength="parseInt(maxlength, 10)"
26
- :cursor-spacing="cursorSpacing"
27
- :focus="focus"
28
- :disabled="getDisabled"
29
- :confirm-hold="confirmHold"
30
- :cursor="cursor"
31
- :selection-start="selectionStart"
32
- :selection-end="selectionEnd"
33
- :adjust-position="adjustPosition"
34
- :hold-keyboard="holdKeyboard"
35
- :auto-blur="autoBlur"
36
- :show-confirm-bar="showConfirmbar"
37
- :auto-height="autoHeight"
38
- :disable-default-padding="disableDefaultPadding"
39
- @focus="handleFocus"
40
- @input="handleInput"
41
- @blur="handleBlur"
42
- @confirm="handleConfirm"
43
- @keyboardheightchange="$emit('keyboardheightchange', $event)"
44
- @linechange="$emit('linechange', $event)"
45
- @tap="handleItemClick"
46
- />
47
- <input
48
- v-else
49
- class="pi-input"
50
- :style="[customStyle]"
51
- :class="[customClass]"
52
- :type="type == 'password' ? 'text' : type"
53
- :value="val"
54
- :password="password"
55
- :placeholder="placeholder"
56
- :placeholder-style="placeholderStyle"
57
- :placeholder-class="placeholderClass"
58
- :maxlength="parseInt(maxlength, 10)"
59
- :cursor-spacing="cursorSpacing"
60
- :focus="focus"
61
- :disabled="getDisabled"
62
- :confirm-hold="confirmHold"
63
- :cursor="cursor"
64
- :selection-start="selectionStart"
65
- :selection-end="selectionEnd"
66
- :adjust-position="adjustPosition"
67
- :hold-keyboard="holdKeyboard"
68
- :auto-blur="autoBlur"
69
- @focus="handleFocus"
70
- @input="handleInput"
71
- @blur="handleBlur"
72
- @confirm="handleConfirm"
73
- @keyboardheightchange="$emit('keyboardheightchange', $event)"
74
- @tap="handleItemClick"
75
- />
76
- <!-- 清空icon -->
77
- <view class="pi-input-close-icon">
78
- <pi-icon
79
- v-if="showClearIcon"
80
- :custom-style="clearIcon.customStyle"
81
- :custom-class="`pi-pd-left-12 ${clearIcon.customClass}`"
82
- :name="clearIcon.name"
83
- :dot="clearIcon.dot"
84
- :dot-radius="clearIcon.dotRadius"
85
- :badge="clearIcon.badge"
86
- :color="clearIcon.color"
87
- :size="clearIcon.size"
88
- :class-prefix="clearIcon.classPrefix"
89
- @click="handleClearInput"
90
- />
91
- </view>
92
- </view>
93
- </template>
94
-
95
- <script>
96
- /**
97
- *
98
- * @description 输入框
99
- */
100
- import Emitter from '../../mixin/emitter'
101
- import ValueSync from '../../mixin/value-sync'
102
- import { getConfig } from '../../config'
103
- import { debounce } from '@sadais/piui-tool/tools/common'
104
-
105
- const { input } = getConfig()
106
-
107
- const TAG = 'PiInput'
108
-
109
- export default {
110
- name: 'PiInput',
111
- // 混入v-model
112
- mixins: [ValueSync, Emitter],
113
- props: {
114
- // 初始值
115
- value: {
116
- required: false
117
- },
118
- // 自定义样式
119
- customStyle: {
120
- type: Object,
121
- default() {
122
- // {}
123
- return input.customStyle
124
- }
125
- },
126
- // 自定义样式类
127
- customClass: {
128
- type: String,
129
- default() {
130
- // ''
131
- return input.customClass
132
- }
133
- },
134
- // 输入框类型
135
- type: {
136
- required: false,
137
- // `'textarea'` `'text'` `'number'` `'idcard'` `'digit'`
138
- type: String,
139
- // `'text'`
140
- default() {
141
- return input.type
142
- },
143
- validator: function(value) {
144
- return ['textarea', 'text', 'number', 'idcard', 'digit'].includes(value)
145
- }
146
- },
147
- // 是否是密码类型
148
- password: {
149
- type: Boolean,
150
- // false
151
- default: input.password
152
- },
153
- placeholder: {
154
- type: String,
155
- // ''
156
- default: input.placeholder
157
- },
158
- placeholderStyle: {
159
- type: String,
160
- // color: #c0c4cc; font-weight: 400;
161
- default: input.placeholderStyle
162
- },
163
- placeholderClass: {
164
- type: String,
165
- // input-placeholder
166
- default: input.placeholderClass
167
- },
168
- // 是否禁用
169
- disabled: {
170
- type: Boolean,
171
- // false
172
- default: input.disabled
173
- },
174
- // 边框样式设置
175
- border: {
176
- type: [Boolean, String],
177
- // false
178
- default: input.border
179
- },
180
- // 最大输入长度,设置为 -1 的时候不限制最大长度
181
- maxlength: {
182
- type: [Number, String],
183
- // 140
184
- default: input.maxlength
185
- },
186
- // 指定光标与键盘的距离,单位 px
187
- cursorSpacing: {
188
- type: [Number, String],
189
- // 0
190
- default: input.cursorSpacing
191
- },
192
- // 是否自动获得焦点
193
- focus: {
194
- type: Boolean,
195
- // false
196
- default: input.focus
197
- },
198
- // 设置键盘右下角按钮的文字,仅在 type="text" 时生效。
199
- confirmType: {
200
- type: String,
201
- // 'done'
202
- default: input.confirmType
203
- },
204
- // 点击键盘右下角按钮时是否保持键盘不收起
205
- confirmHold: {
206
- type: Boolean,
207
- // false
208
- default: input.confirmHold
209
- },
210
- // 指定focus时的光标位置
211
- cursor: {
212
- type: [Object, Number],
213
- // null
214
- default: input.cursor
215
- },
216
- // 光标起始位置,自动聚焦时有效,需与selection-end搭配使用
217
- selectionStart: {
218
- type: [Number, String],
219
- // -1
220
- default: input.selectionStart
221
- },
222
- // 光标结束位置,自动聚焦时有效,需与selection-start搭配使用
223
- selectionEnd: {
224
- type: [Number, String],
225
- // -1
226
- default: input.selectionEnd
227
- },
228
- // 键盘弹起时,是否自动上推页面
229
- adjustPosition: {
230
- type: Boolean,
231
- // true
232
- default: input.adjustPosition
233
- },
234
- // focus时,点击页面的时候不收起键盘
235
- holdKeyboard: {
236
- type: Boolean,
237
- // false
238
- default: input.holdKeyboard
239
- },
240
- // 键盘收起时,是否自动失去焦点
241
- autoBlur: {
242
- type: Boolean,
243
- // true
244
- default: input.autoBlur
245
- },
246
- // 以下是textarea组件的属性
247
- // 是否显示键盘上方带有”完成“按钮那一栏
248
- showConfirmbar: {
249
- type: Boolean,
250
- // true
251
- default: input.showConfirmbar
252
- },
253
- // 是否自动增高
254
- autoHeight: {
255
- type: Boolean,
256
- // false
257
- default: input.autoHeight
258
- },
259
- // 如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true
260
- fixed: {
261
- type: Boolean,
262
- // false
263
- default: input.fixed
264
- },
265
- // 是否去掉 iOS 下的默认内边距
266
- disableDefaultPadding: {
267
- type: Boolean,
268
- // false
269
- default: input.disableDefaultPadding
270
- },
271
- // 是否可清空
272
- clearable: {
273
- type: Boolean,
274
- // false
275
- default: input.clearable
276
- },
277
- // 清空图标设置
278
- clearIcon: {
279
- type: Object,
280
- default() {
281
- return input.clearIcon
282
- }
283
- }
284
- },
285
- data() {
286
- return {
287
- focused: this.focus,
288
- closeIconWidth: 0
289
- }
290
- },
291
- computed: {
292
- getDisabled() {
293
- const parentFormItem = this.$pi.parent(this, 'PiFormItem')
294
- const disabled =
295
- this.disabled || (parentFormItem && parentFormItem.getDisabled)
296
- return disabled
297
- },
298
- getInputWrapStyle() {
299
- const style = {}
300
- if (this.border) {
301
- style.padding = '8rpx 14rpx'
302
- style.borderRadius = '4rpx'
303
- if (this.$pi.lang.isString(this.border)) {
304
- style.border = this.border
305
- } else {
306
- style.border = '1px solid #d9d9d9'
307
- }
308
- }
309
- return style
310
- },
311
- showClearIcon() {
312
- return this.clearable && this.val
313
- }
314
- },
315
- watch: {
316
- showClearIcon() {
317
- this.$nextTick(() => {
318
- this.init()
319
- })
320
- }
321
- },
322
- mounted() {
323
- this.init()
324
- },
325
- methods: {
326
- async init() {
327
- if (!this.closeIconWidth) {
328
- const closeIconRect = await this.$pi.common.queryRect(
329
- this,
330
- '.pi-input-close-icon',
331
- false
332
- )
333
- if (closeIconRect && closeIconRect.width) {
334
- this.closeIconWidth = closeIconRect.width
335
- }
336
- }
337
- },
338
- handleItemClick(e) {
339
- this.$emit('click', e)
340
- },
341
- handleInput(e) {
342
- const value = e.detail.value
343
- this.handleChange(value)
344
- },
345
- handleFocus() {
346
- this.focused = true
347
- // 获得焦点
348
- this.$emit('focus')
349
- },
350
- handleBlur() {
351
- setTimeout(() => {
352
- this.focused = false
353
- }, 100)
354
- this.$emit('blur', value)
355
- setTimeout(() => {
356
- this.dispatch('PiFormItem', 'form-blur', value)
357
- }, 40)
358
- },
359
- handleClearInput() {
360
- this.handleChange('')
361
- this.$emit('clear')
362
- },
363
- /**
364
- * @vuese
365
- * 确认选择
366
- */
367
- handleConfirm(e) {
368
- // 输入完成事件
369
- this.$emit('confirm', e.detail.value)
370
- },
371
- handleChange(value) {
372
- this.val = value
373
- this.handleEmitChange()
374
- this.dispatch('PiForm', 'form-change', this.val)
375
- this.dispatch('PiFormItem', 'form-change', this.val)
376
- }
377
- }
378
- }
379
- </script>
380
-
381
- <style lang="scss" scoped>
382
- .pi-input-wrap {
383
- position: relative;
384
- width: 100%;
385
- display: flex;
386
- align-items: center;
387
- .pi-input,
388
- .pi-input-textarea {
389
- width: 100%;
390
- }
391
-
392
- .pi-input-mask {
393
- position: absolute;
394
- left: 0;
395
- top: 0;
396
- bottom: 0;
397
- background: transparent;
398
- z-index: 101;
399
- }
400
- }
401
- </style>
1
+ <template>
2
+ <view
3
+ class="pi-input-wrap"
4
+ :style="[getInputWrapStyle]"
5
+ :class="[{ disabled: getDisabled }]"
6
+ >
7
+ <!-- 当disabled,增加一个abso的蒙层,为了触发click事件 -->
8
+ <view
9
+ v-if="getDisabled"
10
+ class="pi-input-mask"
11
+ :style="{ width: `calc(100% - ${closeIconWidth}px)` }"
12
+ @tap="handleItemClick"
13
+ />
14
+
15
+ <textarea
16
+ v-if="type === 'textarea'"
17
+ class="pi-input-textarea"
18
+ :style="[customStyle]"
19
+ :class="[customClass]"
20
+ :value="val"
21
+ :password="password"
22
+ :placeholder="placeholder"
23
+ :placeholder-style="placeholderStyle"
24
+ :placeholder-class="placeholderClass"
25
+ :maxlength="parseInt(maxlength, 10)"
26
+ :cursor-spacing="cursorSpacing"
27
+ :focus="focus"
28
+ :disabled="getDisabled"
29
+ :confirm-hold="confirmHold"
30
+ :cursor="cursor"
31
+ :selection-start="selectionStart"
32
+ :selection-end="selectionEnd"
33
+ :adjust-position="adjustPosition"
34
+ :hold-keyboard="holdKeyboard"
35
+ :auto-blur="autoBlur"
36
+ :show-confirm-bar="showConfirmbar"
37
+ :auto-height="autoHeight"
38
+ :disable-default-padding="disableDefaultPadding"
39
+ @focus="handleFocus"
40
+ @input="handleInput"
41
+ @blur="handleBlur"
42
+ @confirm="handleConfirm"
43
+ @keyboardheightchange="$emit('keyboardheightchange', $event)"
44
+ @linechange="$emit('linechange', $event)"
45
+ @tap="handleItemClick"
46
+ />
47
+ <input
48
+ v-else
49
+ class="pi-input"
50
+ :style="[customStyle]"
51
+ :class="[customClass]"
52
+ :type="type == 'password' ? 'text' : type"
53
+ :value="val"
54
+ :password="password"
55
+ :placeholder="placeholder"
56
+ :placeholder-style="placeholderStyle"
57
+ :placeholder-class="placeholderClass"
58
+ :maxlength="parseInt(maxlength, 10)"
59
+ :cursor-spacing="cursorSpacing"
60
+ :focus="focus"
61
+ :disabled="getDisabled"
62
+ :confirm-hold="confirmHold"
63
+ :cursor="cursor"
64
+ :selection-start="selectionStart"
65
+ :selection-end="selectionEnd"
66
+ :adjust-position="adjustPosition"
67
+ :hold-keyboard="holdKeyboard"
68
+ :auto-blur="autoBlur"
69
+ @focus="handleFocus"
70
+ @input="handleInput"
71
+ @blur="handleBlur"
72
+ @confirm="handleConfirm"
73
+ @keyboardheightchange="$emit('keyboardheightchange', $event)"
74
+ @tap="handleItemClick"
75
+ />
76
+ <!-- 清空icon -->
77
+ <view class="pi-input-close-icon">
78
+ <pi-icon
79
+ v-if="showClearIcon"
80
+ :custom-style="clearIcon.customStyle"
81
+ :custom-class="`pi-pd-left-12 ${clearIcon.customClass}`"
82
+ :name="clearIcon.name"
83
+ :dot="clearIcon.dot"
84
+ :dot-radius="clearIcon.dotRadius"
85
+ :badge="clearIcon.badge"
86
+ :color="clearIcon.color"
87
+ :size="clearIcon.size"
88
+ :class-prefix="clearIcon.classPrefix"
89
+ @click="handleClearInput"
90
+ />
91
+ </view>
92
+ </view>
93
+ </template>
94
+
95
+ <script>
96
+ /**
97
+ *
98
+ * @description 输入框
99
+ */
100
+ import Emitter from '../../mixin/emitter'
101
+ import ValueSync from '../../mixin/value-sync'
102
+ import { getConfig } from '../../config'
103
+ import { debounce } from '@sadais/piui-tool/tools/common'
104
+
105
+ const { input } = getConfig()
106
+
107
+ const TAG = 'PiInput'
108
+
109
+ export default {
110
+ name: 'PiInput',
111
+ // 混入v-model
112
+ mixins: [ValueSync, Emitter],
113
+ props: {
114
+ // 初始值
115
+ value: {
116
+ required: false
117
+ },
118
+ // 自定义样式
119
+ customStyle: {
120
+ type: Object,
121
+ default() {
122
+ // {}
123
+ return input.customStyle
124
+ }
125
+ },
126
+ // 自定义样式类
127
+ customClass: {
128
+ type: String,
129
+ default() {
130
+ // ''
131
+ return input.customClass
132
+ }
133
+ },
134
+ // 输入框类型
135
+ type: {
136
+ required: false,
137
+ // `'textarea'` `'text'` `'number'` `'idcard'` `'digit'`
138
+ type: String,
139
+ // `'text'`
140
+ default() {
141
+ return input.type
142
+ },
143
+ validator: function(value) {
144
+ return ['textarea', 'text', 'number', 'idcard', 'digit'].includes(value)
145
+ }
146
+ },
147
+ // 是否是密码类型
148
+ password: {
149
+ type: Boolean,
150
+ // false
151
+ default: input.password
152
+ },
153
+ placeholder: {
154
+ type: String,
155
+ // ''
156
+ default: input.placeholder
157
+ },
158
+ placeholderStyle: {
159
+ type: String,
160
+ // color: #c0c4cc; font-weight: 400;
161
+ default: input.placeholderStyle
162
+ },
163
+ placeholderClass: {
164
+ type: String,
165
+ // input-placeholder
166
+ default: input.placeholderClass
167
+ },
168
+ // 是否禁用
169
+ disabled: {
170
+ type: Boolean,
171
+ // false
172
+ default: input.disabled
173
+ },
174
+ // 边框样式设置
175
+ border: {
176
+ type: [Boolean, String],
177
+ // false
178
+ default: input.border
179
+ },
180
+ // 最大输入长度,设置为 -1 的时候不限制最大长度
181
+ maxlength: {
182
+ type: [Number, String],
183
+ // 140
184
+ default: input.maxlength
185
+ },
186
+ // 指定光标与键盘的距离,单位 px
187
+ cursorSpacing: {
188
+ type: [Number, String],
189
+ // 0
190
+ default: input.cursorSpacing
191
+ },
192
+ // 是否自动获得焦点
193
+ focus: {
194
+ type: Boolean,
195
+ // false
196
+ default: input.focus
197
+ },
198
+ // 设置键盘右下角按钮的文字,仅在 type="text" 时生效。
199
+ confirmType: {
200
+ type: String,
201
+ // 'done'
202
+ default: input.confirmType
203
+ },
204
+ // 点击键盘右下角按钮时是否保持键盘不收起
205
+ confirmHold: {
206
+ type: Boolean,
207
+ // false
208
+ default: input.confirmHold
209
+ },
210
+ // 指定focus时的光标位置
211
+ cursor: {
212
+ type: [Object, Number],
213
+ // null
214
+ default: input.cursor
215
+ },
216
+ // 光标起始位置,自动聚焦时有效,需与selection-end搭配使用
217
+ selectionStart: {
218
+ type: [Number, String],
219
+ // -1
220
+ default: input.selectionStart
221
+ },
222
+ // 光标结束位置,自动聚焦时有效,需与selection-start搭配使用
223
+ selectionEnd: {
224
+ type: [Number, String],
225
+ // -1
226
+ default: input.selectionEnd
227
+ },
228
+ // 键盘弹起时,是否自动上推页面
229
+ adjustPosition: {
230
+ type: Boolean,
231
+ // true
232
+ default: input.adjustPosition
233
+ },
234
+ // focus时,点击页面的时候不收起键盘
235
+ holdKeyboard: {
236
+ type: Boolean,
237
+ // false
238
+ default: input.holdKeyboard
239
+ },
240
+ // 键盘收起时,是否自动失去焦点
241
+ autoBlur: {
242
+ type: Boolean,
243
+ // true
244
+ default: input.autoBlur
245
+ },
246
+ // 以下是textarea组件的属性
247
+ // 是否显示键盘上方带有”完成“按钮那一栏
248
+ showConfirmbar: {
249
+ type: Boolean,
250
+ // true
251
+ default: input.showConfirmbar
252
+ },
253
+ // 是否自动增高
254
+ autoHeight: {
255
+ type: Boolean,
256
+ // false
257
+ default: input.autoHeight
258
+ },
259
+ // 如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true
260
+ fixed: {
261
+ type: Boolean,
262
+ // false
263
+ default: input.fixed
264
+ },
265
+ // 是否去掉 iOS 下的默认内边距
266
+ disableDefaultPadding: {
267
+ type: Boolean,
268
+ // false
269
+ default: input.disableDefaultPadding
270
+ },
271
+ // 是否可清空
272
+ clearable: {
273
+ type: Boolean,
274
+ // false
275
+ default: input.clearable
276
+ },
277
+ // 清空图标设置
278
+ clearIcon: {
279
+ type: Object,
280
+ default() {
281
+ return input.clearIcon
282
+ }
283
+ },
284
+ // 是否失去焦点更新v-model
285
+ updateOnBlur: {
286
+ type: Boolean,
287
+ // true
288
+ default: input.updateOnBlur
289
+ }
290
+ },
291
+ data() {
292
+ return {
293
+ focused: this.focus,
294
+ closeIconWidth: 0
295
+ }
296
+ },
297
+ computed: {
298
+ getDisabled() {
299
+ const parentFormItem = this.$pi.parent(this, 'PiFormItem')
300
+ const disabled =
301
+ this.disabled || (parentFormItem && parentFormItem.getDisabled)
302
+ return disabled
303
+ },
304
+ getInputWrapStyle() {
305
+ const style = {}
306
+ if (this.border) {
307
+ style.padding = '8rpx 14rpx'
308
+ style.borderRadius = '4rpx'
309
+ if (this.$pi.lang.isString(this.border)) {
310
+ style.border = this.border
311
+ } else {
312
+ style.border = '1px solid #d9d9d9'
313
+ }
314
+ }
315
+ return style
316
+ },
317
+ showClearIcon() {
318
+ return this.clearable && this.val
319
+ }
320
+ },
321
+ watch: {
322
+ showClearIcon() {
323
+ this.$nextTick(() => {
324
+ this.init()
325
+ })
326
+ }
327
+ },
328
+ mounted() {
329
+ this.init()
330
+ },
331
+ methods: {
332
+ async init() {
333
+ if (!this.closeIconWidth) {
334
+ const closeIconRect = await this.$pi.common.queryRect(
335
+ this,
336
+ '.pi-input-close-icon',
337
+ false
338
+ )
339
+ if (closeIconRect && closeIconRect.width) {
340
+ this.closeIconWidth = closeIconRect.width
341
+ }
342
+ }
343
+ },
344
+ handleItemClick(e) {
345
+ this.$emit('click', e)
346
+ },
347
+ handleInput(e) {
348
+ const value = e.detail.value
349
+ this.handleChange(value)
350
+ },
351
+ handleFocus() {
352
+ this.focused = true
353
+ // 获得焦点
354
+ this.$emit('focus')
355
+ },
356
+ handleBlur(e) {
357
+ const value = e.detail.value
358
+ if (this.updateOnBlur) {
359
+ this.handleChange(value)
360
+ }
361
+ this.$emit('blur', value)
362
+ setTimeout(() => {
363
+ this.focused = false
364
+ this.dispatch('PiFormItem', 'form-blur', value)
365
+ }, 100)
366
+ },
367
+ handleClearInput() {
368
+ this.handleChange('')
369
+ this.$emit('clear')
370
+ },
371
+ /**
372
+ * @vuese
373
+ * 确认选择
374
+ */
375
+ handleConfirm(e) {
376
+ // 输入完成事件
377
+ this.$emit('confirm', e.detail.value)
378
+ },
379
+ handleChange(value) {
380
+ this.val = value
381
+ this.handleEmitChange()
382
+ this.dispatch('PiForm', 'form-change', this.val)
383
+ this.dispatch('PiFormItem', 'form-change', this.val)
384
+ }
385
+ }
386
+ }
387
+ </script>
388
+
389
+ <style lang="scss" scoped>
390
+ .pi-input-wrap {
391
+ position: relative;
392
+ width: 100%;
393
+ display: flex;
394
+ align-items: center;
395
+ .pi-input,
396
+ .pi-input-textarea {
397
+ width: 100%;
398
+ }
399
+
400
+ .pi-input-mask {
401
+ position: absolute;
402
+ left: 0;
403
+ top: 0;
404
+ bottom: 0;
405
+ background: transparent;
406
+ z-index: 101;
407
+ }
408
+ }
409
+ </style>