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.
- package/changelog.md +61 -18
- package/components/u-action-sheet/types.ts +10 -3
- package/components/u-action-sheet/u-action-sheet.vue +21 -9
- package/components/u-action-sheet-item/types.ts +27 -0
- package/components/u-action-sheet-item/u-action-sheet-item.vue +85 -0
- package/components/u-checkbox-group/u-checkbox-group.vue +3 -2
- package/components/u-form-item/u-form-item.vue +15 -25
- package/components/u-input/u-input.vue +12 -11
- package/components/u-line-progress/u-line-progress.vue +1 -1
- package/components/u-popup/u-popup.vue +12 -17
- package/components/u-radio-group/u-radio-group.vue +3 -3
- package/components/u-safe-bottom/props.ts +11 -0
- package/components/u-safe-bottom/u-safe-bottom.vue +12 -17
- package/components/u-search/u-search.vue +14 -3
- package/components/u-status-bar/props.ts +13 -0
- package/components/u-status-bar/u-status-bar.vue +13 -23
- package/components/u-subsection/u-subsection.vue +28 -9
- package/libs/function/addUnit.ts +40 -3
- package/libs/hooks/index.ts +0 -1
- package/libs/hooks/useCompRelation.ts +13 -1
- package/libs/index.ts +0 -11
- package/package.json +1 -1
- package/types/components.d.ts +2 -2
- package/libs/hooks/useComponent.ts +0 -759
- package/libs/hooks/useParent.ts +0 -33
- package/libs/util/eventBus.ts +0 -86
- package/libs/util/parent.ts +0 -20
package/libs/hooks/useParent.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { getCurrentInstance, onUnmounted } from 'vue';
|
|
2
|
-
|
|
3
|
-
export function useParent(name: string) {
|
|
4
|
-
const instance = getCurrentInstance();
|
|
5
|
-
|
|
6
|
-
function getParent() {
|
|
7
|
-
if (!instance) return null;
|
|
8
|
-
|
|
9
|
-
// 查找父组件
|
|
10
|
-
let parent: any = instance.parent;
|
|
11
|
-
while (parent) {
|
|
12
|
-
const parentName = parent.type?.name;
|
|
13
|
-
if (parentName === name) break;
|
|
14
|
-
parent = parent.parent;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// 建立父子关系
|
|
18
|
-
if (parent) {
|
|
19
|
-
(parent as any).children = (parent as any).children || [];
|
|
20
|
-
(parent as any).children.push(instance);
|
|
21
|
-
// 卸载时移除
|
|
22
|
-
onUnmounted(() => {
|
|
23
|
-
const i = parent.children.indexOf(instance);
|
|
24
|
-
i > -1 && parent.children.splice(i, 1);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return parent;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
getParent
|
|
32
|
-
};
|
|
33
|
-
}
|
package/libs/util/eventBus.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// utils/eventBus.ts
|
|
2
|
-
|
|
3
|
-
// 更灵活的事件回调类型定义
|
|
4
|
-
type EventCallback = (data?: any, ...args: any[]) => void;
|
|
5
|
-
|
|
6
|
-
class EventBus {
|
|
7
|
-
private events: Map<string, EventCallback[]> = new Map();
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 监听事件
|
|
11
|
-
*/
|
|
12
|
-
on(event: string, callback: EventCallback): void {
|
|
13
|
-
if (!this.events.has(event)) {
|
|
14
|
-
this.events.set(event, []);
|
|
15
|
-
}
|
|
16
|
-
this.events.get(event)!.push(callback);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 一次性监听
|
|
21
|
-
*/
|
|
22
|
-
once(event: string, callback: EventCallback): void {
|
|
23
|
-
const onceCallback: EventCallback = (data, ...args) => {
|
|
24
|
-
callback(data, ...args);
|
|
25
|
-
this.off(event, onceCallback);
|
|
26
|
-
};
|
|
27
|
-
this.on(event, onceCallback);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 触发事件
|
|
32
|
-
*/
|
|
33
|
-
emit(event: string, data?: any, ...args: any[]): void {
|
|
34
|
-
if (this.events.has(event)) {
|
|
35
|
-
this.events.get(event)!.forEach(callback => {
|
|
36
|
-
try {
|
|
37
|
-
callback(data, ...args);
|
|
38
|
-
} catch (error) {
|
|
39
|
-
console.error(`EventBus error in ${event}:`, error);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 取消监听
|
|
47
|
-
*/
|
|
48
|
-
off(event: string, callback?: EventCallback): void {
|
|
49
|
-
if (!this.events.has(event)) return;
|
|
50
|
-
|
|
51
|
-
if (callback) {
|
|
52
|
-
const callbacks = this.events.get(event)!;
|
|
53
|
-
const index = callbacks.indexOf(callback);
|
|
54
|
-
if (index > -1) {
|
|
55
|
-
callbacks.splice(index, 1);
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
this.events.delete(event);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 检查是否有监听器
|
|
64
|
-
*/
|
|
65
|
-
has(event: string): boolean {
|
|
66
|
-
return this.events.has(event) && this.events.get(event)!.length > 0;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* 清理所有事件
|
|
71
|
-
*/
|
|
72
|
-
clear(): void {
|
|
73
|
-
this.events.clear();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// 创建全局实例
|
|
78
|
-
export const eventBus = new EventBus();
|
|
79
|
-
|
|
80
|
-
// 热更新处理
|
|
81
|
-
if (import.meta.hot) {
|
|
82
|
-
import.meta.hot.accept(() => {
|
|
83
|
-
// 热更新时不清理事件,保持事件监听
|
|
84
|
-
console.log('EventBus hot updated');
|
|
85
|
-
});
|
|
86
|
-
}
|
package/libs/util/parent.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type ComponentInternalInstance, getCurrentInstance } from 'vue';
|
|
2
|
-
|
|
3
|
-
export function parent(componentName?: string) {
|
|
4
|
-
const instance: ComponentInternalInstance | null | undefined = getCurrentInstance();
|
|
5
|
-
let parent = instance && (instance.parent as ComponentInternalInstance | null | undefined);
|
|
6
|
-
|
|
7
|
-
while (parent) {
|
|
8
|
-
const name = (parent.type as any)?.name as string | undefined;
|
|
9
|
-
if (name === componentName) {
|
|
10
|
-
return parent;
|
|
11
|
-
}
|
|
12
|
-
parent = parent.parent;
|
|
13
|
-
}
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function parentData(componentName?: string) {
|
|
18
|
-
const parentData = parent(componentName);
|
|
19
|
-
return parentData?.exposed ?? null;
|
|
20
|
-
}
|