hy-app 0.2.16 → 0.3.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 (100) hide show
  1. package/components/hy-action-sheet/hy-action-sheet.vue +5 -5
  2. package/components/hy-action-sheet/index.scss +6 -1
  3. package/components/hy-address-picker/hy-address-picker.vue +5 -5
  4. package/components/hy-avatar/hy-avatar.vue +5 -5
  5. package/components/hy-back-top/hy-back-top.vue +5 -5
  6. package/components/hy-badge/hy-badge.vue +5 -5
  7. package/components/hy-button/hy-button.vue +5 -5
  8. package/components/hy-calendar/hy-calendar.vue +22 -18
  9. package/components/hy-calendar/typing.d.ts +1 -1
  10. package/components/hy-card/hy-card.vue +5 -5
  11. package/components/hy-cell/hy-cell.vue +10 -11
  12. package/components/hy-check-button/hy-check-button.vue +7 -6
  13. package/components/hy-checkbox/hy-checkbox.vue +14 -14
  14. package/components/hy-code-input/hy-code-input.vue +8 -15
  15. package/components/hy-code-input/index.scss +1 -1
  16. package/components/hy-config-provider/hy-config-provider.vue +8 -6
  17. package/components/hy-count-down/hy-count-down.vue +7 -6
  18. package/components/hy-count-to/hy-count-to.vue +6 -5
  19. package/components/hy-datetime-picker/hy-datetime-picker.vue +7 -7
  20. package/components/hy-divider/hy-divider.vue +10 -7
  21. package/components/hy-dropdown/hy-dropdown.vue +6 -5
  22. package/components/hy-dropdown-item/hy-dropdown-item.vue +7 -5
  23. package/components/hy-empty/hy-empty.vue +6 -5
  24. package/components/hy-float-button/hy-float-button.vue +6 -6
  25. package/components/hy-folding-panel/hy-folding-panel.vue +6 -5
  26. package/components/hy-form/README.md +301 -0
  27. package/components/hy-form/hy-form.vue +252 -533
  28. package/components/hy-form/index.ts +5 -0
  29. package/components/hy-form/typing.d.ts +57 -77
  30. package/components/hy-form-group/hy-form-group.vue +533 -0
  31. package/components/hy-form-group/typing.d.ts +77 -0
  32. package/components/hy-form-item/hy-form-item.vue +199 -0
  33. package/components/hy-form-item/index.scss +41 -0
  34. package/components/hy-form-item/typing.d.ts +43 -0
  35. package/components/hy-grid/hy-grid.vue +11 -13
  36. package/components/hy-grid/typing.d.ts +1 -1
  37. package/components/hy-icon/hy-icon.vue +15 -15
  38. package/components/hy-image/hy-image.vue +15 -9
  39. package/components/hy-input/hy-input.vue +17 -11
  40. package/components/hy-line/hy-line.vue +8 -6
  41. package/components/hy-line-progress/hy-line-progress.vue +9 -16
  42. package/components/hy-list/hy-list.vue +6 -5
  43. package/components/hy-loading/hy-loading.vue +9 -10
  44. package/components/hy-login/TheUserLogin.vue +82 -90
  45. package/components/hy-menu/hy-menu.vue +11 -8
  46. package/components/hy-modal/hy-modal.vue +6 -6
  47. package/components/hy-modal/index.scss +1 -1
  48. package/components/hy-navbar/hy-navbar.vue +6 -6
  49. package/components/hy-notice-bar/hy-notice-bar.vue +14 -9
  50. package/components/hy-notify/hy-notify.vue +6 -6
  51. package/components/hy-number-step/hy-number-step.vue +8 -6
  52. package/components/hy-overlay/hy-overlay.vue +8 -9
  53. package/components/hy-pagination/hy-pagination.vue +11 -8
  54. package/components/hy-picker/hy-picker.vue +9 -9
  55. package/components/hy-popover/hy-popover.vue +11 -7
  56. package/components/hy-popup/hy-popup.vue +9 -7
  57. package/components/hy-price/hy-price.vue +6 -5
  58. package/components/hy-qrcode/hy-qrcode.vue +6 -8
  59. package/components/hy-radio/hy-radio.vue +10 -12
  60. package/components/hy-rate/hy-rate.vue +7 -7
  61. package/components/hy-read-more/hy-read-more.vue +6 -5
  62. package/components/hy-scroll-list/hy-scroll-list.vue +6 -5
  63. package/components/hy-search/hy-search.vue +8 -6
  64. package/components/hy-signature/hy-signature.vue +6 -5
  65. package/components/hy-slider/hy-slider.vue +8 -7
  66. package/components/hy-steps/hy-steps.vue +10 -17
  67. package/components/hy-submit-bar/hy-submit-bar.vue +6 -6
  68. package/components/hy-subsection/hy-subsection.vue +16 -19
  69. package/components/hy-swipe-action/hy-swipe-action.vue +31 -25
  70. package/components/hy-swipe-action/typing.d.ts +1 -1
  71. package/components/hy-swiper/hy-swiper.vue +15 -15
  72. package/components/hy-swiper/typing.d.ts +13 -1
  73. package/components/hy-switch/hy-switch.vue +17 -10
  74. package/components/hy-tabBar/hy-tabBar.vue +35 -26
  75. package/components/hy-tabs/hy-tabs.vue +28 -21
  76. package/components/hy-tag/hy-tag.vue +13 -17
  77. package/components/hy-tag/typing.d.ts +1 -1
  78. package/components/hy-text/hy-text.vue +12 -14
  79. package/components/hy-textarea/hy-textarea.vue +16 -13
  80. package/components/hy-textarea/index.scss +7 -2
  81. package/components/hy-textarea/typing.d.ts +1 -1
  82. package/components/hy-toast/hy-toast.vue +72 -75
  83. package/components/hy-tooltip/hy-tooltip.vue +8 -14
  84. package/components/hy-transition/hy-transition.vue +8 -6
  85. package/components/hy-upload/hy-upload.vue +6 -5
  86. package/components/hy-warn/hy-warn.vue +6 -6
  87. package/components/hy-waterfall/hy-waterfall.vue +8 -7
  88. package/components/hy-watermark/hy-watermark.vue +20 -10
  89. package/components/index.ts +7 -1
  90. package/global.d.ts +3 -1
  91. package/libs/css/common.scss +5 -0
  92. package/libs/css/mixin.scss +2 -1
  93. package/libs/css/vars.css +1 -1
  94. package/package.json +2 -2
  95. package/theme.scss +1 -1
  96. package/utils/inspect.ts +34 -34
  97. package/utils/utils.ts +1 -19
  98. package/web-types.json +1 -1
  99. /package/components/{hy-form → hy-form-group}/index.scss +0 -0
  100. /package/components/{hy-form → hy-form-group}/props.ts +0 -0
@@ -5,11 +5,6 @@
5
5
  </template>
6
6
 
7
7
  <script lang="ts">
8
- /**
9
- * 主要提供筛选下拉筛选框,内置基础筛选功能,可以根据自己的需求自定义筛选项。
10
- * @displayName hy-dropdown
11
- */
12
- defineOptions({})
13
8
  export default {
14
9
  name: 'hy-dropdown',
15
10
  options: {
@@ -24,6 +19,12 @@ export default {
24
19
  import { provide, ref, computed, type CSSProperties, toRefs, PropType } from 'vue'
25
20
  import { addUnit, IconConfig } from '@/package'
26
21
 
22
+ /**
23
+ * 主要提供筛选下拉筛选框,内置基础筛选功能,可以根据自己的需求自定义筛选项。
24
+ * @displayName hy-dropdown
25
+ */
26
+ defineOptions({})
27
+
27
28
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
28
29
  const props = defineProps({
29
30
  /** 标题菜单的高度,单位px */
@@ -58,10 +58,6 @@
58
58
  </template>
59
59
 
60
60
  <script lang="ts">
61
- /**
62
- * 主要提供筛选下拉筛选框,内置基础筛选功能,可以根据自己的需求自定义筛选项。和hy-dropdown组合用法
63
- * @displayName hy-dropdown-item
64
- */
65
61
  export default {
66
62
  name: 'hy-dropdown-item',
67
63
  options: {
@@ -87,10 +83,16 @@ import type FatherIProps from '../hy-dropdown/typing'
87
83
  import type { DropdownMenuItem } from './typing'
88
84
  import { addUnit, getRect, throttle } from '../../utils'
89
85
  import { IconConfig } from '../../config'
90
-
86
+ // 组件
91
87
  import HyOverlay from '../hy-overlay/hy-overlay.vue'
92
88
  import HyIcon from '../hy-icon/hy-icon.vue'
93
89
 
90
+ /**
91
+ * 主要提供筛选下拉筛选框,内置基础筛选功能,可以根据自己的需求自定义筛选项。和hy-dropdown组合用法
92
+ * @displayName hy-dropdown-item
93
+ */
94
+ defineOptions({})
95
+
94
96
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
95
97
  const props = defineProps({
96
98
  /** 获取值 */
@@ -30,11 +30,6 @@
30
30
  </template>
31
31
 
32
32
  <script lang="ts">
33
- /**
34
- * 加载的第一页数据就为空
35
- * @displayName hy-empty
36
- */
37
- defineOptions({})
38
33
  export default {
39
34
  name: 'hy-empty',
40
35
  options: {
@@ -57,6 +52,12 @@ import type { IEmptyEmits } from './typing'
57
52
  import HyButton from '../hy-button/hy-button.vue'
58
53
  import HyIcon from '../hy-icon/hy-icon.vue'
59
54
 
55
+ /**
56
+ * 加载的第一页数据就为空
57
+ * @displayName hy-empty
58
+ */
59
+ defineOptions({})
60
+
60
61
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
61
62
  const props = defineProps({
62
63
  /** 是否显示空状态 */
@@ -61,11 +61,6 @@
61
61
  </template>
62
62
 
63
63
  <script lang="ts">
64
- /**
65
- * 悬浮动作按钮组件,按下可显示一组动作按钮。
66
- * @displayName hy-float-button
67
- */
68
- defineOptions({})
69
64
  export default {
70
65
  name: 'hy-float-button',
71
66
  options: {
@@ -84,11 +79,16 @@ import type { MenusType } from './typing'
84
79
  import { addUnit, getPx, getRect, guid, isH5 } from '../../utils'
85
80
  import { HyApp } from '../../typing/modules/common'
86
81
  import { IconConfig } from '../../config'
87
-
88
82
  // 组件
89
83
  import HyIcon from '../hy-icon/hy-icon.vue'
90
84
  import HyLine from '../hy-line/hy-line.vue'
91
85
 
86
+ /**
87
+ * 悬浮动作按钮组件,按下可显示一组动作按钮。
88
+ * @displayName hy-float-button
89
+ */
90
+ defineOptions({})
91
+
92
92
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
93
93
  const props = defineProps({
94
94
  /** 菜单栏集合 */
@@ -39,11 +39,6 @@
39
39
  </template>
40
40
 
41
41
  <script lang="ts">
42
- /**
43
- * 通过折叠面板收纳内容区域。
44
- * @displayName hy-folding-panel
45
- */
46
- defineOptions({})
47
42
  export default {
48
43
  name: 'hy-folding-panel',
49
44
  options: {
@@ -64,6 +59,12 @@ import { ColorConfig } from '../../config'
64
59
  import HyCell from '../hy-cell/hy-cell.vue'
65
60
  import HyLine from '../hy-line/hy-line.vue'
66
61
 
62
+ /**
63
+ * 通过折叠面板收纳内容区域。
64
+ * @displayName hy-folding-panel
65
+ */
66
+ defineOptions({})
67
+
67
68
  // const props = withDefaults(defineProps<IProps>(), defaultProps);
68
69
  const props = defineProps({
69
70
  /** 数据集 */
@@ -0,0 +1,301 @@
1
+ # 表单组件 (hy-form-simple)
2
+
3
+ 一个简单易用的表单组件,包含 `hy-form-simple` 和 `hy-form-item-simple` 两个组件,支持表单验证、数据绑定等功能。
4
+
5
+ ## 组件特性
6
+
7
+ - ✅ 表单数据双向绑定
8
+ - ✅ 表单验证(必填、长度、类型、自定义验证)
9
+ - ✅ 实时验证和失焦验证
10
+ - ✅ 支持多种表单控件
11
+ - ✅ 灵活的标签布局
12
+ - ✅ 错误信息显示
13
+ - ✅ 表单重置和清除验证
14
+
15
+ ## 基础用法
16
+
17
+ ```vue
18
+ <template>
19
+ <hy-form-simple
20
+ ref="formRef"
21
+ :model="formData"
22
+ :rules="rules"
23
+ label-width="80px"
24
+ @submit="handleSubmit"
25
+ >
26
+ <hy-form-item-simple label="用户名" prop="username" required>
27
+ <hy-input v-model="formData.username" placeholder="请输入用户名" />
28
+ </hy-form-item-simple>
29
+
30
+ <hy-form-item-simple label="手机号" prop="phone" required>
31
+ <hy-input v-model="formData.phone" type="number" placeholder="请输入手机号" />
32
+ </hy-form-item-simple>
33
+
34
+ <hy-form-item-simple label="性别" prop="gender">
35
+ <hy-radio v-model="formData.gender" :columns="genderOptions" />
36
+ </hy-form-item-simple>
37
+ </hy-form-simple>
38
+ </template>
39
+
40
+ <script setup lang="ts">
41
+ import { reactive, ref } from 'vue'
42
+
43
+ const formData = reactive({
44
+ username: '',
45
+ phone: '',
46
+ gender: ''
47
+ })
48
+
49
+ const rules = {
50
+ username: [
51
+ { required: true, message: '请输入用户名' },
52
+ { min: 2, max: 20, message: '用户名长度在 2 到 20 个字符' }
53
+ ],
54
+ phone: [
55
+ { required: true, message: '请输入手机号' },
56
+ { type: 'phone', message: '请输入正确的手机号' }
57
+ ]
58
+ }
59
+
60
+ const formRef = ref()
61
+
62
+ const handleSubmit = (data: any) => {
63
+ console.log('表单数据:', data)
64
+ }
65
+ </script>
66
+ ```
67
+
68
+ ## API
69
+
70
+ ### hy-form-simple Props
71
+
72
+ | 参数 | 说明 | 类型 | 默认值 |
73
+ |------|------|------|--------|
74
+ | model | 表单数据对象 | `Record<string, any>` | `{}` |
75
+ | rules | 验证规则 | `FormItemRule` | `{}` |
76
+ | labelWidth | 标签宽度 | `string \| number` | `'auto'` |
77
+ | labelPosition | 标签位置 | `'left' \| 'top'` | `'left'` |
78
+ | labelAlign | 标签对齐方式 | `'left' \| 'center' \| 'right'` | `'left'` |
79
+
80
+ ### hy-form-simple Events
81
+
82
+ | 事件名 | 说明 | 回调参数 |
83
+ |--------|------|----------|
84
+ | submit | 表单提交时触发 | `(data: Record<string, any>)` |
85
+ | validate | 表单验证时触发 | `(valid: boolean, errors: Record<string, string>)` |
86
+
87
+ ### hy-form-simple Methods
88
+
89
+ | 方法名 | 说明 | 参数 |
90
+ |--------|------|------|
91
+ | validate | 验证表单 | - |
92
+ | resetFields | 重置表单 | - |
93
+ | clearValidate | 清除验证 | `(fields?: string[])` |
94
+ | submit | 提交表单 | - |
95
+
96
+ ### hy-form-item-simple Props
97
+
98
+ | 参数 | 说明 | 类型 | 默认值 |
99
+ |------|------|------|--------|
100
+ | label | 标签文本 | `string` | `''` |
101
+ | prop | 表单字段名 | `string` | `''` |
102
+ | required | 是否必填 | `boolean` | `false` |
103
+ | rules | 验证规则 | `any` | `{}` |
104
+
105
+ ### hy-form-item-simple Events
106
+
107
+ | 事件名 | 说明 | 回调参数 |
108
+ |--------|------|----------|
109
+ | change | 值变化时触发 | `(value: any)` |
110
+ | blur | 失焦时触发 | `(value: any)` |
111
+
112
+ ### hy-form-item-simple Methods
113
+
114
+ | 方法名 | 说明 | 参数 |
115
+ |--------|------|------|
116
+ | validate | 验证字段 | `(trigger?: 'blur' \| 'change')` |
117
+ | resetField | 重置字段 | - |
118
+ | clearValidate | 清除验证 | - |
119
+
120
+ ## 验证规则
121
+
122
+ ### 基础验证
123
+
124
+ ```javascript
125
+ const rules = {
126
+ username: [
127
+ { required: true, message: '请输入用户名' },
128
+ { min: 2, max: 20, message: '用户名长度在 2 到 20 个字符' }
129
+ ]
130
+ }
131
+ ```
132
+
133
+ ### 类型验证
134
+
135
+ ```javascript
136
+ const rules = {
137
+ phone: [
138
+ { required: true, message: '请输入手机号' },
139
+ { type: 'phone', message: '请输入正确的手机号' }
140
+ ],
141
+ email: [
142
+ { type: 'email', message: '请输入正确的邮箱格式' }
143
+ ],
144
+ password: [
145
+ { type: 'password', message: '密码格式不正确' }
146
+ ]
147
+ }
148
+ ```
149
+
150
+ ### 自定义验证
151
+
152
+ ```javascript
153
+ const rules = {
154
+ confirmPassword: [
155
+ { required: true, message: '请确认密码' },
156
+ {
157
+ validator: (value: string) => {
158
+ if (value !== formData.password) {
159
+ return '两次输入的密码不一致'
160
+ }
161
+ return true
162
+ }
163
+ }
164
+ ]
165
+ }
166
+ ```
167
+
168
+ ### 触发时机
169
+
170
+ ```javascript
171
+ const rules = {
172
+ username: [
173
+ {
174
+ required: true,
175
+ message: '请输入用户名',
176
+ trigger: ['blur', 'change'] // 失焦和变化时都验证
177
+ }
178
+ ]
179
+ }
180
+ ```
181
+
182
+ ## 支持的表单控件
183
+
184
+ - `hy-input` - 输入框
185
+ - `hy-textarea` - 文本域
186
+ - `hy-radio` - 单选框
187
+ - `hy-check-button` - 选择按钮
188
+ - `hy-switch` - 开关
189
+ - `hy-picker` - 选择器
190
+ - `hy-datetime-picker` - 时间选择器
191
+ - `hy-address-picker` - 地址选择器
192
+ - 其他自定义组件
193
+
194
+ ## 完整示例
195
+
196
+ ```vue
197
+ <template>
198
+ <view class="form-demo">
199
+ <hy-form-simple
200
+ ref="formRef"
201
+ :model="formData"
202
+ :rules="rules"
203
+ label-width="100px"
204
+ label-position="left"
205
+ @submit="handleSubmit"
206
+ >
207
+ <hy-form-item-simple label="用户名" prop="username" required>
208
+ <hy-input v-model="formData.username" placeholder="请输入用户名" />
209
+ </hy-form-item-simple>
210
+
211
+ <hy-form-item-simple label="手机号" prop="phone" required>
212
+ <hy-input v-model="formData.phone" type="number" placeholder="请输入手机号" />
213
+ </hy-form-item-simple>
214
+
215
+ <hy-form-item-simple label="邮箱" prop="email">
216
+ <hy-input v-model="formData.email" placeholder="请输入邮箱" />
217
+ </hy-form-item-simple>
218
+
219
+ <hy-form-item-simple label="性别" prop="gender">
220
+ <hy-radio v-model="formData.gender" :columns="genderOptions" />
221
+ </hy-form-item-simple>
222
+
223
+ <hy-form-item-simple label="爱好" prop="hobbies">
224
+ <hy-check-button
225
+ v-model="formData.hobbies"
226
+ :columns="hobbyOptions"
227
+ select-type="multiple"
228
+ />
229
+ </hy-form-item-simple>
230
+
231
+ <hy-form-item-simple label="备注" prop="remark">
232
+ <hy-textarea v-model="formData.remark" placeholder="请输入备注" />
233
+ </hy-form-item-simple>
234
+ </hy-form-simple>
235
+
236
+ <view class="form-actions">
237
+ <hy-button type="primary" @click="handleSubmit">提交</hy-button>
238
+ <hy-button @click="handleReset">重置</hy-button>
239
+ </view>
240
+ </view>
241
+ </template>
242
+
243
+ <script setup lang="ts">
244
+ import { reactive, ref } from 'vue'
245
+
246
+ const formData = reactive({
247
+ username: '',
248
+ phone: '',
249
+ email: '',
250
+ gender: '',
251
+ hobbies: [],
252
+ remark: ''
253
+ })
254
+
255
+ const rules = {
256
+ username: [
257
+ { required: true, message: '请输入用户名' },
258
+ { min: 2, max: 20, message: '用户名长度在 2 到 20 个字符' }
259
+ ],
260
+ phone: [
261
+ { required: true, message: '请输入手机号' },
262
+ { type: 'phone', message: '请输入正确的手机号' }
263
+ ],
264
+ email: [
265
+ { type: 'email', message: '请输入正确的邮箱格式' }
266
+ ]
267
+ }
268
+
269
+ const genderOptions = [
270
+ { text: '男', value: 'male' },
271
+ { text: '女', value: 'female' }
272
+ ]
273
+
274
+ const hobbyOptions = [
275
+ { text: '阅读', value: 'reading' },
276
+ { text: '音乐', value: 'music' },
277
+ { text: '运动', value: 'sports' }
278
+ ]
279
+
280
+ const formRef = ref()
281
+
282
+ const handleSubmit = () => {
283
+ const result = formRef.value?.submit()
284
+ if (result) {
285
+ console.log('表单提交成功:', result)
286
+ }
287
+ }
288
+
289
+ const handleReset = () => {
290
+ formRef.value?.resetFields()
291
+ }
292
+ </script>
293
+ ```
294
+
295
+ ## 注意事项
296
+
297
+ 1. 表单组件使用 `provide/inject` 进行数据通信,确保 `hy-form-item-simple` 组件在 `hy-form-simple` 内部使用
298
+ 2. 验证规则支持数组形式,可以设置多个验证规则
299
+ 3. 自定义验证函数返回 `true` 表示验证通过,返回 `false` 或字符串表示验证失败
300
+ 4. 表单数据会自动双向绑定,无需手动处理数据同步
301
+ 5. 支持实时验证和失焦验证,可以通过 `trigger` 属性控制验证时机