hy-app 0.3.1 → 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.
Files changed (96) hide show
  1. package/README.md +6 -3
  2. package/common/shakeService.ts +31 -29
  3. package/components/avatar.zip +0 -0
  4. package/components/hy-action-sheet/hy-action-sheet.vue +71 -46
  5. package/components/hy-address-picker/hy-address-picker.vue +94 -83
  6. package/components/hy-avatar/hy-avatar.vue +84 -85
  7. package/components/hy-badge/hy-badge.vue +47 -46
  8. package/components/hy-button/hy-button.vue +117 -93
  9. package/components/hy-calendar/hy-calendar.vue +168 -160
  10. package/components/hy-card/hy-card.vue +50 -43
  11. package/components/hy-card/typing.d.ts +33 -32
  12. package/components/hy-cell/hy-cell.vue +73 -51
  13. package/components/hy-check-button/hy-check-button.vue +54 -47
  14. package/components/hy-checkbox/hy-checkbox.vue +97 -105
  15. package/components/hy-code-input/hy-code-input.vue +80 -89
  16. package/components/hy-config-provider/hy-config-provider.vue +19 -20
  17. package/components/hy-count-down/hy-count-down.vue +66 -67
  18. package/components/hy-count-to/hy-count-to.vue +105 -99
  19. package/components/hy-count-to/typing.d.ts +13 -12
  20. package/components/hy-datetime-picker/hy-datetime-picker.vue +261 -253
  21. package/components/hy-datetime-picker/typing.d.ts +42 -40
  22. package/components/hy-divider/hy-divider.vue +68 -73
  23. package/components/hy-dropdown/hy-dropdown.vue +20 -19
  24. package/components/hy-dropdown-item/hy-dropdown-item.vue +66 -61
  25. package/components/hy-dropdown-item/typing.d.ts +9 -9
  26. package/components/hy-empty/hy-empty.vue +42 -42
  27. package/components/hy-flex/hy-flex.vue +52 -26
  28. package/components/hy-float-button/hy-float-button.vue +218 -210
  29. package/components/hy-folding-panel/hy-folding-panel.vue +32 -33
  30. package/components/hy-form/hy-form.vue +264 -259
  31. package/components/hy-grid/hy-grid.vue +44 -43
  32. package/components/hy-icon/hy-icon.vue +61 -67
  33. package/components/hy-image/hy-image.vue +112 -88
  34. package/components/hy-image/typing.d.ts +27 -23
  35. package/components/hy-input/hy-input.vue +157 -127
  36. package/components/hy-input/typing.d.ts +53 -47
  37. package/components/hy-line/hy-line.vue +26 -26
  38. package/components/hy-line-progress/hy-line-progress.vue +42 -35
  39. package/components/hy-list/hy-list.vue +76 -85
  40. package/components/hy-loading/hy-loading.vue +26 -23
  41. package/components/hy-menu/hy-menu.vue +48 -43
  42. package/components/hy-menu/typing.d.ts +18 -17
  43. package/components/hy-modal/hy-modal.vue +39 -35
  44. package/components/hy-navbar/hy-navbar.vue +25 -25
  45. package/components/hy-navbar/typing.d.ts +24 -22
  46. package/components/hy-notice-bar/hy-notice-bar.vue +26 -27
  47. package/components/hy-notify/hy-notify.vue +53 -53
  48. package/components/hy-number-step/hy-number-step.vue +134 -146
  49. package/components/hy-number-step/typing.d.ts +35 -35
  50. package/components/hy-overlay/hy-overlay.vue +23 -21
  51. package/components/hy-pagination/hy-pagination.vue +41 -36
  52. package/components/hy-picker/hy-picker.vue +184 -154
  53. package/components/hy-picker/typing.d.ts +39 -39
  54. package/components/hy-popover/hy-popover.vue +97 -77
  55. package/components/hy-popup/hy-popup.vue +107 -98
  56. package/components/hy-price/hy-price.vue +38 -34
  57. package/components/hy-qrcode/hy-qrcode.vue +50 -51
  58. package/components/hy-radio/hy-radio.vue +101 -113
  59. package/components/hy-rate/hy-rate.vue +107 -88
  60. package/components/hy-read-more/hy-read-more.vue +64 -49
  61. package/components/hy-scroll-list/hy-scroll-list.vue +45 -48
  62. package/components/hy-search/hy-search.vue +73 -66
  63. package/components/hy-search/typing.d.ts +36 -35
  64. package/components/hy-signature/hy-signature.vue +282 -240
  65. package/components/hy-slider/hy-slider.vue +195 -153
  66. package/components/hy-slider/typing.d.ts +21 -21
  67. package/components/hy-steps/hy-steps.vue +118 -90
  68. package/components/hy-steps/index.scss +31 -21
  69. package/components/hy-submit-bar/hy-submit-bar.vue +61 -70
  70. package/components/hy-subsection/hy-subsection.vue +99 -102
  71. package/components/hy-subsection/typing.d.ts +19 -19
  72. package/components/hy-swipe-action/hy-swipe-action.vue +131 -118
  73. package/components/hy-swiper/hy-swiper.vue +85 -71
  74. package/components/hy-switch/hy-switch.vue +67 -72
  75. package/components/hy-switch/typing.d.ts +21 -19
  76. package/components/hy-tabs/hy-tabs.vue +168 -113
  77. package/components/hy-tag/hy-tag.vue +90 -86
  78. package/components/hy-tag/typing.d.ts +26 -21
  79. package/components/hy-text/hy-text.vue +119 -111
  80. package/components/hy-textarea/hy-textarea.vue +100 -93
  81. package/components/hy-textarea/typing.d.ts +36 -31
  82. package/components/hy-toast/hy-toast.vue +77 -67
  83. package/components/hy-tooltip/hy-tooltip.vue +109 -91
  84. package/components/hy-transition/hy-transition.vue +62 -66
  85. package/components/hy-upload/hy-upload.vue +294 -152
  86. package/components/hy-upload/typing.d.ts +41 -36
  87. package/components/hy-warn/hy-warn.vue +34 -27
  88. package/components/hy-waterfall/hy-waterfall.vue +83 -74
  89. package/components/hy-watermark/hy-watermark.vue +134 -115
  90. package/composables/usePopover.ts +236 -221
  91. package/composables/useQueue.ts +53 -52
  92. package/package.json +2 -2
  93. package/store/index.ts +9 -1
  94. package/typing/index.ts +0 -1
  95. package/typing/modules/common.d.ts +0 -2
  96. package/web-types.json +1 -1
@@ -40,30 +40,30 @@
40
40
 
41
41
  <script lang="ts">
42
42
  export default {
43
- name: 'hy-folding-panel',
43
+ name: "hy-folding-panel",
44
44
  options: {
45
45
  addGlobalClass: true,
46
46
  virtualHost: true,
47
- styleIsolation: 'shared',
47
+ styleIsolation: "shared",
48
48
  },
49
- }
49
+ };
50
50
  </script>
51
51
 
52
52
  <script setup lang="ts">
53
- import { toRefs, ref, watch } from 'vue'
54
- import type { CSSProperties, PropType } from 'vue'
55
- import type { IFoldingPanel, PanelVo } from './typing'
56
- import { addUnit } from '../../utils'
57
- import { ColorConfig } from '../../config'
58
-
59
- import HyCell from '../hy-cell/hy-cell.vue'
60
- import HyLine from '../hy-line/hy-line.vue'
53
+ import { toRefs, ref, watch } from "vue";
54
+ import type { CSSProperties, PropType } from "vue";
55
+ import type { IFoldingPanel, PanelVo } from "./typing";
56
+ import { addUnit } from "../../utils";
57
+ import { ColorConfig } from "../../config";
58
+ // 组件
59
+ import HyCell from "../hy-cell/hy-cell.vue";
60
+ import HyLine from "../hy-line/hy-line.vue";
61
61
 
62
62
  /**
63
63
  * 通过折叠面板收纳内容区域。
64
64
  * @displayName hy-folding-panel
65
65
  */
66
- defineOptions({})
66
+ defineOptions({});
67
67
 
68
68
  // const props = withDefaults(defineProps<IProps>(), defaultProps);
69
69
  const props = defineProps({
@@ -110,7 +110,7 @@ const props = defineProps({
110
110
  * */
111
111
  size: {
112
112
  type: String,
113
- default: 'medium',
113
+ default: "medium",
114
114
  },
115
115
  /** 内容面板高度 */
116
116
  contentHeight: {
@@ -121,45 +121,44 @@ const props = defineProps({
121
121
  customStyle: {
122
122
  type: Object as PropType<CSSProperties>,
123
123
  },
124
- })
125
- const { list, contentHeight, accordion } = toRefs(props)
126
- const emit = defineEmits<IFoldingPanel>()
124
+ });
125
+ const emit = defineEmits<IFoldingPanel>();
127
126
 
128
- const lists = ref<PanelVo[]>([])
127
+ const lists = ref<PanelVo[]>([]);
129
128
 
130
129
  watch(
131
- () => list.value,
130
+ () => props.list,
132
131
  (newValue: PanelVo[]) => {
133
132
  lists.value = newValue.map((item) => ({
134
133
  ...item,
135
- arrowDirection: 'down',
134
+ arrowDirection: "down",
136
135
  spread: false,
137
- }))
136
+ }));
138
137
  },
139
138
  { immediate: true },
140
- )
139
+ );
141
140
 
142
141
  const clickHandler = (temp: PanelVo, index: number) => {
143
142
  // if (temp?.disabled && temp?.animating) return;
144
- lists.value = list.value.map((item, i) => {
145
- if (accordion.value) {
143
+ lists.value = props.list.map((item, i) => {
144
+ if (props.accordion) {
146
145
  // 判断是否是收起来
147
- item.spread = i === index ? !item.spread : false
146
+ item.spread = i === index ? !item.spread : false;
148
147
  } else {
149
148
  if (i === index) {
150
- item.spread = !item.spread
149
+ item.spread = !item.spread;
151
150
  }
152
151
  }
153
152
 
154
- item.arrowDirection = item.spread ? 'up' : 'down'
155
- return item
156
- })
157
- const event = temp.spread ? 'open' : 'close'
158
- emit('change', temp, index)
159
- emit(event, temp, index)
160
- }
153
+ item.arrowDirection = item.spread ? "up" : "down";
154
+ return item;
155
+ });
156
+ const event: "open" | "close" = temp.spread ? "open" : "close";
157
+ emit("change", temp, index);
158
+ emit(event, temp, index);
159
+ };
161
160
  </script>
162
161
 
163
162
  <style lang="scss" scoped>
164
- @import './index.scss';
163
+ @import "./index.scss";
165
164
  </style>
@@ -1,259 +1,264 @@
1
- <template>
2
- <view class="hy-form">
3
- <slot></slot>
4
- </view>
5
- </template>
6
-
7
- <script lang="ts">
8
- export default {
9
- name: 'hy-form',
10
- options: {
11
- addGlobalClass: true,
12
- virtualHost: true,
13
- styleIsolation: 'shared',
14
- },
15
- }
16
- </script>
17
-
18
- <script setup lang="ts">
19
- import { provide, reactive, ref, toRefs } from 'vue'
20
- import type { PropType } from 'vue'
21
- import type { FormItemRule } from './typing'
22
- import { clearVal } from '../../utils'
23
-
24
- /**
25
- * 表单组件父组件,需要搭配hy-form-item
26
- * @displayName hy-form
27
- */
28
- defineOptions({})
29
-
30
- const props = defineProps({
31
- /** 表单数据对象 */
32
- model: Object as PropType<AnyObject>,
33
- /** 表单校验规则 */
34
- rules: Object as PropType<FormItemRule>,
35
- /** 表单底部边框 */
36
- border: {
37
- type: Boolean,
38
- default: false,
39
- },
40
- /** label标签的宽度,单位rpx */
41
- labelWidth: {
42
- type: String,
43
- default: 'auto',
44
- },
45
- /**
46
- * 标签位置
47
- * @values left,top
48
- * */
49
- labelPosition: {
50
- type: String,
51
- default: 'left',
52
- },
53
- /**
54
- * 标签位置
55
- * @values left,center,right
56
- * */
57
- labelAlign: {
58
- type: String,
59
- default: 'left',
60
- },
61
- })
62
- const { rules, border, labelWidth, labelAlign, labelPosition } = toRefs(props)
63
-
64
- const emit = defineEmits<{
65
- submit: [data: Record<string, any>]
66
- validate: [valid: boolean, errors: Record<string, string>]
67
- }>()
68
-
69
- // 表单数据
70
- const formData = reactive(props.model || {})
71
- const formItems = ref<any[]>([])
72
- const errors = reactive<Record<string, string>>({})
73
-
74
- // 表单上下文
75
- const formContext = {
76
- formData,
77
- errors,
78
- rules: rules.value,
79
- border: border.value,
80
- labelWidth: labelWidth.value,
81
- labelPosition: labelPosition.value,
82
- labelAlign: labelAlign.value,
83
- addFormItem: (item: any) => {
84
- formItems.value.push(item)
85
- },
86
- removeFormItem: (item: any) => {
87
- const index = formItems.value.indexOf(item)
88
- if (index > -1) {
89
- formItems.value.splice(index, 1)
90
- }
91
- },
92
- validateField: (field: string, value: any, trigger?: 'blur' | 'change') => {
93
- const fieldRules = props.rules?.[field]
94
- if (!fieldRules) return true
95
-
96
- const rules = Array.isArray(fieldRules) ? fieldRules : [fieldRules]
97
- let isValid = true
98
- let errorMessage = ''
99
-
100
- for (const rule of rules) {
101
- // 检查触发时机
102
- if (
103
- (trigger && !rule.trigger) ||
104
- (trigger && rule.trigger && !rule.trigger.includes(trigger))
105
- ) {
106
- continue
107
- }
108
-
109
- // 必填校验
110
- if (rule.required && (!value || value === '')) {
111
- errorMessage = rule.message || `${field} 是必填项`
112
- isValid = false
113
- break
114
- }
115
-
116
- // 长度校验
117
- if (rule.min && String(value).length < rule.min) {
118
- errorMessage = rule.message || `${field} 长度不能少于 ${rule.min} 个字符`
119
- isValid = false
120
- break
121
- }
122
-
123
- if (rule.max && String(value).length > rule.max) {
124
- errorMessage = rule.message || `${field} 长度不能超过 ${rule.max} 个字符`
125
- isValid = false
126
- break
127
- }
128
-
129
- // 类型校验
130
- if (rule.type === 'phone') {
131
- const phoneRegex = /^1[3-9]\d{9}$/
132
- if (!phoneRegex.test(String(value))) {
133
- errorMessage = rule.message || '请输入正确的手机号'
134
- isValid = false
135
- break
136
- }
137
- }
138
-
139
- if (rule.type === 'email') {
140
- const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/
141
- if (!emailRegex.test(String(value))) {
142
- errorMessage = rule.message || '请输入正确的邮箱格式'
143
- isValid = false
144
- break
145
- }
146
- }
147
-
148
- if (rule.type === 'password') {
149
- const passwordRegex =
150
- /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]).{8,}$/
151
- if (!passwordRegex.test(String(value))) {
152
- errorMessage = rule.message || '密码至少8个字符,包含大小写字母、数字和特殊符号'
153
- isValid = false
154
- break
155
- }
156
- }
157
-
158
- // 自定义校验
159
- if (rule.validator) {
160
- const result = rule.validator(value)
161
- if (result === false || typeof result === 'string') {
162
- errorMessage = typeof result === 'string' ? result : rule.message || `${field} 校验失败`
163
- isValid = false
164
- break
165
- }
166
- }
167
- }
168
-
169
- if (isValid) {
170
- delete errors[field]
171
- } else {
172
- errors[field] = errorMessage
173
- }
174
-
175
- return isValid
176
- },
177
- setFieldValue: (field: string, value: any) => {
178
- formData[field] = value
179
- },
180
- getFieldValue: (field: string) => {
181
- return formData[field]
182
- },
183
- }
184
-
185
- // 提供表单上下文给子组件
186
- provide('formContext', formContext)
187
-
188
- // 验证所有字段
189
- const validate = () => {
190
- return new Promise((resolve, reject) => {
191
- let isValid = true
192
- const allErrors: Record<string, string> = {}
193
-
194
- formItems.value.forEach((item) => {
195
- const field = item.props?.prop
196
- if (field) {
197
- const value = formData[field]
198
- const fieldValid = formContext.validateField(field, value)
199
- if (!fieldValid) {
200
- isValid = false
201
- allErrors[field] = errors[field]
202
- }
203
- }
204
- })
205
-
206
- emit('validate', isValid, allErrors)
207
- if (isValid) {
208
- resolve(isValid)
209
- } else {
210
- reject(allErrors)
211
- }
212
- })
213
- }
214
-
215
- // 重置表单
216
- const resetFields = () => {
217
- clearVal(formData)
218
- Object.keys(errors).forEach((key) => {
219
- delete errors[key]
220
- })
221
- }
222
-
223
- // 清除验证
224
- const clearValidate = (fields?: string[]) => {
225
- if (fields) {
226
- fields.forEach((field) => {
227
- delete errors[field]
228
- })
229
- } else {
230
- Object.keys(errors).forEach((key) => {
231
- delete errors[key]
232
- })
233
- }
234
- }
235
-
236
- // 提交表单
237
- const submit = async () => {
238
- if (await validate()) {
239
- emit('submit', { ...formData })
240
- return formData
241
- }
242
- return false
243
- }
244
-
245
- defineExpose({
246
- validate,
247
- resetFields,
248
- clearValidate,
249
- submit,
250
- formData,
251
- errors,
252
- })
253
- </script>
254
-
255
- <style lang="scss" scoped>
256
- .hy-form {
257
- width: 100%;
258
- }
259
- </style>
1
+ <template>
2
+ <view class="hy-form">
3
+ <slot></slot>
4
+ </view>
5
+ </template>
6
+
7
+ <script lang="ts">
8
+ export default {
9
+ name: "hy-form",
10
+ options: {
11
+ addGlobalClass: true,
12
+ virtualHost: true,
13
+ styleIsolation: "shared",
14
+ },
15
+ };
16
+ </script>
17
+
18
+ <script setup lang="ts">
19
+ import { provide, reactive, ref } from "vue";
20
+ import type { PropType } from "vue";
21
+ import type { FormItemRule } from "./typing";
22
+ import { clearVal, isArray } from "../../utils";
23
+
24
+ /**
25
+ * 表单组件父组件,需要搭配hy-form-item
26
+ * @displayName hy-form
27
+ */
28
+ defineOptions({});
29
+
30
+ const props = defineProps({
31
+ /** 表单数据对象 */
32
+ model: Object as PropType<AnyObject>,
33
+ /** 表单校验规则 */
34
+ rules: Object as PropType<FormItemRule>,
35
+ /** 表单底部边框 */
36
+ border: {
37
+ type: Boolean,
38
+ default: false,
39
+ },
40
+ /** label标签的宽度,单位rpx */
41
+ labelWidth: {
42
+ type: String,
43
+ default: "auto",
44
+ },
45
+ /**
46
+ * 标签位置
47
+ * @values left,top
48
+ * */
49
+ labelPosition: {
50
+ type: String,
51
+ default: "left",
52
+ },
53
+ /**
54
+ * 标签位置
55
+ * @values left,center,right
56
+ * */
57
+ labelAlign: {
58
+ type: String,
59
+ default: "left",
60
+ },
61
+ });
62
+
63
+ const emit = defineEmits<{
64
+ submit: [data: Record<string, any>];
65
+ validate: [valid: boolean, errors: Record<string, string>];
66
+ }>();
67
+
68
+ // 表单数据
69
+ const formData = reactive(props.model || {});
70
+ const formItems = ref<any[]>([]);
71
+ const errors = reactive<Record<string, string>>({});
72
+
73
+ // 表单上下文
74
+ const formContext = {
75
+ formData,
76
+ errors,
77
+ rules: props.rules,
78
+ border: props.border,
79
+ labelWidth: props.labelWidth,
80
+ labelPosition: props.labelPosition,
81
+ labelAlign: props.labelAlign,
82
+ addFormItem: (item: any) => {
83
+ formItems.value.push(item);
84
+ },
85
+ removeFormItem: (item: any) => {
86
+ const index = formItems.value.indexOf(item);
87
+ if (index > -1) {
88
+ formItems.value.splice(index, 1);
89
+ }
90
+ },
91
+ validateField: (field: string, value: any, trigger?: "blur" | "change") => {
92
+ const fieldRules = props.rules?.[field];
93
+ if (!fieldRules) return true;
94
+
95
+ const rules = isArray(fieldRules) ? fieldRules : [fieldRules];
96
+ let isValid = true;
97
+ let errorMessage = "";
98
+
99
+ for (const rule of rules) {
100
+ // 检查触发时机
101
+ if (
102
+ (trigger && !rule.trigger) ||
103
+ (trigger && rule.trigger && !rule.trigger.includes(trigger))
104
+ ) {
105
+ continue;
106
+ }
107
+
108
+ // 必填校验
109
+ if (rule.required && (!value || value === "")) {
110
+ errorMessage = rule.message || `${field} 是必填项`;
111
+ isValid = false;
112
+ break;
113
+ }
114
+
115
+ // 长度校验
116
+ if (rule.min && String(value).length < rule.min) {
117
+ errorMessage =
118
+ rule.message || `${field} 长度不能少于 ${rule.min} 个字符`;
119
+ isValid = false;
120
+ break;
121
+ }
122
+
123
+ if (rule.max && String(value).length > rule.max) {
124
+ errorMessage =
125
+ rule.message || `${field} 长度不能超过 ${rule.max} 个字符`;
126
+ isValid = false;
127
+ break;
128
+ }
129
+
130
+ // 类型校验
131
+ if (rule.type === "phone") {
132
+ const phoneRegex = /^1[3-9]\d{9}$/;
133
+ if (!phoneRegex.test(String(value))) {
134
+ errorMessage = rule.message || "请输入正确的手机号";
135
+ isValid = false;
136
+ break;
137
+ }
138
+ }
139
+
140
+ if (rule.type === "email") {
141
+ const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
142
+ if (!emailRegex.test(String(value))) {
143
+ errorMessage = rule.message || "请输入正确的邮箱格式";
144
+ isValid = false;
145
+ break;
146
+ }
147
+ }
148
+
149
+ if (rule.type === "password") {
150
+ const passwordRegex =
151
+ /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]).{8,}$/;
152
+ if (!passwordRegex.test(String(value))) {
153
+ errorMessage =
154
+ rule.message || "密码至少8个字符,包含大小写字母、数字和特殊符号";
155
+ isValid = false;
156
+ break;
157
+ }
158
+ }
159
+
160
+ // 自定义校验
161
+ if (rule.validator) {
162
+ const result = rule.validator(value);
163
+ if (result === false || typeof result === "string") {
164
+ errorMessage =
165
+ typeof result === "string"
166
+ ? result
167
+ : rule.message || `${field} 校验失败`;
168
+ isValid = false;
169
+ break;
170
+ }
171
+ }
172
+ }
173
+
174
+ if (isValid) {
175
+ delete errors[field];
176
+ } else {
177
+ errors[field] = errorMessage;
178
+ }
179
+
180
+ return isValid;
181
+ },
182
+ setFieldValue: (field: string, value: any) => {
183
+ formData[field] = value;
184
+ },
185
+ getFieldValue: (field: string) => {
186
+ return formData[field];
187
+ },
188
+ };
189
+
190
+ // 提供表单上下文给子组件
191
+ provide("formContext", formContext);
192
+
193
+ // 验证所有字段
194
+ const validate = () => {
195
+ return new Promise((resolve, reject) => {
196
+ let isValid = true;
197
+ const allErrors: Record<string, string> = {};
198
+
199
+ formItems.value.forEach((item) => {
200
+ const field = item.props?.prop;
201
+ if (field) {
202
+ const value = formData[field];
203
+ const fieldValid = formContext.validateField(field, value);
204
+ if (!fieldValid) {
205
+ isValid = false;
206
+ allErrors[field] = errors[field];
207
+ }
208
+ }
209
+ });
210
+
211
+ emit("validate", isValid, allErrors);
212
+ if (isValid) {
213
+ resolve(isValid);
214
+ } else {
215
+ reject(allErrors);
216
+ }
217
+ });
218
+ };
219
+
220
+ // 重置表单
221
+ const resetFields = () => {
222
+ clearVal(formData);
223
+ Object.keys(errors).forEach((key) => {
224
+ delete errors[key];
225
+ });
226
+ };
227
+
228
+ // 清除验证
229
+ const clearValidate = (fields?: string[]) => {
230
+ if (fields) {
231
+ fields.forEach((field) => {
232
+ delete errors[field];
233
+ });
234
+ } else {
235
+ Object.keys(errors).forEach((key) => {
236
+ delete errors[key];
237
+ });
238
+ }
239
+ };
240
+
241
+ // 提交表单
242
+ const submit = async () => {
243
+ if (await validate()) {
244
+ emit("submit", { ...formData });
245
+ return formData;
246
+ }
247
+ return false;
248
+ };
249
+
250
+ defineExpose({
251
+ validate,
252
+ resetFields,
253
+ clearValidate,
254
+ submit,
255
+ formData,
256
+ errors,
257
+ });
258
+ </script>
259
+
260
+ <style lang="scss" scoped>
261
+ .hy-form {
262
+ width: 100%;
263
+ }
264
+ </style>