hy-app 0.3.0 → 0.3.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.
@@ -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
- v-if="isRequired(item.rules)"
11
- style="color: red; font-size: 20px; line-height: 10px"
12
- >*</text
13
- >{{ item.label }} <text v-if="symbol">:</text>
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
- item?.input?.placeholderClass || input?.placeholderClass
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
- item?.textarea?.placeholderClass || textarea?.placeholderClass
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
- item?.textarea?.selectionStart || textarea?.selectionStart
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
- item?.switchItem?.activeColor || switchItem?.activeColor
174
- "
175
- :inactiveColor="
176
- item?.switchItem?.inactiveColor || switchItem?.inactiveColor
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, type CSSProperties, reactive, toRefs } from "vue";
329
- import type IProps from "./typing";
330
- import defaultProps from "./props";
331
- import { addUnit, error } from "../../utils";
332
- import type { FormColumnsType, RulesVo } from "../../typing";
333
- import { FormTypeEnum } from "../../typing";
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 "../hy-input/hy-input.vue";
337
- import HyPicker from "../hy-picker/hy-picker.vue";
338
- import HyUpload from "../hy-upload/hy-upload.vue";
339
- import HyTextarea from "../hy-textarea/hy-textarea.vue";
340
- import HySwitch from "../hy-switch/hy-switch.vue";
341
- import HyRadio from "../hy-radio/hy-radio.vue";
342
- import HyDatetimePicker from "../hy-datetime-picker/hy-datetime-picker.vue";
343
- import HyAddressPicker from "../hy-address-picker/hy-address-picker.vue";
344
- import HyTransition from "../hy-transition/hy-transition.vue";
345
- import HyCheckButton from "../hy-check-button/hy-check-button.vue";
346
-
347
- const props = withDefaults(defineProps<IProps>(), defaultProps);
348
- const {
349
- formData,
350
- columns,
351
- labelWidth,
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 = "#dd6161";
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
- (rule?.min || rule?.max) &&
415
- (value.length < rule?.min! || value.length > rule?.max!)
416
- ) {
417
- return rule.message!;
418
- } else if (rule.type === "phone" && !phoneExpression.test(String(value))) {
419
- return rule.message || "请输入正确的手机号";
420
- } else if (rule.type === "email" && !emitExpression.test(String(value))) {
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?: "blur" | "change",
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, "change");
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, "blur");
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 "./index.scss";
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 class="hy-form-item" :class="[`hy-form-item--${labelPosition}`]">
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, type PropType, provide, ref } from 'vue'
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.value !== 'auto') {
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.value) {
119
- style.textAlign = formContext.labelAlign.value
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?.value || 'left'
129
+ return formContext?.labelPosition || 'left'
128
130
  })
129
131
 
130
132
  // 监听表单数据变化
@@ -18,8 +18,8 @@
18
18
  position: relative;
19
19
  padding-right: 8px;
20
20
  font-size: 14px;
21
- color: #333;
22
- line-height: 1.5;
21
+ color: $hy-text-color;
22
+ line-height: 2.5;
23
23
 
24
24
  @include m(required) {
25
25
  color: #ff4d4f;
@@ -1,10 +1,7 @@
1
- export interface FormContext {
2
- formData: Record<string, any>
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
@@ -32,7 +32,7 @@ import type { UserLoginInfoVo } from './typing'
32
32
 
33
33
  // 组件
34
34
  import HyCheckbox from '../hy-checkbox/hy-checkbox.vue'
35
- import HyForm from '@/package/components/hy-form-group/hy-form.vue'
35
+ import HyForm from '@/package/components/hy-form-group/hy-form-group.vue'
36
36
 
37
37
  interface IProps {
38
38
  themeColor: string
@@ -18,7 +18,7 @@ import HyDropdown from './hy-dropdown/hy-dropdown.vue'
18
18
  import HyDropdownItem from './hy-dropdown-item/hy-dropdown-item.vue'
19
19
  import YkEmpty from './hy-empty/hy-empty.vue'
20
20
  import YkFloatButton from './hy-float-button/hy-float-button.vue'
21
- import HyFoldingPanel from './hy-folding-panel/hy-folding-panel.vue'
21
+ import HyFoldingPanel from '@/package/components/hy-folding-panel/hy-folding-panel.vue'
22
22
  import HyForm from '@/package/components/hy-form-group/hy-form.vue'
23
23
  import HyFormSimple from '@/package/components/hy-form/hy-form-simple.vue'
24
24
  import HyFormItem from './hy-form-item/hy-form-item.vue'
package/global.d.ts CHANGED
@@ -22,6 +22,7 @@ declare module 'vue' {
22
22
  HyDropdown: (typeof import('./components/hy-dropdown/hy-dropdown.vue'))['default']
23
23
  HyDropdownItem: (typeof import('./components/hy-dropdown-item/hy-dropdown-item.vue'))['default']
24
24
  HyEmpty: (typeof import('./components/hy-empty/hy-empty.vue'))['default']
25
+ HyFlex: (typeof import('./components/hy-flex/hy-flex.vue'))['default']
25
26
  HyFloatButton: (typeof import('./components/hy-float-button/hy-float-button.vue'))['default']
26
27
  HyFloatingPanel: (typeof import('./components/hy-floating-panel/hy-floating-panel.vue'))['default']
27
28
  HyForm: (typeof import('@/package/components/hy-form-group/hy-form.vue'))['default']
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hy-app",
3
- "version": "0.3.0",
4
- "description": "添加分离式表单组件",
3
+ "version": "0.3.1",
4
+ "description": "feat: 弹性布局组件",
5
5
  "main": "./index.ts",
6
6
  "private": false,
7
7
  "scripts": {},
package/theme.scss CHANGED
@@ -40,14 +40,14 @@ $hy-text-color--hover: var(--hy-text-color--hover, #58595b)!default; // 点击
40
40
  /* 背景色 */
41
41
  $hy-background: var(--hy-background, #f8f8f8) !default; // 背景色
42
42
  $hy-background--2: var(--hy-background--2, #ffffff) !default; // 弹窗背景色
43
- $hy-background--3: var(--hy-background--3, #646566) !default; // 弹窗背景色
43
+ $hy-background--3: var(--hy-background--3, rgb(238, 238, 239)) !default; // 弹窗背景色
44
44
  $hy-background--container: var(--hy-background--container, #ffffff) !default; // 容器背景色
45
- $hy-background--disabled: var(--hy-background--disabled, #F5F5F5); // 禁用背景色
45
+ $hy-background--disabled: var(--hy-background--disabled, rgba(0, 0, 0, 0.04)); // 禁用背景色
46
46
  $hy-background--track: var(--hy-background--track, #F6F6F6) !default; // 轨道背景色
47
47
  $hy-background--empty: var(--hy-background--empty, #F3F3F3) !default; // 搜索背景色
48
- $hy-background--hover: var(--hy-background--hover, rgba(0,0,0,0.1)) !default; // 点击状态
48
+ $hy-background--hover: var(--hy-background--hover, rgba(0,0,0,0.05)) !default; // 点击状态
49
49
  $hy-light-background-mask: var(--hy-light-background-mask, rgba(0, 0, 0, 0.5)); //遮罩颜色
50
- $hy-background--active: var(--hy-background--active, #131313); // 选中背景色
50
+ $hy-background--active: var(--hy-background--active, #FFFFFF); // 选中背景色
51
51
  $hy-background--close: var(--hy-background--close, #f0f0f0); // 选中背景色
52
52
 
53
53
  /* 文字尺寸 */
@@ -88,4 +88,4 @@ $hy-border-margin-padding-sm: var(--hy-border-margin-padding-sm, 10rpx) !default
88
88
  $hy-border-margin-padding-base: var(--hy-border-margin-padding-base, 20rpx) !default;
89
89
  $hy-border-margin-padding-lg: var(--hy-border-margin-padding-lg, 30rpx) !default;
90
90
  /* 底部线条 */
91
- $hy-border-line: var(--hy-border-line, 1rpx solid rgba(0, 0, 0, 0.02)) !default;
91
+ $hy-border-line: var(--hy-border-line, 1rpx solid #e8e8e8) !default;