hy-app 0.1.1

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 (206) hide show
  1. package/README.md +42 -0
  2. package/api/http.ts +138 -0
  3. package/api/index.ts +1 -0
  4. package/common/index.ts +1 -0
  5. package/common/versionControl.ts +102 -0
  6. package/components/dialog/TheDialog.vue +128 -0
  7. package/components/dialog/index.ts +38 -0
  8. package/components/hy-address-picker/hy-address-picker.vue +262 -0
  9. package/components/hy-address-picker/props.ts +27 -0
  10. package/components/hy-address-picker/typing.d.ts +98 -0
  11. package/components/hy-avatar/hy-avatar.vue +217 -0
  12. package/components/hy-avatar/props.ts +20 -0
  13. package/components/hy-avatar/typing.d.ts +64 -0
  14. package/components/hy-back-top/hy-back-top.vue +71 -0
  15. package/components/hy-back-top/props.ts +23 -0
  16. package/components/hy-back-top/typing.d.ts +49 -0
  17. package/components/hy-badge/hy-badge.vue +155 -0
  18. package/components/hy-badge/props.ts +19 -0
  19. package/components/hy-badge/typing.d.ts +60 -0
  20. package/components/hy-button/hy-button.vue +394 -0
  21. package/components/hy-button/props.ts +36 -0
  22. package/components/hy-button/typing.d.ts +125 -0
  23. package/components/hy-card/hy-card.vue +198 -0
  24. package/components/hy-card/props.ts +29 -0
  25. package/components/hy-card/typing.d.ts +112 -0
  26. package/components/hy-cell/hy-cell.vue +268 -0
  27. package/components/hy-cell/props.ts +20 -0
  28. package/components/hy-cell/typing.d.ts +98 -0
  29. package/components/hy-check-button/hy-check-button.vue +71 -0
  30. package/components/hy-check-button/props.ts +20 -0
  31. package/components/hy-check-button/typing.d.ts +79 -0
  32. package/components/hy-checkbox/hy-checkbox.vue +299 -0
  33. package/components/hy-checkbox/props.ts +28 -0
  34. package/components/hy-checkbox/typing.d.ts +77 -0
  35. package/components/hy-datetime-picker/hy-datetime-picker.vue +584 -0
  36. package/components/hy-datetime-picker/props.ts +36 -0
  37. package/components/hy-datetime-picker/typing.d.ts +135 -0
  38. package/components/hy-divider/hy-divider.vue +164 -0
  39. package/components/hy-divider/props.ts +21 -0
  40. package/components/hy-divider/typing.d.ts +64 -0
  41. package/components/hy-empty/hy-empty.vue +122 -0
  42. package/components/hy-empty/props.ts +21 -0
  43. package/components/hy-empty/typing.d.ts +68 -0
  44. package/components/hy-folding-panel/hy-folding-panel.vue +94 -0
  45. package/components/hy-folding-panel/props.ts +17 -0
  46. package/components/hy-folding-panel/typing.d.ts +59 -0
  47. package/components/hy-form/hy-form.vue +372 -0
  48. package/components/hy-form/props.ts +15 -0
  49. package/components/hy-form/typing.d.ts +51 -0
  50. package/components/hy-grid/hy-grid.vue +126 -0
  51. package/components/hy-grid/props.ts +16 -0
  52. package/components/hy-grid/typing.d.ts +62 -0
  53. package/components/hy-icon/hy-icon.vue +207 -0
  54. package/components/hy-icon/props.ts +24 -0
  55. package/components/hy-icon/typing.d.ts +80 -0
  56. package/components/hy-input/hy-input.vue +402 -0
  57. package/components/hy-input/props.ts +41 -0
  58. package/components/hy-input/typing.d.ts +148 -0
  59. package/components/hy-line/hy-line.vue +44 -0
  60. package/components/hy-line/props.ts +12 -0
  61. package/components/hy-line/typing.d.ts +32 -0
  62. package/components/hy-line-progress/hy-line-progress.vue +118 -0
  63. package/components/hy-line-progress/props.ts +12 -0
  64. package/components/hy-line-progress/typing.d.ts +28 -0
  65. package/components/hy-list/hy-list.vue +250 -0
  66. package/components/hy-list/props.ts +18 -0
  67. package/components/hy-list/typing.d.ts +50 -0
  68. package/components/hy-login/ThePhoneLogin.vue +106 -0
  69. package/components/hy-login/TheUserLogin.vue +391 -0
  70. package/components/hy-login/hy-login.vue +283 -0
  71. package/components/hy-login/props.ts +32 -0
  72. package/components/hy-login/typing.d.ts +60 -0
  73. package/components/hy-modal/hy-modal.vue +240 -0
  74. package/components/hy-modal/props.ts +24 -0
  75. package/components/hy-modal/typing.d.ts +70 -0
  76. package/components/hy-navbar/hy-navbar.vue +194 -0
  77. package/components/hy-navbar/props.ts +24 -0
  78. package/components/hy-navbar/typing.d.ts +81 -0
  79. package/components/hy-notice-bar/hy-column-notice.vue +130 -0
  80. package/components/hy-notice-bar/hy-notice-bar.vue +82 -0
  81. package/components/hy-notice-bar/hy-row-notice.vue +182 -0
  82. package/components/hy-notice-bar/props.ts +19 -0
  83. package/components/hy-notice-bar/typing.d.ts +56 -0
  84. package/components/hy-number-step/hy-number-step.vue +428 -0
  85. package/components/hy-number-step/props.ts +29 -0
  86. package/components/hy-number-step/typing.d.ts +104 -0
  87. package/components/hy-overlay/hy-overlay.vue +54 -0
  88. package/components/hy-overlay/props.ts +10 -0
  89. package/components/hy-overlay/typing.d.ts +24 -0
  90. package/components/hy-picker/hy-picker.vue +499 -0
  91. package/components/hy-picker/props.ts +30 -0
  92. package/components/hy-picker/typing.d.ts +115 -0
  93. package/components/hy-popup/hy-popup.vue +269 -0
  94. package/components/hy-popup/props.ts +21 -0
  95. package/components/hy-popup/typing.d.ts +68 -0
  96. package/components/hy-price/hy-price.vue +86 -0
  97. package/components/hy-price/props.ts +13 -0
  98. package/components/hy-price/typing.d.ts +36 -0
  99. package/components/hy-qrcode/hy-qrcode.vue +153 -0
  100. package/components/hy-qrcode/props.ts +20 -0
  101. package/components/hy-qrcode/qrcode.js +1364 -0
  102. package/components/hy-qrcode/typing.d.ts +64 -0
  103. package/components/hy-radio/hy-radio.vue +319 -0
  104. package/components/hy-radio/props.ts +28 -0
  105. package/components/hy-radio/typing.d.ts +85 -0
  106. package/components/hy-rate/hy-rate.vue +261 -0
  107. package/components/hy-rate/props.ts +18 -0
  108. package/components/hy-rate/typing.d.ts +60 -0
  109. package/components/hy-read-more/hy-read-more.vue +134 -0
  110. package/components/hy-read-more/props.ts +20 -0
  111. package/components/hy-read-more/typing.d.ts +44 -0
  112. package/components/hy-safe-bottom/hy-safe-bottom.vue +64 -0
  113. package/components/hy-scroll-list/hy-scroll-list.vue +146 -0
  114. package/components/hy-scroll-list/props.ts +12 -0
  115. package/components/hy-scroll-list/typing.d.ts +28 -0
  116. package/components/hy-search/hy-search.vue +294 -0
  117. package/components/hy-search/props.ts +29 -0
  118. package/components/hy-search/typing.d.ts +109 -0
  119. package/components/hy-slider/hy-slider.vue +511 -0
  120. package/components/hy-slider/props.ts +21 -0
  121. package/components/hy-slider/typing.d.ts +68 -0
  122. package/components/hy-steps/hy-steps.vue +352 -0
  123. package/components/hy-steps/props.ts +15 -0
  124. package/components/hy-steps/typing.d.ts +58 -0
  125. package/components/hy-subsection/hy-subsection.vue +272 -0
  126. package/components/hy-subsection/props.ts +16 -0
  127. package/components/hy-subsection/typing.d.ts +44 -0
  128. package/components/hy-swiper/hy-swiper-indicator.vue +105 -0
  129. package/components/hy-swiper/hy-swiper.vue +242 -0
  130. package/components/hy-swiper/props.ts +30 -0
  131. package/components/hy-swiper/typing.d.ts +107 -0
  132. package/components/hy-switch/hy-switch.vue +168 -0
  133. package/components/hy-switch/props.ts +16 -0
  134. package/components/hy-switch/typing.d.ts +48 -0
  135. package/components/hy-tabs/hy-tabs.vue +416 -0
  136. package/components/hy-tabs/props.ts +26 -0
  137. package/components/hy-tabs/typing.d.ts +86 -0
  138. package/components/hy-tag/hy-tag.vue +374 -0
  139. package/components/hy-tag/props.ts +22 -0
  140. package/components/hy-tag/typing.d.ts +76 -0
  141. package/components/hy-textarea/hy-textarea.vue +229 -0
  142. package/components/hy-textarea/props.ts +26 -0
  143. package/components/hy-textarea/typing.d.ts +27 -0
  144. package/components/hy-tooltip/hy-tooltip.vue +332 -0
  145. package/components/hy-tooltip/props.ts +17 -0
  146. package/components/hy-tooltip/typing.d.ts +52 -0
  147. package/components/hy-transition/hy-transition.vue +150 -0
  148. package/components/hy-transition/index.scss +113 -0
  149. package/components/hy-transition/props.ts +10 -0
  150. package/components/hy-transition/typing.d.ts +36 -0
  151. package/components/hy-upload/hy-upload.vue +557 -0
  152. package/components/hy-upload/props.ts +29 -0
  153. package/components/hy-upload/typing.d.ts +147 -0
  154. package/components/hy-warn/hy-warn.vue +228 -0
  155. package/components/hy-warn/props.ts +14 -0
  156. package/components/hy-warn/typing.d.ts +40 -0
  157. package/components/hy-waterfall/hy-waterfall.vue +51 -0
  158. package/components/hy-waterfall/props.ts +10 -0
  159. package/components/hy-waterfall/typing.d.ts +20 -0
  160. package/components/index.ts +162 -0
  161. package/components/message/TheMessage.vue +169 -0
  162. package/components/message/index.ts +54 -0
  163. package/components/u-form/form.js +22 -0
  164. package/components/u-form/hy-form.vue +324 -0
  165. package/components/u-form/props.js +49 -0
  166. package/components/u-form/schema.js +1451 -0
  167. package/components/u-form/u-form.vue +267 -0
  168. package/components/u-form/utils.js +65 -0
  169. package/components/u-form-item/formItem.js +24 -0
  170. package/components/u-form-item/hy-form-item.vue +360 -0
  171. package/components/u-form-item/props.js +57 -0
  172. package/components/u-form-item/u-form-item.vue +294 -0
  173. package/components/yk-dialog/yk-dialog.vue +129 -0
  174. package/components/yk-tabbar/props.ts +49 -0
  175. package/components/yk-tabbar/yk-tabbar.vue +224 -0
  176. package/config/color.ts +6 -0
  177. package/config/icon.ts +366 -0
  178. package/config/index.ts +2 -0
  179. package/global/index.ts +6 -0
  180. package/global/register-properties.ts +37 -0
  181. package/index.ts +8 -0
  182. package/libs/css/common.scss +0 -0
  183. package/libs/css/iconfont.css +379 -0
  184. package/libs/css/iconfont.ttf +0 -0
  185. package/libs/css/mixin.scss +15 -0
  186. package/package.json +42 -0
  187. package/public/icons/error.png +0 -0
  188. package/public/icons/success.png +0 -0
  189. package/public/icons/warning.png +0 -0
  190. package/store/index.ts +1 -0
  191. package/store/userInfo.ts +25 -0
  192. package/theme.scss +94 -0
  193. package/typing/index.ts +7 -0
  194. package/typing/modules/common.d.ts +50 -0
  195. package/typing/modules/dialog.ts +17 -0
  196. package/typing/modules/enum.ts +67 -0
  197. package/typing/modules/form.ts +161 -0
  198. package/typing/modules/http.ts +68 -0
  199. package/typing/modules/icon.d.ts +366 -0
  200. package/typing/modules/img.ts +15 -0
  201. package/typing/modules/rect.ts +10 -0
  202. package/utils/address.json +5890 -0
  203. package/utils/base64.ts +119 -0
  204. package/utils/index.ts +3 -0
  205. package/utils/inside.ts +310 -0
  206. package/utils/utils.ts +446 -0
@@ -0,0 +1,207 @@
1
+ <template>
2
+ <view class="hy-icon" @tap="clickHandler" :class="[`hy-icon--${labelPos}`]">
3
+ <image
4
+ class="hy-icon__img"
5
+ v-if="isImg"
6
+ :src="name"
7
+ :mode="imgMode"
8
+ :style="[imgStyle, customStyle]"
9
+ ></image>
10
+ <text
11
+ v-else
12
+ class="hy-icon__icon"
13
+ :class="uClasses"
14
+ :style="[iconStyle, customStyle]"
15
+ ></text>
16
+ <!-- 这里进行空字符串判断,如果仅仅是v-if="label",可能会出现传递0的时候,结果也无法显示 -->
17
+ <text
18
+ v-if="label !== ''"
19
+ class="hy-icon__label"
20
+ :style="{
21
+ color: labelColor,
22
+ fontSize: addUnit(labelSize),
23
+ marginLeft: labelPos == 'right' ? addUnit(space) : 0,
24
+ marginTop: labelPos == 'bottom' ? addUnit(space) : 0
25
+ }"
26
+ >{{ label }}</text
27
+ >
28
+ </view>
29
+ </template>
30
+
31
+ <script setup lang="ts">
32
+ import { computed, CSSProperties, toRefs } from "vue";
33
+ import { ColorConfig, IconConfig } from "../../config";
34
+ import { addUnit } from "../../utils";
35
+ import defaultProps from "./props";
36
+ import IProps from "./typing";
37
+
38
+ const props = withDefaults(defineProps<IProps>(), defaultProps);
39
+ const {
40
+ customPrefix,
41
+ name,
42
+ color,
43
+ size,
44
+ bold,
45
+ top,
46
+ width,
47
+ height,
48
+ stop,
49
+ index,
50
+ isRotate,
51
+ round
52
+ } = toRefs(props);
53
+ const emit = defineEmits(["click"]);
54
+
55
+ const uClasses = computed(() => {
56
+ let classes = [];
57
+ classes.push(`${customPrefix.value}-${name.value}`);
58
+ classes.push("iconfont");
59
+ classes.push(customPrefix.value);
60
+ if (isRotate.value) classes.push("hy-rotate");
61
+ if (color.value)
62
+ // 主题色,通过类配置
63
+ classes.push("hy-icon__icon--" + color.value);
64
+ // 阿里,头条,百度小程序通过数组绑定类名时,无法直接使用[a, b, c]的形式,否则无法识别
65
+ // 故需将其拆成一个字符串的形式,通过空格隔开各个类名
66
+ //#ifdef MP-ALIPAY || MP-TOUTIAO || MP-BAIDU
67
+ classes = classes.join(" ");
68
+ //#endif
69
+ return classes;
70
+ });
71
+ const iconStyle = computed<CSSProperties>(() => {
72
+ let style: CSSProperties = {};
73
+ style = {
74
+ fontSize: addUnit(size.value),
75
+ lineHeight: addUnit(size.value),
76
+ fontWeight: bold.value ? "bold" : "normal",
77
+ // 某些特殊情况需要设置一个到顶部的距离,才能更好的垂直居中
78
+ top: addUnit(top.value),
79
+ borderRadius: addUnit(round.value),
80
+ color: color.value
81
+ ? color.value
82
+ : name.value === IconConfig.LOADING
83
+ ? ColorConfig.primary
84
+ : "#606266"
85
+ };
86
+
87
+ return style;
88
+ });
89
+
90
+ /**
91
+ * @description 判断传入的name属性,是否图片路径,只要带有"/"均认为是图片形式
92
+ * */
93
+ const isImg = computed(() => {
94
+ return name.value.indexOf("/") !== -1;
95
+ });
96
+ const imgStyle = computed((): CSSProperties => {
97
+ let style: CSSProperties = {};
98
+ // 如果设置width和height属性,则优先使用,否则使用size属性
99
+ style.width = width.value ? addUnit(width.value) : addUnit(size.value);
100
+ style.height = height.value ? addUnit(height.value) : addUnit(size.value);
101
+ style.borderRadius = addUnit(round.value);
102
+ return style;
103
+ });
104
+
105
+ /**
106
+ * @description 点击
107
+ * */
108
+ const clickHandler = (e: any) => {
109
+ emit("click", index.value, e);
110
+ // 是否阻止事件冒泡
111
+ stop.value && e.stopPropagation();
112
+ };
113
+ </script>
114
+
115
+ <style lang="scss" scoped>
116
+ @import "../../libs/css/mixin.scss";
117
+ @import "../../libs/css/iconfont.css";
118
+ @import "../../theme.scss";
119
+
120
+ /* #ifndef APP-NVUE */
121
+ // 非nvue下加载字体
122
+ @font-face {
123
+ font-family: "uicon-iconfont";
124
+ src: url("https://at.alicdn.com/t/font_2225171_8kdcwk4po24.ttf")
125
+ format("truetype");
126
+ }
127
+
128
+ /* #endif */
129
+
130
+ .hy-icon {
131
+ /* #ifndef APP-NVUE */
132
+ display: flex;
133
+ /* #endif */
134
+ align-items: center;
135
+
136
+ &--left {
137
+ flex-direction: row-reverse;
138
+ align-items: center;
139
+ }
140
+
141
+ &--right {
142
+ flex-direction: row;
143
+ align-items: center;
144
+ }
145
+
146
+ &--top {
147
+ flex-direction: column-reverse;
148
+ justify-content: center;
149
+ }
150
+
151
+ &--bottom {
152
+ flex-direction: column;
153
+ justify-content: center;
154
+ }
155
+
156
+ &__icon {
157
+ position: relative;
158
+ @include flex;
159
+ align-items: center;
160
+
161
+ &--primary {
162
+ color: $hy-primary;
163
+ }
164
+
165
+ &--success {
166
+ color: $hy-success;
167
+ }
168
+
169
+ &--error {
170
+ color: $hy-error;
171
+ }
172
+
173
+ &--warning {
174
+ color: $hy-warning;
175
+ }
176
+
177
+ &--info {
178
+ color: $hy-info;
179
+ }
180
+ }
181
+
182
+ &__img {
183
+ /* #ifndef APP-NVUE */
184
+ height: auto;
185
+ will-change: transform;
186
+ /* #endif */
187
+ }
188
+
189
+ &__label {
190
+ /* #ifndef APP-NVUE */
191
+ line-height: 1;
192
+ /* #endif */
193
+ }
194
+ }
195
+ .hy-rotate {
196
+ animation: hy-rotate 1s infinite linear;
197
+ @keyframes hy-rotate {
198
+ 0% {
199
+ transform: rotate(0deg);
200
+ }
201
+
202
+ to {
203
+ transform: rotate(1turn);
204
+ }
205
+ }
206
+ }
207
+ </style>
@@ -0,0 +1,24 @@
1
+ import IProps from "./typing";
2
+
3
+ const defaultProps: IProps = {
4
+ name: "",
5
+ color: "",
6
+ size: "16px",
7
+ bold: false,
8
+ index: "",
9
+ customPrefix: "hy-icon",
10
+ label: "",
11
+ labelPos: "right",
12
+ labelSize: "15px",
13
+ labelColor: "#606266",
14
+ space: "3px",
15
+ imgMode: "",
16
+ width: "",
17
+ height: "",
18
+ top: 0,
19
+ stop: false,
20
+ isRotate: false,
21
+ round: 0
22
+ };
23
+
24
+ export default defaultProps;
@@ -0,0 +1,80 @@
1
+ import { CSSProperties } from "vue";
2
+
3
+ export default interface IProps {
4
+ /**
5
+ * @description 图标名称,见示例图标集
6
+ * */
7
+ name: string | HyIconConfig;
8
+ /**
9
+ * @description 图标颜色
10
+ * */
11
+ color?: string;
12
+ /**
13
+ * @description 图标字体大小,单位px (默认 '16px' )
14
+ * */
15
+ size?: string | number;
16
+ /**
17
+ * @description 是否显示粗体 (默认 false )
18
+ * */
19
+ bold?: boolean;
20
+ /**
21
+ * @description 点击图标的时候传递事件出去的index(用于区分点击了哪一个)
22
+ * */
23
+ index?: string | number;
24
+ /**
25
+ * @description 自定义扩展前缀,方便用户扩展自己的图标库 (默认 'hy-icon' )
26
+ * */
27
+ customPrefix?: string;
28
+ /**
29
+ * @description 图标右侧的label文字
30
+ * */
31
+ label?: string;
32
+ /**
33
+ * @description label相对于图标的位置,只能right或bottom (默认 'right' )
34
+ * */
35
+ labelPos?: "right" | "bottom";
36
+ /**
37
+ * @description label字体大小,单位px (默认 '15px' )
38
+ * */
39
+ labelSize?: string | number;
40
+ /**
41
+ * @description 图标右侧的label文字颜色
42
+ * */
43
+ labelColor?: string;
44
+ /**
45
+ * @description label与图标的距离,单位px (默认 '3px' )
46
+ * */
47
+ space?: string | number;
48
+ /**
49
+ * @description 图片的mode
50
+ * */
51
+ imgMode?: string;
52
+ /**
53
+ * @description 显示图片小图标时的宽度
54
+ * */
55
+ width?: string | number;
56
+ /**
57
+ * @description 显示图片小图标时的高度
58
+ * */
59
+ height?: string | number;
60
+ /**
61
+ * @description 图标在垂直方向上的定位 用于解决某些情况下,让图标垂直居中的用途 (默认 0 )
62
+ * */
63
+ top?: number | string;
64
+ /**
65
+ * @description 是否阻止事件传播 (默认 false )
66
+ * */
67
+ stop?: boolean;
68
+ /**
69
+ * @description 是否旋转 (默认 false )
70
+ * */
71
+ isRotate?: boolean;
72
+ /**
73
+ * @description 图标圆角
74
+ * */
75
+ round?: string | number;
76
+ /**
77
+ * @description 自定义样式
78
+ * */
79
+ customStyle?: CSSProperties;
80
+ }
@@ -0,0 +1,402 @@
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 || $slots.prefix"
10
+ >
11
+ <slot name="prefix">
12
+ <HyIcon
13
+ :name="prefixIcon"
14
+ size="18"
15
+ :customStyle="prefixIconStyle"
16
+ ></HyIcon>
17
+ </slot>
18
+ </view>
19
+ <view class="hy-input__content__field-wrapper" @tap="clickHandler">
20
+ <!-- 根据uni-app的input组件文档,H5和APP中只要声明了password参数(无论true还是false),type均失效,此时
21
+ 为了防止type=number时,又存在password属性,type无效,此时需要设置password为undefined
22
+ -->
23
+ <input
24
+ ref="input-native"
25
+ class="hy-input__content__field-wrapper__field"
26
+ :style="[inputStyle]"
27
+ :type="type"
28
+ :focus="focus"
29
+ :cursor="cursor"
30
+ :value="innerValue"
31
+ :auto-blur="autoBlur"
32
+ :disabled="disabled || readonly"
33
+ :maxlength="maxlength"
34
+ :placeholder="placeholder || ''"
35
+ :placeholder-style="formatObject(placeholderStyle)"
36
+ :placeholder-class="placeholderClass"
37
+ :confirm-type="confirmType"
38
+ :confirm-hold="confirmHold"
39
+ :hold-keyboard="holdKeyboard"
40
+ :cursor-spacing="cursorSpacing"
41
+ :adjust-position="adjustPosition"
42
+ :selection-end="selectionEnd"
43
+ :selection-start="selectionStart"
44
+ :password="password || type === 'password' || false"
45
+ :ignoreCompositionEvent="ignoreCompositionEvent"
46
+ @input="onInput"
47
+ @blur="onBlur"
48
+ @focus="onFocus"
49
+ @confirm="onConfirm"
50
+ @keyboardheightchange="onkeyboardheightchange"
51
+ @nicknamereview="onnicknamereview"
52
+ />
53
+ </view>
54
+ <view
55
+ class="hy-input__content__clear"
56
+ v-if="isShowClear"
57
+ @click="onClear"
58
+ >
59
+ <HyIcon
60
+ :name="IconConfig.COLSE"
61
+ size="11"
62
+ color="#ffffff"
63
+ :customStyle="{ lineHeight: '12px' }"
64
+ ></HyIcon>
65
+ </view>
66
+ <view
67
+ class="hy-input__content__subfix-icon"
68
+ v-if="suffixIcon || $slots.suffix"
69
+ >
70
+ <slot name="suffix">
71
+ <HyIcon
72
+ :name="suffixIcon"
73
+ size="18"
74
+ :customStyle="suffixIconStyle"
75
+ ></HyIcon>
76
+ </slot>
77
+ </view>
78
+ </view>
79
+ </view>
80
+ </template>
81
+
82
+ <script setup lang="ts">
83
+ import {
84
+ computed,
85
+ CSSProperties,
86
+ inject,
87
+ nextTick,
88
+ ref,
89
+ toRefs,
90
+ watch,
91
+ getCurrentInstance
92
+ } from "vue";
93
+ import HyIcon from "../hy-icon/hy-icon.vue";
94
+ import { addUnit, formatObject, formValidate } from "../../utils";
95
+ import defaultProps from "./props";
96
+ import { ColorConfig, IconConfig } from "../../config";
97
+ import IProps from "./typing";
98
+
99
+ const props = withDefaults(defineProps<IProps>(), defaultProps);
100
+ const {
101
+ disabled,
102
+ disabledColor,
103
+ border,
104
+ color,
105
+ inputAlign,
106
+ customStyle,
107
+ fontSize,
108
+ readonly,
109
+ placeholderStyle
110
+ } = toRefs(props);
111
+ const emit = defineEmits([
112
+ "blur",
113
+ "focus",
114
+ "confirm",
115
+ "keyboardheightchange",
116
+ "nicknamereview",
117
+ "change",
118
+ "update:modelValue",
119
+ "clear"
120
+ ]);
121
+
122
+ const instance = getCurrentInstance();
123
+ // 清除操作
124
+ const clearInput = ref<boolean>(false);
125
+ // 输入框的值
126
+ const innerValue = ref<string | number>("");
127
+ // 是否处于获得焦点状态
128
+ const focused = ref<boolean>(false);
129
+ // value是否第一次变化,在watch中,由于加入immediate属性,会在第一次触发,此时不应该认为value发生了变化
130
+ const firstChange = ref<boolean>(true);
131
+ // value绑定值的变化是由内部还是外部引起的
132
+ const changeFromInner = ref<boolean>(false);
133
+ const innerFormatter = (value: string) => value;
134
+
135
+ watch(
136
+ () => props.modelValue,
137
+ (newVal) => {
138
+ if (changeFromInner.value || innerValue.value === newVal) {
139
+ changeFromInner.value = false; // 重要否则会出现双向绑定失效问题https://github.com/ijry/uview-plus/issues/419
140
+ return;
141
+ }
142
+ innerValue.value = newVal;
143
+ // 在H5中,外部value变化后,修改input中的值,不会触发@input事件,此时手动调用值变化方法
144
+ if (firstChange.value === false && changeFromInner.value === false) {
145
+ valueChange(innerValue.value, true);
146
+ } else {
147
+ // 尝试调用up-form的验证方法
148
+ // if (!firstChange.value) formValidate(this, "change");
149
+ }
150
+ firstChange.value = false;
151
+ // 重置changeFromInner的值为false,标识下一次引起默认为外部引起的
152
+ changeFromInner.value = false;
153
+ },
154
+ { immediate: true }
155
+ );
156
+
157
+ /**
158
+ * @description 是否显示清除控件
159
+ * */
160
+ const isShowClear = computed(() => {
161
+ const { clearable, readonly } = props;
162
+ return clearable && !readonly && !!focused.value && innerValue.value !== "";
163
+ });
164
+ /**
165
+ * @description 组件的类名
166
+ * */
167
+ const inputClass = computed((): string => {
168
+ let classes: string[] = [],
169
+ { border, shape } = props;
170
+ border === "surround" &&
171
+ (classes = classes.concat(["hy-border", "hy-input--radius"]));
172
+ classes.push(`hy-input--${shape}`);
173
+ border === "bottom" &&
174
+ (classes = classes.concat(["hy-border-bottom", "hy-input--no-radius"]));
175
+ return classes.join(" ");
176
+ });
177
+
178
+ /**
179
+ * @description 组件的样式
180
+ * */
181
+ const wrapperStyle = computed((): CSSProperties => {
182
+ const style: CSSProperties = {};
183
+ // 禁用状态下,被背景色加上对应的样式
184
+ // 无边框时,去除内边距
185
+ if (border.value === "none") {
186
+ style.padding = "0";
187
+ } else {
188
+ // 由于uni-app的iOS开发者能力有限,导致需要分开写才有效
189
+ style.paddingTop = "6px";
190
+ style.paddingBottom = "6px";
191
+ style.paddingLeft = "9px";
192
+ style.paddingRight = "9px";
193
+ }
194
+ if (disabled.value) {
195
+ style.backgroundColor = disabledColor.value;
196
+ }
197
+ return Object.assign(style, customStyle.value);
198
+ });
199
+ /**
200
+ * @description 输入框的样式
201
+ * */
202
+ const inputStyle = computed((): CSSProperties => {
203
+ return {
204
+ color: color.value,
205
+ fontSize: addUnit(fontSize.value),
206
+ textAlign: inputAlign.value
207
+ };
208
+ });
209
+
210
+ /**
211
+ * @description 边框颜色
212
+ * */
213
+ const borderStyle = computed(() => {
214
+ return (isFocus: boolean) => {
215
+ let style: CSSProperties = {};
216
+ if (isFocus) {
217
+ switch (border.value) {
218
+ case "surround":
219
+ style = { border: `1px solid ${ColorConfig.primary}` };
220
+ break;
221
+ case "bottom":
222
+ style = { borderBottom: `1px solid ${ColorConfig.primary}` };
223
+ break;
224
+ default:
225
+ break;
226
+ }
227
+ }
228
+ return style;
229
+ };
230
+ });
231
+
232
+ /**
233
+ * @description 当键盘输入时,触发input事件
234
+ */
235
+ const onInput = (e: any) => {
236
+ let { value = "" } = e.detail || {};
237
+ // 为了避免props的单向数据流特性,需要先将innerValue值设置为当前值,再在$nextTick中重新赋予设置后的值才有效
238
+ // console.log('onInput', value, this.innerValue)
239
+ innerValue.value = value;
240
+ nextTick(() => {
241
+ let formatValue = innerFormatter(value);
242
+ innerValue.value = formatValue;
243
+ valueChange(formatValue);
244
+ });
245
+ };
246
+ /**
247
+ * @description 输入框失去焦点时触发
248
+ * */
249
+ const onBlur = (event: Event) => {
250
+ emit("blur", event.detail.value);
251
+ // H5端的blur会先于点击清除控件的点击click事件触发,导致focused
252
+ // 瞬间为false,从而隐藏了清除控件而无法被点击到
253
+ setTimeout(() => {
254
+ focused.value = false;
255
+ }, 150);
256
+ };
257
+ /**
258
+ * @description 输入框聚焦时触发
259
+ * */
260
+ const onFocus = () => {
261
+ focused.value = true;
262
+ emit("focus");
263
+ };
264
+
265
+ /**
266
+ * @description 点击完成按钮时触发
267
+ * */
268
+ const onConfirm = (event: string) => {
269
+ emit("confirm", innerValue.value);
270
+ };
271
+ /**
272
+ * 键盘高度发生变化的时候触发此事件
273
+ * 兼容性:微信小程序2.7.0+、App 3.1.0+
274
+ * */
275
+ const onkeyboardheightchange = (event: any) => {
276
+ emit("keyboardheightchange", event);
277
+ };
278
+ const onnicknamereview = (event: any) => {
279
+ emit("nicknamereview", event);
280
+ };
281
+ /**
282
+ * 内容发生变化,进行处理
283
+ */
284
+ const valueChange = (value: string | number, isOut = false) => {
285
+ if (clearInput.value) {
286
+ innerValue.value = "";
287
+ clearInput.value = false;
288
+ }
289
+ nextTick(() => {
290
+ if (!isOut || clearInput.value) {
291
+ // 标识value值的变化是由内部引起的
292
+ changeFromInner.value = true;
293
+ emit("change", value);
294
+
295
+ emit("update:modelValue", value);
296
+ }
297
+ });
298
+ };
299
+ /**
300
+ * @description 点击清除控件
301
+ */
302
+ const onClear = () => {
303
+ clearInput.value = true;
304
+ innerValue.value = "";
305
+ nextTick(() => {
306
+ valueChange("");
307
+ emit("clear");
308
+ });
309
+ };
310
+ /**
311
+ * 在安卓nvue上,事件无法冒泡
312
+ * 在某些时间,我们希望监听u-from-item的点击事件,此时会导致点击u-form-item内的u-input后
313
+ * 无法触发u-form-item的点击事件,这里通过手动调用u-form-item的方法进行触发
314
+ */
315
+ const clickHandler = () => {
316
+ if (disabled.value || readonly.value) {
317
+ uni.hideKeyboard();
318
+ }
319
+ // #ifdef APP-NVUE
320
+ if (os() === "android") {
321
+ const formItem = $parent.call(this, "u-form-item");
322
+ if (formItem) {
323
+ formItem.clickHandler();
324
+ }
325
+ }
326
+ // #endif
327
+ };
328
+ </script>
329
+
330
+ <style lang="scss" scoped>
331
+ @import "../../libs/css/mixin.scss";
332
+ @import "../../theme.scss";
333
+
334
+ .hy-input {
335
+ @include flex(row);
336
+ align-items: center;
337
+ justify-content: space-between;
338
+ flex: 1;
339
+
340
+ &--radius,
341
+ &--square {
342
+ border-radius: 4px;
343
+ }
344
+
345
+ &--no-radius {
346
+ border-radius: 0;
347
+ }
348
+
349
+ &--circle {
350
+ border-radius: 100px;
351
+ }
352
+
353
+ &__content {
354
+ flex: 1;
355
+ @include flex(row);
356
+ align-items: center;
357
+ justify-content: space-between;
358
+
359
+ &__field-wrapper {
360
+ position: relative;
361
+ @include flex(row);
362
+ margin: 0;
363
+ flex: 1;
364
+
365
+ &__field {
366
+ line-height: 26px;
367
+ text-align: left;
368
+ color: $hy-text-color;
369
+ height: 24px;
370
+ font-size: 15px;
371
+ flex: 1;
372
+ }
373
+ }
374
+
375
+ &__clear {
376
+ width: 20px;
377
+ height: 20px;
378
+ border-radius: 100px;
379
+ background-color: #c6c7cb;
380
+ @include flex(row);
381
+ align-items: center;
382
+ justify-content: center;
383
+ transform: scale(0.82);
384
+ margin-left: 4px;
385
+ }
386
+
387
+ &__subfix-icon {
388
+ margin-left: 4px;
389
+ }
390
+
391
+ &__prefix-icon {
392
+ margin-right: 4px;
393
+ }
394
+ }
395
+ }
396
+ .hy-border-bottom {
397
+ border-bottom: $hy-border-line;
398
+ }
399
+ .hy-border {
400
+ border: $hy-border-line;
401
+ }
402
+ </style>