vue-chat-kit 0.1.3 → 0.2.2
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/README.md +121 -54
- package/dist/vue-chat-kit.css +1 -1
- package/dist/vue-chat-kit.es.js +1990 -1062
- package/dist/vue-chat-kit.umd.js +1 -1
- package/package.json +4 -3
- package/src/components/ChatPanel.vue +2089 -0
- package/src/composables/useChat.js +17 -2
- package/src/config/index.js +6 -0
- package/src/core/api.js +3 -1
- package/src/core/request.js +15 -1
- package/src/index.js +6 -1
- package/src/style.css +23 -3
|
@@ -6,7 +6,7 @@ import dayjs from 'dayjs'
|
|
|
6
6
|
import { ChatWebSocket } from '../core/websocket.js'
|
|
7
7
|
import { ChatApi } from '../core/api.js'
|
|
8
8
|
|
|
9
|
-
export function useChat(config) {
|
|
9
|
+
export function useChat(config, emit) {
|
|
10
10
|
// ========== 配置 ==========
|
|
11
11
|
const api = new ChatApi(config)
|
|
12
12
|
let socket = null
|
|
@@ -378,11 +378,21 @@ export function useChat(config) {
|
|
|
378
378
|
|
|
379
379
|
const msgInfo = parseWsMessage(data)
|
|
380
380
|
if (msgInfo) {
|
|
381
|
+
const message = {
|
|
382
|
+
content: msgInfo.content,
|
|
383
|
+
username: msgInfo.username || currentSelectName.value,
|
|
384
|
+
type: msgInfo.type || 'text',
|
|
385
|
+
fileUrl: msgInfo.fileUrl || '',
|
|
386
|
+
fileName: msgInfo.fileName || '',
|
|
387
|
+
fileSize: msgInfo.fileSize || 0,
|
|
388
|
+
timestamp: new Date()
|
|
389
|
+
}
|
|
390
|
+
|
|
381
391
|
if (currentSelectName.value) {
|
|
382
392
|
try {
|
|
383
393
|
let tempMsg = {
|
|
384
394
|
msgContent: msgInfo.content,
|
|
385
|
-
sendUsername:
|
|
395
|
+
sendUsername: message.username,
|
|
386
396
|
receiveUsername: myUsername,
|
|
387
397
|
createTime: new Date(),
|
|
388
398
|
isRead: 0,
|
|
@@ -399,6 +409,11 @@ export function useChat(config) {
|
|
|
399
409
|
getChatHistory(currentSelectName.value)
|
|
400
410
|
}
|
|
401
411
|
getFriendList()
|
|
412
|
+
|
|
413
|
+
// emit 消息事件
|
|
414
|
+
if (emit && typeof emit === 'function') {
|
|
415
|
+
emit(message)
|
|
416
|
+
}
|
|
402
417
|
}
|
|
403
418
|
}
|
|
404
419
|
|
package/src/config/index.js
CHANGED
package/src/core/api.js
CHANGED
|
@@ -14,7 +14,9 @@ export class ChatApi {
|
|
|
14
14
|
} else {
|
|
15
15
|
this.http = new HttpClient({
|
|
16
16
|
baseUrl: config.api.baseUrl,
|
|
17
|
-
headers: config.headers
|
|
17
|
+
headers: config.headers,
|
|
18
|
+
requestInterceptors: config.requestInterceptors,
|
|
19
|
+
responseInterceptors: config.responseInterceptors
|
|
18
20
|
})
|
|
19
21
|
}
|
|
20
22
|
}
|
package/src/core/request.js
CHANGED
|
@@ -22,7 +22,14 @@ export class HttpClient {
|
|
|
22
22
|
this.requestInterceptors = []
|
|
23
23
|
this.responseInterceptors = []
|
|
24
24
|
|
|
25
|
-
//
|
|
25
|
+
// 先添加用户传入的请求拦截器(如果有)
|
|
26
|
+
if (config.requestInterceptors && Array.isArray(config.requestInterceptors)) {
|
|
27
|
+
config.requestInterceptors.forEach(interceptor => {
|
|
28
|
+
this.requestInterceptors.push(interceptor)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 默认添加 Content-Type(放在用户拦截器之后,让用户可以覆盖)
|
|
26
33
|
this.addRequestInterceptor((config) => {
|
|
27
34
|
if (!(config.body instanceof FormData)) {
|
|
28
35
|
config.headers = {
|
|
@@ -32,6 +39,13 @@ export class HttpClient {
|
|
|
32
39
|
}
|
|
33
40
|
return config
|
|
34
41
|
})
|
|
42
|
+
|
|
43
|
+
// 添加用户传入的响应拦截器(如果有)
|
|
44
|
+
if (config.responseInterceptors && Array.isArray(config.responseInterceptors)) {
|
|
45
|
+
config.responseInterceptors.forEach(interceptor => {
|
|
46
|
+
this.responseInterceptors.push(interceptor)
|
|
47
|
+
})
|
|
48
|
+
}
|
|
35
49
|
}
|
|
36
50
|
|
|
37
51
|
/**
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// 导入样式
|
|
2
2
|
import './style.css'
|
|
3
3
|
|
|
4
|
-
// 导出组件
|
|
4
|
+
// 导出组件 - 新的独立面板组件(推荐使用)
|
|
5
|
+
export { default as ChatPanel } from './components/ChatPanel.vue'
|
|
6
|
+
|
|
7
|
+
// 保留旧版弹窗组件,向后兼容
|
|
5
8
|
export { default as ChatWindow } from './components/ChatWindow.vue'
|
|
9
|
+
|
|
6
10
|
export { default as AvatarCrop } from './components/AvatarCrop.vue'
|
|
7
11
|
|
|
8
12
|
// 导出 composables
|
|
@@ -22,6 +26,7 @@ export { HttpClient } from './core/request.js'
|
|
|
22
26
|
// 安装函数,用于 Vue 插件安装
|
|
23
27
|
export const VueChatKit = {
|
|
24
28
|
install(app) {
|
|
29
|
+
app.component('ChatPanel', ChatPanel)
|
|
25
30
|
app.component('ChatWindow', ChatWindow)
|
|
26
31
|
app.component('AvatarCrop', AvatarCrop)
|
|
27
32
|
}
|
package/src/style.css
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/* Vue Chat Kit - 基础样式 */
|
|
2
|
+
|
|
3
|
+
/* 这个文件是为了兼容,主要样式都在组件内部 */
|
|
4
|
+
|
|
5
|
+
/* 一些全局的辅助类和重置 */
|
|
6
|
+
*, *::before, *::after {
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/* 简单的滚动条样式 */
|
|
11
|
+
::-webkit-scrollbar {
|
|
12
|
+
width: 6px;
|
|
13
|
+
height: 6px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
::-webkit-scrollbar-thumb {
|
|
17
|
+
background: #ccc;
|
|
18
|
+
border-radius: 3px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
::-webkit-scrollbar-track {
|
|
22
|
+
background: transparent;
|
|
23
|
+
}
|