hy-app 0.3.0 → 0.3.2
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.
- package/README.md +6 -3
- package/common/shakeService.ts +31 -29
- package/components/avatar.zip +0 -0
- package/components/hy-action-sheet/hy-action-sheet.vue +71 -46
- package/components/hy-address-picker/hy-address-picker.vue +94 -83
- package/components/hy-avatar/hy-avatar.vue +84 -85
- package/components/hy-back-top/hy-back-top.vue +8 -6
- package/components/hy-badge/hy-badge.vue +47 -46
- package/components/hy-button/hy-button.vue +117 -93
- package/components/hy-calendar/hy-calendar.vue +168 -160
- package/components/hy-card/hy-card.vue +50 -43
- package/components/hy-card/typing.d.ts +33 -32
- package/components/hy-cell/hy-cell.vue +73 -51
- package/components/hy-check-button/hy-check-button.vue +54 -47
- package/components/hy-checkbox/hy-checkbox.vue +97 -105
- package/components/hy-code-input/hy-code-input.vue +80 -89
- package/components/hy-config-provider/hy-config-provider.vue +20 -21
- package/components/hy-count-down/hy-count-down.vue +66 -67
- package/components/hy-count-to/hy-count-to.vue +105 -99
- package/components/hy-count-to/typing.d.ts +13 -12
- package/components/hy-datetime-picker/hy-datetime-picker.vue +261 -253
- package/components/hy-datetime-picker/typing.d.ts +42 -40
- package/components/hy-divider/hy-divider.vue +68 -73
- package/components/hy-dropdown/hy-dropdown.vue +20 -19
- package/components/hy-dropdown-item/hy-dropdown-item.vue +66 -61
- package/components/hy-dropdown-item/typing.d.ts +9 -9
- package/components/hy-empty/hy-empty.vue +42 -42
- package/components/hy-flex/hy-flex.vue +99 -0
- package/components/hy-flex/index.scss +8 -0
- package/components/hy-flex/typing.d.ts +23 -0
- package/components/hy-float-button/hy-float-button.vue +218 -210
- package/components/hy-folding-panel/hy-folding-panel.vue +32 -33
- package/components/hy-form/hy-form.vue +264 -252
- package/components/hy-form/typing.d.ts +4 -0
- package/components/hy-form-group/hy-form-group.vue +114 -183
- package/components/hy-form-item/hy-form-item.vue +12 -10
- package/components/hy-form-item/index.scss +2 -2
- package/components/hy-form-item/typing.d.ts +3 -6
- package/components/hy-grid/hy-grid.vue +44 -43
- package/components/hy-icon/hy-icon.vue +61 -67
- package/components/hy-image/hy-image.vue +112 -88
- package/components/hy-image/typing.d.ts +27 -23
- package/components/hy-input/hy-input.vue +157 -127
- package/components/hy-input/typing.d.ts +53 -47
- package/components/hy-line/hy-line.vue +26 -26
- package/components/hy-line-progress/hy-line-progress.vue +42 -35
- package/components/hy-list/hy-list.vue +76 -85
- package/components/hy-loading/hy-loading.vue +26 -23
- package/components/hy-login/TheUserLogin.vue +1 -1
- package/components/hy-menu/hy-menu.vue +48 -43
- package/components/hy-menu/typing.d.ts +18 -17
- package/components/hy-modal/hy-modal.vue +39 -35
- package/components/hy-navbar/hy-navbar.vue +25 -25
- package/components/hy-navbar/typing.d.ts +24 -22
- package/components/hy-notice-bar/hy-notice-bar.vue +26 -27
- package/components/hy-notify/hy-notify.vue +53 -53
- package/components/hy-number-step/hy-number-step.vue +134 -146
- package/components/hy-number-step/typing.d.ts +35 -35
- package/components/hy-overlay/hy-overlay.vue +23 -21
- package/components/hy-pagination/hy-pagination.vue +41 -36
- package/components/hy-picker/hy-picker.vue +184 -154
- package/components/hy-picker/typing.d.ts +39 -39
- package/components/hy-popover/hy-popover.vue +97 -77
- package/components/hy-popup/hy-popup.vue +107 -98
- package/components/hy-price/hy-price.vue +38 -34
- package/components/hy-qrcode/hy-qrcode.vue +50 -51
- package/components/hy-radio/hy-radio.vue +101 -113
- package/components/hy-rate/hy-rate.vue +107 -88
- package/components/hy-read-more/hy-read-more.vue +64 -49
- package/components/hy-scroll-list/hy-scroll-list.vue +45 -48
- package/components/hy-search/hy-search.vue +73 -66
- package/components/hy-search/typing.d.ts +36 -35
- package/components/hy-signature/hy-signature.vue +282 -240
- package/components/hy-slider/hy-slider.vue +195 -153
- package/components/hy-slider/typing.d.ts +21 -21
- package/components/hy-steps/hy-steps.vue +118 -90
- package/components/hy-steps/index.scss +31 -21
- package/components/hy-submit-bar/hy-submit-bar.vue +61 -70
- package/components/hy-subsection/hy-subsection.vue +99 -102
- package/components/hy-subsection/typing.d.ts +19 -19
- package/components/hy-swipe-action/hy-swipe-action.vue +131 -118
- package/components/hy-swiper/hy-swiper.vue +85 -71
- package/components/hy-switch/hy-switch.vue +67 -72
- package/components/hy-switch/typing.d.ts +21 -19
- package/components/hy-tabs/hy-tabs.vue +168 -113
- package/components/hy-tag/hy-tag.vue +90 -86
- package/components/hy-tag/typing.d.ts +26 -21
- package/components/hy-text/hy-text.vue +119 -111
- package/components/hy-textarea/hy-textarea.vue +100 -93
- package/components/hy-textarea/typing.d.ts +36 -31
- package/components/hy-toast/hy-toast.vue +77 -67
- package/components/hy-tooltip/hy-tooltip.vue +109 -91
- package/components/hy-transition/hy-transition.vue +62 -66
- package/components/hy-upload/hy-upload.vue +294 -152
- package/components/hy-upload/typing.d.ts +41 -36
- package/components/hy-warn/hy-warn.vue +34 -27
- package/components/hy-waterfall/hy-waterfall.vue +83 -74
- package/components/hy-watermark/hy-watermark.vue +134 -115
- package/components/index.ts +1 -1
- package/composables/usePopover.ts +236 -221
- package/composables/useQueue.ts +53 -52
- package/global.d.ts +1 -0
- package/package.json +2 -2
- package/store/index.ts +9 -1
- package/theme.scss +5 -5
- package/typing/index.ts +0 -1
- package/typing/modules/common.d.ts +0 -2
- package/web-types.json +1 -1
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
:key="item.field"
|
|
7
7
|
>
|
|
8
8
|
<view v-if="item.label" class="hy-form--item__label" :style="labelStyle">
|
|
9
|
-
<text
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
<text v-if="isRequired(item.rules)" style="color: red; font-size: 20px; line-height: 10px">
|
|
10
|
+
*
|
|
11
|
+
</text>
|
|
12
|
+
{{ item.label }}
|
|
13
|
+
<text v-if="symbol">:</text>
|
|
14
14
|
</view>
|
|
15
15
|
<view class="hy-form--item__container">
|
|
16
16
|
<view class="hy-form--item__container-content">
|
|
@@ -20,35 +20,23 @@
|
|
|
20
20
|
v-model="formData[item.field]"
|
|
21
21
|
:type="item.type"
|
|
22
22
|
:disabled="item?.input?.disabled || input?.disabled"
|
|
23
|
-
:disabledColor="
|
|
24
|
-
item?.input?.disabledColor || input?.disabledColor
|
|
25
|
-
"
|
|
23
|
+
:disabledColor="item?.input?.disabledColor || input?.disabledColor"
|
|
26
24
|
:maxlength="item?.input?.maxlength || input?.maxlength"
|
|
27
25
|
:password="item?.input?.password"
|
|
28
26
|
:clearable="item?.input?.clearable || input?.clearable"
|
|
29
27
|
:readonly="item?.input?.readonly || input?.readonly"
|
|
30
28
|
:placeholder="item?.input?.placeholder"
|
|
31
|
-
:placeholderClass="
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
:placeholderStyle="
|
|
35
|
-
item?.input?.placeholderStyle || input?.placeholderStyle
|
|
36
|
-
"
|
|
37
|
-
:showWordLimit="
|
|
38
|
-
item?.input?.showWordLimit || input?.showWordLimit
|
|
39
|
-
"
|
|
29
|
+
:placeholderClass="item?.input?.placeholderClass || input?.placeholderClass"
|
|
30
|
+
:placeholderStyle="item?.input?.placeholderStyle || input?.placeholderStyle"
|
|
31
|
+
:showWordLimit="item?.input?.showWordLimit || input?.showWordLimit"
|
|
40
32
|
:confirmType="item?.input?.confirmType || input?.confirmType"
|
|
41
33
|
:confirmHold="item?.input?.confirmHold || input?.confirmHold"
|
|
42
34
|
:holdKeyboard="item?.input?.holdKeyboard || input?.holdKeyboard"
|
|
43
35
|
:focus="item?.input?.focus || input?.focus"
|
|
44
36
|
:autoBlur="item?.input?.autoBlur || input?.autoBlur"
|
|
45
|
-
:selectionStart="
|
|
46
|
-
item?.input?.selectionStart || input?.selectionStart
|
|
47
|
-
"
|
|
37
|
+
:selectionStart="item?.input?.selectionStart || input?.selectionStart"
|
|
48
38
|
:selectionEnd="item?.input?.selectionEnd || input?.selectionEnd"
|
|
49
|
-
:adjustPosition="
|
|
50
|
-
item?.input?.adjustPosition || input?.adjustPosition
|
|
51
|
-
"
|
|
39
|
+
:adjustPosition="item?.input?.adjustPosition || input?.adjustPosition"
|
|
52
40
|
:inputAlign="item?.input?.inputAlign || input?.inputAlign"
|
|
53
41
|
:fontSize="item?.input?.fontSize || input?.fontSize"
|
|
54
42
|
:color="item?.input?.color || input?.color"
|
|
@@ -91,25 +79,13 @@
|
|
|
91
79
|
:disabled="item?.textarea?.disabled || textarea?.disabled"
|
|
92
80
|
:maxlength="item?.textarea?.maxlength || textarea?.maxlength"
|
|
93
81
|
:placeholder="item?.textarea?.placeholder"
|
|
94
|
-
:placeholderClass="
|
|
95
|
-
|
|
96
|
-
"
|
|
97
|
-
:placeholderStyle="
|
|
98
|
-
item?.textarea?.placeholderStyle || textarea?.placeholderStyle
|
|
99
|
-
"
|
|
100
|
-
:holdKeyboard="
|
|
101
|
-
item?.textarea?.holdKeyboard || textarea?.holdKeyboard
|
|
102
|
-
"
|
|
82
|
+
:placeholderClass="item?.textarea?.placeholderClass || textarea?.placeholderClass"
|
|
83
|
+
:placeholderStyle="item?.textarea?.placeholderStyle || textarea?.placeholderStyle"
|
|
84
|
+
:holdKeyboard="item?.textarea?.holdKeyboard || textarea?.holdKeyboard"
|
|
103
85
|
:focus="item?.textarea?.focus || textarea?.focus"
|
|
104
|
-
:selectionStart="
|
|
105
|
-
|
|
106
|
-
"
|
|
107
|
-
:selectionEnd="
|
|
108
|
-
item?.textarea?.selectionEnd || textarea?.selectionEnd
|
|
109
|
-
"
|
|
110
|
-
:adjustPosition="
|
|
111
|
-
item?.textarea?.adjustPosition || textarea?.adjustPosition
|
|
112
|
-
"
|
|
86
|
+
:selectionStart="item?.textarea?.selectionStart || textarea?.selectionStart"
|
|
87
|
+
:selectionEnd="item?.textarea?.selectionEnd || textarea?.selectionEnd"
|
|
88
|
+
:adjustPosition="item?.textarea?.adjustPosition || textarea?.adjustPosition"
|
|
113
89
|
:formatter="item?.textarea?.formatter || textarea?.formatter"
|
|
114
90
|
:border="item?.textarea?.border || textarea?.border"
|
|
115
91
|
:customStyle="errorStyle(!!errors[item.field])"
|
|
@@ -130,13 +106,9 @@
|
|
|
130
106
|
:size="item?.checkButton?.size || checkButton?.size"
|
|
131
107
|
:col="item?.checkButton?.col || checkButton?.col"
|
|
132
108
|
:gap="item?.checkButton?.gap || checkButton?.gap"
|
|
133
|
-
:fieldNames="
|
|
134
|
-
item?.checkButton?.fieldNames || checkButton?.fieldNames
|
|
135
|
-
"
|
|
109
|
+
:fieldNames="item?.checkButton?.fieldNames || checkButton?.fieldNames"
|
|
136
110
|
:disabled="item?.checkButton?.size || checkButton?.disabled"
|
|
137
|
-
:selectType="
|
|
138
|
-
item?.checkButton?.selectType || checkButton?.selectType
|
|
139
|
-
"
|
|
111
|
+
:selectType="item?.checkButton?.selectType || checkButton?.selectType"
|
|
140
112
|
></hy-check-button>
|
|
141
113
|
</template>
|
|
142
114
|
<!-- 复选框/单选框 -->
|
|
@@ -151,9 +123,7 @@
|
|
|
151
123
|
:disabled="item?.radio?.disabled || radio?.disabled"
|
|
152
124
|
:size="item?.radio?.size || radio?.size"
|
|
153
125
|
:activeColor="item?.radio?.activeColor || radio?.activeColor"
|
|
154
|
-
:inactiveColor="
|
|
155
|
-
item?.radio?.inactiveColor || radio?.inactiveColor
|
|
156
|
-
"
|
|
126
|
+
:inactiveColor="item?.radio?.inactiveColor || radio?.inactiveColor"
|
|
157
127
|
:iconSize="item?.radio?.iconSize || radio?.iconSize"
|
|
158
128
|
:iconColor="item?.radio?.iconColor || radio?.iconColor"
|
|
159
129
|
:labelDisabled="item?.radio?.disabled || radio?.labelDisabled"
|
|
@@ -169,24 +139,12 @@
|
|
|
169
139
|
:loading="item?.switchItem?.loading || switchItem?.loading"
|
|
170
140
|
:disabled="item?.switchItem?.disabled || switchItem?.disabled"
|
|
171
141
|
:size="item?.switchItem?.size || switchItem?.size"
|
|
172
|
-
:activeColor="
|
|
173
|
-
|
|
174
|
-
"
|
|
175
|
-
:
|
|
176
|
-
|
|
177
|
-
"
|
|
178
|
-
:activeValue="
|
|
179
|
-
item?.switchItem?.activeValue || switchItem?.activeValue
|
|
180
|
-
"
|
|
181
|
-
:inactiveValue="
|
|
182
|
-
item?.switchItem?.inactiveValue || switchItem?.inactiveValue
|
|
183
|
-
"
|
|
184
|
-
:activeIcon="
|
|
185
|
-
item?.switchItem?.activeIcon || switchItem?.activeIcon
|
|
186
|
-
"
|
|
187
|
-
:inactiveIcon="
|
|
188
|
-
item?.switchItem?.inactiveIcon || switchItem?.inactiveIcon
|
|
189
|
-
"
|
|
142
|
+
:activeColor="item?.switchItem?.activeColor || switchItem?.activeColor"
|
|
143
|
+
:inactiveColor="item?.switchItem?.inactiveColor || switchItem?.inactiveColor"
|
|
144
|
+
:activeValue="item?.switchItem?.activeValue || switchItem?.activeValue"
|
|
145
|
+
:inactiveValue="item?.switchItem?.inactiveValue || switchItem?.inactiveValue"
|
|
146
|
+
:activeIcon="item?.switchItem?.activeIcon || switchItem?.activeIcon"
|
|
147
|
+
:inactiveIcon="item?.switchItem?.inactiveIcon || switchItem?.inactiveIcon"
|
|
190
148
|
:space="item?.switchItem?.space || switchItem?.space"
|
|
191
149
|
></HySwitch>
|
|
192
150
|
</template>
|
|
@@ -204,9 +162,7 @@
|
|
|
204
162
|
:confirmText="item?.picker?.confirmText || picker?.confirmText"
|
|
205
163
|
:cancelColor="item?.picker?.cancelColor || picker?.cancelColor"
|
|
206
164
|
:confirmColor="item?.picker?.confirmColor || picker?.confirmColor"
|
|
207
|
-
:visibleItemCount="
|
|
208
|
-
item?.picker?.visibleItemCount || picker?.visibleItemCount
|
|
209
|
-
"
|
|
165
|
+
:visibleItemCount="item?.picker?.visibleItemCount || picker?.visibleItemCount"
|
|
210
166
|
:closeOnClickOverlay="
|
|
211
167
|
item?.picker?.closeOnClickOverlay || picker?.closeOnClickOverlay
|
|
212
168
|
"
|
|
@@ -214,8 +170,7 @@
|
|
|
214
170
|
:showToolbar="item?.picker?.showToolbar || picker?.showToolbar"
|
|
215
171
|
:customStyle="errorStyle(!!errors[item.field])"
|
|
216
172
|
:input="{
|
|
217
|
-
disabled:
|
|
218
|
-
item?.picker?.input?.disabled || picker?.input?.disabled,
|
|
173
|
+
disabled: item?.picker?.input?.disabled || picker?.input?.disabled,
|
|
219
174
|
placeholder: item.picker?.input?.placeholder,
|
|
220
175
|
shape: item?.picker?.input?.shape || picker?.input?.shape,
|
|
221
176
|
border: item?.picker?.input?.border || picker?.input?.border,
|
|
@@ -237,9 +192,7 @@
|
|
|
237
192
|
:confirmText="item?.picker?.confirmText || picker?.confirmText"
|
|
238
193
|
:cancelColor="item?.picker?.cancelColor || picker?.cancelColor"
|
|
239
194
|
:confirmColor="item?.picker?.confirmColor || picker?.confirmColor"
|
|
240
|
-
:visibleItemCount="
|
|
241
|
-
item?.picker?.visibleItemCount || picker?.visibleItemCount
|
|
242
|
-
"
|
|
195
|
+
:visibleItemCount="item?.picker?.visibleItemCount || picker?.visibleItemCount"
|
|
243
196
|
:closeOnClickOverlay="
|
|
244
197
|
item?.picker?.closeOnClickOverlay || picker?.closeOnClickOverlay
|
|
245
198
|
"
|
|
@@ -247,8 +200,7 @@
|
|
|
247
200
|
:showToolbar="item?.picker?.showToolbar || picker?.showToolbar"
|
|
248
201
|
:customStyle="errorStyle(!!errors[item.field])"
|
|
249
202
|
:input="{
|
|
250
|
-
disabled:
|
|
251
|
-
item?.picker?.input?.disabled || picker?.input?.disabled,
|
|
203
|
+
disabled: item?.picker?.input?.disabled || picker?.input?.disabled,
|
|
252
204
|
placeholder: item.picker?.input?.placeholder,
|
|
253
205
|
shape: item?.picker?.input?.shape || picker?.input?.shape,
|
|
254
206
|
border: item?.picker?.input?.border || picker?.input?.border,
|
|
@@ -269,9 +221,7 @@
|
|
|
269
221
|
:confirmText="item?.picker?.confirmText || picker?.confirmText"
|
|
270
222
|
:cancelColor="item?.picker?.cancelColor || picker?.cancelColor"
|
|
271
223
|
:confirmColor="item?.picker?.confirmColor || picker?.confirmColor"
|
|
272
|
-
:visibleItemCount="
|
|
273
|
-
item?.picker?.visibleItemCount || picker?.visibleItemCount
|
|
274
|
-
"
|
|
224
|
+
:visibleItemCount="item?.picker?.visibleItemCount || picker?.visibleItemCount"
|
|
275
225
|
:closeOnClickOverlay="
|
|
276
226
|
item?.picker?.closeOnClickOverlay || picker?.closeOnClickOverlay
|
|
277
227
|
"
|
|
@@ -279,8 +229,7 @@
|
|
|
279
229
|
:showToolbar="item?.picker?.showToolbar || picker?.showToolbar"
|
|
280
230
|
:customStyle="errorStyle(!!errors[item.field])"
|
|
281
231
|
:input="{
|
|
282
|
-
disabled:
|
|
283
|
-
item?.picker?.input?.disabled || picker?.input?.disabled,
|
|
232
|
+
disabled: item?.picker?.input?.disabled || picker?.input?.disabled,
|
|
284
233
|
placeholder: item.picker?.input?.placeholder,
|
|
285
234
|
shape: item?.picker?.input?.shape || picker?.input?.shape,
|
|
286
235
|
border: item?.picker?.input?.border || picker?.input?.border,
|
|
@@ -303,9 +252,7 @@
|
|
|
303
252
|
|
|
304
253
|
<!-- 提示信息 -->
|
|
305
254
|
<HyTransition :show="!!errors[item.field]" mode="slide-left">
|
|
306
|
-
<view class="hy-form--item__container-warning">{{
|
|
307
|
-
errors[item.field]
|
|
308
|
-
}}</view>
|
|
255
|
+
<view class="hy-form--item__container-warning">{{ errors[item.field] }}</view>
|
|
309
256
|
</HyTransition>
|
|
310
257
|
<!-- 提示信息 -->
|
|
311
258
|
</view>
|
|
@@ -319,73 +266,65 @@ export default {
|
|
|
319
266
|
options: {
|
|
320
267
|
addGlobalClass: true,
|
|
321
268
|
virtualHost: true,
|
|
322
|
-
styleIsolation: 'shared'
|
|
323
|
-
}
|
|
269
|
+
styleIsolation: 'shared',
|
|
270
|
+
},
|
|
324
271
|
}
|
|
325
272
|
</script>
|
|
326
273
|
|
|
327
274
|
<script setup lang="ts">
|
|
328
|
-
import { computed,
|
|
329
|
-
import type
|
|
330
|
-
import
|
|
331
|
-
import
|
|
332
|
-
import
|
|
333
|
-
import {
|
|
275
|
+
import { computed, reactive, toRefs } from 'vue'
|
|
276
|
+
import type { CSSProperties } from 'vue'
|
|
277
|
+
import type IProps from './typing'
|
|
278
|
+
import defaultProps from './props'
|
|
279
|
+
import { addUnit, error } from '../../utils'
|
|
280
|
+
import type { FormColumnsType, RulesVo } from '../../typing'
|
|
281
|
+
import { FormTypeEnum } from '../../typing'
|
|
334
282
|
|
|
335
283
|
// 组件
|
|
336
|
-
import HyInput from
|
|
337
|
-
import HyPicker from
|
|
338
|
-
import HyUpload from
|
|
339
|
-
import HyTextarea from
|
|
340
|
-
import HySwitch from
|
|
341
|
-
import HyRadio from
|
|
342
|
-
import HyDatetimePicker from
|
|
343
|
-
import HyAddressPicker from
|
|
344
|
-
import HyTransition from
|
|
345
|
-
import HyCheckButton from
|
|
346
|
-
|
|
347
|
-
const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
348
|
-
const {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
labelAlign,
|
|
353
|
-
labelPosition,
|
|
354
|
-
borderBottom,
|
|
355
|
-
} = toRefs(props);
|
|
356
|
-
const emit = defineEmits(["click"]);
|
|
357
|
-
|
|
358
|
-
const labelPos = labelPosition.value === "top" ? "column" : "row";
|
|
284
|
+
import HyInput from '../hy-input/hy-input.vue'
|
|
285
|
+
import HyPicker from '../hy-picker/hy-picker.vue'
|
|
286
|
+
import HyUpload from '../hy-upload/hy-upload.vue'
|
|
287
|
+
import HyTextarea from '../hy-textarea/hy-textarea.vue'
|
|
288
|
+
import HySwitch from '../hy-switch/hy-switch.vue'
|
|
289
|
+
import HyRadio from '../hy-radio/hy-radio.vue'
|
|
290
|
+
import HyDatetimePicker from '../hy-datetime-picker/hy-datetime-picker.vue'
|
|
291
|
+
import HyAddressPicker from '../hy-address-picker/hy-address-picker.vue'
|
|
292
|
+
import HyTransition from '../hy-transition/hy-transition.vue'
|
|
293
|
+
import HyCheckButton from '../hy-check-button/hy-check-button.vue'
|
|
294
|
+
|
|
295
|
+
const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
296
|
+
const { formData, columns, labelWidth, labelAlign, labelPosition, borderBottom } = toRefs(props)
|
|
297
|
+
const emit = defineEmits(['click'])
|
|
298
|
+
|
|
299
|
+
const labelPos = labelPosition.value === 'top' ? 'column' : 'row'
|
|
359
300
|
const isInput = (type: FormTypeEnum) =>
|
|
360
|
-
type === FormTypeEnum.TEXT ||
|
|
361
|
-
type === FormTypeEnum.NUMBER ||
|
|
362
|
-
type === FormTypeEnum.PASSWORD;
|
|
301
|
+
type === FormTypeEnum.TEXT || type === FormTypeEnum.NUMBER || type === FormTypeEnum.PASSWORD
|
|
363
302
|
|
|
364
303
|
/**
|
|
365
304
|
* @description 错误输入框样式
|
|
366
305
|
* */
|
|
367
306
|
const errorStyle = computed(() => {
|
|
368
307
|
return (err: boolean) => {
|
|
369
|
-
const style: CSSProperties = {}
|
|
308
|
+
const style: CSSProperties = {}
|
|
370
309
|
if (err) {
|
|
371
|
-
style.background =
|
|
310
|
+
style.background = '#dd6161'
|
|
372
311
|
}
|
|
373
312
|
|
|
374
|
-
return style
|
|
375
|
-
}
|
|
376
|
-
})
|
|
313
|
+
return style
|
|
314
|
+
}
|
|
315
|
+
})
|
|
377
316
|
|
|
378
317
|
const isRequired = computed(() => {
|
|
379
318
|
return (temp: any) => {
|
|
380
319
|
if (Array.isArray(temp)) {
|
|
381
|
-
return temp.some((item) => item?.required)
|
|
320
|
+
return temp.some((item) => item?.required)
|
|
382
321
|
} else {
|
|
383
|
-
return temp?.required
|
|
322
|
+
return temp?.required
|
|
384
323
|
}
|
|
385
|
-
}
|
|
386
|
-
})
|
|
324
|
+
}
|
|
325
|
+
})
|
|
387
326
|
|
|
388
|
-
const errors: AnyObject = reactive({})
|
|
327
|
+
const errors: AnyObject = reactive({})
|
|
389
328
|
|
|
390
329
|
/**
|
|
391
330
|
* @description 标题行内样式
|
|
@@ -394,44 +333,36 @@ const labelStyle = computed(() => {
|
|
|
394
333
|
return {
|
|
395
334
|
textAlign: labelAlign.value,
|
|
396
335
|
width: addUnit(labelWidth.value),
|
|
397
|
-
}
|
|
398
|
-
})
|
|
336
|
+
}
|
|
337
|
+
})
|
|
399
338
|
|
|
400
339
|
/**
|
|
401
340
|
* @description 错误信息校验
|
|
402
341
|
* */
|
|
403
342
|
const errorMsg = (rule: RulesVo, value: string): string => {
|
|
404
343
|
// 手机正则
|
|
405
|
-
const phoneExpression = /^1[3-9]\d{9}
|
|
344
|
+
const phoneExpression = /^1[3-9]\d{9}$/
|
|
406
345
|
// 邮箱正则
|
|
407
|
-
const emitExpression = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}
|
|
346
|
+
const emitExpression = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/
|
|
408
347
|
// 复杂密码正则
|
|
409
348
|
const passwordExpression =
|
|
410
|
-
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]).{8,}
|
|
349
|
+
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]).{8,}$/
|
|
411
350
|
if (rule.required && !value) {
|
|
412
|
-
return rule.message
|
|
413
|
-
} else if (
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
return rule.message || "请输入正确的邮箱格式";
|
|
422
|
-
} else if (
|
|
423
|
-
rule.type === "password" &&
|
|
424
|
-
!passwordExpression.test(String(value))
|
|
425
|
-
) {
|
|
426
|
-
return (
|
|
427
|
-
rule.message || "至少8个字符串,并且包含大、小写字母、数字和特殊符号"
|
|
428
|
-
);
|
|
351
|
+
return rule.message!
|
|
352
|
+
} else if ((rule?.min || rule?.max) && (value.length < rule?.min! || value.length > rule?.max!)) {
|
|
353
|
+
return rule.message!
|
|
354
|
+
} else if (rule.type === 'phone' && !phoneExpression.test(String(value))) {
|
|
355
|
+
return rule.message || '请输入正确的手机号'
|
|
356
|
+
} else if (rule.type === 'email' && !emitExpression.test(String(value))) {
|
|
357
|
+
return rule.message || '请输入正确的邮箱格式'
|
|
358
|
+
} else if (rule.type === 'password' && !passwordExpression.test(String(value))) {
|
|
359
|
+
return rule.message || '至少8个字符串,并且包含大、小写字母、数字和特殊符号'
|
|
429
360
|
} else if (rule?.validator && !rule.validator(rule, value)) {
|
|
430
|
-
return rule.message ||
|
|
361
|
+
return rule.message || ''
|
|
431
362
|
} else {
|
|
432
|
-
return
|
|
363
|
+
return ''
|
|
433
364
|
}
|
|
434
|
-
}
|
|
365
|
+
}
|
|
435
366
|
|
|
436
367
|
/**
|
|
437
368
|
* @description 校验字段
|
|
@@ -440,28 +371,28 @@ const validateField = (
|
|
|
440
371
|
rules: RulesVo | RulesVo[] | undefined,
|
|
441
372
|
value: string,
|
|
442
373
|
field: string,
|
|
443
|
-
event?:
|
|
374
|
+
event?: 'blur' | 'change',
|
|
444
375
|
) => {
|
|
445
|
-
if (!rules) return
|
|
376
|
+
if (!rules) return
|
|
446
377
|
|
|
447
|
-
let errorMessage =
|
|
378
|
+
let errorMessage = ''
|
|
448
379
|
|
|
449
380
|
if (Array.isArray(rules)) {
|
|
450
381
|
// 遍历所有规则
|
|
451
382
|
for (const index in rules) {
|
|
452
383
|
// 判断是否有change事件或者blur事件
|
|
453
|
-
if (event && !rules[index]?.trigger?.includes(event)) continue
|
|
454
|
-
errorMessage = errorMsg(rules[index], value)
|
|
384
|
+
if (event && !rules[index]?.trigger?.includes(event)) continue
|
|
385
|
+
errorMessage = errorMsg(rules[index], value)
|
|
455
386
|
if (errorMessage) {
|
|
456
|
-
errors[field] = errorMessage
|
|
457
|
-
return
|
|
387
|
+
errors[field] = errorMessage
|
|
388
|
+
return
|
|
458
389
|
}
|
|
459
390
|
// 可以继续添加更多规则
|
|
460
391
|
}
|
|
461
392
|
} else {
|
|
462
393
|
// 必填校验
|
|
463
|
-
if (event && !rules?.trigger?.includes(event)) return
|
|
464
|
-
errorMessage = errorMsg(rules, value)
|
|
394
|
+
if (event && !rules?.trigger?.includes(event)) return
|
|
395
|
+
errorMessage = errorMsg(rules, value)
|
|
465
396
|
}
|
|
466
397
|
|
|
467
398
|
// 自定义校验规则
|
|
@@ -472,61 +403,61 @@ const validateField = (
|
|
|
472
403
|
// }
|
|
473
404
|
// }
|
|
474
405
|
|
|
475
|
-
errors[field] = errorMessage
|
|
476
|
-
}
|
|
406
|
+
errors[field] = errorMessage
|
|
407
|
+
}
|
|
477
408
|
|
|
478
409
|
/**
|
|
479
410
|
* @description 提交表单
|
|
480
411
|
* */
|
|
481
412
|
const handleSubmit = () => {
|
|
482
413
|
return new Promise((resolve, reject) => {
|
|
483
|
-
let isValid = true
|
|
414
|
+
let isValid = true
|
|
484
415
|
|
|
485
416
|
// 校验所有字段
|
|
486
417
|
props.columns.forEach((col) => {
|
|
487
|
-
validateField(col.rules, formData.value[col.field], col.field)
|
|
418
|
+
validateField(col.rules, formData.value[col.field], col.field)
|
|
488
419
|
if (errors[col.field]) {
|
|
489
|
-
isValid = false
|
|
420
|
+
isValid = false
|
|
490
421
|
}
|
|
491
|
-
})
|
|
422
|
+
})
|
|
492
423
|
|
|
493
424
|
if (isValid) {
|
|
494
425
|
// alert("表单提交成功!");
|
|
495
|
-
resolve(formData.value)
|
|
426
|
+
resolve(formData.value)
|
|
496
427
|
} else {
|
|
497
|
-
reject()
|
|
498
|
-
error(
|
|
428
|
+
reject()
|
|
429
|
+
error('表单校验失败,请检查输入!')
|
|
499
430
|
}
|
|
500
|
-
})
|
|
501
|
-
}
|
|
431
|
+
})
|
|
432
|
+
}
|
|
502
433
|
|
|
503
434
|
/**
|
|
504
435
|
* @description 输入值触发
|
|
505
436
|
* */
|
|
506
437
|
const handleChange = (event: string, temp: FormColumnsType) => {
|
|
507
438
|
if (isInput(temp.type) && temp?.input?.onChange) {
|
|
508
|
-
temp.input.onChange(event, temp)
|
|
439
|
+
temp.input.onChange(event, temp)
|
|
509
440
|
}
|
|
510
|
-
validateField(temp.rules, event, temp.field,
|
|
511
|
-
}
|
|
441
|
+
validateField(temp.rules, event, temp.field, 'change')
|
|
442
|
+
}
|
|
512
443
|
/**
|
|
513
444
|
* @description 输入值触发
|
|
514
445
|
* */
|
|
515
446
|
const handleBlur = (event: string, temp: FormColumnsType) => {
|
|
516
447
|
if (isInput(temp.type) && temp?.input?.onBlur) {
|
|
517
|
-
temp.input.onBlur(event, temp)
|
|
448
|
+
temp.input.onBlur(event, temp)
|
|
518
449
|
}
|
|
519
|
-
validateField(temp.rules, event, temp.field,
|
|
520
|
-
}
|
|
450
|
+
validateField(temp.rules, event, temp.field, 'blur')
|
|
451
|
+
}
|
|
521
452
|
|
|
522
453
|
defineExpose({
|
|
523
454
|
validateField,
|
|
524
455
|
handleSubmit,
|
|
525
|
-
})
|
|
456
|
+
})
|
|
526
457
|
</script>
|
|
527
458
|
|
|
528
459
|
<style lang="scss" scoped>
|
|
529
|
-
@import
|
|
460
|
+
@import './index.scss';
|
|
530
461
|
.hy-form--item {
|
|
531
462
|
flex-direction: v-bind(labelPos);
|
|
532
463
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view
|
|
2
|
+
<view
|
|
3
|
+
class="hy-form-item"
|
|
4
|
+
:class="[`hy-form-item--${labelPosition}`, formContext.border && 'hy-border__bottom']"
|
|
5
|
+
>
|
|
3
6
|
<view v-if="label" class="hy-form-item__label" :style="labelStyle">
|
|
4
7
|
<text v-if="isRequired" class="hy-form-item__label--required">*</text>
|
|
5
8
|
{{ label }}
|
|
@@ -25,8 +28,10 @@ export default {
|
|
|
25
28
|
</script>
|
|
26
29
|
|
|
27
30
|
<script setup lang="ts">
|
|
28
|
-
import { computed, inject, onMounted, onUnmounted,
|
|
31
|
+
import { computed, inject, onMounted, onUnmounted, provide, ref } from 'vue'
|
|
32
|
+
import type { PropType } from 'vue'
|
|
29
33
|
import type { FormContext } from './typing'
|
|
34
|
+
import { addUnit } from '../../utils'
|
|
30
35
|
|
|
31
36
|
/**
|
|
32
37
|
* 表单组件子组件,需要搭配hy-form
|
|
@@ -108,15 +113,12 @@ const labelStyle = computed(() => {
|
|
|
108
113
|
|
|
109
114
|
const style: Record<string, any> = {}
|
|
110
115
|
|
|
111
|
-
if (formContext.labelWidth
|
|
112
|
-
style.width =
|
|
113
|
-
typeof formContext.labelWidth.value === 'number'
|
|
114
|
-
? `${formContext.labelWidth.value}px`
|
|
115
|
-
: formContext.labelWidth.value
|
|
116
|
+
if (formContext.labelWidth !== 'auto') {
|
|
117
|
+
style.width = addUnit(formContext.labelWidth)
|
|
116
118
|
}
|
|
117
119
|
|
|
118
|
-
if (formContext.labelAlign
|
|
119
|
-
style.textAlign = formContext.labelAlign
|
|
120
|
+
if (formContext.labelAlign) {
|
|
121
|
+
style.textAlign = formContext.labelAlign
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
return style
|
|
@@ -124,7 +126,7 @@ const labelStyle = computed(() => {
|
|
|
124
126
|
|
|
125
127
|
// 标签位置
|
|
126
128
|
const labelPosition = computed(() => {
|
|
127
|
-
return formContext?.labelPosition
|
|
129
|
+
return formContext?.labelPosition || 'left'
|
|
128
130
|
})
|
|
129
131
|
|
|
130
132
|
// 监听表单数据变化
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import HyFormSimpleProps from '../hy-form/typing'
|
|
2
|
+
|
|
3
|
+
export interface FormContext extends HyFormSimpleProps {
|
|
3
4
|
errors: Record<string, string>
|
|
4
|
-
rules: any
|
|
5
|
-
labelWidth: any
|
|
6
|
-
labelPosition: any
|
|
7
|
-
labelAlign: any
|
|
8
5
|
addFormItem: (item: any) => void
|
|
9
6
|
removeFormItem: (item: any) => void
|
|
10
7
|
validateField: (field: string, value: any, trigger?: 'blur' | 'change') => boolean
|