@zfqh/uview-x 0.0.6 → 0.0.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +52 -9
  3. package/components/uv-badge/uv-badge.vue +4 -4
  4. package/components/uv-button/uv-button.vue +10 -10
  5. package/components/uv-checkbox/uv-checkbox.vue +11 -9
  6. package/components/uv-checkbox-group/uv-checkbox-group.vue +2 -2
  7. package/components/uv-code/uv-code.vue +2 -2
  8. package/components/uv-dialog/uv-dialog.vue +11 -10
  9. package/components/uv-form/uv-form.vue +244 -246
  10. package/components/uv-form-item/uv-form-item.vue +10 -9
  11. package/components/uv-icon/uv-icon.vue +13 -13
  12. package/components/uv-input/uv-input.vue +6 -5
  13. package/components/uv-line/uv-line.vue +7 -6
  14. package/components/uv-line-progress/uv-line-progress.vue +5 -5
  15. package/components/uv-loading-icon/uv-loading-icon.vue +9 -8
  16. package/components/uv-overlay/uv-overlay.vue +3 -2
  17. package/components/uv-popup/uv-popup.vue +7 -5
  18. package/components/uv-safe-bottom/uv-safe-bottom.vue +4 -3
  19. package/components/uv-status-bar/uv-status-bar.vue +4 -3
  20. package/components/uv-tabs/uv-tabs.vue +15 -12
  21. package/components/uv-transition/uv-transition.vue +2 -2
  22. package/hooks/index.ts +5 -5
  23. package/hooks/useDebounce.ts +33 -35
  24. package/hooks/useI18n.ts +4 -3
  25. package/hooks/useThrottle.ts +36 -38
  26. package/index.ts +50 -29
  27. package/locales/en.ts +56 -0
  28. package/locales/es.ts +57 -0
  29. package/locales/fr.ts +57 -0
  30. package/locales/index.ts +15 -159
  31. package/locales/ru.ts +57 -0
  32. package/locales/zh-Hans.ts +57 -0
  33. package/locales/zh-Hant.ts +57 -0
  34. package/package.json +2 -2
  35. package/types/index.d.ts +68 -59
  36. package/utils/color.ts +139 -0
  37. package/utils/compress.ts +28 -28
  38. package/utils/config.ts +45 -10
  39. package/utils/debounce.ts +4 -4
  40. package/utils/function.ts +2 -87
  41. package/utils/locale.ts +444 -270
  42. package/utils/merge.ts +74 -0
  43. package/utils/platform.ts +28 -28
  44. package/utils/route.ts +123 -129
  45. package/utils/scrollbar.ts +19 -19
  46. package/utils/throttle.ts +4 -4
  47. package/locales/en-US.ts +0 -79
  48. package/locales/es-ES.ts +0 -79
  49. package/locales/fr-FR.ts +0 -79
  50. package/locales/ru-RU.ts +0 -79
  51. package/locales/zh-CN.ts +0 -79
  52. package/locales/zh-TW.ts +0 -79
  53. package/utils/colorGradient.ts +0 -139
  54. package/utils/index.ts +0 -58
@@ -68,7 +68,8 @@
68
68
 
69
69
  <script setup lang="ts">
70
70
  import { computed, inject, nextTick, ref, watch } from 'vue'
71
- import { $uv } from '../../utils'
71
+ import { addStyle, addUnit, sleep } from '../../utils/function'
72
+ import { deepMerge } from '../../utils/merge'
72
73
  import props from './props'
73
74
  import UvIcon from '../uv-icon/uv-icon.vue'
74
75
 
@@ -237,7 +238,7 @@
237
238
  return p.placeholder === null || p.placeholder === undefined ? '' : String(p.placeholder)
238
239
  })
239
240
 
240
- const placeholderStyleStr = computed(() => $uv.addStyle(p.placeholderStyle, 'string'))
241
+ const placeholderStyleStr = computed(() => addStyle(p.placeholderStyle, 'string'))
241
242
 
242
243
  // 是否显示清除控件
243
244
  const isShowClear = computed(() => {
@@ -275,14 +276,14 @@
275
276
  style.paddingLeft = '9px'
276
277
  style.paddingRight = '9px'
277
278
  }
278
- return $uv.deepMerge(style, $uv.addStyle(p.customStyle))
279
+ return deepMerge(style, addStyle(p.customStyle))
279
280
  })
280
281
 
281
282
  // 输入框的样式
282
283
  const inputStyle = computed(() => {
283
284
  const style: any = {
284
285
  color: p.color,
285
- fontSize: $uv.addUnit(p.fontSize),
286
+ fontSize: addUnit(p.fontSize),
286
287
  textAlign: p.inputAlign
287
288
  }
288
289
  if (p.disabled || p.readonly) {
@@ -323,7 +324,7 @@
323
324
  emit('blur', currentValue)
324
325
  // H5端的blur会先于点击清除控件的点击click事件触发,导致focused
325
326
  // 瞬间为false,从而隐藏了清除控件而无法被点击到
326
- $uv.sleep(100).then(() => {
327
+ sleep(100).then(() => {
327
328
  focused.value = false
328
329
  })
329
330
  // 尝试调用uv-form的验证方法
@@ -8,7 +8,8 @@
8
8
 
9
9
  <script setup lang="ts">
10
10
  import { computed } from 'vue'
11
- import { $uv } from '../../utils'
11
+ import { addStyle, addUnit } from '../../utils/function'
12
+ import { deepMerge } from '../../utils/merge'
12
13
  import props from './props'
13
14
 
14
15
  defineOptions({
@@ -42,10 +43,10 @@
42
43
  style.borderBottomWidth = '1px'
43
44
  style.borderBottomStyle = p.dashed ? 'dashed' : 'solid'
44
45
  if (!isPercent) {
45
- style.width = $uv.addUnit(p.length)
46
+ style.width = addUnit(p.length)
46
47
  } else {
47
48
  // #ifndef APP-NVUE
48
- style.width = $uv.addUnit(p.length)
49
+ style.width = addUnit(p.length)
49
50
  // #endif
50
51
  }
51
52
  if (p.hairline) style.transform = 'scaleY(0.5)'
@@ -53,16 +54,16 @@
53
54
  style.borderLeftWidth = '1px'
54
55
  style.borderLeftStyle = p.dashed ? 'dashed' : 'solid'
55
56
  if (!isPercent) {
56
- style.height = $uv.addUnit(p.length)
57
+ style.height = addUnit(p.length)
57
58
  } else {
58
59
  // #ifndef APP-NVUE
59
- style.height = $uv.addUnit(p.length)
60
+ style.height = addUnit(p.length)
60
61
  // #endif
61
62
  }
62
63
  if (p.hairline) style.transform = 'scaleX(0.5)'
63
64
  }
64
65
  style.borderColor = p.color
65
- return $uv.deepMerge(style, $uv.addStyle(p.customStyle))
66
+ return deepMerge(style, addStyle(p.customStyle))
66
67
  })
67
68
  </script>
68
69
 
@@ -2,7 +2,7 @@
2
2
  <view
3
3
  class="uv-line-progress"
4
4
  :class="[p.customClass]"
5
- :style="[$uv.addStyle(p.customStyle)]"
5
+ :style="[addStyle(p.customStyle)]"
6
6
  >
7
7
  <view
8
8
  ref="barRef"
@@ -26,7 +26,7 @@
26
26
 
27
27
  <script setup lang="ts">
28
28
  import { computed, onMounted, ref, watch } from 'vue'
29
- import { $uv } from '../../utils'
29
+ import { addStyle, addUnit, getPx, range } from '../../utils/function'
30
30
  import props from './props'
31
31
  import { getRectNvue } from '../../utils/compat'
32
32
 
@@ -54,7 +54,7 @@
54
54
 
55
55
  // 控制范围在0-100之间
56
56
  const innserPercentage = computed(() => {
57
- return $uv.range(0, 100, p.percentage)
57
+ return range(0, 100, p.percentage)
58
58
  })
59
59
 
60
60
  const percentageText = computed(() => `${innserPercentage.value}%`)
@@ -82,7 +82,7 @@
82
82
  const backgroundStyle = computed(() => {
83
83
  const style: any = {
84
84
  backgroundColor: p.inactiveColor,
85
- height: $uv.addUnit($uv.getPx(p.height))
85
+ height: addUnit(getPx(p.height))
86
86
  }
87
87
  return style
88
88
  })
@@ -91,7 +91,7 @@
91
91
  const progressStyle = computed(() => {
92
92
  const style: any = {
93
93
  backgroundColor: p.activeColor,
94
- height: $uv.addUnit($uv.getPx(p.height))
94
+ height: addUnit(getPx(p.height))
95
95
  }
96
96
  // #ifdef APP-NVUE
97
97
  style.width = nvueBarWidth.value > 0 ? `${(nvueBarWidth.value * innserPercentage.value) / 100}px` : '0px'
@@ -3,7 +3,7 @@
3
3
  v-if="p.show"
4
4
  class="uv-loading-icon"
5
5
  :class="[p.vertical ? 'uv-loading-icon--vertical' : '', p.customClass]"
6
- :style="[$uv.addStyle(p.customStyle)]"
6
+ :style="[addStyle(p.customStyle)]"
7
7
  >
8
8
  <view
9
9
  class="uv-loading-icon__spinner"
@@ -14,7 +14,7 @@
14
14
  <loading-indicator
15
15
  v-if="p.mode === 'spinner'"
16
16
  :animating="true"
17
- :style="{ color: p.color, width: $uv.addUnit(p.size), height: $uv.addUnit(p.size) }"
17
+ :style="{ color: p.color, width: addUnit(p.size), height: addUnit(p.size) }"
18
18
  />
19
19
  <!-- #endif -->
20
20
  <!-- #ifndef APP-NVUE -->
@@ -38,16 +38,17 @@
38
38
  class="uv-loading-icon__text"
39
39
  :class="[p.vertical ? 'uv-loading-icon__text--vertical' : '']"
40
40
  :style="[{
41
- fontSize: $uv.addUnit(p.textSize),
41
+ fontSize: addUnit(p.textSize),
42
42
  color: p.textColor
43
- }, $uv.addStyle(p.textStyle)]"
43
+ }, addStyle(p.textStyle)]"
44
44
  >{{ p.text }}</text>
45
45
  </view>
46
46
  </template>
47
47
 
48
48
  <script setup lang="ts">
49
49
  import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
50
- import { $uv } from '../../utils'
50
+ import { addStyle, addUnit } from '../../utils/function'
51
+ import { colorGradient } from '../../utils/color'
51
52
  import props from './props'
52
53
 
53
54
  defineOptions({
@@ -92,7 +93,7 @@
92
93
  // 当为circle类型时,给其另外三边设置一个更轻一些的颜色
93
94
  // 之所以需要这么做的原因是,比如父组件传了color为红色,那么需要另外的三个边为浅红色
94
95
  const otherBorderColor = computed(() => {
95
- const lightColor = $uv.colorGradient(p.color, '#ffffff', 100)[80]
96
+ const lightColor = colorGradient(p.color, '#ffffff', 100)[80]
96
97
  if (p.mode === 'circle') {
97
98
  return p.inactiveColor ? p.inactiveColor : lightColor
98
99
  }
@@ -102,8 +103,8 @@
102
103
  const spinnerStyle = computed(() => {
103
104
  return {
104
105
  color: p.color,
105
- width: $uv.addUnit(p.size),
106
- height: $uv.addUnit(p.size),
106
+ width: addUnit(p.size),
107
+ height: addUnit(p.size),
107
108
  borderTopColor: p.color,
108
109
  borderBottomColor: otherBorderColor.value,
109
110
  borderLeftColor: otherBorderColor.value,
@@ -14,7 +14,8 @@
14
14
 
15
15
  <script setup lang="ts">
16
16
  import { computed, onUnmounted, watch } from 'vue'
17
- import { $uv } from '../../utils'
17
+ import { addStyle } from '../../utils/function'
18
+ import { deepMerge } from '../../utils/merge'
18
19
  import props from './props'
19
20
  import UvTransition from '../uv-transition/uv-transition.vue'
20
21
  import { preventEvent } from '../../utils/compat'
@@ -60,7 +61,7 @@
60
61
  zIndex: p.zIndex,
61
62
  backgroundColor: `rgba(0, 0, 0, ${p.opacity})`
62
63
  }
63
- return $uv.deepMerge(style, $uv.addStyle(p.customStyle))
64
+ return deepMerge(style, addStyle(p.customStyle))
64
65
  })
65
66
 
66
67
  const clickHandler = () => {
@@ -57,7 +57,9 @@
57
57
 
58
58
  <script setup lang="ts">
59
59
  import { computed, onMounted, onUnmounted, ref } from 'vue'
60
- import { $uv, platform } from '../../utils'
60
+ import { addStyle, addUnit, error, getPx } from '../../utils/function'
61
+ import { deepMerge } from '../../utils/merge'
62
+ import { platform } from '../../utils/platform'
61
63
  import props from './props'
62
64
  import UvIcon from '../uv-icon/uv-icon.vue'
63
65
  import UvOverlay from '../uv-overlay/uv-overlay.vue'
@@ -121,7 +123,7 @@
121
123
  let closeTimer: any = null
122
124
 
123
125
  const bg = computed(() => {
124
- if (p.bgColor === '' || p.bgColor === 'none' || $uv.getPx(p.round) > 0) {
126
+ if (p.bgColor === '' || p.bgColor === 'none' || getPx(p.round) > 0) {
125
127
  return 'transparent'
126
128
  }
127
129
  return p.bgColor
@@ -133,7 +135,7 @@
133
135
  style.backgroundColor = bg.value
134
136
  }
135
137
  if (p.round) {
136
- const value = $uv.addUnit(p.round)
138
+ const value = addUnit(p.round)
137
139
  const mode = layoutMode.value
138
140
  style.backgroundColor = p.bgColor
139
141
  if (mode === 'top') {
@@ -149,7 +151,7 @@
149
151
  style.borderBottomRightRadius = value
150
152
  }
151
153
  }
152
- return $uv.deepMerge(style, $uv.addStyle(p.customStyle))
154
+ return deepMerge(style, addStyle(p.customStyle))
153
155
  })
154
156
 
155
157
  const ani = computed<string[]>(() => {
@@ -279,7 +281,7 @@
279
281
  direction = p.mode
280
282
  }
281
283
  if (innerType.indexOf(direction) === -1) {
282
- $uv.error('缺少类型:' + direction)
284
+ error('缺少类型:' + direction)
283
285
  return
284
286
  }
285
287
  layoutMode.value = getLayoutMode(direction)
@@ -8,7 +8,8 @@
8
8
 
9
9
  <script setup lang="ts">
10
10
  import { computed, onMounted, ref } from 'vue'
11
- import { $uv } from '../../utils'
11
+ import { addStyle, addUnit } from '../../utils/function'
12
+ import { deepMerge } from '../../utils/merge'
12
13
  import props from './props'
13
14
 
14
15
 
@@ -89,9 +90,9 @@
89
90
  const style: any = {}
90
91
  const height = safeBottomHeight.value
91
92
  if (height > 0) {
92
- style.height = $uv.addUnit(height, 'px')
93
+ style.height = addUnit(height, 'px')
93
94
  }
94
- return $uv.deepMerge(style, $uv.addStyle(p.customStyle))
95
+ return deepMerge(style, addStyle(p.customStyle))
95
96
  })
96
97
  </script>
97
98
 
@@ -10,7 +10,8 @@
10
10
 
11
11
  <script setup lang="ts">
12
12
  import { computed, onMounted, ref } from 'vue'
13
- import { $uv } from '../../utils'
13
+ import { addStyle, addUnit } from '../../utils/function'
14
+ import { deepMerge } from '../../utils/merge'
14
15
  import props from './props'
15
16
 
16
17
  defineOptions({
@@ -83,7 +84,7 @@
83
84
  const style: any = {}
84
85
  const height = statusBarHeight.value
85
86
  if (height > 0) {
86
- style.height = $uv.addUnit(height, 'px')
87
+ style.height = addUnit(height, 'px')
87
88
  }
88
89
  if (p.bgColor) {
89
90
  if (p.bgColor.indexOf('gradient') > -1) {
@@ -97,7 +98,7 @@
97
98
  style.background = p.bgColor
98
99
  }
99
100
  }
100
- return $uv.deepMerge(style, $uv.addStyle(p.customStyle))
101
+ return deepMerge(style, addStyle(p.customStyle))
101
102
  })
102
103
  </script>
103
104
 
@@ -2,7 +2,7 @@
2
2
  <view
3
3
  class="uv-tabs"
4
4
  :class="[p.customClass]"
5
- :style="[$uv.addStyle(p.customStyle)]"
5
+ :style="[addStyle(p.customStyle)]"
6
6
  >
7
7
  <view class="uv-tabs__wrapper">
8
8
  <slot name="left" />
@@ -40,7 +40,7 @@
40
40
  `uv-tabs__wrapper__nav__item-${index}`,
41
41
  item.disabled ? 'uv-tabs__wrapper__nav__item--disabled' : ''
42
42
  ]"
43
- :style="[itemFlexStyle, $uv.addStyle(p.itemStyle)]"
43
+ :style="[itemFlexStyle, addStyle(p.itemStyle)]"
44
44
  @tap="clickHandler(item, index)"
45
45
  >
46
46
  <text
@@ -78,7 +78,10 @@
78
78
 
79
79
  <script setup lang="ts">
80
80
  import { computed, getCurrentInstance, nextTick, onMounted, ref, watch } from 'vue'
81
- import { $uv } from '../../utils'
81
+ import { addStyle, addUnit, getPx, sleep, sys } from '../../utils/function'
82
+ import { deepMerge } from '../../utils/merge'
83
+ import { number as isNumber } from '../../utils/test'
84
+ import config from '../../utils/config'
82
85
  import props from './props'
83
86
  import UvBadge from '../uv-badge/uv-badge.vue'
84
87
  import { getRect, getRectNvue } from '../../utils/compat'
@@ -169,10 +172,10 @@
169
172
 
170
173
  const lineStyle = computed(() => {
171
174
  const style: any = {
172
- width: $uv.addUnit(p.lineWidth),
175
+ width: addUnit(p.lineWidth),
173
176
  transform: `translate(${lineOffsetLeft.value}px)`,
174
177
  transitionDuration: `${firstTime.value ? 0 : Number(p.duration) || 0}ms`,
175
- height: firstTime.value ? 0 : $uv.addUnit(p.lineHeight),
178
+ height: firstTime.value ? 0 : addUnit(p.lineHeight),
176
179
  // 使用 background 简写而不是 backgroundColor:lineColor 支持传入背景图(url(...))
177
180
  background: p.lineColor,
178
181
  backgroundSize: p.lineBgSize
@@ -184,13 +187,13 @@
184
187
  const item = p.list[index] as any
185
188
  // 取当前是否激活的样式
186
189
  const style: any =
187
- (index === innerCurrent.value ? $uv.addStyle(p.activeStyle) : $uv.addStyle(p.inactiveStyle)) || {}
190
+ (index === innerCurrent.value ? addStyle(p.activeStyle) : addStyle(p.inactiveStyle)) || {}
188
191
  const extra: any = {}
189
192
  // 如果当前菜单被禁用,则加上对应颜色
190
193
  if (item && item.disabled) {
191
194
  extra.color = '#c8c9cc'
192
195
  }
193
- return $uv.deepMerge(style, extra)
196
+ return deepMerge(style, extra)
194
197
  }
195
198
 
196
199
  // 获取单个节点的尺寸(返回 unbounded 的 rect 对象)
@@ -231,9 +234,9 @@
231
234
  if (rect) offsetLeft += rect.width
232
235
  }
233
236
  // 获取下划线的数值px表示法
234
- let lineWidth = $uv.getPx(p.lineWidth)
235
- if ($uv.test.number(p.lineWidth) && $uv.config.unit) {
236
- lineWidth = $uv.getPx(`${p.lineWidth}${$uv.config.unit}`)
237
+ let lineWidth = getPx(p.lineWidth)
238
+ if (isNumber(p.lineWidth) && config.unit) {
239
+ lineWidth = getPx(`${p.lineWidth}${config.unit}`)
237
240
  }
238
241
  lineOffsetLeft.value = offsetLeft + (tabItem.width - lineWidth) / 2
239
242
  // 第一次移动滑块,需要等过渡结束后再开启动画
@@ -254,7 +257,7 @@
254
257
  const rect = itemRects[i]
255
258
  if (rect) offsetLeft += rect.width
256
259
  }
257
- const windowWidth = $uv.sys().windowWidth || 0
260
+ const windowWidth = sys().windowWidth || 0
258
261
  // nvue 的 dom.getComponentRect 在部分基座下只返回 width/height,缺失 left/right 时兜底:
259
262
  // right 用 left + width 补齐,left 缺失按 0 处理,避免 NaN 导致 scrollLeft 失效。
260
263
  const tabsWidth = Number(tabsRect.width) || 0
@@ -296,7 +299,7 @@
296
299
  }
297
300
 
298
301
  const init = () => {
299
- $uv.sleep().then(() => {
302
+ sleep().then(() => {
300
303
  resize()
301
304
  })
302
305
  }
@@ -12,7 +12,7 @@
12
12
 
13
13
  <script setup lang="ts">
14
14
  import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'
15
- import { $uv } from '../../utils'
15
+ import { addStyle } from '../../utils/function'
16
16
  import props from './props'
17
17
 
18
18
  defineOptions({
@@ -94,7 +94,7 @@
94
94
  transform: active.value ? '' : hidden.transform,
95
95
  opacity: active.value ? 1 : hidden.opacity
96
96
  }
97
- return Object.assign(style, $uv.addStyle(p.customStyle))
97
+ return Object.assign(style, addStyle(p.customStyle))
98
98
  })
99
99
 
100
100
  const clearTimers = () => {
package/hooks/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { useDebounce } from './useDebounce';
2
- export { useThrottle } from './useThrottle';
3
- export * from './useI18n';
4
- export type { DebounceFunction } from './useDebounce';
5
- export type { ThrottleFunction } from './useThrottle';
1
+ export { default as useDebounce } from './useDebounce';
2
+ export { default as useThrottle } from './useThrottle';
3
+ export { default as useI18n } from './useI18n';
4
+ export type { UViewDebounceFunction } from './useDebounce';
5
+ export type { UViewThrottleFunction } from './useThrottle';
@@ -1,35 +1,33 @@
1
- /**
2
- * 实例级防抖。
3
- *
4
- * @example
5
- * const debounce = useDebounce()
6
- * debounce(fn) // 使用实例 delay(默认 500)
7
- * debounce(fn, 1000) // 调用层覆盖 delay
8
- * const debounce300 = useDebounce(300)
9
- *
10
- * 每个 useDebounce() 返回独立闭包,多个实例互不干扰。
11
- */
12
- export type DebounceFunction = (
13
- func: (...args: any[]) => void,
14
- wait?: number,
15
- immediate?: boolean
16
- ) => void
17
-
18
- export function useDebounce(delay = 500): DebounceFunction {
19
- let timeout: ReturnType<typeof setTimeout> | null = null
20
- return (func: (...args: any[]) => void, wait = delay, immediate = false) => {
21
- if (timeout !== null) clearTimeout(timeout)
22
- if (immediate) {
23
- const callNow = !timeout
24
- timeout = setTimeout(() => {
25
- timeout = null
26
- }, wait)
27
- if (callNow) typeof func === 'function' && func()
28
- } else {
29
- timeout = setTimeout(() => {
30
- timeout = null
31
- typeof func === 'function' && func()
32
- }, wait)
33
- }
34
- }
35
- }
1
+ /**
2
+ * 实例级防抖。
3
+ *
4
+ * @example
5
+ * const debounce = useDebounce()
6
+ * debounce(fn) // 使用实例 delay(默认 500)
7
+ * debounce(fn, 1000) // 调用层覆盖 delay
8
+ * const debounce300 = useDebounce(300)
9
+ *
10
+ * 每个 useDebounce() 返回独立闭包,多个实例互不干扰。
11
+ */
12
+ export type UViewDebounceFunction = (func: (...args: any[]) => void, wait?: number, immediate?: boolean) => void;
13
+
14
+ function useDebounce(delay = 500): UViewDebounceFunction {
15
+ let timeout: ReturnType<typeof setTimeout> | null = null;
16
+ return (func: (...args: any[]) => void, wait = delay, immediate = false) => {
17
+ if (timeout !== null) clearTimeout(timeout);
18
+ if (immediate) {
19
+ const callNow = !timeout;
20
+ timeout = setTimeout(() => {
21
+ timeout = null;
22
+ }, wait);
23
+ if (callNow) typeof func === 'function' && func();
24
+ } else {
25
+ timeout = setTimeout(() => {
26
+ timeout = null;
27
+ typeof func === 'function' && func();
28
+ }, wait);
29
+ }
30
+ };
31
+ }
32
+
33
+ export default useDebounce;
package/hooks/useI18n.ts CHANGED
@@ -5,7 +5,7 @@ import { getCurrentInstance } from 'vue';
5
5
  import { useI18n as vueUseI18n } from 'vue-i18n';
6
6
  // #endif
7
7
  import { appTranslate, getI18nGlobal, getI18nMessages, localeState, unwrapI18nValue } from '../utils/locale';
8
- import type { I18nMessages } from '../utils/locale';
8
+ import type { I18nGlobalMessages } from '../utils/locale';
9
9
 
10
10
  /** 页面内使用的 i18n hook 类型:与 vue-i18n 的 `useI18n` 保持一致 */
11
11
  type UseI18n = typeof import('vue-i18n').useI18n;
@@ -14,7 +14,7 @@ type UseI18n = typeof import('vue-i18n').useI18n;
14
14
  interface UseI18nFallback {
15
15
  t: (key: string, values?: Record<string, string | number>) => string;
16
16
  locale: WritableComputedRef<string>;
17
- messages: I18nMessages;
17
+ messages: I18nGlobalMessages;
18
18
  }
19
19
 
20
20
  /**
@@ -92,4 +92,5 @@ _useI18n = function (...args: unknown[]) {
92
92
  } as unknown as UseI18n;
93
93
  // #endif
94
94
 
95
- export const useI18n: UseI18n = _useI18n;
95
+ const useI18n: UseI18n = _useI18n;
96
+ export default useI18n;
@@ -1,38 +1,36 @@
1
- /**
2
- * 实例级节流。
3
- *
4
- * @example
5
- * const throttle = useThrottle()
6
- * throttle(fn) // 使用实例 delay(默认 500)
7
- * throttle(fn, 1000) // 调用层覆盖 delay
8
- * const throttle300 = useThrottle(300)
9
- *
10
- * 每个 useThrottle() 返回独立闭包,多个实例互不干扰。
11
- */
12
- export type ThrottleFunction = (
13
- func: (...args: any[]) => void,
14
- wait?: number,
15
- immediate?: boolean
16
- ) => void
17
-
18
- export function useThrottle(delay = 500): ThrottleFunction {
19
- let timer: ReturnType<typeof setTimeout> | null = null
20
- let flag = false
21
- return (func: (...args: any[]) => void, wait = delay, immediate = true) => {
22
- if (immediate) {
23
- if (!flag) {
24
- flag = true
25
- typeof func === 'function' && func()
26
- timer = setTimeout(() => {
27
- flag = false
28
- }, wait)
29
- }
30
- } else if (!flag) {
31
- flag = true
32
- timer = setTimeout(() => {
33
- flag = false
34
- typeof func === 'function' && func()
35
- }, wait)
36
- }
37
- }
38
- }
1
+ /**
2
+ * 实例级节流。
3
+ *
4
+ * @example
5
+ * const throttle = useThrottle()
6
+ * throttle(fn) // 使用实例 delay(默认 500)
7
+ * throttle(fn, 1000) // 调用层覆盖 delay
8
+ * const throttle300 = useThrottle(300)
9
+ *
10
+ * 每个 useThrottle() 返回独立闭包,多个实例互不干扰。
11
+ */
12
+ export type UViewThrottleFunction = (func: (...args: any[]) => void, wait?: number, immediate?: boolean) => void;
13
+
14
+ function useThrottle(delay = 500): UViewThrottleFunction {
15
+ let timer: ReturnType<typeof setTimeout> | null = null;
16
+ let flag = false;
17
+ return (func: (...args: any[]) => void, wait = delay, immediate = true) => {
18
+ if (immediate) {
19
+ if (!flag) {
20
+ flag = true;
21
+ typeof func === 'function' && func();
22
+ timer = setTimeout(() => {
23
+ flag = false;
24
+ }, wait);
25
+ }
26
+ } else if (!flag) {
27
+ flag = true;
28
+ timer = setTimeout(() => {
29
+ flag = false;
30
+ typeof func === 'function' && func();
31
+ }, wait);
32
+ }
33
+ };
34
+ }
35
+
36
+ export default useThrottle;