hy-app 0.3.0 → 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 (108) 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-back-top/hy-back-top.vue +8 -6
  8. package/components/hy-badge/hy-badge.vue +47 -46
  9. package/components/hy-button/hy-button.vue +117 -93
  10. package/components/hy-calendar/hy-calendar.vue +168 -160
  11. package/components/hy-card/hy-card.vue +50 -43
  12. package/components/hy-card/typing.d.ts +33 -32
  13. package/components/hy-cell/hy-cell.vue +73 -51
  14. package/components/hy-check-button/hy-check-button.vue +54 -47
  15. package/components/hy-checkbox/hy-checkbox.vue +97 -105
  16. package/components/hy-code-input/hy-code-input.vue +80 -89
  17. package/components/hy-config-provider/hy-config-provider.vue +20 -21
  18. package/components/hy-count-down/hy-count-down.vue +66 -67
  19. package/components/hy-count-to/hy-count-to.vue +105 -99
  20. package/components/hy-count-to/typing.d.ts +13 -12
  21. package/components/hy-datetime-picker/hy-datetime-picker.vue +261 -253
  22. package/components/hy-datetime-picker/typing.d.ts +42 -40
  23. package/components/hy-divider/hy-divider.vue +68 -73
  24. package/components/hy-dropdown/hy-dropdown.vue +20 -19
  25. package/components/hy-dropdown-item/hy-dropdown-item.vue +66 -61
  26. package/components/hy-dropdown-item/typing.d.ts +9 -9
  27. package/components/hy-empty/hy-empty.vue +42 -42
  28. package/components/hy-flex/hy-flex.vue +99 -0
  29. package/components/hy-flex/index.scss +8 -0
  30. package/components/hy-flex/typing.d.ts +23 -0
  31. package/components/hy-float-button/hy-float-button.vue +218 -210
  32. package/components/hy-folding-panel/hy-folding-panel.vue +32 -33
  33. package/components/hy-form/hy-form.vue +264 -252
  34. package/components/hy-form/typing.d.ts +4 -0
  35. package/components/hy-form-group/hy-form-group.vue +114 -183
  36. package/components/hy-form-item/hy-form-item.vue +12 -10
  37. package/components/hy-form-item/index.scss +2 -2
  38. package/components/hy-form-item/typing.d.ts +3 -6
  39. package/components/hy-grid/hy-grid.vue +44 -43
  40. package/components/hy-icon/hy-icon.vue +61 -67
  41. package/components/hy-image/hy-image.vue +112 -88
  42. package/components/hy-image/typing.d.ts +27 -23
  43. package/components/hy-input/hy-input.vue +157 -127
  44. package/components/hy-input/typing.d.ts +53 -47
  45. package/components/hy-line/hy-line.vue +26 -26
  46. package/components/hy-line-progress/hy-line-progress.vue +42 -35
  47. package/components/hy-list/hy-list.vue +76 -85
  48. package/components/hy-loading/hy-loading.vue +26 -23
  49. package/components/hy-login/TheUserLogin.vue +1 -1
  50. package/components/hy-menu/hy-menu.vue +48 -43
  51. package/components/hy-menu/typing.d.ts +18 -17
  52. package/components/hy-modal/hy-modal.vue +39 -35
  53. package/components/hy-navbar/hy-navbar.vue +25 -25
  54. package/components/hy-navbar/typing.d.ts +24 -22
  55. package/components/hy-notice-bar/hy-notice-bar.vue +26 -27
  56. package/components/hy-notify/hy-notify.vue +53 -53
  57. package/components/hy-number-step/hy-number-step.vue +134 -146
  58. package/components/hy-number-step/typing.d.ts +35 -35
  59. package/components/hy-overlay/hy-overlay.vue +23 -21
  60. package/components/hy-pagination/hy-pagination.vue +41 -36
  61. package/components/hy-picker/hy-picker.vue +184 -154
  62. package/components/hy-picker/typing.d.ts +39 -39
  63. package/components/hy-popover/hy-popover.vue +97 -77
  64. package/components/hy-popup/hy-popup.vue +107 -98
  65. package/components/hy-price/hy-price.vue +38 -34
  66. package/components/hy-qrcode/hy-qrcode.vue +50 -51
  67. package/components/hy-radio/hy-radio.vue +101 -113
  68. package/components/hy-rate/hy-rate.vue +107 -88
  69. package/components/hy-read-more/hy-read-more.vue +64 -49
  70. package/components/hy-scroll-list/hy-scroll-list.vue +45 -48
  71. package/components/hy-search/hy-search.vue +73 -66
  72. package/components/hy-search/typing.d.ts +36 -35
  73. package/components/hy-signature/hy-signature.vue +282 -240
  74. package/components/hy-slider/hy-slider.vue +195 -153
  75. package/components/hy-slider/typing.d.ts +21 -21
  76. package/components/hy-steps/hy-steps.vue +118 -90
  77. package/components/hy-steps/index.scss +31 -21
  78. package/components/hy-submit-bar/hy-submit-bar.vue +61 -70
  79. package/components/hy-subsection/hy-subsection.vue +99 -102
  80. package/components/hy-subsection/typing.d.ts +19 -19
  81. package/components/hy-swipe-action/hy-swipe-action.vue +131 -118
  82. package/components/hy-swiper/hy-swiper.vue +85 -71
  83. package/components/hy-switch/hy-switch.vue +67 -72
  84. package/components/hy-switch/typing.d.ts +21 -19
  85. package/components/hy-tabs/hy-tabs.vue +168 -113
  86. package/components/hy-tag/hy-tag.vue +90 -86
  87. package/components/hy-tag/typing.d.ts +26 -21
  88. package/components/hy-text/hy-text.vue +119 -111
  89. package/components/hy-textarea/hy-textarea.vue +100 -93
  90. package/components/hy-textarea/typing.d.ts +36 -31
  91. package/components/hy-toast/hy-toast.vue +77 -67
  92. package/components/hy-tooltip/hy-tooltip.vue +109 -91
  93. package/components/hy-transition/hy-transition.vue +62 -66
  94. package/components/hy-upload/hy-upload.vue +294 -152
  95. package/components/hy-upload/typing.d.ts +41 -36
  96. package/components/hy-warn/hy-warn.vue +34 -27
  97. package/components/hy-waterfall/hy-waterfall.vue +83 -74
  98. package/components/hy-watermark/hy-watermark.vue +134 -115
  99. package/components/index.ts +1 -1
  100. package/composables/usePopover.ts +236 -221
  101. package/composables/useQueue.ts +53 -52
  102. package/global.d.ts +1 -0
  103. package/package.json +2 -2
  104. package/store/index.ts +9 -1
  105. package/theme.scss +5 -5
  106. package/typing/index.ts +0 -1
  107. package/typing/modules/common.d.ts +0 -2
  108. package/web-types.json +1 -1
@@ -9,7 +9,10 @@
9
9
  class="hy-virtual-container"
10
10
  >
11
11
  <view class="hy-virtual-container__list">
12
- <slot v-if="slotDefault" :record="line === 1 ? virtualData : waterfall"></slot>
12
+ <slot
13
+ v-if="slotDefault"
14
+ :record="line === 1 ? virtualData : waterfall"
15
+ ></slot>
13
16
  <template v-else>
14
17
  <view
15
18
  v-if="line === 1"
@@ -63,55 +66,53 @@
63
66
 
64
67
  <script lang="ts">
65
68
  export default {
66
- name: 'hy-list',
69
+ name: "hy-list",
67
70
  options: {
68
71
  addGlobalClass: true,
69
72
  virtualHost: true,
70
- styleIsolation: 'shared',
73
+ styleIsolation: "shared",
71
74
  },
72
- }
75
+ };
73
76
  </script>
74
77
 
75
78
  <script lang="ts" setup>
76
79
  import {
77
80
  computed,
78
- type CSSProperties,
79
81
  getCurrentInstance,
80
82
  nextTick,
81
83
  onMounted,
84
+ type PropType,
82
85
  reactive,
83
86
  ref,
84
- toRefs,
85
87
  useSlots,
86
88
  watch,
87
- } from 'vue'
88
- import { addUnit, getPx, getRect } from '../../utils'
89
- import type { IListEmits } from './typing'
89
+ } from "vue";
90
+ import type { CSSProperties } from "vue";
91
+ import { addUnit, getPx, getRect } from "../../utils";
92
+ import type { IListEmits } from "./typing";
90
93
 
91
94
  /**
92
95
  * 实现只展示可视内容的dom,减少dom创建,优化滚动性能
93
96
  * @displayName hy-list
94
97
  */
95
- defineOptions({})
98
+ defineOptions({});
96
99
 
97
100
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
98
101
  const props = defineProps({
99
102
  /** 数据列表 */
100
103
  list: {
101
- type: Array,
102
- default() {
103
- return []
104
- },
104
+ type: Array as PropType<(string | Record<string, any>)[]>,
105
+ default: () => [],
105
106
  },
106
107
  /** 容器高度,必须给个高度,否则加载全部数据 */
107
108
  containerHeight: {
108
109
  type: String,
109
- default: '100%',
110
+ default: "100%",
110
111
  },
111
112
  /** 子容器的高度,必须和内容一致,否则计算有问题 */
112
113
  itemHeight: {
113
114
  type: [String, Number],
114
- default: '40px',
115
+ default: "40px",
115
116
  },
116
117
  /** 子容器的底部,会计算到容器内 */
117
118
  marginBottom: {
@@ -126,12 +127,12 @@ const props = defineProps({
126
127
  /** 子容器的圆角,单位px */
127
128
  borderRadius: {
128
129
  type: [String, Number],
129
- default: '3px',
130
+ default: "3px",
130
131
  },
131
132
  /** 容器背景色 */
132
133
  background: {
133
134
  type: String,
134
- default: 'transparent',
135
+ default: "transparent",
135
136
  },
136
137
  /** 是否显示边框 */
137
138
  border: {
@@ -146,7 +147,7 @@ const props = defineProps({
146
147
  /** 每一项的唯一标识key */
147
148
  keyField: {
148
149
  type: String,
149
- default: 'id',
150
+ default: "id",
150
151
  },
151
152
  /**
152
153
  * 加载状态
@@ -154,143 +155,133 @@ const props = defineProps({
154
155
  * */
155
156
  load: {
156
157
  type: String,
157
- default: 'loadMore',
158
+ default: "loadMore",
158
159
  },
159
160
  /** 显示底部加载状态 */
160
161
  showDivider: {
161
162
  type: Boolean,
162
163
  default: true,
163
164
  },
164
- })
165
- const {
166
- list,
167
- line,
168
- keyField,
169
- itemHeight,
170
- containerHeight,
171
- marginBottom,
172
- padding,
173
- borderRadius,
174
- background,
175
- border,
176
- } = toRefs(props)
177
- const emit = defineEmits<IListEmits>()
165
+ });
166
+ const emit = defineEmits<IListEmits>();
178
167
 
179
- const slots = useSlots()
168
+ const slots = useSlots();
180
169
  // 滚动条距离顶部距离
181
- const scrollTop = ref(0)
170
+ const scrollTop = ref(0);
182
171
  // 可视区域的高度
183
- const viewHeight = ref(0)
172
+ const viewHeight = ref(0);
184
173
  const waterfall: {
185
- left: AnyObject[]
186
- right: AnyObject[]
174
+ left: AnyObject[];
175
+ right: AnyObject[];
187
176
  } = reactive({
188
177
  left: [],
189
178
  right: [],
190
- })
179
+ });
191
180
  // 排列方式
192
- const arrange = computed(() => (line.value === 1 ? 'column' : 'row'))
193
- const boxHeight = getPx(itemHeight.value) + getPx(marginBottom.value)
194
- const listHeight = addUnit(containerHeight.value)
195
- const instance = getCurrentInstance()
181
+ const arrange = computed(() => (props.line === 1 ? "column" : "row"));
182
+ const boxHeight = getPx(props.itemHeight) + getPx(props.marginBottom);
183
+ const listHeight = addUnit(props.containerHeight);
184
+ const instance = getCurrentInstance();
196
185
 
197
186
  onMounted(() => {
198
187
  nextTick(async () => {
199
- const res = await getRect('.hy-virtual-container', false, instance)
200
- viewHeight.value = (res as UniApp.NodeInfo).height ?? 0
201
- })
202
- })
188
+ const res = await getRect(".hy-virtual-container", false, instance);
189
+ viewHeight.value = (res as UniApp.NodeInfo).height ?? 0;
190
+ });
191
+ });
203
192
 
204
193
  const itemStyle = computed((): CSSProperties => {
205
194
  return {
206
- height: addUnit(itemHeight.value),
207
- padding: addUnit(padding.value),
208
- marginBottom: addUnit(marginBottom.value),
209
- borderRadius: addUnit(borderRadius.value),
210
- background: background.value,
211
- border: border.value ? '1px solid #dadbde' : '',
212
- }
213
- })
195
+ height: addUnit(props.itemHeight),
196
+ padding: addUnit(props.padding),
197
+ marginBottom: addUnit(props.marginBottom),
198
+ borderRadius: addUnit(props.borderRadius),
199
+ background: props.background,
200
+ border: props.border ? "1px solid #dadbde" : "",
201
+ };
202
+ });
214
203
 
215
204
  /**
216
205
  * @description 虚拟列表真实展示数据:起始下标
217
206
  */
218
207
  const start = computed(() => {
219
- const s = Math.floor(scrollTop.value / boxHeight)
220
- return Math.max(0, s * line.value)
221
- })
208
+ const s = Math.floor(scrollTop.value / boxHeight);
209
+ return Math.max(0, s * props.line);
210
+ });
222
211
 
223
212
  /**
224
213
  * @description 虚拟列表真实展示数据:结束下标
225
214
  */
226
215
  const over = computed(() => {
227
- const o = Math.floor((scrollTop.value + viewHeight.value + 1) / boxHeight + 5)
228
- return Math.min(list.value.length, o * line.value)
229
- })
216
+ const o = Math.floor(
217
+ (scrollTop.value + viewHeight.value + 1) / boxHeight + 5,
218
+ );
219
+ return Math.min(props.list.length, o * props.line);
220
+ });
230
221
 
231
222
  /**
232
223
  * @description 计算虚拟列表的padding(保持列表高度完整且滚动条能正常滚动)
233
224
  */
234
225
  const paddingAttr = computed(() => {
235
- const paddingTop = start.value * boxHeight
236
- const paddingBottom = (list.value.length - over.value) * boxHeight
237
- return `${paddingTop / line.value}px 0 ${paddingBottom / line.value}px`
238
- })
226
+ const paddingTop = start.value * boxHeight;
227
+ const paddingBottom = (props.list.length - over.value) * boxHeight;
228
+ return `${paddingTop / props.line}px 0 ${paddingBottom / props.line}px`;
229
+ });
239
230
 
240
231
  /**
241
232
  * @description 虚拟列表真实展示数据
242
233
  */
243
- const virtualData = computed(() => {
244
- return list.value.slice(start.value, over.value)
245
- })
234
+ const virtualData = computed<(string | Record<string, any>)[]>(() => {
235
+ return props.list.slice(start.value, over.value);
236
+ });
246
237
 
247
238
  watch(
248
239
  () => virtualData.value,
249
- (newVal, oldValue) => {
250
- waterfall.left.length = 0
251
- waterfall.right.length = 0
252
- if (line.value === 2 && newVal.every((item) => typeof item !== 'string')) {
240
+ (newVal) => {
241
+ waterfall.left.length = 0;
242
+ waterfall.right.length = 0;
243
+ if (props.line === 2 && newVal!.every((item) => typeof item !== "string")) {
253
244
  newVal.forEach((item, i) => {
254
245
  if (i % 2 === 0) {
255
- waterfall.left.push(item as AnyObject)
246
+ waterfall.left.push(item as AnyObject);
256
247
  } else {
257
- waterfall.right.push(item as AnyObject)
248
+ waterfall.right.push(item as AnyObject);
258
249
  }
259
- })
250
+ });
260
251
  }
261
252
  },
262
253
  { immediate: true, deep: true },
263
- )
254
+ );
264
255
 
265
256
  /**
266
257
  * @description 监听滚动条距离顶部距离,实时更新
267
258
  */
268
259
  const onScroll = async (e: any) => {
269
- scrollTop.value = e.detail.scrollTop ?? 0
270
- }
260
+ scrollTop.value = e.detail.scrollTop ?? 0;
261
+ };
271
262
 
272
263
  /**
273
264
  * @description 滚动底部函数
274
265
  * */
275
266
  const scrollToLower = () => {
276
- emit('scrollToLower')
277
- }
267
+ emit("scrollToLower");
268
+ };
278
269
 
279
270
  /**
280
271
  * @description 点击行触发函数
281
272
  * */
282
273
  const handleClick = (temp: string | AnyObject) => {
283
- emit('click', temp)
284
- }
274
+ emit("click", temp);
275
+ };
285
276
 
286
277
  /**
287
278
  * @description 获取默认插槽
288
279
  */
289
- const slotDefault = useSlots().default
280
+ const slotDefault = useSlots().default;
290
281
  </script>
291
282
 
292
283
  <style lang="scss" scoped>
293
- @import './index.scss';
284
+ @import "./index.scss";
294
285
  .hy-virtual-container {
295
286
  height: v-bind(listHeight);
296
287
  &__list {
@@ -25,7 +25,11 @@
25
25
  >
26
26
  <block v-if="mode === 'spinner'">
27
27
  <!-- #ifndef APP-NVUE -->
28
- <view v-for="(item, index) in array12" :key="index" class="hy-loading-icon__dot"></view>
28
+ <view
29
+ v-for="(item, index) in array12"
30
+ :key="index"
31
+ class="hy-loading-icon__dot"
32
+ ></view>
29
33
  <!-- #endif -->
30
34
  </block>
31
35
  </view>
@@ -44,25 +48,25 @@
44
48
 
45
49
  <script lang="ts">
46
50
  export default {
47
- name: 'hy-loading',
51
+ name: "hy-loading",
48
52
  options: {
49
53
  addGlobalClass: true,
50
54
  virtualHost: true,
51
- styleIsolation: 'shared',
55
+ styleIsolation: "shared",
52
56
  },
53
- }
57
+ };
54
58
  </script>
55
59
 
56
60
  <script setup lang="ts">
57
- import { toRefs, ref, computed } from 'vue'
58
- import type { CSSProperties, PropType } from 'vue'
59
- import { addUnit, colorGradient } from '../../utils'
61
+ import { ref, computed } from "vue";
62
+ import type { CSSProperties, PropType } from "vue";
63
+ import { addUnit, colorGradient } from "../../utils";
60
64
 
61
65
  /**
62
66
  * 目前用在华玥的loadMore加载更多等组件的正在加载状态场景。
63
67
  * @displayName hy-loading
64
68
  */
65
- defineOptions({})
69
+ defineOptions({});
66
70
 
67
71
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
68
72
  const props = defineProps({
@@ -74,12 +78,12 @@ const props = defineProps({
74
78
  /** 动画活动区域的颜色,只对 mode = flower 模式有效 */
75
79
  color: {
76
80
  type: String,
77
- default: '#909399',
81
+ default: "#909399",
78
82
  },
79
83
  /** 提示文本的颜色 */
80
84
  textColor: {
81
85
  type: String,
82
- default: '#909399',
86
+ default: "#909399",
83
87
  },
84
88
  /** 文字和图标是否垂直排列 */
85
89
  vertical: {
@@ -89,7 +93,7 @@ const props = defineProps({
89
93
  /** 模式选择,见官网说明 */
90
94
  mode: {
91
95
  type: String,
92
- default: 'spinner',
96
+ default: "spinner",
93
97
  },
94
98
  /** 加载图标的大小,单位px */
95
99
  size: {
@@ -106,7 +110,7 @@ const props = defineProps({
106
110
  /** 动画模式 */
107
111
  timingFunction: {
108
112
  type: String,
109
- default: 'ease-in-out',
113
+ default: "ease-in-out",
110
114
  },
111
115
  /** 动画执行周期时间 */
112
116
  duration: {
@@ -117,24 +121,23 @@ const props = defineProps({
117
121
  inactiveColor: String,
118
122
  /** 定义需要用到的外部样式 */
119
123
  customStyle: Object as PropType<CSSProperties>,
120
- })
121
- const { show, size, color, mode, inactiveColor } = toRefs(props)
124
+ });
122
125
 
123
126
  //动画旋转角度
124
- const aniAngel = ref(360)
127
+ const aniAngel = ref(360);
125
128
  const array12 = Array.from({
126
129
  length: 12,
127
- })
128
- const webviewHide = ref(false)
130
+ });
131
+ const webviewHide = ref(false);
129
132
 
130
133
  const otherBorderColor = computed(() => {
131
- const lightColor = colorGradient(color.value, '#ffffff', 100)[80]
132
- if (mode.value === 'circle') {
133
- return inactiveColor.value ? inactiveColor.value : lightColor
134
+ const lightColor = colorGradient(props.color, "#ffffff", 100)[80];
135
+ if (props.mode === "circle") {
136
+ return props.inactiveColor ? props.inactiveColor : lightColor;
134
137
  } else {
135
- return 'transparent'
138
+ return "transparent";
136
139
  }
137
- })
140
+ });
138
141
 
139
142
  // 监听webview的显示与隐藏
140
143
  // const addEventListenerToWebview = () => {
@@ -155,5 +158,5 @@ const otherBorderColor = computed(() => {
155
158
  </script>
156
159
 
157
160
  <style lang="scss" scoped>
158
- @import './index.scss';
161
+ @import "./index.scss";
159
162
  </style>
@@ -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
@@ -1,7 +1,11 @@
1
1
  <template>
2
2
  <view class="hy-menu" :style="{ width: addUnit(width) }">
3
3
  <template v-for="(item, i) in list">
4
- <view @click="handleClick(item, i)" :class="menuItemClass(item, i)" :style="customStyle">
4
+ <view
5
+ @click="handleClick(item, i)"
6
+ :class="menuItemClass(item, i)"
7
+ :style="customStyle"
8
+ >
5
9
  <slot name="icon">
6
10
  <hy-icon
7
11
  class="hy-menu-item__icon"
@@ -44,37 +48,36 @@
44
48
 
45
49
  <script lang="ts">
46
50
  export default {
47
- name: 'hy-menu',
51
+ name: "hy-menu",
48
52
  options: {
49
53
  addGlobalClass: true,
50
54
  virtualHost: true,
51
- styleIsolation: 'shared',
55
+ styleIsolation: "shared",
52
56
  },
53
- }
57
+ };
54
58
  </script>
55
59
 
56
60
  <script lang="ts" setup>
57
- import { computed, ref, toRefs, watch } from 'vue'
58
- import type { CSSProperties, PropType } from 'vue'
59
- import type { IMenuEmits, MenusType } from './typing'
60
- import { addUnit } from '../../utils'
61
-
62
- import type HyBadgeProps from '../hy-badge/typing'
63
- import type HyIconProps from '../hy-icon/typing'
61
+ import { computed, ref, watch } from "vue";
62
+ import type { CSSProperties, PropType } from "vue";
63
+ import type { IMenuEmits, MenusType, ModelValueVo } from "./typing";
64
+ import { addUnit } from "../../utils";
65
+ import type HyBadgeProps from "../hy-badge/typing";
66
+ import type HyIconProps from "../hy-icon/typing";
64
67
  // 组件
65
- import HyIcon from '../hy-icon/hy-icon.vue'
66
- import HyBadge from '../hy-badge/hy-badge.vue'
68
+ import HyIcon from "../hy-icon/hy-icon.vue";
69
+ import HyBadge from "../hy-badge/hy-badge.vue";
67
70
 
68
71
  /**
69
72
  * 垂直展示的导航栏,用于在不同的内容区域之间进行切换。
70
73
  * @displayName hy-menu
71
74
  */
72
- defineOptions({})
75
+ defineOptions({});
73
76
 
74
77
  // const props = withDefaults(defineProps<IProps>(), defaultProps);
75
78
  const props = defineProps({
76
79
  /** 当前值 */
77
- modelValue: [String, Number],
80
+ modelValue: [String, Number] as PropType<ModelValueVo>,
78
81
  /** 菜单数据集 */
79
82
  list: {
80
83
  type: Array as PropType<Array<MenusType>>,
@@ -99,38 +102,40 @@ const props = defineProps({
99
102
  },
100
103
  /** 定义需要用到的外部样式 */
101
104
  customStyle: Object as PropType<CSSProperties>,
102
- })
103
- const { modelValue, list, color } = toRefs(props)
104
- const emit = defineEmits<IMenuEmits>()
105
+ });
106
+ const emit = defineEmits<IMenuEmits>();
105
107
 
106
- const current = ref<string | number>(0)
108
+ const current = ref<string | number>(0);
107
109
 
108
110
  watch(
109
- () => modelValue.value,
110
- (newVal: string | number) => {
111
- current.value = list.value.findIndex((item) => item.id === newVal)
111
+ () => props.modelValue,
112
+ (newVal) => {
113
+ current.value = props.list.findIndex((item) => item.id === newVal);
112
114
  // current.value = newVal;
113
115
  },
114
- )
116
+ );
115
117
 
116
118
  const menuItemClass = computed(() => {
117
119
  return (temp: MenusType, i: number) => {
118
120
  const classes = [
119
- 'hy-menu-item',
120
- prefix.value && 'hy-menu-item--prefix',
121
- suffix.value && 'hy-menu-item--suffix',
122
- temp.disabled && 'hy-menu-item--disabled',
123
- ]
121
+ "hy-menu-item",
122
+ prefix.value && "hy-menu-item--prefix",
123
+ suffix.value && "hy-menu-item--suffix",
124
+ temp.disabled && "hy-menu-item--disabled",
125
+ ];
124
126
  if (current.value === i) {
125
- classes.push('hy-menu-item--active', color.value && 'hy-menu-item--active__color')
127
+ classes.push(
128
+ "hy-menu-item--active",
129
+ props.color && "hy-menu-item--active__color",
130
+ );
126
131
  }
127
132
 
128
- return classes
129
- }
130
- })
133
+ return classes;
134
+ };
135
+ });
131
136
 
132
137
  const prefix = computed(() => {
133
- // let prefix: boolean = false;
138
+ let prefix: boolean = false;
134
139
  // if (sidebar) {
135
140
  // let activeIndex: number = sidebar.children.findIndex((c: any) => {
136
141
  // return c.value === sidebar.props.modelValue;
@@ -144,11 +149,11 @@ const prefix = computed(() => {
144
149
  // prefix = true;
145
150
  // }
146
151
  // }
147
- return prefix
148
- })
152
+ return prefix;
153
+ });
149
154
 
150
155
  const suffix = computed(() => {
151
- let suffix: boolean = false
156
+ let suffix: boolean = false;
152
157
  // if (sidebar) {
153
158
  // let activeIndex: number = sidebar.children.findIndex((c: any) => {
154
159
  // return c.value === sidebar.props.modelValue;
@@ -162,21 +167,21 @@ const suffix = computed(() => {
162
167
  // suffix = true;
163
168
  // }
164
169
  // }
165
- return suffix
166
- })
170
+ return suffix;
171
+ });
167
172
 
168
173
  function handleClick(temp: MenusType, i: number) {
169
174
  if (temp?.disabled) {
170
- return
175
+ return;
171
176
  }
172
- current.value = i
173
- emit('update:modelValue', temp.id)
174
- emit('change', temp)
177
+ current.value = i;
178
+ emit("update:modelValue", temp.id);
179
+ emit("change", temp);
175
180
  }
176
181
  </script>
177
182
 
178
183
  <style lang="scss" scoped>
179
- @import './index.scss';
184
+ @import "./index.scss";
180
185
  .hy-menu-item--active__color {
181
186
  color: v-bind(color);
182
187
  &::before {
@@ -1,64 +1,65 @@
1
- import type { CSSProperties } from 'vue'
2
- import type HyBadgeProps from '../hy-badge/typing'
3
- import type HyIconProps from '../hy-icon/typing'
1
+ import type { CSSProperties } from "vue";
2
+ import type HyBadgeProps from "../hy-badge/typing";
3
+ import type HyIconProps from "../hy-icon/typing";
4
4
 
5
+ export type ModelValueVo = string | number;
5
6
  export interface MenusType {
6
7
  /**
7
8
  * @description 唯一id
8
9
  * */
9
- id: string | number
10
+ id: string | number;
10
11
  /**
11
12
  * @description 标题
12
13
  * */
13
- title: string
14
+ title: string;
14
15
  /**
15
16
  * @description 是否禁用
16
17
  * */
17
- disabled?: boolean
18
+ disabled?: boolean;
18
19
  /**
19
20
  * @description icon
20
21
  * */
21
- icon?: string
22
+ icon?: string;
22
23
  /**
23
24
  * @description 徽标值
24
25
  * */
25
- badge?: number
26
+ badge?: number;
26
27
  }
27
28
 
28
29
  export default interface HyMenuProps {
29
30
  /**
30
31
  * @description 当前值
31
32
  * */
32
- modelValue: string | number
33
+ modelValue: string | number;
33
34
  /**
34
35
  * @description 菜单数据集
35
36
  * */
36
- list: MenusType[]
37
+ list: MenusType[];
37
38
  /**
38
39
  * @description 侧边菜单栏宽度
39
40
  * */
40
- width?: string | number
41
+ width?: string | number;
41
42
  /**
42
43
  * @description 选中颜色
43
44
  * */
44
- color?: string
45
+ color?: string;
45
46
  /**
46
47
  * @description 图标属性值
47
48
  * */
48
- icon?: Partial<HyIconProps>
49
+ icon?: Partial<HyIconProps>;
49
50
  /**
50
51
  * @description 徽标属性值
51
52
  * */
52
- badge?: Partial<HyBadgeProps>
53
+ badge?: Partial<HyBadgeProps>;
53
54
  /**
54
55
  * @description 定义需要用到的外部样式
55
56
  * */
56
- customStyle?: CSSProperties
57
+ customStyle?: CSSProperties;
57
58
  }
58
59
 
59
60
  export interface IMenuEmits {
60
61
  /** 选中触发 */
61
- (e: 'change', temp: MenusType): void
62
+ (e: "change", temp: MenusType): void;
62
63
  /** 选中触发 */
63
- (e: 'update:modelValue', id: MenusType['id']): void
64
+ (e: "update:modelValue", id: MenusType["id"]): void;
64
65
  }