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
@@ -1,5 +1,8 @@
1
1
  <template>
2
- <view :class="['hy-submit-bar', border && 'hy-border__top', customClass]" :style="submitBarStyle">
2
+ <view
3
+ :class="['hy-submit-bar', border && 'hy-border__top', customClass]"
4
+ :style="submitBarStyle"
5
+ >
3
6
  <view class="hy-submit-bar__left">
4
7
  <slot name="left">
5
8
  <view
@@ -68,30 +71,29 @@
68
71
 
69
72
  <script lang="ts">
70
73
  export default {
71
- name: 'hy-submit-bar',
74
+ name: "hy-submit-bar",
72
75
  options: {
73
76
  addGlobalClass: true,
74
77
  virtualHost: true,
75
- styleIsolation: 'shared',
78
+ styleIsolation: "shared",
76
79
  },
77
- }
80
+ };
78
81
  </script>
79
82
 
80
83
  <script setup lang="ts">
81
- import { computed, toRefs } from 'vue'
82
- import type { CSSProperties, PropType } from 'vue'
83
- import type { IconMenus, ISubmitBarEmits } from './typing'
84
-
84
+ import { computed } from "vue";
85
+ import type { CSSProperties, PropType } from "vue";
86
+ import type { IconMenus, ISubmitBarEmits } from "./typing";
85
87
  // 组件
86
- import HyIcon from '../hy-icon/hy-icon.vue'
87
- import HyLoading from '../hy-loading/hy-loading.vue'
88
- import HyBadge from '../hy-badge/hy-badge.vue'
88
+ import HyIcon from "../hy-icon/hy-icon.vue";
89
+ import HyLoading from "../hy-loading/hy-loading.vue";
90
+ import HyBadge from "../hy-badge/hy-badge.vue";
89
91
 
90
92
  /**
91
93
  * 该布局一般用于商品详情页底部引导用户快速购买商品的场景,开发者可以根据自己的需求修改布局结构和样式。
92
94
  * @displayName hy-submit-bar
93
95
  */
94
- defineOptions({})
96
+ defineOptions({});
95
97
 
96
98
  // const props = withDefaults(defineProps<IProps>(), defaultProps)
97
99
  const props = defineProps({
@@ -125,7 +127,7 @@ const props = defineProps({
125
127
  /** 左边文字的颜色 */
126
128
  iconLabelColor: {
127
129
  type: String,
128
- default: '#909193FF',
130
+ default: "#909193FF",
129
131
  },
130
132
  /** 右边按钮文字颜色 */
131
133
  textColor: String,
@@ -142,22 +144,22 @@ const props = defineProps({
142
144
  /** 左边按钮文字 */
143
145
  leftBtnText: {
144
146
  type: String,
145
- default: '加入购物车',
147
+ default: "加入购物车",
146
148
  },
147
149
  /** 右边按钮文字 */
148
150
  rightBtnText: {
149
151
  type: String,
150
- default: '立即购买',
152
+ default: "立即购买",
151
153
  },
152
154
  /** 左边按钮颜色,支持渐变色 */
153
155
  leftBtnColor: {
154
156
  type: String,
155
- default: '#ed3f14',
157
+ default: "#ed3f14",
156
158
  },
157
159
  /** 有边按钮颜色,支持渐变色 */
158
160
  rightBtnColor: {
159
161
  type: String,
160
- default: '#ff7900',
162
+ default: "#ff7900",
161
163
  },
162
164
  /**
163
165
  * 按钮的形状
@@ -165,28 +167,17 @@ const props = defineProps({
165
167
  * */
166
168
  shape: {
167
169
  type: String,
168
- default: 'circle',
170
+ default: "circle",
169
171
  },
170
172
  /** 定义需要用到的外部样式 */
171
173
  customStyle: {
172
174
  type: Object as PropType<CSSProperties>,
175
+ default: () => {},
173
176
  },
174
177
  /** 自定义外部类名 */
175
178
  customClass: String,
176
- })
177
- const {
178
- fixed,
179
- showLeftBtn,
180
- showRightBtn,
181
- leftBtnColor,
182
- rightBtnColor,
183
- shape,
184
- textColor,
185
- leftLoading,
186
- rightLoading,
187
- customStyle,
188
- } = toRefs(props)
189
- const emit = defineEmits<ISubmitBarEmits>()
179
+ });
180
+ const emit = defineEmits<ISubmitBarEmits>();
190
181
 
191
182
  /**
192
183
  * @description 整体样式
@@ -195,82 +186,82 @@ const submitBarStyle = computed(() => {
195
186
  const style: CSSProperties = {
196
187
  bottom: 0,
197
188
  left: 0,
198
- }
199
- if (fixed.value) style.position = 'fixed'
200
- return Object.assign(style, customStyle.value)
201
- })
189
+ };
190
+ if (props.fixed) style.position = "fixed";
191
+ return Object.assign(style, props.customStyle);
192
+ });
202
193
 
203
194
  /**
204
195
  * @description 左边按钮样式
205
196
  * */
206
197
  const leftBtnStyle = computed(() => {
207
198
  const style: CSSProperties = {
208
- background: leftBtnColor.value,
209
- color: textColor.value,
210
- }
211
- if (!showRightBtn.value) {
212
- style.flex = 1
213
- if (shape.value === 'circle') {
214
- style.borderRadius = '100px'
199
+ background: props.leftBtnColor,
200
+ color: props.textColor,
201
+ };
202
+ if (!props.showRightBtn) {
203
+ style.flex = 1;
204
+ if (props.shape === "circle") {
205
+ style.borderRadius = "100px";
215
206
  } else {
216
- style.borderRadius = '2px'
207
+ style.borderRadius = "2px";
217
208
  }
218
209
  } else {
219
- if (shape.value === 'circle') {
220
- style.borderRadius = '100px 0 0 100px'
210
+ if (props.shape === "circle") {
211
+ style.borderRadius = "100px 0 0 100px";
221
212
  } else {
222
- style.borderRadius = '2px 0 0 2px'
213
+ style.borderRadius = "2px 0 0 2px";
223
214
  }
224
215
  }
225
- return style
226
- })
216
+ return style;
217
+ });
227
218
 
228
219
  /**
229
220
  * @description 右边按钮样式
230
221
  * */
231
222
  const rightBtnStyle = computed(() => {
232
223
  const style: CSSProperties = {
233
- background: rightBtnColor.value,
234
- color: textColor.value,
235
- }
236
- if (!showLeftBtn.value) {
237
- style.flex = 1
238
- if (shape.value === 'circle') {
239
- style.borderRadius = '100px'
224
+ background: props.rightBtnColor,
225
+ color: props.textColor,
226
+ };
227
+ if (!props.showLeftBtn) {
228
+ style.flex = 1;
229
+ if (props.shape === "circle") {
230
+ style.borderRadius = "100px";
240
231
  } else {
241
- style.borderRadius = '2px'
232
+ style.borderRadius = "2px";
242
233
  }
243
234
  } else {
244
- if (shape.value === 'circle') {
245
- style.borderRadius = '0 100px 100px 0'
235
+ if (props.shape === "circle") {
236
+ style.borderRadius = "0 100px 100px 0";
246
237
  } else {
247
- style.borderRadius = '0 2px 2px 0'
238
+ style.borderRadius = "0 2px 2px 0";
248
239
  }
249
240
  }
250
- return style
251
- })
241
+ return style;
242
+ });
252
243
 
253
244
  /**
254
245
  * @description 点击左边图标
255
246
  * */
256
247
  const clickMenuFn = (i: number) => {
257
- emit('menuClick', i)
258
- }
248
+ emit("menuClick", i);
249
+ };
259
250
 
260
251
  /**
261
252
  * @description 点击按钮
262
253
  * */
263
254
  const confirmClickFn = (i: number) => {
264
255
  if (
265
- (!leftLoading.value && !rightLoading.value) ||
266
- (leftLoading.value && i !== 0) ||
267
- (rightLoading.value && i !== 1)
256
+ (!props.leftLoading && !props.rightLoading) ||
257
+ (props.leftLoading && i !== 0) ||
258
+ (props.rightLoading && i !== 1)
268
259
  ) {
269
- emit('click', i)
260
+ emit("click", i);
270
261
  }
271
- }
262
+ };
272
263
  </script>
273
264
 
274
265
  <style lang="scss" scoped>
275
- @import './index.scss';
266
+ @import "./index.scss";
276
267
  </style>
@@ -13,33 +13,35 @@
13
13
  v-for="(item, index) in list"
14
14
  :key="index"
15
15
  >
16
- <text class="hy-subsection__item__text" :style="[textStyle(index)]">{{ getName(item) }}</text>
16
+ <text class="hy-subsection__item__text" :style="[textStyle(index)]">{{
17
+ getName(item)
18
+ }}</text>
17
19
  </view>
18
20
  </view>
19
21
  </template>
20
22
 
21
23
  <script lang="ts">
22
24
  export default {
23
- name: 'hy-subsection',
25
+ name: "hy-subsection",
24
26
  options: {
25
27
  addGlobalClass: true,
26
28
  virtualHost: true,
27
- styleIsolation: 'shared',
29
+ styleIsolation: "shared",
28
30
  },
29
- }
31
+ };
30
32
  </script>
31
33
 
32
34
  <script setup lang="ts">
33
- import { computed, toRefs, ref, onMounted, getCurrentInstance } from 'vue'
34
- import type { CSSProperties, PropType } from 'vue'
35
- import type { ISubsectionEmits, SubSectionVo } from './typing'
36
- import { addUnit, getRect, guid } from '../../utils'
35
+ import { computed, ref, onMounted, getCurrentInstance } from "vue";
36
+ import type { CSSProperties, PropType } from "vue";
37
+ import type { ISubsectionEmits, SubSectionVo } from "./typing";
38
+ import { addUnit, getRect, guid } from "../../utils";
37
39
 
38
40
  /**
39
41
  * 该分段器一般用于用户从几个选项中选择某一个的场景
40
42
  * @displayName hy-subsection
41
43
  */
42
- defineOptions({})
44
+ defineOptions({});
43
45
 
44
46
  // const props = withDefaults(defineProps<IProps>(), defaultProps);
45
47
  const props = defineProps({
@@ -52,13 +54,13 @@ const props = defineProps({
52
54
  },
53
55
  /** tab的数据 */
54
56
  list: {
55
- type: Array,
57
+ type: Array as PropType<SubSectionVo[]>,
56
58
  default: () => [],
57
59
  },
58
60
  /** list的键值 */
59
61
  customKeys: {
60
62
  type: Object,
61
- default: () => ({ name: 'name', value: 'value' }),
63
+ default: () => ({ name: "name", value: "value" }),
62
64
  },
63
65
  /** 激活时的颜色 */
64
66
  activeColor: String,
@@ -70,7 +72,7 @@ const props = defineProps({
70
72
  * */
71
73
  mode: {
72
74
  type: String,
73
- default: 'button',
75
+ default: "button",
74
76
  },
75
77
  /** 字体大小,单位px */
76
78
  fontSize: {
@@ -88,162 +90,157 @@ const props = defineProps({
88
90
  customStyle: Object as PropType<CSSProperties>,
89
91
  /** 自定义外部类名 */
90
92
  customClass: String,
91
- })
92
- const {
93
- modelValue,
94
- current,
95
- list,
96
- mode,
97
- activeColor,
98
- fontSize,
99
- bold,
100
- bgColor,
101
- inactiveColor,
102
- customKeys,
103
- } = toRefs(props)
104
- const emit = defineEmits<ISubsectionEmits>()
93
+ });
94
+ const emit = defineEmits<ISubsectionEmits>();
105
95
 
106
- const instance = getCurrentInstance()
96
+ const instance = getCurrentInstance();
107
97
  // 组件尺寸
108
98
  const itemRect = ref<UniApp.NodeInfo>({
109
99
  width: 0,
110
100
  height: 0,
111
- })
112
- const innerCurrent = ref<number>(0)
113
- const guidClass = guid()
101
+ });
102
+ const innerCurrent = ref<number>(0);
103
+ const guidClass = guid();
114
104
 
115
105
  /**
116
106
  * @description 容器样式
117
107
  * */
118
108
  const wrapperStyle = computed<CSSProperties>(() => {
119
- const style: CSSProperties = {}
109
+ const style: CSSProperties = {};
120
110
  // button模式时,设置背景色
121
- if (mode.value === 'button') {
122
- style.backgroundColor = bgColor.value
111
+ if (props.mode === "button") {
112
+ style.backgroundColor = props.bgColor;
123
113
  }
124
- return style
125
- })
114
+ return style;
115
+ });
126
116
  /**
127
117
  * @description 容器类名
128
118
  * */
129
119
  const wrapperClass = computed(() => {
130
120
  return (index: number) => {
131
121
  return [
132
- 'hy-subsection__item',
133
- 'cursor-pointer',
122
+ "hy-subsection__item",
123
+ "cursor-pointer",
134
124
  `hy-subsection__item--${innerCurrent.value}__${guidClass}`,
135
- `hy-subsection__item--${mode.value}`,
136
- index < list.value.length - 1 && 'hy-subsection__item--no-border-right',
137
- index === 0 && 'hy-subsection__item--first',
138
- index === list.value.length - 1 && 'hy-subsection__item--last',
139
- ]
140
- }
141
- })
125
+ `hy-subsection__item--${props.mode}`,
126
+ index < props.list.length - 1 && "hy-subsection__item--no-border-right",
127
+ index === 0 && "hy-subsection__item--first",
128
+ index === props.list.length - 1 && "hy-subsection__item--last",
129
+ ];
130
+ };
131
+ });
142
132
  /**
143
133
  * @description 滑块的样式
144
134
  * */
145
135
  const barStyle = computed<CSSProperties>(() => {
146
- const style: CSSProperties = {}
147
- style.width = `${itemRect.value.width}px`
148
- style.height = `${itemRect.value.height}px`
136
+ const style: CSSProperties = {};
137
+ style.width = `${itemRect.value.width}px`;
138
+ style.height = `${itemRect.value.height}px`;
149
139
  // 通过translateX移动滑块,其移动的距离为索引*item的宽度
150
- style.transform = `translateX(${innerCurrent.value * itemRect.value.width!}px)`
151
- if (mode.value === 'subsection') {
140
+ style.transform = `translateX(${innerCurrent.value * itemRect.value.width!}px)`;
141
+ if (props.mode === "subsection") {
152
142
  // 在subsection模式下,需要动态设置滑块的圆角,因为移动滑块使用的是translateX,无法通过父元素设置overflow: hidden隐藏滑块的直角
153
- style.backgroundColor = activeColor.value
143
+ style.backgroundColor = props.activeColor;
154
144
  }
155
- return style
156
- })
145
+ return style;
146
+ });
157
147
  /**
158
148
  * @description 滑块的类目
159
149
  * */
160
150
  const barClass = computed(() => {
161
- let className: string[] = ['hy-subsection__bar', 'cursor-pointer']
151
+ let className: string[] = ["hy-subsection__bar", "cursor-pointer"];
162
152
  const className_2 = [
163
- mode.value === 'button' && 'hy-subsection--button__bar',
164
- innerCurrent.value === 0 && mode.value === 'subsection' && 'hy-subsection__bar--first',
153
+ props.mode === "button" && "hy-subsection--button__bar",
154
+ innerCurrent.value === 0 &&
155
+ props.mode === "subsection" &&
156
+ "hy-subsection__bar--first",
165
157
  innerCurrent.value > 0 &&
166
- innerCurrent.value < list.value.length - 1 &&
167
- mode.value === 'subsection' &&
168
- 'hy-subsection__bar--center',
169
- innerCurrent.value === list.value.length - 1 &&
170
- mode.value === 'subsection' &&
171
- 'hy-subsection__bar--last',
172
- ].filter(Boolean) as string[]
173
- className = className.concat(className_2)
158
+ innerCurrent.value < props.list.length - 1 &&
159
+ props.mode === "subsection" &&
160
+ "hy-subsection__bar--center",
161
+ innerCurrent.value === props.list.length - 1 &&
162
+ props.mode === "subsection" &&
163
+ "hy-subsection__bar--last",
164
+ ].filter(Boolean) as string[];
165
+ className = className.concat(className_2);
174
166
 
175
- return className
176
- })
167
+ return className;
168
+ });
177
169
  /**
178
170
  * @description 分段器item的样式
179
171
  * */
180
172
  const itemStyle = computed<CSSProperties>(() => {
181
- const style: CSSProperties = {}
182
- if (mode.value === 'subsection') {
173
+ const style: CSSProperties = {};
174
+ if (props.mode === "subsection") {
183
175
  // 设置border的样式
184
- style.borderColor = activeColor.value
185
- style.borderWidth = '1px'
186
- style.borderStyle = 'solid'
176
+ style.borderColor = props.activeColor;
177
+ style.borderWidth = "1px";
178
+ style.borderStyle = "solid";
187
179
  }
188
- return style
189
- })
180
+ return style;
181
+ });
190
182
  /**
191
183
  * @description 分段器文字颜色
192
184
  * */
193
185
  const textStyle = computed(() => {
194
186
  return (index: number): CSSProperties => {
195
- const style: CSSProperties = {}
196
- style.fontWeight = bold.value && innerCurrent.value === index ? 'bold' : 'normal'
197
- style.fontSize = addUnit(fontSize.value)
187
+ const style: CSSProperties = {};
188
+ style.fontWeight =
189
+ props.bold && innerCurrent.value === index ? "bold" : "normal";
190
+ style.fontSize = addUnit(props.fontSize);
198
191
  // subsection模式下,激活时默认为白色的文字
199
- if (mode.value === 'subsection') {
200
- style.color = innerCurrent.value === index ? '#fff' : inactiveColor.value
192
+ if (props.mode === "subsection") {
193
+ style.color = innerCurrent.value === index ? "#fff" : props.inactiveColor;
201
194
  } else {
202
195
  // button模式下,激活时文字颜色默认为activeColor
203
- style.color = innerCurrent.value === index ? activeColor.value : inactiveColor.value
196
+ style.color =
197
+ innerCurrent.value === index ? props.activeColor : props.inactiveColor;
204
198
  }
205
- return style
206
- }
207
- })
199
+ return style;
200
+ };
201
+ });
208
202
 
209
203
  onMounted(() => {
210
- init()
211
- })
204
+ init();
205
+ });
212
206
 
213
207
  /**
214
208
  * @description 初始化
215
209
  * */
216
210
  const init = () => {
217
- innerCurrent.value = list.value.findIndex((item: SubSectionVo) => {
218
- if (typeof item === 'string' || typeof item === 'number') {
219
- return item === modelValue.value
211
+ innerCurrent.value = props.list.findIndex((item: SubSectionVo) => {
212
+ if (typeof item === "string" || typeof item === "number") {
213
+ return item === props.modelValue;
220
214
  } else {
221
- return item[customKeys.value.value] === modelValue.value
215
+ return item[props.customKeys.value] === props.modelValue;
222
216
  }
223
- })
217
+ });
224
218
 
225
219
  // 设置默认值当没有找的时候导致样式问题
226
- innerCurrent.value = innerCurrent.value === -1 ? current.value : innerCurrent.value
220
+ innerCurrent.value =
221
+ innerCurrent.value === -1 ? props.current : innerCurrent.value;
227
222
 
228
223
  // TODO: 多个数组在一起计算宽度, 宽度不一样会有问题,所以必须加guidClass随机数
229
- getRect(`.hy-subsection__item--0__${guidClass}`, false, instance).then((size) => {
230
- itemRect.value = size as UniApp.NodeInfo
231
- })
232
- }
224
+ getRect(`.hy-subsection__item--0__${guidClass}`, false, instance).then(
225
+ (size) => {
226
+ itemRect.value = size as UniApp.NodeInfo;
227
+ },
228
+ );
229
+ };
233
230
 
234
231
  /**
235
232
  * @description 判断值
236
233
  * */
237
234
  const getValue = (item: SubSectionVo) => {
238
- return typeof item === 'object' ? item[customKeys.value.value] : item
239
- }
235
+ return typeof item === "object" ? item[props.customKeys.value] : item;
236
+ };
240
237
 
241
238
  /**
242
239
  * @description 判断展示文本
243
240
  * */
244
241
  const getName = (item: SubSectionVo) => {
245
- return typeof item === 'object' ? item[customKeys.value.name] : item
246
- }
242
+ return typeof item === "object" ? item[props.customKeys.name] : item;
243
+ };
247
244
 
248
245
  /**
249
246
  * @description 点击事件
@@ -251,13 +248,13 @@ const getName = (item: SubSectionVo) => {
251
248
  const clickHandler = (temp: SubSectionVo, index: number) => {
252
249
  // 值改变才触发
253
250
  if (innerCurrent.value !== index) {
254
- emit('change', index)
255
- emit('update:modelValue', getValue(temp))
251
+ emit("change", index);
252
+ emit("update:modelValue", getValue(temp));
256
253
  }
257
- innerCurrent.value = index
258
- }
254
+ innerCurrent.value = index;
255
+ };
259
256
  </script>
260
257
 
261
258
  <style lang="scss" scoped>
262
- @import './index.scss';
259
+ @import "./index.scss";
263
260
  </style>
@@ -1,63 +1,63 @@
1
- import type { CSSProperties } from 'vue'
2
- import { HyApp } from '@/package/typing/modules/common'
1
+ import type { CSSProperties } from "vue";
2
+ import { HyApp } from "@/package/typing/modules/common";
3
3
 
4
- export interface SubSectionItemVo extends HyApp.FieldNamesType {
5
- name: string
6
- value: string | number
4
+ export interface SubSectionItemVo extends AnyObject {
5
+ name: string;
6
+ value: string | number;
7
7
  }
8
8
 
9
- export type SubSectionVo = string | number | SubSectionItemVo
9
+ export type SubSectionVo = string | number | SubSectionItemVo;
10
10
 
11
11
  export default interface HySubsectionProps {
12
12
  /**
13
13
  * @description 接收值
14
14
  * */
15
- modelValue: string | number
15
+ modelValue: string | number;
16
16
  /**
17
17
  * @description 默认值 (默认0)
18
18
  * */
19
- current?: number
19
+ current?: number;
20
20
  /**
21
21
  * @description tab的数据
22
22
  * */
23
- list: SubSectionVo[]
23
+ list: SubSectionVo[];
24
24
  /**
25
25
  * @description list的键值
26
26
  * */
27
- customKeys?: HyApp.IFieldNames
27
+ customKeys?: HyApp.IFieldNames;
28
28
  /**
29
29
  * @description 激活时的颜色(默认 '#3c9cff' )
30
30
  * */
31
- activeColor?: string
31
+ activeColor?: string;
32
32
  /**
33
33
  * @description 未激活时的颜色(默认 '#303133' )
34
34
  * */
35
- inactiveColor?: string
35
+ inactiveColor?: string;
36
36
  /**
37
37
  * @description 模式选择,mode=button为按钮形式,mode=subsection时为分段模式(默认 'button' )
38
38
  * */
39
- mode?: 'button' | 'subsection'
39
+ mode?: "button" | "subsection";
40
40
  /**
41
41
  * @description 字体大小,单位px(默认 12 )
42
42
  * */
43
- fontSize?: number | string
43
+ fontSize?: number | string;
44
44
  /**
45
45
  * @description 激活选项的字体是否加粗(默认 true )
46
46
  * */
47
- bold?: boolean
47
+ bold?: boolean;
48
48
  /**
49
49
  * @description 组件背景颜色,mode为button时有效(默认 '#eeeeef' )
50
50
  * */
51
- bgColor?: string
51
+ bgColor?: string;
52
52
  /**
53
53
  * @description 定义需要用到的外部样式
54
54
  * */
55
- customStyle?: CSSProperties
55
+ customStyle?: CSSProperties;
56
56
  }
57
57
 
58
58
  export interface ISubsectionEmits {
59
59
  /** 改变触发 */
60
- (e: 'change', index: number): void
60
+ (e: "change", index: number): void;
61
61
  /** 改变触发 */
62
- (e: 'update:modelValue', value: any): void
62
+ (e: "update:modelValue", value: any): void;
63
63
  }