hy-app 0.6.5 → 0.6.7

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.
@@ -17,4 +17,6 @@ export interface IDatetimePickerEmits {
17
17
  (e: 'change', param: IParam): void
18
18
  /** 更新值触发 */
19
19
  (e: 'update:modelValue', value: IParam['value']): void
20
+ /** 更新值关闭值 */
21
+ (e: 'update:show', value: boolean): void
20
22
  }
@@ -2,7 +2,7 @@
2
2
  <view class="hy-grid" ref="hy-grid" :style="gridStyle">
3
3
  <template v-for="(item, i) in list" :key="i">
4
4
  <view
5
- class="hy-grid__item"
5
+ :class="getItemClass(i)"
6
6
  hover-class="hy-grid__item--hover-class"
7
7
  :hover-stay-time="200"
8
8
  @tap="childClick(item)"
@@ -46,7 +46,7 @@ export default {
46
46
  <script setup lang="ts">
47
47
  import { computed } from 'vue'
48
48
  import type { CSSProperties } from 'vue'
49
- import type { IGridEmits } from './typing'
49
+ import type { GridItemVo, IGridEmits } from './typing'
50
50
  import { addUnit } from '../../libs'
51
51
  import gridProps from './props'
52
52
  // 组件
@@ -62,10 +62,13 @@ const props = defineProps(gridProps)
62
62
  const emit = defineEmits<IGridEmits>()
63
63
 
64
64
  /**
65
- * @description 宫格对齐方式
65
+ * 宫格对齐方式
66
66
  * */
67
67
  const gridStyle = computed<CSSProperties>(() => {
68
- let style: CSSProperties = {}
68
+ let style: CSSProperties = {
69
+ gap: addUnit(props.gap),
70
+ gridTemplateColumns: `repeat(${props.col}, 1fr)`
71
+ }
69
72
  switch (props.align) {
70
73
  case 'left':
71
74
  style.justifyContent = 'flex-start'
@@ -86,24 +89,42 @@ const itemStyle = computed<CSSProperties>(() => {
86
89
  const style: CSSProperties = {
87
90
  background: props.bgColor,
88
91
  height: addUnit(props.itemHeight),
89
- width: '100%',
90
- border: props.border ? '0.5px solid #c8c7cc66' : ''
92
+ width: '100%'
91
93
  }
92
94
  return style
93
95
  })
94
96
 
95
97
  /**
96
- * @description 点击事件
98
+ * 获取宫格项的类名
99
+ * @param index 当前项的索引
100
+ * @returns 类名数组
101
+ */
102
+ const getItemClass = computed(() => {
103
+ return (index: number): string[] => {
104
+ const classes: string[] = ['hy-grid__item']
105
+ if (props.border) {
106
+ classes.push('hy-grid__item--border')
107
+ // 判断是否为最后一列
108
+ if (index % props.col === props.col - 1) {
109
+ classes.push('hy-grid__item--border__last-col')
110
+ }
111
+ // 判断是否为最后一行
112
+ if (index >= props.list.length - props.col) {
113
+ classes.push('hy-grid__item--border__last-row')
114
+ }
115
+ }
116
+ return classes
117
+ }
118
+ })
119
+
120
+ /**
121
+ * 点击事件
97
122
  * */
98
- const childClick = (temp: string | Record<string, any>) => {
123
+ const childClick = (temp: string | GridItemVo) => {
99
124
  emit('click', temp)
100
125
  }
101
126
  </script>
102
127
 
103
128
  <style lang="scss" scoped>
104
- .hy-grid {
105
- grid-gap: v-bind(gap);
106
- grid-template-columns: repeat(v-bind(col), 1fr);
107
- }
108
129
  @import './index.scss';
109
130
  </style>
@@ -11,6 +11,7 @@
11
11
  /* #ifndef APP-NVUE */
12
12
  display: grid;
13
13
  /* #endif */
14
+
14
15
  @include e(item) {
15
16
  align-items: center;
16
17
  justify-content: center;
@@ -27,6 +28,23 @@
27
28
  float: left;
28
29
  /* #endif */
29
30
 
31
+ // 只有当有 border 类时才显示边框
32
+ @include m(border) {
33
+ // 添加右边框和下边框
34
+ border-right: $hy-border-line;
35
+ border-bottom: $hy-border-line;
36
+
37
+ // 最后一列不显示右边框
38
+ @include e(last-col) {
39
+ border-right: none;
40
+ }
41
+
42
+ // 最后一行不显示下边框
43
+ @include e(last-row) {
44
+ border-bottom: none;
45
+ }
46
+ }
47
+
30
48
  @include m(hover-class) {
31
49
  opacity: 0.7;
32
50
  }
@@ -2,34 +2,35 @@ import type { HyIconProps } from '../hy-icon/typing'
2
2
 
3
3
  export interface GridItemVo {
4
4
  /**
5
- * @description 图标名称或图片地址
5
+ * 图标名称或图片地址
6
6
  * */
7
7
  icon?: string
8
8
  /**
9
- * @description 名称
9
+ * 名称
10
10
  * */
11
11
  name?: string
12
12
  /**
13
- * @description 图标属性api配置
13
+ * 图标属性api配置
14
14
  * */
15
15
  iconConfig?: Partial<HyIconProps>
16
16
  /**
17
- * @description 自定义内容键值对
17
+ * 自定义内容键值对
18
18
  * */
19
19
  [key: string]: any
20
20
  }
21
+
21
22
  export interface CustomKeysVo {
22
23
  /**
23
- * @description 自定义标题键名
24
+ * 自定义标题键名
24
25
  * */
25
26
  name: string
26
27
  /**
27
- * @description 自定义icon键名
28
+ * 自定义icon键名
28
29
  * */
29
30
  icon: string
30
31
  }
31
32
 
32
33
  export interface IGridEmits {
33
34
  /** 点击小菜单触发 */
34
- (e: 'click', name: string | Record<string, any>): void
35
+ (e: 'click', name: string | GridItemVo): void
35
36
  }
@@ -1,159 +1,117 @@
1
- <template>
2
- <view class="hy-menu" :style="{ width: addUnit(width) }">
3
- <template v-for="(item, i) in list">
4
- <view
5
- @click="handleClick(item, i)"
6
- :class="menuItemClass(item, i)"
7
- :style="customStyle"
8
- >
9
- <template v-if="item.icon">
10
- <slot v-if="$slots.icon" name="icon" :value="item.icon"></slot>
11
- <hy-icon
12
- v-else
13
- class="hy-menu__item__icon"
14
- :name="item.icon"
15
- :color="current === i ? color || 'var(--hy-theme-color)' : ''"
16
- :size="icon?.size || 16"
17
- :bold="icon?.bold"
18
- :customPrefix="icon?.customPrefix"
19
- :imgMode="icon?.imgMode"
20
- :width="icon?.width"
21
- :height="icon?.height"
22
- :top="icon?.top"
23
- :stop="icon?.stop"
24
- :round="icon?.round"
25
- :customStyle="icon?.customStyle || { marginRight: '2px' }"
26
- ></hy-icon>
27
- </template>
28
- <slot v-if="$slots.default"></slot>
29
- <text v-else class="hy-menu__item--title">{{ item.title }}</text>
30
- <hy-badge
31
- :value="item?.badge"
32
- :offset="badge?.offset"
33
- :shape="badge?.shape"
34
- :color="badge?.color"
35
- :bg-color="badge?.bgColor"
36
- :inverted="badge?.inverted"
37
- :type="badge?.type"
38
- :number-type="badge?.numberType"
39
- :is-dot="badge?.isDot"
40
- :absolute="badge?.absolute"
41
- :max="badge?.max"
42
- :show-zero="badge?.showZero"
43
- :custom-style="badge?.customStyle"
44
- ></hy-badge>
45
- </view>
46
- </template>
47
- </view>
48
- </template>
49
-
50
- <script lang="ts">
51
- export default {
52
- name: 'hy-menu',
53
- options: {
54
- addGlobalClass: true,
55
- virtualHost: true,
56
- styleIsolation: 'shared'
57
- }
58
- }
59
- </script>
60
-
61
- <script lang="ts" setup>
62
- import { computed, ref, watch } from 'vue'
63
- import type { IMenuEmits, MenusType } from './typing'
64
- import { addUnit } from '../../libs'
65
- import menuProps from './props'
66
- // 组件
67
- import HyIcon from '../hy-icon/hy-icon.vue'
68
- import HyBadge from '../hy-badge/hy-badge.vue'
69
-
70
- /**
71
- * 垂直展示的导航栏,用于在不同的内容区域之间进行切换。
72
- * @displayName hy-menu
73
- */
74
- defineOptions({})
75
-
76
- const props = defineProps(menuProps)
77
- const emit = defineEmits<IMenuEmits>()
78
-
79
- const current = ref<string | number>(0)
80
-
81
- watch(
82
- () => props.modelValue,
83
- (newVal) => {
84
- if (newVal) current.value = newVal
85
- },
86
- { immediate: true }
87
- )
88
-
89
- const menuItemClass = computed(() => {
90
- return (temp: MenusType, i: number) => {
91
- const classes = [
92
- 'hy-menu__item',
93
- prefix.value && 'hy-menu__item--prefix',
94
- suffix.value && 'hy-menu__item--suffix',
95
- temp.disabled && 'hy-menu__item--disabled'
96
- ]
97
- if (current.value === temp[props.id]) {
98
- classes.push('hy-menu__item--active', props.color && 'hy-menu__item--active__color')
99
- }
100
-
101
- return classes
102
- }
103
- })
104
-
105
- const prefix = computed(() => {
106
- let prefix: boolean = false
107
- // if (sidebar) {
108
- // let activeIndex: number = sidebar.children.findIndex((c: any) => {
109
- // return c.value === sidebar.props.modelValue;
110
- // });
111
- //
112
- // let currentIndex: number = sidebar.children.findIndex((c: any) => {
113
- // return c.value === props.value;
114
- // });
115
- //
116
- // if (currentIndex === activeIndex - 1) {
117
- // prefix = true;
118
- // }
119
- // }
120
- return prefix
121
- })
122
-
123
- const suffix = computed(() => {
124
- let suffix: boolean = false
125
- // if (sidebar) {
126
- // let activeIndex: number = sidebar.children.findIndex((c: any) => {
127
- // return c.value === sidebar.props.modelValue;
128
- // });
129
- //
130
- // let currentIndex: number = sidebar.children.findIndex((c: any) => {
131
- // return c.value === props.value;
132
- // });
133
- //
134
- // if (currentIndex === activeIndex + 1) {
135
- // suffix = true;
136
- // }
137
- // }
138
- return suffix
139
- })
140
-
141
- function handleClick(temp: MenusType, i: number) {
142
- if (temp?.disabled) {
143
- return
144
- }
145
- current.value = i
146
- emit('update:modelValue', temp.id)
147
- emit('change', temp)
148
- }
149
- </script>
150
-
151
- <style lang="scss" scoped>
152
- @import './index.scss';
153
- .hy-menu__item--active__color {
154
- color: v-bind(color);
155
- &::before {
156
- background: v-bind(color);
157
- }
158
- }
159
- </style>
1
+ <template>
2
+ <view class="hy-menu" :style="{ width: addUnit(width) }">
3
+ <template v-for="(item, i) in list">
4
+ <view @click="handleClick(item, i)" :class="menuItemClass(item)" :style="customStyle">
5
+ <template v-if="item.icon">
6
+ <slot v-if="$slots.icon" name="icon" :value="item.icon"></slot>
7
+ <hy-icon
8
+ v-else
9
+ class="hy-menu__item__icon"
10
+ :name="item.icon"
11
+ :color="current === i ? color || 'var(--hy-theme-color)' : ''"
12
+ :size="icon?.size || 16"
13
+ :bold="icon?.bold"
14
+ :customPrefix="icon?.customPrefix"
15
+ :imgMode="icon?.imgMode"
16
+ :width="icon?.width"
17
+ :height="icon?.height"
18
+ :top="icon?.top"
19
+ :stop="icon?.stop"
20
+ :round="icon?.round"
21
+ :customStyle="icon?.customStyle || { marginRight: '2px' }"
22
+ ></hy-icon>
23
+ </template>
24
+ <slot v-if="$slots.default"></slot>
25
+ <text v-else class="hy-menu__item--title">{{ item.title }}</text>
26
+ <hy-badge
27
+ :value="item?.badge"
28
+ :offset="badge?.offset"
29
+ :shape="badge?.shape"
30
+ :color="badge?.color"
31
+ :bg-color="badge?.bgColor"
32
+ :inverted="badge?.inverted"
33
+ :type="badge?.type"
34
+ :number-type="badge?.numberType"
35
+ :is-dot="badge?.isDot"
36
+ :absolute="badge?.absolute"
37
+ :max="badge?.max"
38
+ :show-zero="badge?.showZero"
39
+ :custom-style="badge?.customStyle"
40
+ ></hy-badge>
41
+ </view>
42
+ </template>
43
+ </view>
44
+ </template>
45
+
46
+ <script lang="ts">
47
+ export default {
48
+ name: 'hy-menu',
49
+ options: {
50
+ addGlobalClass: true,
51
+ virtualHost: true,
52
+ styleIsolation: 'shared'
53
+ }
54
+ }
55
+ </script>
56
+
57
+ <script lang="ts" setup>
58
+ import { computed, ref, watch } from 'vue'
59
+ import type { IMenuEmits, MenuParamsVo } from './typing'
60
+ import { addUnit } from '../../libs'
61
+ import menuProps from './props'
62
+ // 组件
63
+ import HyIcon from '../hy-icon/hy-icon.vue'
64
+ import HyBadge from '../hy-badge/hy-badge.vue'
65
+ import index from '@/pages/mine/Index.vue'
66
+
67
+ /**
68
+ * 垂直展示的导航栏,用于在不同的内容区域之间进行切换。
69
+ * @displayName hy-menu
70
+ */
71
+ defineOptions({})
72
+
73
+ const props = defineProps(menuProps)
74
+ const emit = defineEmits<IMenuEmits>()
75
+
76
+ const current = ref<string | number>(0)
77
+
78
+ watch(
79
+ () => props.modelValue,
80
+ (newVal) => {
81
+ if (newVal) current.value = newVal
82
+ },
83
+ { immediate: true }
84
+ )
85
+
86
+ const menuItemClass = computed(() => {
87
+ return (temp: MenuParamsVo) => {
88
+ const classes = ['hy-menu__item', temp.disabled && 'hy-menu__item--disabled']
89
+ if (current.value === temp[props.id]) {
90
+ classes.push('hy-menu__item--active', props.color && 'hy-menu__item--active__color')
91
+ }
92
+
93
+ return classes
94
+ }
95
+ })
96
+
97
+ function handleClick(temp: MenuParamsVo, i: number) {
98
+ if (temp?.disabled) {
99
+ return
100
+ }
101
+ if (current.value !== temp.id) {
102
+ current.value = temp.id
103
+ emit('update:modelValue', temp.id)
104
+ emit('change', temp, i)
105
+ }
106
+ }
107
+ </script>
108
+
109
+ <style lang="scss" scoped>
110
+ @import './index.scss';
111
+ .hy-menu__item--active__color {
112
+ color: v-bind(color);
113
+ &::before {
114
+ background: v-bind(color);
115
+ }
116
+ }
117
+ </style>
@@ -1,14 +1,14 @@
1
- import type { MenusType, ModelValueVo } from './typing'
1
+ import type { MenuParamsVo } from './typing'
2
2
  import type { CSSProperties, PropType } from 'vue'
3
3
  import type { HyIconProps } from '../hy-icon/typing'
4
4
  import type { HyBadgeProps } from '../hy-badge/typing'
5
5
 
6
6
  const menuProps = {
7
7
  /** 当前值 */
8
- modelValue: [String, Number] as PropType<ModelValueVo>,
8
+ modelValue: [String, Number] as PropType<MenuParamsVo['id']>,
9
9
  /** 菜单数据集 */
10
10
  list: {
11
- type: Array as PropType<Array<MenusType>>,
11
+ type: Array as PropType<Array<MenuParamsVo>>,
12
12
  default: []
13
13
  },
14
14
  /** 对应的键 */
@@ -1,5 +1,4 @@
1
- export type ModelValueVo = string | number
2
- export interface MenusType {
1
+ export interface MenuParamsVo {
3
2
  /**
4
3
  * 唯一id
5
4
  * */
@@ -28,7 +27,7 @@ export interface MenusType {
28
27
 
29
28
  export interface IMenuEmits {
30
29
  /** 选中触发 */
31
- (e: 'change', temp: MenusType): void
30
+ (e: 'change', temp: MenuParamsVo, index: number): void
32
31
  /** 选中触发 */
33
- (e: 'update:modelValue', id: MenusType['id']): void
32
+ (e: 'update:modelValue', id: MenuParamsVo['id']): void
34
33
  }
@@ -59,8 +59,8 @@ watch(
59
59
  // 进行一定的延时
60
60
  await sleep()
61
61
  // 查询盒子和文字的宽度
62
- textWidth = (await getRect('.hy-notice__content--text', false, instance)).width
63
- boxWidth = (await getRect('.hy-notice__content', false, instance)).width
62
+ textWidth = (await getRect('.hy-notice__content--text', false, instance)).width!
63
+ boxWidth = (await getRect('.hy-notice__content', false, instance)).width!
64
64
  // 根据t=s/v(时间=路程/速度),这里为何不需要加上#u-notice-box的宽度,因为中设置了.u-notice-content样式中设置了padding-left: 100%
65
65
  // 恰巧计算出来的结果中已经包含了#u-notice-box的宽度
66
66
  animationDuration.value = `${textWidth / speed.value}s`