hy-app 0.4.13 → 0.5.0

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 (211) hide show
  1. package/components/hy-action-sheet/hy-action-sheet.vue +155 -238
  2. package/components/hy-action-sheet/props.ts +68 -15
  3. package/components/hy-action-sheet/typing.d.ts +115 -115
  4. package/components/hy-address-picker/hy-address-picker.vue +185 -289
  5. package/components/hy-address-picker/props.ts +97 -21
  6. package/components/hy-address-picker/typing.d.ts +90 -89
  7. package/components/hy-avatar/hy-avatar.vue +121 -204
  8. package/components/hy-avatar/props.ts +76 -18
  9. package/components/hy-avatar/typing.d.ts +63 -62
  10. package/components/hy-back-top/hy-back-top.vue +65 -120
  11. package/components/hy-back-top/props.ts +57 -16
  12. package/components/hy-back-top/typing.d.ts +43 -42
  13. package/components/hy-badge/hy-badge.vue +66 -138
  14. package/components/hy-badge/props.ts +73 -17
  15. package/components/hy-badge/typing.d.ts +59 -58
  16. package/components/hy-button/hy-button.vue +226 -375
  17. package/components/hy-button/props.ts +129 -158
  18. package/components/hy-calendar/header.vue +48 -64
  19. package/components/hy-calendar/hy-calendar.vue +274 -438
  20. package/components/hy-calendar/month.vue +508 -516
  21. package/components/hy-calendar/props.ts +157 -35
  22. package/components/hy-calendar/typing.d.ts +129 -128
  23. package/components/hy-card/hy-card.vue +118 -240
  24. package/components/hy-card/index.scss +1 -2
  25. package/components/hy-card/props.ts +122 -27
  26. package/components/hy-card/typing.d.ts +119 -118
  27. package/components/hy-cell/hy-cell.vue +176 -258
  28. package/components/hy-cell/props.ts +71 -17
  29. package/components/hy-cell/typing.d.ts +87 -86
  30. package/components/hy-check-button/hy-check-button.vue +69 -139
  31. package/components/hy-check-button/props.ts +72 -18
  32. package/components/hy-check-button/typing.d.ts +74 -73
  33. package/components/hy-checkbox/hy-checkbox.vue +170 -263
  34. package/components/hy-checkbox/props.ts +94 -24
  35. package/components/hy-checkbox/typing.d.ts +72 -72
  36. package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
  37. package/components/hy-checkbox-group/props.ts +80 -0
  38. package/components/hy-checkbox-group/typing.d.ts +65 -65
  39. package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
  40. package/components/hy-checkbox-item/props.ts +24 -0
  41. package/components/hy-checkbox-item/typing.d.ts +4 -3
  42. package/components/hy-code-input/hy-code-input.vue +179 -262
  43. package/components/hy-code-input/props.ts +84 -18
  44. package/components/hy-code-input/typing.d.ts +71 -71
  45. package/components/hy-config-provider/hy-config-provider.vue +28 -50
  46. package/components/hy-config-provider/props.ts +26 -11
  47. package/components/hy-config-provider/typing.d.ts +20 -20
  48. package/components/hy-count-down/hy-count-down.vue +103 -131
  49. package/components/hy-count-down/props.ts +30 -8
  50. package/components/hy-count-down/typing.d.ts +25 -25
  51. package/components/hy-count-to/hy-count-to.vue +148 -213
  52. package/components/hy-count-to/props.ts +60 -15
  53. package/components/hy-count-to/typing.d.ts +46 -46
  54. package/components/hy-coupon/README.md +133 -0
  55. package/components/hy-coupon/hy-coupon.vue +180 -0
  56. package/components/hy-coupon/index.scss +553 -0
  57. package/components/hy-coupon/props.ts +129 -0
  58. package/components/hy-coupon/typing.d.ts +146 -0
  59. package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
  60. package/components/hy-datetime-picker/props.ts +142 -32
  61. package/components/hy-datetime-picker/typing.d.ts +132 -132
  62. package/components/hy-divider/hy-divider.vue +90 -169
  63. package/components/hy-divider/props.ts +78 -19
  64. package/components/hy-divider/typing.d.ts +60 -60
  65. package/components/hy-dropdown/hy-dropdown.vue +37 -71
  66. package/components/hy-dropdown/props.ts +38 -15
  67. package/components/hy-dropdown/typing.d.ts +44 -44
  68. package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
  69. package/components/hy-dropdown-item/props.ts +19 -8
  70. package/components/hy-empty/hy-empty.vue +75 -129
  71. package/components/hy-empty/props.ts +57 -15
  72. package/components/hy-empty/typing.d.ts +84 -84
  73. package/components/hy-flex/hy-flex.vue +33 -88
  74. package/components/hy-flex/props.ts +58 -0
  75. package/components/hy-flex/typing.d.ts +14 -16
  76. package/components/hy-float-button/hy-float-button.vue +289 -406
  77. package/components/hy-float-button/props.ts +109 -25
  78. package/components/hy-folding-panel/hy-folding-panel.vue +86 -374
  79. package/components/hy-folding-panel/props.ts +40 -15
  80. package/components/hy-folding-panel/typing.d.ts +52 -63
  81. package/components/hy-folding-panel-item/hy-folding-panel-item.vue +186 -228
  82. package/components/hy-folding-panel-item/index.scss +87 -0
  83. package/components/hy-folding-panel-item/props.ts +81 -0
  84. package/components/hy-folding-panel-item/typing.d.ts +23 -0
  85. package/components/hy-form/hy-form.vue +172 -212
  86. package/components/hy-form/props.ts +37 -0
  87. package/components/hy-form/typing.d.ts +68 -61
  88. package/components/hy-form-group/typing.d.ts +74 -74
  89. package/components/hy-form-item/hy-form-item.vue +100 -129
  90. package/components/hy-form-item/props.ts +25 -0
  91. package/components/hy-form-item/typing.d.ts +40 -37
  92. package/components/hy-grid/hy-grid.vue +76 -132
  93. package/components/hy-grid/props.ts +58 -16
  94. package/components/hy-grid/typing.d.ts +66 -66
  95. package/components/hy-icon/hy-icon.vue +84 -161
  96. package/components/hy-icon/props.ts +76 -22
  97. package/components/hy-icon/typing.d.ts +83 -82
  98. package/components/hy-image/hy-image.vue +142 -272
  99. package/components/hy-image/props.ts +105 -23
  100. package/components/hy-image/typing.d.ts +84 -87
  101. package/components/hy-input/hy-input.vue +230 -421
  102. package/components/hy-input/props.ts +183 -35
  103. package/components/hy-input/typing.d.ts +169 -169
  104. package/components/hy-line/hy-line.vue +34 -72
  105. package/components/hy-line/props.ts +41 -10
  106. package/components/hy-line/typing.d.ts +29 -29
  107. package/components/hy-line-progress/hy-line-progress.vue +66 -101
  108. package/components/hy-line-progress/props.ts +31 -10
  109. package/components/hy-line-progress/typing.d.ts +29 -29
  110. package/components/hy-list/hy-list.vue +151 -220
  111. package/components/hy-list/props.ts +67 -16
  112. package/components/hy-list/typing.d.ts +52 -52
  113. package/components/hy-loading/hy-loading.vue +63 -119
  114. package/components/hy-loading/props.ts +63 -15
  115. package/components/hy-loading/typing.d.ts +49 -49
  116. package/components/hy-menu/hy-menu.vue +124 -166
  117. package/components/hy-menu/props.ts +42 -10
  118. package/components/hy-menu/typing.d.ts +60 -60
  119. package/components/hy-modal/hy-modal.vue +127 -218
  120. package/components/hy-modal/props.ts +89 -24
  121. package/components/hy-navbar/hy-navbar.vue +104 -177
  122. package/components/hy-navbar/props.ts +76 -22
  123. package/components/hy-navbar/typing.d.ts +81 -81
  124. package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
  125. package/components/hy-notice-bar/props.ts +80 -19
  126. package/components/hy-notice-bar/typing.d.ts +62 -62
  127. package/components/hy-notify/hy-notify.vue +128 -177
  128. package/components/hy-notify/props.ts +49 -12
  129. package/components/hy-notify/typing.d.ts +45 -41
  130. package/components/hy-number-step/hy-number-step.vue +281 -394
  131. package/components/hy-number-step/props.ts +110 -27
  132. package/components/hy-number-step/typing.d.ts +120 -120
  133. package/components/hy-overlay/hy-overlay.vue +39 -66
  134. package/components/hy-overlay/props.ts +31 -8
  135. package/components/hy-pagination/hy-pagination.vue +100 -155
  136. package/components/hy-pagination/props.ts +53 -13
  137. package/components/hy-picker/hy-picker.vue +309 -430
  138. package/components/hy-picker/index.scss +8 -12
  139. package/components/hy-picker/props.ts +110 -26
  140. package/components/hy-popover/hy-popover.vue +190 -252
  141. package/components/hy-popover/props.ts +48 -10
  142. package/components/hy-popup/hy-popup.vue +162 -248
  143. package/components/hy-popup/props.ts +82 -18
  144. package/components/hy-price/hy-price.vue +45 -104
  145. package/components/hy-price/props.ts +52 -12
  146. package/components/hy-price/typing.d.ts +41 -36
  147. package/components/hy-qrcode/hy-qrcode.vue +115 -185
  148. package/components/hy-qrcode/props.ts +68 -18
  149. package/components/hy-qrcode/typing.d.ts +67 -66
  150. package/components/hy-radio/hy-radio.vue +161 -259
  151. package/components/hy-radio/props.ts +95 -25
  152. package/components/hy-radio/typing.d.ts +85 -84
  153. package/components/hy-rate/hy-rate.vue +185 -270
  154. package/components/hy-rate/props.ts +76 -18
  155. package/components/hy-rate/typing.d.ts +61 -60
  156. package/components/hy-read-more/hy-read-more.vue +93 -136
  157. package/components/hy-read-more/props.ts +43 -13
  158. package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
  159. package/components/hy-scroll-list/props.ts +22 -11
  160. package/components/hy-search/hy-search.vue +155 -284
  161. package/components/hy-search/props.ts +130 -25
  162. package/components/hy-signature/hy-signature.vue +491 -635
  163. package/components/hy-signature/props.ts +115 -26
  164. package/components/hy-signature/typing.d.ts +138 -138
  165. package/components/hy-slider/hy-slider.vue +388 -477
  166. package/components/hy-slider/props.ts +75 -19
  167. package/components/hy-steps/hy-steps.vue +212 -279
  168. package/components/hy-steps/props.ts +47 -13
  169. package/components/hy-submit-bar/hy-submit-bar.vue +137 -222
  170. package/components/hy-submit-bar/props.ts +89 -20
  171. package/components/hy-submit-bar/typing.d.ts +86 -85
  172. package/components/hy-subsection/hy-subsection.vue +132 -185
  173. package/components/hy-subsection/props.ts +50 -17
  174. package/components/hy-subsection/typing.d.ts +52 -52
  175. package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
  176. package/components/hy-swipe-action/props.ts +43 -18
  177. package/components/hy-swipe-action/typing.d.ts +46 -46
  178. package/components/hy-swiper/hy-swiper.vue +159 -286
  179. package/components/hy-swiper/props.ts +126 -28
  180. package/components/hy-swiper/typing.d.ts +115 -115
  181. package/components/hy-switch/hy-switch.vue +112 -176
  182. package/components/hy-switch/props.ts +60 -15
  183. package/components/hy-switch/typing.d.ts +63 -63
  184. package/components/hy-tabBar/hy-tabBar.vue +64 -60
  185. package/components/hy-tabs/hy-tabs.vue +277 -380
  186. package/components/hy-tabs/props.ts +75 -18
  187. package/components/hy-tag/hy-tag.vue +111 -204
  188. package/components/hy-tag/props.ts +81 -19
  189. package/components/hy-text/hy-text.vue +200 -322
  190. package/components/hy-text/props.ts +107 -28
  191. package/components/hy-textarea/hy-textarea.vue +147 -256
  192. package/components/hy-textarea/props.ts +112 -25
  193. package/components/hy-textarea/typing.d.ts +42 -42
  194. package/components/hy-toast/hy-toast.vue +135 -143
  195. package/components/hy-tooltip/hy-tooltip.vue +220 -306
  196. package/components/hy-tooltip/props.ts +79 -15
  197. package/components/hy-transition/hy-transition.vue +111 -138
  198. package/components/hy-transition/props.ts +30 -8
  199. package/components/hy-upload/hy-upload.vue +320 -469
  200. package/components/hy-upload/props.ts +130 -27
  201. package/components/hy-warn/hy-warn.vue +80 -129
  202. package/components/hy-warn/props.ts +47 -12
  203. package/components/hy-waterfall/hy-waterfall.vue +139 -163
  204. package/components/hy-waterfall/props.ts +19 -7
  205. package/components/hy-watermark/hy-watermark.vue +762 -870
  206. package/components/hy-watermark/props.ts +103 -22
  207. package/global.d.ts +2 -0
  208. package/libs/css/theme.scss +3 -3
  209. package/package.json +2 -2
  210. package/web-types.json +1 -1
  211. package/components/hy-folding-panel/index.scss +0 -9
@@ -1,522 +1,331 @@
1
1
  <template>
2
- <view
3
- :class="['hy-input', inputClass]"
4
- :style="[wrapperStyle, borderStyle(focused)]"
5
- >
6
- <view class="hy-input__content">
7
- <view
8
- class="hy-input__content--prefix-icon"
9
- v-if="prefixIcon?.name || $slots.prefix"
10
- @tap.stop="onPrefix"
11
- >
12
- <slot v-if="$slots.prefix" name="prefix"></slot>
13
- <HyIcon
14
- v-else
15
- :name="prefixIcon?.name"
16
- :size="prefixIcon?.size"
17
- :color="prefixIcon?.color"
18
- :bold="prefixIcon?.bold"
19
- :customPrefix="prefixIcon?.customPrefix"
20
- :imgMode="prefixIcon?.imgMode"
21
- :width="prefixIcon?.width"
22
- :height="prefixIcon?.height"
23
- :top="prefixIcon?.top"
24
- :stop="prefixIcon?.stop"
25
- :round="prefixIcon?.round"
26
- :customStyle="prefixIcon?.customStyle"
27
- ></HyIcon>
28
- </view>
29
- <view class="hy-input__content--field-wrapper" @tap="clickHandler">
30
- <!-- 根据uni-app的input组件文档,H5和APP中只要声明了password参数(无论true还是false),type均失效,此时
2
+ <view :class="['hy-input', inputClass]" :style="[wrapperStyle, borderStyle(focused)]">
3
+ <view class="hy-input__content">
4
+ <view
5
+ class="hy-input__content--prefix-icon"
6
+ v-if="prefixIcon?.name || $slots.prefix"
7
+ @tap.stop="onPrefix"
8
+ >
9
+ <slot v-if="$slots.prefix" name="prefix"></slot>
10
+ <HyIcon
11
+ v-else
12
+ :name="prefixIcon?.name"
13
+ :size="prefixIcon?.size"
14
+ :color="prefixIcon?.color"
15
+ :bold="prefixIcon?.bold"
16
+ :customPrefix="prefixIcon?.customPrefix"
17
+ :imgMode="prefixIcon?.imgMode"
18
+ :width="prefixIcon?.width"
19
+ :height="prefixIcon?.height"
20
+ :top="prefixIcon?.top"
21
+ :stop="prefixIcon?.stop"
22
+ :round="prefixIcon?.round"
23
+ :customStyle="prefixIcon?.customStyle"
24
+ ></HyIcon>
25
+ </view>
26
+ <view class="hy-input__content--field-wrapper" @tap="clickHandler">
27
+ <!-- 根据uni-app的input组件文档,H5和APP中只要声明了password参数(无论true还是false),type均失效,此时
31
28
  为了防止type=number时,又存在password属性,type无效,此时需要设置password为undefined
32
29
  -->
33
- <input
34
- ref="input-native"
35
- class="hy-input__content--field-wrapper__field"
36
- :style="[inputStyle]"
37
- :type="type"
38
- :focus="focus"
39
- :cursor="cursor"
40
- :value="String(innerValue)"
41
- :auto-blur="autoBlur"
42
- :disabled="disabled || readonly"
43
- :maxlength="maxlength"
44
- :placeholder="placeholder || ''"
45
- :placeholder-style="formatObject(placeholderStyle)"
46
- :placeholder-class="placeholderClass"
47
- :confirm-type="confirmType"
48
- :confirm-hold="confirmHold"
49
- :hold-keyboard="holdKeyboard"
50
- :cursor-spacing="cursorSpacing"
51
- :adjust-position="adjustPosition"
52
- :selection-end="selectionEnd"
53
- :selection-start="selectionStart"
54
- :password="password || type === 'safe-password' || false"
55
- :ignoreCompositionEvent="ignoreCompositionEvent"
56
- @input="onInput"
57
- @blur="onBlur"
58
- @focus="onFocus"
59
- @confirm="onConfirm"
60
- @keyboardheightchange="onkeyboardheightchange"
61
- />
62
- </view>
63
- <view
64
- class="hy-input__content--clear"
65
- v-if="isShowClear"
66
- @tap.stop="onClear"
67
- >
68
- <HyIcon
69
- :name="IconConfig.CLOSE"
70
- size="11"
71
- color="#ffffff"
72
- :customStyle="{ lineHeight: '12px' }"
73
- ></HyIcon>
74
- </view>
75
- <view
76
- class="hy-input__content--subfix-icon"
77
- v-if="suffixIcon?.name || $slots.suffix"
78
- @tap.stop="onSuffix"
79
- >
80
- <slot v-if="$slots.suffix" name="suffix"></slot>
81
- <HyIcon
82
- v-else
83
- :name="suffixIcon?.name"
84
- :size="suffixIcon?.size"
85
- :color="suffixIcon?.color"
86
- :bold="suffixIcon?.bold"
87
- :customPrefix="suffixIcon?.customPrefix"
88
- :imgMode="suffixIcon?.imgMode"
89
- :width="suffixIcon?.width"
90
- :height="suffixIcon?.height"
91
- :top="suffixIcon?.top"
92
- :stop="suffixIcon?.stop"
93
- :round="suffixIcon?.round"
94
- :customStyle="suffixIcon?.customStyle"
95
- ></HyIcon>
96
- </view>
30
+ <input
31
+ ref="input-native"
32
+ class="hy-input__content--field-wrapper__field"
33
+ :style="[inputStyle]"
34
+ :type="type"
35
+ :focus="focus"
36
+ :cursor="cursor"
37
+ :value="String(innerValue)"
38
+ :auto-blur="autoBlur"
39
+ :disabled="disabled || readonly"
40
+ :maxlength="maxlength"
41
+ :placeholder="placeholder || ''"
42
+ :placeholder-style="formatObject(placeholderStyle)"
43
+ :placeholder-class="placeholderClass"
44
+ :confirm-type="confirmType"
45
+ :confirm-hold="confirmHold"
46
+ :hold-keyboard="holdKeyboard"
47
+ :cursor-spacing="cursorSpacing"
48
+ :adjust-position="adjustPosition"
49
+ :selection-end="selectionEnd"
50
+ :selection-start="selectionStart"
51
+ :password="password || type === 'safe-password' || false"
52
+ :ignoreCompositionEvent="ignoreCompositionEvent"
53
+ @input="onInput"
54
+ @blur="onBlur"
55
+ @focus="onFocus"
56
+ @confirm="onConfirm"
57
+ @keyboardheightchange="onkeyboardheightchange"
58
+ />
59
+ </view>
60
+ <view class="hy-input__content--clear" v-if="isShowClear" @tap.stop="onClear">
61
+ <HyIcon
62
+ :name="IconConfig.CLOSE"
63
+ size="11"
64
+ color="#ffffff"
65
+ :customStyle="{ lineHeight: '12px' }"
66
+ ></HyIcon>
67
+ </view>
68
+ <view
69
+ class="hy-input__content--subfix-icon"
70
+ v-if="suffixIcon?.name || $slots.suffix"
71
+ @tap.stop="onSuffix"
72
+ >
73
+ <slot v-if="$slots.suffix" name="suffix"></slot>
74
+ <HyIcon
75
+ v-else
76
+ :name="suffixIcon?.name"
77
+ :size="suffixIcon?.size"
78
+ :color="suffixIcon?.color"
79
+ :bold="suffixIcon?.bold"
80
+ :customPrefix="suffixIcon?.customPrefix"
81
+ :imgMode="suffixIcon?.imgMode"
82
+ :width="suffixIcon?.width"
83
+ :height="suffixIcon?.height"
84
+ :top="suffixIcon?.top"
85
+ :stop="suffixIcon?.stop"
86
+ :round="suffixIcon?.round"
87
+ :customStyle="suffixIcon?.customStyle"
88
+ ></HyIcon>
89
+ </view>
90
+ </view>
97
91
  </view>
98
- </view>
99
92
  </template>
100
93
 
101
94
  <script lang="ts">
102
95
  export default {
103
- name: "hy-input",
104
- options: {
105
- addGlobalClass: true,
106
- virtualHost: true,
107
- styleIsolation: "shared",
108
- },
109
- };
96
+ name: 'hy-input',
97
+ options: {
98
+ addGlobalClass: true,
99
+ virtualHost: true,
100
+ styleIsolation: 'shared'
101
+ }
102
+ }
110
103
  </script>
111
104
 
112
105
  <script setup lang="ts">
113
- import { computed, nextTick, ref, watch, inject } from "vue";
114
- import type { CSSProperties, PropType } from "vue";
115
- import HyIcon from "../hy-icon/hy-icon.vue";
116
- import { addUnit, formatObject, sleep, IconConfig } from "../../libs";
117
- import type { IInputEmits } from "./typing";
118
- import type HyIconProps from "../hy-icon/typing";
119
- import type { FormItemContext } from "../hy-form-item/typing";
106
+ import { computed, nextTick, ref, watch, inject } from 'vue'
107
+ import type { CSSProperties } from 'vue'
108
+ import HyIcon from '../hy-icon/hy-icon.vue'
109
+ import { addUnit, formatObject, sleep, IconConfig } from '../../libs'
110
+ import type { IInputEmits } from './typing'
111
+ import type { FormItemContext } from '../hy-form-item/typing'
120
112
  import type {
121
- InputConfirmType,
122
- InputOnBlurEvent,
123
- InputOnConfirmEvent,
124
- InputOnFocusEvent,
125
- InputOnKeyboardheightchange,
126
- InputType,
127
- } from "@uni-helper/uni-types";
113
+ InputOnBlurEvent,
114
+ InputOnConfirmEvent,
115
+ InputOnFocusEvent,
116
+ InputOnKeyboardheightchange
117
+ } from '@uni-helper/uni-types'
118
+ import inputProps from './props'
128
119
 
129
120
  /**
130
121
  * 为一个输入框,利用它可以快速实现表单验证,输入内容,下拉选择等功能。
131
122
  * @displayName hy-input
132
123
  */
133
- defineOptions({});
124
+ defineOptions({})
134
125
 
135
- // const props = withDefaults(defineProps<IProps>(), defaultProps)
136
- const props = defineProps({
137
- /** 输入的值 */
138
- modelValue: {
139
- type: [String, Number],
140
- required: true,
141
- },
142
- /**
143
- * 输入框类型,见上方说明
144
- * @values text,idcard,number,digit,safe-password,tel,nickname
145
- * */
146
- type: {
147
- type: String as PropType<InputType>,
148
- default: "text",
149
- },
150
- /** 如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true,兼容性:微信小程序、百度小程序、字节跳动小程序、QQ小程序 */
151
- fixed: {
152
- type: Boolean,
153
- default: false,
154
- },
155
- /** 是否禁用输入框 */
156
- disabled: {
157
- type: Boolean,
158
- default: false,
159
- },
160
- /** 禁用状态时的背景色 */
161
- disabledColor: {
162
- type: String,
163
- default: "",
164
- },
165
- /** 是否显示清除控件 */
166
- clearable: {
167
- type: Boolean,
168
- default: false,
169
- },
170
- /** 是否密码类型 */
171
- password: {
172
- type: Boolean,
173
- default: false,
174
- },
175
- /** 最大输入长度,设置为 -1 的时候不限制最大长度 */
176
- maxlength: {
177
- type: Number,
178
- default: -1,
179
- },
180
- /** 输入框为空时的占位符 */
181
- placeholder: String,
182
- /** 指定placeholder的样式类,注意页面或组件的style中写了scoped时,需要在类名前写/deep/ */
183
- placeholderClass: {
184
- type: String,
185
- default: "input-placeholder",
186
- },
187
- /** 指定placeholder的样式,字符串/对象形式,如"color: red;" */
188
- placeholderStyle: {
189
- type: Object as PropType<CSSProperties>,
190
- default: () => ({}),
191
- },
192
- /** 是否显示输入字数统计,只在 type ="text"或type ="textarea"时有效 */
193
- showWordLimit: {
194
- type: Boolean,
195
- default: false,
196
- },
197
- /** 设置右下角按钮的文字,兼容性详见uni-app文档 */
198
- confirmType: {
199
- type: String as PropType<InputConfirmType>,
200
- default: "done",
201
- },
202
- /** 点击键盘右下角按钮时是否保持键盘不收起,H5无效 */
203
- confirmHold: {
204
- type: Boolean,
205
- default: false,
206
- },
207
- /** focus时,点击页面的时候不收起键盘,微信小程序有效 */
208
- holdKeyboard: {
209
- type: Boolean,
210
- default: false,
211
- },
212
- /** 自动获取焦点,在 H5 平台能否聚焦以及软键盘是否跟随弹出,取决于当前浏览器本身的实现。nvue 页面不支持,需使用组件的 focus()、blur() 方法控制焦点 */
213
- focus: {
214
- type: Boolean,
215
- default: false,
216
- },
217
- /** 键盘收起时,是否自动失去焦点,目前仅App3.0.0+有效 */
218
- autoBlur: {
219
- type: Boolean,
220
- default: false,
221
- },
222
- /** 是否去掉 iOS 下的默认内边距,仅微信小程序,且type=textarea时有效 */
223
- disableDefaultPadding: {
224
- type: Boolean,
225
- default: false,
226
- },
227
- /** 指定focus时光标的位置 */
228
- cursor: {
229
- type: Number,
230
- default: 140,
231
- },
232
- /** 输入框聚焦时底部与键盘的距离 */
233
- cursorSpacing: {
234
- type: Number,
235
- default: 30,
236
- },
237
- /** 光标起始位置,自动聚集时有效,需与selection-end搭配使用 */
238
- selectionStart: {
239
- type: Number,
240
- default: -1,
241
- },
242
- /** 光标结束位置,自动聚集时有效,需与selection-start搭配使用 */
243
- selectionEnd: {
244
- type: Number,
245
- default: -1,
246
- },
247
- /** 键盘弹起时,是否自动上推页面 */
248
- adjustPosition: {
249
- type: Boolean,
250
- default: true,
251
- },
252
- /**
253
- * 输入框内容对齐方式
254
- * @values left,center,right
255
- * */
256
- inputAlign: {
257
- type: String as PropType<HyApp.RowCenterType>,
258
- default: "left",
259
- },
260
- /** 输入框字体的大小 */
261
- fontSize: {
262
- type: [String, Number],
263
- default: "15px",
264
- },
265
- /** 输入框字体颜色 */
266
- color: {
267
- type: String,
268
- default: "",
269
- },
270
- /** 输入框前置图标 */
271
- prefixIcon: {
272
- type: Object as PropType<HyIconProps>,
273
- default: () => {},
274
- },
275
- /** 输入框后置图标 */
276
- suffixIcon: {
277
- type: Object as PropType<HyIconProps>,
278
- default: () => {},
279
- },
280
- /**
281
- * 边框类型
282
- * @values surround,bottom,none
283
- * */
284
- border: {
285
- type: String as PropType<HyApp.BorderType>,
286
- default: "surround",
287
- },
288
- /** 是否只读,与disabled不同之处在于disabled会置灰组件,而readonly则不会 */
289
- readonly: {
290
- type: Boolean,
291
- default: false,
292
- },
293
- /**
294
- * 输入框形状
295
- * @values circle,square
296
- * */
297
- shape: {
298
- type: String as PropType<HyApp.ShapeType>,
299
- default: "square",
300
- },
301
- /** 是否忽略组件内对文本合成系统事件的处理 */
302
- ignoreCompositionEvent: {
303
- type: Boolean,
304
- default: false,
305
- },
306
- /** 内容式化函数 */
307
- formatter: Function,
308
- /** 定义需要用到的外部样式 */
309
- customStyle: {
310
- type: Object as PropType<CSSProperties>,
311
- default: () => {},
312
- },
313
- /** 自定义外部类名 */
314
- customClass: String,
315
- });
316
- const emit = defineEmits<IInputEmits>();
317
- const formItem = inject<FormItemContext | null>("formItem", null);
126
+ const props = defineProps(inputProps)
127
+ const emit = defineEmits<IInputEmits>()
128
+ const formItem = inject<FormItemContext | null>('formItem', null)
318
129
 
319
130
  // 清除操作
320
- const clearInput = ref<boolean>(false);
131
+ const clearInput = ref<boolean>(false)
321
132
  // 输入框的值
322
- const innerValue = ref<string | number>("");
133
+ const innerValue = ref<string | number>('')
323
134
  // 是否处于获得焦点状态
324
- const focused = ref<boolean>(false);
135
+ const focused = ref<boolean>(false)
325
136
  // value是否第一次变化,在watch中,由于加入immediate属性,会在第一次触发,此时不应该认为value发生了变化
326
- const firstChange = ref<boolean>(true);
137
+ const firstChange = ref<boolean>(true)
327
138
  // value绑定值的变化是由内部还是外部引起的
328
- const changeFromInner = ref<boolean>(false);
329
- const innerFormatter = (value: string) => value;
139
+ const changeFromInner = ref<boolean>(false)
140
+ const innerFormatter = (value: string) => value
330
141
 
331
142
  watch(
332
- () => props.modelValue,
333
- (newVal) => {
334
- if (changeFromInner.value || innerValue.value === newVal) {
335
- changeFromInner.value = false; // 重要否则会出现双向绑定失效问题https://github.com/ijry/uview-plus/issues/419
336
- return;
337
- }
338
- innerValue.value = newVal;
339
- // 在H5中,外部value变化后,修改input中的值,不会触发@input事件,此时手动调用值变化方法
340
- if (firstChange.value === false && changeFromInner.value === false) {
341
- valueChange(innerValue.value, true);
342
- }
343
- firstChange.value = false;
344
- // 重置changeFromInner的值为false,标识下一次引起默认为外部引起的
345
- changeFromInner.value = false;
346
- },
347
- { immediate: true },
348
- );
143
+ () => props.modelValue,
144
+ (newVal) => {
145
+ if (changeFromInner.value || innerValue.value === newVal) {
146
+ changeFromInner.value = false // 重要否则会出现双向绑定失效问题https://github.com/ijry/uview-plus/issues/419
147
+ return
148
+ }
149
+ innerValue.value = newVal
150
+ // 在H5中,外部value变化后,修改input中的值,不会触发@input事件,此时手动调用值变化方法
151
+ if (firstChange.value === false && changeFromInner.value === false) {
152
+ valueChange(innerValue.value, true)
153
+ }
154
+ firstChange.value = false
155
+ // 重置changeFromInner的值为false,标识下一次引起默认为外部引起的
156
+ changeFromInner.value = false
157
+ },
158
+ { immediate: true }
159
+ )
349
160
 
350
161
  /**
351
162
  * @description 是否显示清除控件
352
163
  * */
353
164
  const isShowClear = computed(() => {
354
- const { clearable, readonly } = props;
355
- return clearable && !readonly && innerValue.value !== "";
356
- });
165
+ const { clearable, readonly } = props
166
+ return clearable && !readonly && innerValue.value !== ''
167
+ })
357
168
  /**
358
169
  * @description 组件的类名
359
170
  * */
360
171
  const inputClass = computed((): string => {
361
- let classes: string[] = [],
362
- { border, shape } = props;
363
- border === "surround" &&
364
- (classes = classes.concat(["hy-border", "hy-input__radius"]));
365
- classes.push(`hy-input__${shape}`);
366
- border === "bottom" &&
367
- (classes = classes.concat(["hy-border__bottom", "hy-input__no-radius"]));
368
- props.disabled && classes.push("hy-input__disabled");
369
- return classes.join(" ");
370
- });
172
+ let classes: string[] = [],
173
+ { border, shape } = props
174
+ border === 'surround' && (classes = classes.concat(['hy-border', 'hy-input__radius']))
175
+ classes.push(`hy-input__${shape}`)
176
+ border === 'bottom' && (classes = classes.concat(['hy-border__bottom', 'hy-input__no-radius']))
177
+ props.disabled && classes.push('hy-input__disabled')
178
+ return classes.join(' ')
179
+ })
371
180
 
372
181
  /**
373
182
  * @description 组件的样式
374
183
  * */
375
184
  const wrapperStyle = computed((): CSSProperties => {
376
- const style: CSSProperties = {};
377
- style.paddingTop = "6px";
378
- style.paddingBottom = "6px";
379
- style.paddingLeft = "9px";
380
- style.paddingRight = "9px";
381
- // 禁用状态下,被背景色加上对应的样式
382
- if (props.disabled) {
383
- style.backgroundColor = props.disabledColor;
384
- }
385
- return Object.assign(style, props.customStyle);
386
- });
185
+ const style: CSSProperties = {}
186
+ style.paddingTop = '6px'
187
+ style.paddingBottom = '6px'
188
+ style.paddingLeft = '9px'
189
+ style.paddingRight = '9px'
190
+ // 禁用状态下,被背景色加上对应的样式
191
+ if (props.disabled) {
192
+ style.backgroundColor = props.disabledColor
193
+ }
194
+ return Object.assign(style, props.customStyle)
195
+ })
387
196
  /**
388
197
  * @description 输入框的样式
389
198
  * */
390
199
  const inputStyle = computed((): CSSProperties => {
391
- return {
392
- color: props.color,
393
- fontSize: addUnit(props.fontSize),
394
- textAlign: props.inputAlign,
395
- };
396
- });
200
+ return {
201
+ color: props.color,
202
+ fontSize: addUnit(props.fontSize),
203
+ textAlign: props.inputAlign
204
+ }
205
+ })
397
206
 
398
207
  /**
399
208
  * @description 边框颜色
400
209
  * */
401
210
  const borderStyle = computed(() => {
402
- return (isFocus: boolean) => {
403
- let style: CSSProperties = {};
404
- if (isFocus) {
405
- switch (props.border) {
406
- case "surround":
407
- style = { border: `1px solid var(--hy-theme-color, #3c9cff)` };
408
- break;
409
- case "bottom":
410
- style = { borderBottom: `1px solid var(--hy-theme-color, #3c9cff)` };
411
- break;
412
- default:
413
- break;
414
- }
211
+ return (isFocus: boolean) => {
212
+ let style: CSSProperties = {}
213
+ if (isFocus) {
214
+ switch (props.border) {
215
+ case 'surround':
216
+ style = { border: `1px solid var(--hy-theme-color, #3c9cff)` }
217
+ break
218
+ case 'bottom':
219
+ style = { borderBottom: `1px solid var(--hy-theme-color, #3c9cff)` }
220
+ break
221
+ default:
222
+ break
223
+ }
224
+ }
225
+ return style
415
226
  }
416
- return style;
417
- };
418
- });
227
+ })
419
228
 
420
229
  /**
421
230
  * @description 当键盘输入时,触发input事件
422
231
  */
423
232
  const onInput = (e: any) => {
424
- let { value = "" } = e.detail || {};
425
- // 为了避免props的单向数据流特性,需要先将innerValue值设置为当前值,再在$nextTick中重新赋予设置后的值才有效
426
- // console.log('onInput', value, this.innerValue)
427
- innerValue.value = value;
428
- nextTick(() => {
429
- let formatValue = innerFormatter(value);
430
- innerValue.value = formatValue;
431
- valueChange(formatValue);
432
- });
433
- };
233
+ let { value = '' } = e.detail || {}
234
+ // 为了避免props的单向数据流特性,需要先将innerValue值设置为当前值,再在$nextTick中重新赋予设置后的值才有效
235
+ // console.log('onInput', value, this.innerValue)
236
+ innerValue.value = value
237
+ nextTick(() => {
238
+ let formatValue = innerFormatter(value)
239
+ innerValue.value = formatValue
240
+ valueChange(formatValue)
241
+ })
242
+ }
434
243
  /**
435
244
  * @description 输入框失去焦点时触发
436
245
  * */
437
246
  const onBlur = async (event: InputOnBlurEvent) => {
438
- emit("blur", event, event.detail.value);
439
- if (formItem) formItem.handleBlur(event.detail.value);
440
- await sleep();
441
- focused.value = false;
442
- };
247
+ emit('blur', event, event.detail.value)
248
+ if (formItem) formItem.handleBlur(event.detail.value)
249
+ await sleep()
250
+ focused.value = false
251
+ }
443
252
  /**
444
253
  * @description 输入框聚焦时触发
445
254
  * */
446
255
  const onFocus = (e: InputOnFocusEvent) => {
447
- focused.value = true;
448
- emit("focus", e);
449
- };
256
+ focused.value = true
257
+ emit('focus', e)
258
+ }
450
259
 
451
260
  /**
452
261
  * @description 点击完成按钮时触发
453
262
  * */
454
263
  const onConfirm = (e: InputOnConfirmEvent) => {
455
- emit("confirm", e, innerValue.value);
456
- };
264
+ emit('confirm', e, innerValue.value)
265
+ }
457
266
  /**
458
267
  * 键盘高度发生变化的时候触发此事件
459
268
  * 兼容性:微信小程序2.7.0+、App 3.1.0+
460
269
  * */
461
270
  const onkeyboardheightchange = (event: InputOnKeyboardheightchange) => {
462
- emit("keyboardheightchange", event);
463
- };
271
+ emit('keyboardheightchange', event)
272
+ }
464
273
  /**
465
274
  * 内容发生变化,进行处理
466
275
  */
467
276
  const valueChange = (value: string | number, isOut = false) => {
468
- if (clearInput.value) {
469
- innerValue.value = "";
470
- clearInput.value = false;
471
- }
472
- nextTick(() => {
473
- if (!isOut || clearInput.value) {
474
- // 标识value值的变化是由内部引起的
475
- changeFromInner.value = true;
476
- emit("change", value);
477
- if (formItem) formItem.handleChange(value);
478
-
479
- emit("update:modelValue", value);
277
+ if (clearInput.value) {
278
+ innerValue.value = ''
279
+ clearInput.value = false
480
280
  }
481
- });
482
- };
281
+ nextTick(() => {
282
+ if (!isOut || clearInput.value) {
283
+ // 标识value值的变化是由内部引起的
284
+ changeFromInner.value = true
285
+ emit('change', value)
286
+ if (formItem) formItem.handleChange(value)
287
+
288
+ emit('update:modelValue', value)
289
+ }
290
+ })
291
+ }
483
292
  /**
484
293
  * @description 点击清除控件
485
294
  */
486
295
  const onClear = () => {
487
- clearInput.value = true;
488
- innerValue.value = "";
489
- nextTick(() => {
490
- valueChange("");
491
- emit("clear");
492
- });
493
- };
296
+ clearInput.value = true
297
+ innerValue.value = ''
298
+ nextTick(() => {
299
+ valueChange('')
300
+ emit('clear')
301
+ })
302
+ }
494
303
  /**
495
304
  * 在安卓nvue上,事件无法冒泡
496
305
  * 在某些时间,我们希望监听u-from-item的点击事件,此时会导致点击u-form-item内的u-input后
497
306
  * 无法触发u-form-item的点击事件,这里通过手动调用u-form-item的方法进行触发
498
307
  */
499
308
  const clickHandler = () => {
500
- // 隐藏键盘
501
- if (props.disabled || props.readonly) {
502
- uni.hideKeyboard();
503
- }
504
- };
309
+ // 隐藏键盘
310
+ if (props.disabled || props.readonly) {
311
+ uni.hideKeyboard()
312
+ }
313
+ }
505
314
 
506
315
  /**
507
316
  * @description 点击前缀
508
317
  * */
509
318
  const onPrefix = () => {
510
- emit("onPrefix");
511
- };
319
+ emit('onPrefix')
320
+ }
512
321
  /**
513
322
  * @description 点击后缀
514
323
  * */
515
324
  const onSuffix = () => {
516
- emit("onSuffix");
517
- };
325
+ emit('onSuffix')
326
+ }
518
327
  </script>
519
328
 
520
329
  <style lang="scss" scoped>
521
- @import "./index.scss";
330
+ @import './index.scss';
522
331
  </style>