uview-pro 0.3.3 → 0.3.5

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.
@@ -28,7 +28,6 @@
28
28
  :value="modelValue"
29
29
  @confirm="search"
30
30
  @input="inputChange"
31
- :disabled="disabled"
32
31
  @focus="getFocus"
33
32
  :focus="focus"
34
33
  :maxlength="maxlength"
@@ -41,7 +40,8 @@
41
40
  {
42
41
  textAlign: inputAlign,
43
42
  color: color,
44
- backgroundColor: bgColor
43
+ backgroundColor: bgColor,
44
+ pointerEvents: disabled ? 'none' : 'auto'
45
45
  },
46
46
  inputStyle
47
47
  ]"
@@ -114,7 +114,17 @@ import { $u } from '../..';
114
114
 
115
115
  const props = defineProps(SearchProps);
116
116
 
117
- const emit = defineEmits(['update:modelValue', 'change', 'search', 'custom', 'clear', 'focus', 'blur', 'click']);
117
+ const emit = defineEmits([
118
+ 'update:modelValue',
119
+ 'input',
120
+ 'change',
121
+ 'search',
122
+ 'custom',
123
+ 'clear',
124
+ 'focus',
125
+ 'blur',
126
+ 'click'
127
+ ]);
118
128
 
119
129
  // 绑定输入框的值
120
130
  const keyword = ref(props.modelValue);
@@ -134,6 +144,7 @@ watch(
134
144
  );
135
145
  watch(keyword, nVal => {
136
146
  emit('update:modelValue', nVal);
147
+ emit('input', nVal);
137
148
  emit('change', nVal);
138
149
  });
139
150
 
@@ -0,0 +1,13 @@
1
+ import type { ExtractPropTypes, PropType } from 'vue';
2
+ import { baseProps } from '../common/props';
3
+
4
+ export const StatusBarProps = {
5
+ ...baseProps,
6
+ /** 背景设置 */
7
+ background: {
8
+ type: String,
9
+ default: 'transparent'
10
+ },
11
+ };
12
+
13
+ export type StatusBarProps = ExtractPropTypes<typeof StatusBarProps>;
@@ -1,5 +1,8 @@
1
1
  <template>
2
- <view :style="style" :class="['u-status-bar', { 'safe-area-inset-top': noBar }]">
2
+ <view
3
+ :style="$u.toStyle(style, customStyle)"
4
+ :class="['u-status-bar', { 'safe-area-inset-top': noBar }, customClass]"
5
+ >
3
6
  <slot />
4
7
  </view>
5
8
  </template>
@@ -18,11 +21,9 @@ export default {
18
21
  </script>
19
22
 
20
23
  <script setup lang="ts">
21
- import { ref, computed, onMounted, withDefaults, type CSSProperties } from 'vue';
22
- import { sys } from '../../libs/function/sys';
23
- import addUnit from '../../libs/function/addUnit';
24
- import deepMerge from '../../libs/function/deepMerge';
25
- import { mergeStyles } from '../../libs/function/styleUtils';
24
+ import { ref, computed, onMounted, type CSSProperties } from 'vue';
25
+ import { StatusBarProps } from './props';
26
+ import { $u } from '../../';
26
27
 
27
28
  /**
28
29
  * StatusBar 状态栏
@@ -30,31 +31,20 @@ import { mergeStyles } from '../../libs/function/styleUtils';
30
31
  * @property {String} background 背景颜色
31
32
  * @example <u-status-bar></u-status-bar>
32
33
  */
33
- const props = withDefaults(
34
- defineProps<{
35
- background?: string;
36
- customStyle?: string | CSSProperties;
37
- }>(),
38
- {
39
- // 背景颜色
40
- background: 'transparent',
41
- customStyle: () => ({})
42
- }
43
- );
44
-
34
+ const props = defineProps(StatusBarProps);
45
35
  const noBar = ref(false);
46
36
 
47
37
  const style = computed(() => {
48
- let r: CSSProperties = {
38
+ let result: CSSProperties = {
49
39
  background: props.background
50
40
  };
51
- const sh = sys().statusBarHeight;
52
- if (sh === 0) {
41
+ const statusBarHeight = $u.sys().statusBarHeight;
42
+ if (statusBarHeight === 0) {
53
43
  noBar.value = true;
54
44
  } else {
55
- r.height = addUnit(sh, 'px');
45
+ result.height = $u.addUnit(statusBarHeight, 'px');
56
46
  }
57
- return deepMerge(r, mergeStyles(props.customStyle));
47
+ return result;
58
48
  });
59
49
 
60
50
  onMounted(() => {
@@ -28,7 +28,7 @@ export default {
28
28
  </script>
29
29
 
30
30
  <script setup lang="ts">
31
- import { ref, computed, watch, onMounted, getCurrentInstance } from 'vue';
31
+ import { ref, computed, watch, getCurrentInstance, nextTick } from 'vue';
32
32
  import { $u } from '../..';
33
33
  import { SubsectionProps } from './types';
34
34
 
@@ -88,6 +88,33 @@ watch(
88
88
  { immediate: true }
89
89
  );
90
90
 
91
+ watch(
92
+ () => props.list,
93
+ () => {
94
+ if (!props.list || !props.list.length) return;
95
+ initListInfo();
96
+ // 重新获取各个tab的宽度信息
97
+ nextTick(() => {
98
+ setTimeout(() => {
99
+ getTabsInfo();
100
+ }, 10);
101
+ });
102
+ },
103
+ { deep: true, immediate: true }
104
+ );
105
+
106
+ watch(
107
+ () => props.mode,
108
+ () => {
109
+ // 重新获取各个tab的宽度信息
110
+ nextTick(() => {
111
+ setTimeout(() => {
112
+ getTabsInfo();
113
+ }, 10);
114
+ });
115
+ }
116
+ );
117
+
91
118
  // 初始化 listInfo
92
119
  function initListInfo() {
93
120
  // 将list的数据,传入listInfo数组,因为不能修改props传递的list值
@@ -101,14 +128,6 @@ function initListInfo() {
101
128
  });
102
129
  }
103
130
 
104
- initListInfo();
105
-
106
- onMounted(() => {
107
- setTimeout(() => {
108
- getTabsInfo();
109
- }, 10);
110
- });
111
-
112
131
  /**
113
132
  * 设置mode=subsection时,滑块特有的样式
114
133
  */
@@ -1,13 +1,50 @@
1
1
  import validation from './test';
2
2
 
3
3
  /**
4
- * 添加单位,如果有rpx,%,px等单位结尾或者值为auto,直接返回,否则加上rpx单位结尾
5
- * @param value 输入值,可以为字符串或数字,默认'auto'
4
+ * 添加单位,支持以下场景:
5
+ * 1. 单值:如果有rpx、%、px等单位结尾或者值为auto,直接返回,否则加上rpx单位结尾
6
+ * 2. 多值(空格分隔):分别处理每个值,如 "10 20" => "10rpx 20rpx"
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * addUnit(10) => "10rpx"
11
+ * addUnit('10px') => "10px"
12
+ * addUnit('auto') => "auto"
13
+ * addUnit('10 20') => "10rpx 20rpx"
14
+ * addUnit('10rpx 20') => "10rpx 20rpx"
15
+ * ```
16
+ *
17
+ * @param value 输入值,可以为字符串或数字,默认'auto'。支持空格分隔的多值(用于 padding、margin 等)
6
18
  * @param unit 单位,默认'rpx'
7
19
  * @returns 添加单位后的字符串
8
20
  */
9
21
  export default function addUnit(value: string | number = 'auto', unit: string = 'rpx'): string {
22
+ // 若传入 number 类型,转为 string
10
23
  const strValue = String(value);
11
- // 用uView内置验证规则中的number判断是否为数值
24
+
25
+ // 如果是空值,直接返回
26
+ if (!strValue) return '';
27
+
28
+ // auto 直接返回
29
+ if (strValue === 'auto') return strValue;
30
+
31
+ // 检查是否包含空格(多值场景)
32
+ if (strValue.includes(' ')) {
33
+ // 分割每个值并单独处理
34
+ return strValue
35
+ .split(' ')
36
+ .map(s => {
37
+ // 如果当前值已有单位或为 auto,直接返回
38
+ if (s === 'auto' || /^-?\d*\.?\d+(%|px|rpx|em|rem|vh|vw)$/.test(s)) return s;
39
+ // 数字类型的值添加单位
40
+ return validation.number(s) ? `${s}${unit}` : s;
41
+ })
42
+ .join(' ');
43
+ }
44
+
45
+ // 单值场景:如果已有单位或为 auto,直接返回
46
+ if (/^-?\d*\.?\d+(%|px|rpx|em|rem|vh|vw)$/.test(strValue)) return strValue;
47
+
48
+ // 用 uView 内置验证规则判断是否为数值,是则加上单位
12
49
  return validation.number(strValue) ? `${strValue}${unit}` : strValue;
13
50
  }
@@ -1,4 +1,3 @@
1
- // export * from './useComponent';
2
1
  export * from './useEmitter';
3
2
  export * from './useRect';
4
3
  export * from './useCompRelation';
@@ -1,4 +1,3 @@
1
- // utils/useComponent.ts
2
1
  import {
3
2
  ref,
4
3
  reactive,
@@ -28,6 +27,7 @@ interface ParentContext {
28
27
  interface ChildContext {
29
28
  id: string;
30
29
  name: string;
30
+ getChildIndex: () => number;
31
31
  emitToParent: (event: string, data?: any) => void;
32
32
  getParentExposed: () => Record<string, any>;
33
33
  getInstance: () => any;
@@ -320,9 +320,20 @@ export function useChildren(componentName?: string, parentName?: string) {
320
320
  }
321
321
  };
322
322
 
323
+ const getChildIndex = () => {
324
+ if (!parentRef.value) return -1;
325
+ try {
326
+ const children = parentRef.value.getChildren();
327
+ return children.findIndex((child: ChildContext) => child.id === instanceId);
328
+ } catch (error) {
329
+ return -1;
330
+ }
331
+ };
332
+
323
333
  const childContext: ChildContext = {
324
334
  id: instanceId,
325
335
  name: name || 'anonymous',
336
+ getChildIndex,
326
337
  emitToParent,
327
338
  getParentExposed,
328
339
  getInstance: () => instance,
@@ -351,6 +362,7 @@ export function useChildren(componentName?: string, parentName?: string) {
351
362
  return {
352
363
  childId: instanceId,
353
364
  childName: name || 'anonymous',
365
+ childIndex: computed(getChildIndex),
354
366
  parent: parentRef,
355
367
  emitToParent,
356
368
  getParentExposed,
package/libs/index.ts CHANGED
@@ -44,15 +44,12 @@ import debounce from './function/debounce';
44
44
  import throttle from './function/throttle';
45
45
  // 获取元素的位置信息
46
46
  import getRect from './function/getRect';
47
- // 获取父组件
48
- import { parentData, parent } from './function/parent';
49
47
  // 剪贴板
50
48
  import { clipboard } from './function/clipboard';
51
49
  // 配置信息
52
50
  import config from './config/config';
53
51
  // 各个需要fixed的地方的z-index配置文件
54
52
  import zIndex from './config/zIndex';
55
- import { dispatch, broadcast } from './util/emitter';
56
53
  import { mitt } from './util/mitt';
57
54
  // http相关
58
55
  import httpPlugin, {
@@ -268,11 +265,7 @@ export {
268
265
  getRect,
269
266
  getParent,
270
267
  $parent,
271
- parent,
272
- parentData,
273
268
  clipboard,
274
- dispatch,
275
- broadcast,
276
269
  config,
277
270
  zIndex,
278
271
  mitt
@@ -292,8 +285,6 @@ export const $u = {
292
285
  os,
293
286
  type2icon,
294
287
  randomArray,
295
- dispatch,
296
- broadcast,
297
288
  hexToRgb: colorGradients.hexToRgb,
298
289
  rgbToHex: colorGradients.rgbToHex,
299
290
  test,
@@ -302,8 +293,6 @@ export const $u = {
302
293
  deepMerge,
303
294
  getParent,
304
295
  $parent,
305
- parent,
306
- parentData,
307
296
  clipboard,
308
297
  addUnit,
309
298
  trim,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "id": "uview-pro",
3
3
  "name": "uview-pro",
4
4
  "displayName": "【Vue3重构版】uView Pro|基于Vue3+TS全面重构的70+精选UI组件库",
5
- "version": "0.3.3",
5
+ "version": "0.3.5",
6
6
  "description": "uView Pro,是全面支持Vue3的uni-app生态框架,70+精选组件已使用TypeScript重构,已全面支持uni-app Vue3.0",
7
7
  "main": "index.ts",
8
8
  "module": "index.ts",
@@ -1,7 +1,7 @@
1
1
  declare module 'vue' {
2
2
  export interface GlobalComponents {
3
- // 基础组件
4
3
  uActionSheet: (typeof import('../components/u-action-sheet/u-action-sheet.vue'))['default'];
4
+ uActionSheetItem: (typeof import('../components/u-action-sheet-item/u-action-sheet-item.vue'))['default'];
5
5
  uAlertTips: (typeof import('../components/u-alert-tips/u-alert-tips.vue'))['default'];
6
6
  uAvatar: (typeof import('../components/u-avatar/u-avatar.vue'))['default'];
7
7
  uAvatarCropper: (typeof import('../components/u-avatar-cropper/u-avatar-cropper.vue'))['default'];
@@ -96,4 +96,4 @@ declare module 'vue' {
96
96
  }
97
97
  }
98
98
 
99
- export { };
99
+ export {};