uview-pro 0.3.3 → 0.3.4

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.
package/changelog.md CHANGED
@@ -1,21 +1,37 @@
1
- ## 0.3.3(2025-10-16
1
+ ## 0.3.4(2025-10-20
2
2
 
3
- ### 🐛 Bug Fixes | Bug 修复
3
+ ### ♻️ Code Refactoring | 代码重构
4
4
 
5
- - **u-read-more:** 修复 init 方法无法在外部调用的问题 ([415d401](https://github.com/anyup/uView-Pro/commit/415d401883a3567653ab1f311b28b075b7bb5603))
6
- - **u-button:** 修复 hover-class 属性被忽略的问题 ([b919c58](https://github.com/anyup/uView-Pro/commit/b919c58cea048f9e559a6448cebe5abbf1490acf))
5
+ - **components:** 移除不必要的父组件和事件总线相关代码,优化组件间通信 ([280c2f8](https://github.com/anyup/uView-Pro/commit/280c2f8acc75764a7706ec38c742cc16703c941a))
6
+ - **u-safe-bottom:** 优化底部安全区组件 ([161f2d3](https://github.com/anyup/uView-Pro/commit/161f2d32ff6b9abbb6f8221a4dd99c438a606e94))
7
+ - **u-status-bar:** 优化状态栏组件 ([53c50ab](https://github.com/anyup/uView-Pro/commit/53c50ab8b6314a7d702b90e6b48b79301a334090))
7
8
 
8
- ### ♻️ Code Refactoring | 代码重构
9
+ ### 🐛 Bug Fixes | Bug 修复
9
10
 
10
- - **component-relation:** 重构组件关系逻辑并添加新功能 ([85d0cd2](https://github.com/anyup/uView-Pro/commit/85d0cd20db839a61733887f82825d47de0a1b1a6))
11
- - **u-talbe:** 重构u-td和u-th组件,增强u-table的兼容性 ([3fbbc52](https://github.com/anyup/uView-Pro/commit/3fbbc5233bd41b91ca829f9a65cf95ee3b599e36))
12
- - 修改 uView Pro 日志配置 ([6b9bb68](https://github.com/anyup/uView-Pro/commit/6b9bb6852af3eb24f109207f864145771c3e9c79))
13
- - **clipboard:** add clipboard function ([efdaa58](https://github.com/anyup/uView-Pro/commit/efdaa58dda923b281d9b764a82a7492f36717ac4))
11
+ - **u-subsection:** 优化列表和模式变化的监听逻辑,移除不必要的初始化调用 ([f77ee7c](https://github.com/anyup/uView-Pro/commit/f77ee7ccc7521ec2472f72dcf2fb47362ca0abd9))
14
12
 
15
13
  ### 👥 Contributors
16
14
 
17
- <a href="https://github.com/koboshi"><img src="https://github.com/koboshi.png?size=40" width="40" height="40" alt="koboshi" title="koboshi"/></a> <a href="https://github.com/anyup"><img src="https://github.com/anyup.png?size=40" width="40" height="40" alt="anyup" title="anyup"/></a> <a href="https://github.com/lonelyflyer"><img src="https://github.com/lonelyflyer.png?size=40" width="40" height="40" alt="Lonelyflyer" title="Lonelyflyer"/></a>
15
+ <a href="https://github.com/anyup"><img src="https://github.com/anyup.png?size=40" width="40" height="40" alt="anyup" title="anyup"/></a>
18
16
 
17
+ ## 0.3.3(2025-10-16)
18
+
19
+ ### 🐛 Bug Fixes | Bug 修复
20
+
21
+ - **u-read-more:** 修复 init 方法无法在外部调用的问题 ([415d401](https://github.com/anyup/uView-Pro/commit/415d401883a3567653ab1f311b28b075b7bb5603))
22
+ - **u-button:** 修复 hover-class 属性被忽略的问题 ([b919c58](https://github.com/anyup/uView-Pro/commit/b919c58cea048f9e559a6448cebe5abbf1490acf))
23
+
24
+ ### ♻️ Code Refactoring | 代码重构
25
+
26
+ - **component-relation:** 重构组件关系逻辑并添加新功能 ([85d0cd2](https://github.com/anyup/uView-Pro/commit/85d0cd20db839a61733887f82825d47de0a1b1a6))
27
+ - **u-talbe:** 重构u-td和u-th组件,增强u-table的兼容性 ([3fbbc52](https://github.com/anyup/uView-Pro/commit/3fbbc5233bd41b91ca829f9a65cf95ee3b599e36))
28
+ - 修改 uView Pro 日志配置 ([6b9bb68](https://github.com/anyup/uView-Pro/commit/6b9bb6852af3eb24f109207f864145771c3e9c79))
29
+ - **clipboard:** add clipboard function ([efdaa58](https://github.com/anyup/uView-Pro/commit/efdaa58dda923b281d9b764a82a7492f36717ac4))
30
+
31
+ ### 👥 Contributors
32
+
33
+ <a href="https://github.com/koboshi"><img src="https://github.com/koboshi.png?size=40" width="40" height="40" alt="koboshi" title="koboshi"/></a> <a href="https://github.com/anyup"><img src="https://github.com/anyup.png?size=40" width="40" height="40" alt="anyup" title="anyup"/></a> <a href="https://github.com/lonelyflyer"><img src="https://github.com/lonelyflyer.png?size=40" width="40" height="40" alt="Lonelyflyer" title="Lonelyflyer"/></a>
34
+
19
35
  ## 0.3.2(2025-10-15)
20
36
 
21
37
  ### 📝 Documentation | 文档
@@ -19,7 +19,7 @@ export default {
19
19
 
20
20
  <script setup lang="ts">
21
21
  import { getCurrentInstance, computed } from 'vue';
22
- import { $u, useParent } from '../..';
22
+ import { $u, useParent, useChildren } from '../..';
23
23
  import { CheckboxGroupProps } from './types';
24
24
 
25
25
  /**
@@ -44,6 +44,7 @@ const emit = defineEmits(['update:modelValue', 'change']);
44
44
 
45
45
  // 使用父组件Hook
46
46
  const { children, broadcast } = useParent('u-checkbox-group');
47
+ const { emitToParent } = useChildren('u-checkbox-group', 'u-form-item');
47
48
 
48
49
  /**
49
50
  * 派发 change 事件和表单校验
@@ -58,7 +59,7 @@ function emitEvent() {
58
59
  });
59
60
  emit('change', values);
60
61
  setTimeout(() => {
61
- $u.dispatch(instance, 'u-form-item', 'on-form-change', values);
62
+ emitToParent('onFormChange', values);
62
63
  }, 60);
63
64
  }
64
65
 
@@ -88,15 +88,16 @@ export default {
88
88
  </script>
89
89
 
90
90
  <script setup lang="ts">
91
- import { ref, computed, onMounted, onBeforeUnmount, watch, getCurrentInstance, nextTick } from 'vue';
92
- import { $u, useChildren } from '../..';
93
- import { broadcast } from '../../libs/util/emitter';
91
+ import { ref, computed, onMounted, onBeforeUnmount, watch, nextTick } from 'vue';
92
+ import { $u, useChildren, useParent } from '../..';
94
93
  // @ts-ignore
95
94
  import schema from '../../libs/util/async-validator';
96
95
  import { FormItemProps } from './types';
97
96
  // 去除警告信息
98
97
  schema.warning = function () {};
99
98
 
99
+ const { broadcast } = useParent('u-form-item');
100
+
100
101
  /**
101
102
  * form-item 表单item
102
103
  * @description 此组件一般用于表单场景,可以配置Input输入框,Select弹出框,进行表单验证等。
@@ -120,8 +121,6 @@ const props = defineProps(FormItemProps);
120
121
 
121
122
  const { parentExposed } = useChildren('u-form-item', 'u-form');
122
123
 
123
- const instance = getCurrentInstance();
124
-
125
124
  // 组件状态
126
125
  const initialValue = ref(''); // 存储初始值,用于重置
127
126
  const validateState = ref(''); // 校验状态 success/error/validating
@@ -136,6 +135,15 @@ const parentData = ref({
136
135
  labelAlign: 'left' // 父表单 label 对齐
137
136
  });
138
137
 
138
+ // 显示错误提示
139
+ // errorType: ['message', 'toast', 'border-bottom', 'none']
140
+ const showError = computed(() => (type: string) => {
141
+ // 如果errorType数组中含有none,或者toast提示类型
142
+ if (errorType.value.indexOf('none') >= 0) return false;
143
+ else if (errorType.value.indexOf(type) >= 0) return true;
144
+ else return false;
145
+ });
146
+
139
147
  // 监听校验状态和父表单 errorType 变化
140
148
  watch(validateState, () => {
141
149
  broadcastInputError();
@@ -161,15 +169,6 @@ const uLabelWidth = computed(() => {
161
169
  : '100%';
162
170
  });
163
171
 
164
- // 显示错误提示
165
- // errorType: ['message', 'toast', 'border-bottom', 'none']
166
- const showError = computed(() => (type: string) => {
167
- // 如果errorType数组中含有none,或者toast提示类型
168
- if (errorType.value.indexOf('none') >= 0) return false;
169
- else if (errorType.value.indexOf(type) >= 0) return true;
170
- else return false;
171
- });
172
-
173
172
  // label的宽度
174
173
  const elLabelWidth = computed(() => {
175
174
  // label默认宽度为90,优先使用本组件的值,如果没有(如果设置为0,也算是配置了值,依然起效),则用u-form的值
@@ -215,17 +214,8 @@ const elBorderBottom = computed(() => {
215
214
 
216
215
  // 事件派发/广播工具
217
216
  function broadcastInputError() {
218
- // 子组件发出事件,第三个参数为true或者false,true代表有错误
219
- if (instance) {
220
- // 这里可用 emitter 工具库的 broadcast 方法
221
- // 子组件发出事件,第三个参数为true或者false,true代表有错误
222
- broadcast(
223
- instance,
224
- 'u-input',
225
- 'on-form-item-error',
226
- validateState.value === 'error' && showError.value('border')
227
- );
228
- }
217
+ // 子组件发出事件,参数为true或者false,true代表有错误
218
+ broadcast('onFormItemError', validateState.value === 'error' && showError.value('border'));
229
219
  }
230
220
 
231
221
  /**
@@ -105,14 +105,15 @@ export default {
105
105
  </script>
106
106
 
107
107
  <script setup lang="ts">
108
- import { ref, computed, watch, getCurrentInstance } from 'vue';
109
- import { $u } from '../..';
110
- import { dispatch } from '../../libs/util/emitter';
108
+ import { ref, computed, watch } from 'vue';
109
+ import { $u, useChildren } from '../..';
111
110
  import { InputProps } from './types';
112
111
 
113
112
  const props = defineProps(InputProps);
114
113
  const emit = defineEmits(['update:modelValue', 'blur', 'focus', 'confirm', 'click']);
115
114
 
115
+ const { emitToParent } = useChildren('u-input', 'u-form-item');
116
+
116
117
  const defaultValue = ref(props.modelValue);
117
118
  const inputHeight = 70; // input的高度
118
119
  const textareaHeight = 100; // textarea的高度
@@ -158,10 +159,6 @@ const uSelectionStart = computed(() => String(props.selectionStart));
158
159
  // 光标结束位置
159
160
  const uSelectionEnd = computed(() => String(props.selectionEnd));
160
161
 
161
- const instance = getCurrentInstance();
162
-
163
- // 监听u-form-item发出的错误事件,将输入框边框变红色,失效了
164
- // uni.$on('on-form-item-error', onFormItemError);
165
162
  /**
166
163
  * change 事件
167
164
  * @param event
@@ -183,7 +180,7 @@ function handleInput(event: any) {
183
180
  lastValue.value = value;
184
181
  // #endif
185
182
  // 通过 emitter 派发事件
186
- dispatch(instance, 'u-form-item', 'on-form-change', value);
183
+ emitToParent('onFormChange', value);
187
184
  }, 40);
188
185
  }
189
186
 
@@ -205,12 +202,11 @@ function handleBlur(event: any) {
205
202
  if ($u.trim(value) == lastValue.value) return;
206
203
  lastValue.value = value;
207
204
  // #endif
208
- dispatch(instance, 'u-form-item', 'on-form-blur', value);
205
+ emitToParent('onFormBlur', value);
209
206
  }, 40);
210
207
  }
211
208
 
212
209
  function onFormItemError(status: boolean) {
213
- console.log('onFormItemError', status);
214
210
  validateState.value = status;
215
211
  }
216
212
 
@@ -235,6 +231,10 @@ function onClear(event: any) {
235
231
  function inputClick() {
236
232
  emit('click');
237
233
  }
234
+
235
+ defineExpose({
236
+ onFormItemError
237
+ });
238
238
  </script>
239
239
 
240
240
  <style lang="scss" scoped>
@@ -18,8 +18,7 @@ export default {
18
18
  </script>
19
19
 
20
20
  <script setup lang="ts">
21
- import { getCurrentInstance } from 'vue';
22
- import { $u, useParent } from '../..';
21
+ import { $u, useParent, useChildren } from '../..';
23
22
  import { RadioGroupProps } from './types';
24
23
 
25
24
  /**
@@ -42,6 +41,7 @@ const props = defineProps(RadioGroupProps);
42
41
 
43
42
  const emit = defineEmits(['update:modelValue', 'change']);
44
43
 
44
+ const { emitToParent } = useChildren('u-radio-group', 'u-form-item');
45
45
  useParent('u-radio-group');
46
46
 
47
47
  /**
@@ -73,7 +73,7 @@ function setValue(val: string | number) {
73
73
  // 由于头条小程序执行迟钝,故需要用几十毫秒的延时
74
74
  setTimeout(() => {
75
75
  // 将当前的值发送到 u-form-item 进行校验
76
- $u.dispatch(getCurrentInstance(), 'u-form-item', 'on-form-change', val);
76
+ emitToParent('onFormChange', val);
77
77
  }, 60);
78
78
  }
79
79
 
@@ -0,0 +1,11 @@
1
+ import type { ExtractPropTypes } from 'vue';
2
+ import { baseProps } from '../common/props';
3
+
4
+ /**
5
+ * SafeBottomProps SafeBottom 底部安全区
6
+ */
7
+ export const SafeBottomProps = {
8
+ ...baseProps,
9
+ };
10
+
11
+ export type SafeBottomProps = ExtractPropTypes<typeof SafeBottomProps>;
@@ -1,5 +1,9 @@
1
1
  <template>
2
- <view class="u-safe-bottom" :style="style" :class="[!isNVue && 'safe-area-inset-bottom']"></view>
2
+ <view
3
+ class="u-safe-bottom"
4
+ :style="$u.toStyle(style, customStyle)"
5
+ :class="[!isNVue && 'safe-area-inset-bottom', customClass]"
6
+ ></view>
3
7
  </template>
4
8
 
5
9
  <script lang="ts">
@@ -16,11 +20,9 @@ export default {
16
20
  </script>
17
21
 
18
22
  <script setup lang="ts">
19
- import { ref, computed, onMounted, withDefaults, type CSSProperties } from 'vue';
20
- import { sys } from '../../libs/function/sys';
21
- import addUnit from '../../libs/function/addUnit';
22
- import deepMerge from '../../libs/function/deepMerge';
23
- import { mergeStyles } from '../../libs/function/styleUtils';
23
+ import { ref, computed, onMounted, type CSSProperties } from 'vue';
24
+ import { SafeBottomProps } from './props';
25
+ import { $u } from '../../';
24
26
 
25
27
  /**
26
28
  * SafeBottom 底部安全区
@@ -28,24 +30,17 @@ import { mergeStyles } from '../../libs/function/styleUtils';
28
30
  * @property {String | Object} customStyle 自定义样式
29
31
  * @example <u-safe-bottom></u-safe-bottom>
30
32
  */
31
- const props = withDefaults(
32
- defineProps<{
33
- customStyle?: string | CSSProperties;
34
- }>(),
35
- {
36
- customStyle: () => ({})
37
- }
38
- );
33
+ const props = defineProps(SafeBottomProps);
39
34
 
40
35
  const isNVue = ref(false);
41
36
 
42
37
  const style = computed(() => {
43
- let r: CSSProperties = {};
38
+ let result: CSSProperties = {};
44
39
  // #ifdef APP-NVUE || MP-TOUTIAO
45
40
  // nvue下,高度使用js计算填充
46
- r.height = addUnit(sys().safeAreaInsets.bottom, 'px');
41
+ result.height = $u.addUnit($u.sys().safeAreaInsets.bottom, 'px');
47
42
  // #endif
48
- return deepMerge(r, mergeStyles(props.customStyle));
43
+ return result;
49
44
  });
50
45
 
51
46
  onMounted(() => {
@@ -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,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,
@@ -118,8 +117,8 @@ export function useParent(componentName?: string) {
118
117
  const broadcast = (event: string, data?: any, childIds?: string | string[]) => {
119
118
  const targetChildren = childIds
120
119
  ? ((Array.isArray(childIds) ? childIds : [childIds])
121
- .map(id => childrenMap.get(id))
122
- .filter(Boolean) as ChildContext[])
120
+ .map(id => childrenMap.get(id))
121
+ .filter(Boolean) as ChildContext[])
123
122
  : Array.from(childrenMap.values());
124
123
 
125
124
  logger.log(`Parent ${name} broadcasting event: ${event} to ${targetChildren.length} children`);
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.4",
6
6
  "description": "uView Pro,是全面支持Vue3的uni-app生态框架,70+精选组件已使用TypeScript重构,已全面支持uni-app Vue3.0",
7
7
  "main": "index.ts",
8
8
  "module": "index.ts",