im-ui-mobile 0.0.59 → 0.0.60
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/components/im-chat-record/im-chat-record.vue +12 -10
- package/index.js +2 -0
- package/index.scss +17 -0
- package/package.json +3 -2
- package/types/utils/eventBus.d.ts +88 -0
- package/types/utils/requester.d.ts +1 -1
- package/utils/eventBus.js +8 -6
- package/types/utils/env.d.ts +0 -11
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
</template>
|
|
27
27
|
|
|
28
28
|
<script setup lang="ts">
|
|
29
|
-
import { ref, computed } from 'vue'
|
|
29
|
+
import { ref, computed, onUnmounted } from 'vue'
|
|
30
30
|
import { recorderApp, recorderH5 } from '../../index'
|
|
31
31
|
|
|
32
32
|
const recording = ref(false);
|
|
@@ -37,11 +37,11 @@ const rcTimer = ref<number | null>(null);
|
|
|
37
37
|
|
|
38
38
|
const getRecorder = () => {
|
|
39
39
|
// #ifdef H5
|
|
40
|
-
return recorderH5
|
|
40
|
+
return new recorderH5()
|
|
41
41
|
// #endif
|
|
42
42
|
|
|
43
43
|
// #ifndef H5
|
|
44
|
-
return recorderApp
|
|
44
|
+
return new recorderApp()
|
|
45
45
|
// #endif
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -53,6 +53,11 @@ interface Emits {
|
|
|
53
53
|
}
|
|
54
54
|
const emit = defineEmits<Emits>();
|
|
55
55
|
|
|
56
|
+
onUnmounted(() => {
|
|
57
|
+
stopTimer();
|
|
58
|
+
recording.value = false;
|
|
59
|
+
})
|
|
60
|
+
|
|
56
61
|
const onTouchMove = (e: any) => {
|
|
57
62
|
const moveY = e.touches[0].clientY;
|
|
58
63
|
moveToCancel.value = moveY < recordBarTop.value - 40;
|
|
@@ -84,7 +89,7 @@ const onStartRecord = async () => {
|
|
|
84
89
|
console.log("开始录音成功");
|
|
85
90
|
// 开始计时
|
|
86
91
|
startTimer();
|
|
87
|
-
}).catch((e) => {
|
|
92
|
+
}).catch((e: any) => {
|
|
88
93
|
console.log("录音失败" + JSON.stringify(e));
|
|
89
94
|
uni.showToast({
|
|
90
95
|
title: "录音失败",
|
|
@@ -116,9 +121,9 @@ const onEndRecord = () => {
|
|
|
116
121
|
return;
|
|
117
122
|
}
|
|
118
123
|
|
|
119
|
-
rc.upload().then((data) => {
|
|
124
|
+
rc.upload().then((data: any) => {
|
|
120
125
|
emit("send", data);
|
|
121
|
-
}).catch((e) => {
|
|
126
|
+
}).catch((e: any) => {
|
|
122
127
|
uni.showToast({
|
|
123
128
|
title: e,
|
|
124
129
|
icon: 'none'
|
|
@@ -200,10 +205,7 @@ const recordTip = computed(() => {
|
|
|
200
205
|
return `录音时长:${druation.value}s`;
|
|
201
206
|
});
|
|
202
207
|
|
|
203
|
-
|
|
204
|
-
stopTimer();
|
|
205
|
-
recording.value = false;
|
|
206
|
-
});
|
|
208
|
+
|
|
207
209
|
</script>
|
|
208
210
|
|
|
209
211
|
<style lang="scss" scoped>
|
package/index.js
CHANGED
package/index.scss
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.emoji-large {
|
|
2
|
+
width: 64rpx !important;
|
|
3
|
+
height: 64rpx !important;
|
|
4
|
+
vertical-align: bottom !important;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.emoji-normal {
|
|
8
|
+
width: 54rpx !important;
|
|
9
|
+
height: 54rpx !important;
|
|
10
|
+
vertical-align: bottom !important;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.emoji-small {
|
|
14
|
+
width: 36rpx !important;
|
|
15
|
+
height: 36rpx !important;
|
|
16
|
+
vertical-align: bottom !important;
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "im-ui-mobile",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60",
|
|
4
4
|
"description": "A Vue3.0 + typescript instant messaging component library for Uniapp",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"utils",
|
|
13
13
|
"plugins",
|
|
14
14
|
"index.js",
|
|
15
|
-
"theme.scss"
|
|
15
|
+
"theme.scss",
|
|
16
|
+
"index.scss"
|
|
16
17
|
],
|
|
17
18
|
"scripts": {
|
|
18
19
|
"wx": "cd examples && npm run dev:mp-weixin",
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 事件总线类
|
|
3
|
+
*/
|
|
4
|
+
declare class EventBus {
|
|
5
|
+
private events: Map<string, Set<Function>>;
|
|
6
|
+
private globalListeners: Set<Function>;
|
|
7
|
+
|
|
8
|
+
constructor();
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 监听特定事件
|
|
12
|
+
* @param eventName 事件名称
|
|
13
|
+
* @param callback 回调函数
|
|
14
|
+
*/
|
|
15
|
+
on<T = any>(eventName: string, callback: (data: T) => void): void;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 监听所有事件
|
|
19
|
+
* @param callback 全局回调函数
|
|
20
|
+
*/
|
|
21
|
+
onAll(callback: (eventName: string, data: any) => void): void;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 一次性监听特定事件
|
|
25
|
+
* @param eventName 事件名称
|
|
26
|
+
* @param callback 回调函数
|
|
27
|
+
*/
|
|
28
|
+
once<T = any>(eventName: string, callback: (data: T) => void): void;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 触发事件
|
|
32
|
+
* @param eventName 事件名称
|
|
33
|
+
* @param data 事件数据
|
|
34
|
+
*/
|
|
35
|
+
emit<T = any>(eventName: string, data?: T): void;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 移除事件监听器
|
|
39
|
+
* @param eventName 事件名称
|
|
40
|
+
* @param callback 要移除的回调函数(不传则移除所有监听器)
|
|
41
|
+
*/
|
|
42
|
+
off(eventName: string, callback?: Function): void;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 移除所有事件监听器
|
|
46
|
+
*/
|
|
47
|
+
offAll(): void;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 移除全局监听器
|
|
51
|
+
* @param callback 要移除的全局回调函数(不传则移除所有全局监听器)
|
|
52
|
+
*/
|
|
53
|
+
offAllListener(callback?: Function): void;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 获取事件监听器数量
|
|
57
|
+
* @param eventName 事件名称(不传则返回所有事件的总数)
|
|
58
|
+
* @returns 监听器数量
|
|
59
|
+
*/
|
|
60
|
+
getEventCount(eventName?: string): number;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 检查是否存在特定事件的监听器
|
|
64
|
+
* @param eventName 事件名称
|
|
65
|
+
* @returns 是否存在监听器
|
|
66
|
+
*/
|
|
67
|
+
hasEvent(eventName: string): boolean;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 获取所有已注册的事件名称
|
|
71
|
+
* @returns 事件名称数组
|
|
72
|
+
*/
|
|
73
|
+
getEventNames(): string[];
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 清空所有事件(包括全局监听器)
|
|
77
|
+
*/
|
|
78
|
+
clear(): void;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 销毁事件总线实例
|
|
82
|
+
*/
|
|
83
|
+
destroy(): void;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
declare const eventBus: EventBus;
|
|
87
|
+
export { eventBus, EventBus };
|
|
88
|
+
export default eventBus;
|
|
@@ -6,7 +6,7 @@ export default class Requester {
|
|
|
6
6
|
private timeout;
|
|
7
7
|
private headers;
|
|
8
8
|
private accessToken;
|
|
9
|
-
constructor(baseURL: string,
|
|
9
|
+
constructor(baseURL: string, options?: Partial<UniApp.RequestOptions>);
|
|
10
10
|
setToken(token: string): void;
|
|
11
11
|
request<T = any>(options: Partial<UniApp.RequestOptions>): Promise<Response<T>>;
|
|
12
12
|
get<T = any>(url: string, data?: any, options?: Partial<UniApp.RequestOptions>): Promise<Response<T>>;
|
package/utils/eventBus.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 事件总线类
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
class EventBus {
|
|
5
5
|
constructor() {
|
|
6
6
|
/**
|
|
7
7
|
* 存储事件和对应的回调函数列表
|
|
8
8
|
* @private
|
|
9
9
|
*/
|
|
10
10
|
this.events = new Map();
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
/**
|
|
13
13
|
* 存储全局监听器
|
|
14
14
|
* @private
|
|
@@ -99,11 +99,11 @@ export default class EventBus {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
const callbacks = this.events.get(eventName);
|
|
102
|
-
|
|
102
|
+
|
|
103
103
|
if (callback) {
|
|
104
104
|
// 移除特定的回调函数
|
|
105
105
|
callbacks.delete(callback);
|
|
106
|
-
|
|
106
|
+
|
|
107
107
|
// 如果该事件没有监听器了,删除事件
|
|
108
108
|
if (callbacks.size === 0) {
|
|
109
109
|
this.events.delete(eventName);
|
|
@@ -143,7 +143,7 @@ export default class EventBus {
|
|
|
143
143
|
const callbacks = this.events.get(eventName);
|
|
144
144
|
return callbacks ? callbacks.size : 0;
|
|
145
145
|
}
|
|
146
|
-
|
|
146
|
+
|
|
147
147
|
// 计算所有事件的监听器总数
|
|
148
148
|
let total = 0;
|
|
149
149
|
for (const callbacks of this.events.values()) {
|
|
@@ -187,5 +187,7 @@ export default class EventBus {
|
|
|
187
187
|
this.globalListeners = null;
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
+
|
|
190
191
|
const eventBus = new EventBus()
|
|
191
|
-
export {eventBus}
|
|
192
|
+
export { eventBus, EventBus }
|
|
193
|
+
export default eventBus
|