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.
@@ -35,12 +35,8 @@ export default {
35
35
  </script>
36
36
 
37
37
  <script setup lang="ts">
38
- /**
39
- * 该组件一个用于长页面,滑动一定距离后,出现返回顶部按钮,方便快速返回顶部的场景。
40
- * @displayName hy-back-top
41
- */
42
- defineOptions({})
43
- import { computed, type CSSProperties, PropType, toRefs } from 'vue'
38
+ import { computed, toRefs } from 'vue'
39
+ import type { CSSProperties, PropType } from 'vue'
44
40
  import { addUnit, getPx } from '../../utils'
45
41
  import { IconConfig } from '../../config'
46
42
  import type { IBackTopEmit } from './typing'
@@ -49,6 +45,12 @@ import type HyIconProps from '../hy-icon/typing'
49
45
  import HyTransition from '../hy-transition/hy-transition.vue'
50
46
  import HyIcon from '../hy-icon/hy-icon.vue'
51
47
 
48
+ /**
49
+ * 该组件一个用于长页面,滑动一定距离后,出现返回顶部按钮,方便快速返回顶部的场景。
50
+ * @displayName hy-back-top
51
+ */
52
+ defineOptions({})
53
+
52
54
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
53
55
  const props = defineProps({
54
56
  /**
@@ -49,7 +49,7 @@ const props = defineProps({
49
49
  customClass: String,
50
50
  /** 定义需要用到的外部样式 */
51
51
  customStyle: {
52
- type: Object as PropType<CSSProperties>,
52
+ type: [Object, Array] as PropType<CSSProperties | CSSProperties[]>,
53
53
  },
54
54
  })
55
55
  const { theme, themeColor, customClass, customStyle, padding } = toRefs(props)
@@ -0,0 +1,73 @@
1
+ <template>
2
+ <view :class="cls" :style="style">
3
+ <slot />
4
+ </view>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { computed, PropType } from 'vue'
9
+ import { FlexAlign, FlexDirection, FlexJustify, FlexWrap } from './typing'
10
+ import { addUnit, isArray } from '../../utils'
11
+
12
+ const props = defineProps({
13
+ /** flex 主轴的方向是否垂直,使用 flex-direction: column */
14
+ vertical: {
15
+ type: Boolean,
16
+ default: false,
17
+ },
18
+ /** 快捷设置 flex-direction */
19
+ direction: String as PropType<FlexDirection>,
20
+ /** 设置元素在主轴方向上的对齐方式 */
21
+ justify: {
22
+ type: String as PropType<FlexJustify>,
23
+ default: 'flex-start',
24
+ },
25
+ /** 设置元素在交叉轴方向上的对齐方式 */
26
+ align: {
27
+ type: String as PropType<FlexAlign>,
28
+ default: 'flex-start',
29
+ },
30
+ /** 设置元素单行显示还是多行显示 */
31
+ wrap: {
32
+ type: String as PropType<FlexWrap>,
33
+ default: 'nowrap',
34
+ },
35
+ /** flex 属性,支持数字或字符串。如 1 或 'none' */
36
+ flex: {
37
+ type: [String, Number],
38
+ default: 'initial',
39
+ },
40
+ /** 设置网格之间的间隙 */
41
+ gap: {
42
+ type: [String, Number, Array] as PropType<string | number | (string | number)[]>,
43
+ default: 0,
44
+ },
45
+ /** 快捷设置 */
46
+ basis: {
47
+ type: [String, Number],
48
+ default: 'auto',
49
+ },
50
+ })
51
+
52
+ // 计算 class
53
+ const cls = computed(() => ['hy-flex', props.vertical && 'hy-flex--vertical'])
54
+
55
+ // 计算 style
56
+ const style = computed(() => {
57
+ const gap = isArray(props.gap) ? props.gap : [props.gap, props.gap]
58
+ const [rowGap, colGap] = gap.map((v) => addUnit(v))
59
+
60
+ return {
61
+ display: 'flex',
62
+ 'justify-content': props.justify,
63
+ 'align-items': props.align,
64
+ 'flex-wrap': props.wrap,
65
+ flex: props.flex,
66
+ 'flex-basis': props.basis,
67
+ 'row-gap': colGap,
68
+ 'column-gap': rowGap,
69
+ }
70
+ })
71
+ </script>
72
+
73
+ <style scoped></style>
@@ -0,0 +1,8 @@
1
+ @use "../../libs/css/mixin.scss" as *;
2
+ @include b(flex) {
3
+ box-sizing: border-box;
4
+
5
+ @include m(vertical) {
6
+ flex-direction: column;
7
+ }
8
+ }
@@ -0,0 +1,23 @@
1
+ export type FlexAlign = 'flex-start' | 'center' | 'flex-end' | 'stretch' | 'baseline'
2
+
3
+ export type FlexJustify = HyApp.JustifyContentType
4
+ export type FlexDirection = 'row' | 'row-reverse' | 'column' | 'column-reverse'
5
+ export type FlexWrap = 'nowrap' | 'wrap' | 'wrap-reverse'
6
+
7
+ export interface FlexProps {
8
+ /** 主轴方向,等价于 flex-direction */
9
+ vertical?: boolean
10
+ direction?: FlexDirection
11
+ /** justify-content */
12
+ justify?: FlexJustify
13
+ /** align-items */
14
+ align?: FlexAlign
15
+ /** flex-wrap */
16
+ wrap?: FlexWrap
17
+ /** flex 属性,支持数字或字符串。如 1 或 'none' */
18
+ flex?: number | string
19
+ /** 子元素间距,支持数字(px)、字符串或数组 [row, column] */
20
+ gap?: number | string | [number | string, number | string]
21
+ /** flex-basis */
22
+ basis?: number | string
23
+ }
@@ -1,12 +1,12 @@
1
1
  <template>
2
- <view class="hy-form-simple">
2
+ <view class="hy-form">
3
3
  <slot></slot>
4
4
  </view>
5
5
  </template>
6
6
 
7
7
  <script lang="ts">
8
8
  export default {
9
- name: 'hy-form-simple',
9
+ name: 'hy-form',
10
10
  options: {
11
11
  addGlobalClass: true,
12
12
  virtualHost: true,
@@ -16,8 +16,10 @@ export default {
16
16
  </script>
17
17
 
18
18
  <script setup lang="ts">
19
- import { PropType, provide, reactive, ref, toRefs } from 'vue'
19
+ import { provide, reactive, ref, toRefs } from 'vue'
20
+ import type { PropType } from 'vue'
20
21
  import type { FormItemRule } from './typing'
22
+ import { clearVal } from '../../utils'
21
23
 
22
24
  /**
23
25
  * 表单组件父组件,需要搭配hy-form-item
@@ -29,7 +31,12 @@ const props = defineProps({
29
31
  /** 表单数据对象 */
30
32
  model: Object as PropType<AnyObject>,
31
33
  /** 表单校验规则 */
32
- rules: Object as unknown as PropType<FormItemRule>,
34
+ rules: Object as PropType<FormItemRule>,
35
+ /** 表单底部边框 */
36
+ border: {
37
+ type: Boolean,
38
+ default: false,
39
+ },
33
40
  /** label标签的宽度,单位rpx */
34
41
  labelWidth: {
35
42
  type: String,
@@ -52,6 +59,7 @@ const props = defineProps({
52
59
  default: 'left',
53
60
  },
54
61
  })
62
+ const { rules, border, labelWidth, labelAlign, labelPosition } = toRefs(props)
55
63
 
56
64
  const emit = defineEmits<{
57
65
  submit: [data: Record<string, any>]
@@ -67,10 +75,11 @@ const errors = reactive<Record<string, string>>({})
67
75
  const formContext = {
68
76
  formData,
69
77
  errors,
70
- rules: toRefs(props).rules,
71
- labelWidth: toRefs(props).labelWidth,
72
- labelPosition: toRefs(props).labelPosition,
73
- labelAlign: toRefs(props).labelAlign,
78
+ rules: rules.value,
79
+ border: border.value,
80
+ labelWidth: labelWidth.value,
81
+ labelPosition: labelPosition.value,
82
+ labelAlign: labelAlign.value,
74
83
  addFormItem: (item: any) => {
75
84
  formItems.value.push(item)
76
85
  },
@@ -205,9 +214,7 @@ const validate = () => {
205
214
 
206
215
  // 重置表单
207
216
  const resetFields = () => {
208
- Object.keys(formData).forEach((key) => {
209
- formData[key] = undefined
210
- })
217
+ clearVal(formData)
211
218
  Object.keys(errors).forEach((key) => {
212
219
  delete errors[key]
213
220
  })
@@ -246,7 +253,7 @@ defineExpose({
246
253
  </script>
247
254
 
248
255
  <style lang="scss" scoped>
249
- .hy-form-simple {
256
+ .hy-form {
250
257
  width: 100%;
251
258
  }
252
259
  </style>
@@ -54,4 +54,8 @@ export default interface HyFormSimpleProps {
54
54
  * 标签对齐方式
55
55
  */
56
56
  labelAlign?: 'left' | 'center' | 'right'
57
+ /**
58
+ * 表单列底部边框
59
+ * */
60
+ border: boolean
57
61
  }