vue-chat-kit 0.3.7 → 0.3.9

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.
@@ -17,10 +17,25 @@ const defaultConfig = {
17
17
  setChatStatus: '/chart/friend/chat/status',
18
18
  getAvailableUsers: '/chart/user/canAddFriend',
19
19
  searchUser: '/chart/user/search',
20
- getUserInfo: '/user/info',
21
- updateUserInfo: '/user/info',
22
20
  getUserAvatar: '/user/getAvatar',
23
- uploadAvatar: '/user/uploadAvatar'
21
+ uploadAvatar: '/user/uploadAvatar',
22
+ // 群聊相关端点
23
+ createGroup: '/chart/group/create',
24
+ getMyGroups: '/chart/group/my',
25
+ getGroupInfo: '/chart/group/info',
26
+ addGroupMember: '/chart/group/member/add',
27
+ getGroupMembers: '/chart/group/member/list',
28
+ quitGroup: '/chart/group/member/quit',
29
+ getGroupHistory: '/chart/group/history',
30
+ getGroupUnreadCount: '/chart/group/unread/count',
31
+ getMsgReadUserList: '/chart/group/msg/read/list',
32
+ updateGroupInfo: '/chart/group/update/info',
33
+ updateMemberNick: '/chart/group/member/nick/update',
34
+ deleteGroup: '/chart/group/delete',
35
+ removeGroupMember: '/chart/group/member/remove',
36
+ transferGroupOwner: '/chart/group/owner/transfer',
37
+ readSingleGroupMsg: '/chart/group/msg/read/single',
38
+ readAllGroupMsg: '/chart/group/msg/read/all'
24
39
  },
25
40
  adapter: null
26
41
  },
@@ -41,7 +56,9 @@ const defaultConfig = {
41
56
  apply: true,
42
57
  settings: true,
43
58
  fileUpload: true,
44
- avatarCrop: true
59
+ avatarCrop: true,
60
+ groups: true, // 群聊模块
61
+ groupMembers: true // 群成员管理
45
62
  },
46
63
 
47
64
  // 主题配置
@@ -145,26 +145,6 @@ export const customAdapter = {
145
145
  return { code: 200 }
146
146
  },
147
147
 
148
- /**
149
- * 获取用户信息
150
- * @param {string} username - 用户名
151
- * @returns {Promise<{code: number, data: Object}>}
152
- */
153
- async getUserInfo(username) {
154
- console.log('getUserInfo 被调用, username:', username)
155
- return { code: 200, data: { username, nickname: '', avatar: '', email: '', phone: '', bio: '' } }
156
- },
157
-
158
- /**
159
- * 更新用户信息
160
- * @param {string} username - 用户名
161
- * @param {Object} data - 更新的数据
162
- * @returns {Promise<{code: number}>}
163
- */
164
- async updateUserInfo(username, data) {
165
- console.log('updateUserInfo 被调用', { username, data })
166
- return { code: 200 }
167
- },
168
148
 
169
149
  /**
170
150
  * 获取用户头像
@@ -185,5 +165,95 @@ export const customAdapter = {
185
165
  async uploadAvatar(file, username) {
186
166
  console.log('uploadAvatar 被调用', { file, username })
187
167
  return { code: 200, data: '' }
168
+ },
169
+
170
+ // ========== 群聊相关 ==========
171
+
172
+ /**
173
+ * 创建群聊
174
+ * @param {Object} data - 创建群聊数据
175
+ * @returns {Promise<{code: number, data: {groupId: string}}>}
176
+ */
177
+ async createGroup(data) {
178
+ console.log('createGroup 被调用', data)
179
+ return { code: 200, data: { groupId: 'new-group-id' } }
180
+ },
181
+
182
+ /**
183
+ * 获取我的群聊列表
184
+ * @param {string} currentUser - 当前用户名
185
+ * @returns {Promise<{code: number, data: Array}>}
186
+ */
187
+ async getMyGroups(currentUser) {
188
+ console.log('getMyGroups 被调用', currentUser)
189
+ return { code: 200, data: [] }
190
+ },
191
+
192
+ /**
193
+ * 获取群信息
194
+ * @param {string} groupId - 群ID
195
+ * @param {string} currentUser - 当前用户名
196
+ * @returns {Promise<{code: number, data: Object}>}
197
+ */
198
+ async getGroupInfo(groupId, currentUser) {
199
+ console.log('getGroupInfo 被调用', { groupId, currentUser })
200
+ return { code: 200, data: {} }
201
+ },
202
+
203
+ /**
204
+ * 添加群成员
205
+ * @param {string} groupId - 群ID
206
+ * @param {string} targetUser - 目标用户
207
+ * @param {string} currentUser - 当前用户名
208
+ * @returns {Promise<{code: number}>}
209
+ */
210
+ async addGroupMember(groupId, targetUser, currentUser) {
211
+ console.log('addGroupMember 被调用', { groupId, targetUser, currentUser })
212
+ return { code: 200 }
213
+ },
214
+
215
+ /**
216
+ * 批量邀请群成员
217
+ * @param {string} groupId - 群ID
218
+ * @param {string} currentUser - 当前用户名
219
+ * @param {string[]} targetUserList - 目标用户列表
220
+ * @returns {Promise<{code: number}>}
221
+ */
222
+ async inviteGroupMembers(groupId, currentUser, targetUserList) {
223
+ console.log('inviteGroupMembers 被调用', { groupId, currentUser, targetUserList })
224
+ return { code: 200 }
225
+ },
226
+
227
+ /**
228
+ * 获取群成员列表
229
+ * @param {string} groupId - 群ID
230
+ * @param {string} currentUser - 当前用户名
231
+ * @returns {Promise<{code: number, data: Array}>}
232
+ */
233
+ async getGroupMembers(groupId, currentUser) {
234
+ console.log('getGroupMembers 被调用', { groupId, currentUser })
235
+ return { code: 200, data: [] }
236
+ },
237
+
238
+ /**
239
+ * 退出群聊
240
+ * @param {string} groupId - 群ID
241
+ * @param {string} currentUser - 当前用户名
242
+ * @returns {Promise<{code: number}>}
243
+ */
244
+ async quitGroup(groupId, currentUser) {
245
+ console.log('quitGroup 被调用', { groupId, currentUser })
246
+ return { code: 200 }
247
+ },
248
+
249
+ /**
250
+ * 获取群聊历史消息
251
+ * @param {string} groupId - 群ID
252
+ * @param {string} currentUser - 当前用户名
253
+ * @returns {Promise<{code: number, data: Array}>}
254
+ */
255
+ async getGroupHistory(groupId, currentUser) {
256
+ console.log('getGroupHistory 被调用', { groupId, currentUser })
257
+ return { code: 200, data: [] }
188
258
  }
189
259
  }
package/src/core/api.js CHANGED
@@ -149,19 +149,6 @@ export class ChatApi {
149
149
  return this.http.post(this.endpoints.uploadFile, formData)
150
150
  }
151
151
 
152
- // ========== 用户相关 ==========
153
-
154
- /**
155
- * 获取用户信息
156
- */
157
- async getUserInfo(username) {
158
- return this._call('getUserInfo', username)
159
- }
160
-
161
- async _getUserInfo(username) {
162
- return this.http.get(this.endpoints.getUserInfo, { username })
163
- }
164
-
165
152
  /**
166
153
  * 更新用户信息
167
154
  */
@@ -197,6 +184,195 @@ export class ChatApi {
197
184
  formData.append('username', username)
198
185
  return this.http.post(this.endpoints.uploadAvatar, formData)
199
186
  }
187
+
188
+ // ========== 群聊相关 ==========
189
+
190
+ /**
191
+ * 创建群聊
192
+ */
193
+ async createGroup(data) {
194
+ return this._call('createGroup', data)
195
+ }
196
+
197
+ async _createGroup(data) {
198
+ return this.http.post(this.endpoints.createGroup, data)
199
+ }
200
+
201
+ /**
202
+ * 获取我的群聊列表
203
+ */
204
+ async getMyGroups(currentUser) {
205
+ return this._call('getMyGroups', currentUser)
206
+ }
207
+
208
+ async _getMyGroups(currentUser) {
209
+ return this.http.get(this.endpoints.getMyGroups, { currentUser })
210
+ }
211
+
212
+ /**
213
+ * 获取群信息
214
+ */
215
+ async getGroupInfo(groupId, currentUser) {
216
+ return this._call('getGroupInfo', groupId, currentUser)
217
+ }
218
+
219
+ async _getGroupInfo(groupId, currentUser) {
220
+ return this.http.get(this.endpoints.getGroupInfo, { groupId, currentUser })
221
+ }
222
+
223
+ /**
224
+ * 添加群成员(单个)
225
+ */
226
+ async addGroupMember(groupId, targetUser, currentUser) {
227
+ return this._call('addGroupMember', groupId, targetUser, currentUser)
228
+ }
229
+
230
+ async _addGroupMember(groupId, targetUser, currentUser) {
231
+ return this.http.post(this.endpoints.addGroupMember, null, { params: { groupId, targetUser, currentUser } })
232
+ }
233
+
234
+ /**
235
+ * 批量邀请群成员
236
+ */
237
+ async inviteGroupMembers(groupId, currentUser, targetUserList) {
238
+ return this._call('inviteGroupMembers', groupId, currentUser, targetUserList)
239
+ }
240
+
241
+ async _inviteGroupMembers(groupId, currentUser, targetUserList) {
242
+ return this.http.post(this.endpoints.addGroupMember, { groupId, currentUser, targetUserList })
243
+ }
244
+
245
+ /**
246
+ * 获取群成员列表
247
+ */
248
+ async getGroupMembers(groupId, currentUser) {
249
+ return this._call('getGroupMembers', groupId, currentUser)
250
+ }
251
+
252
+ async _getGroupMembers(groupId, currentUser) {
253
+ return this.http.get(this.endpoints.getGroupMembers, { groupId, currentUser })
254
+ }
255
+
256
+ /**
257
+ * 退出群聊
258
+ */
259
+ async quitGroup(groupId, currentUser) {
260
+ return this._call('quitGroup', groupId, currentUser)
261
+ }
262
+
263
+ async _quitGroup(groupId, currentUser) {
264
+ return this.http.post(this.endpoints.quitGroup, null, { params: { groupId, currentUser } })
265
+ }
266
+
267
+ /**
268
+ * 获取群聊历史消息
269
+ */
270
+ async getGroupHistory(groupId, currentUser) {
271
+ return this._call('getGroupHistory', groupId, currentUser)
272
+ }
273
+
274
+ async _getGroupHistory(groupId, currentUser) {
275
+ return this.http.get(this.endpoints.getGroupHistory, { groupId, currentUser })
276
+ }
277
+
278
+ /**
279
+ * 获取群未读消息总数
280
+ */
281
+ async getGroupUnreadCount(groupId, currentUser) {
282
+ return this._call('getGroupUnreadCount', groupId, currentUser)
283
+ }
284
+
285
+ async _getGroupUnreadCount(groupId, currentUser) {
286
+ return this.http.get(this.endpoints.getGroupUnreadCount, { groupId, currentUser })
287
+ }
288
+
289
+ /**
290
+ * 获取单条群消息的已读/未读成员名单
291
+ */
292
+ async getMsgReadUserList(groupId, groupMsgId, currentUser) {
293
+ return this._call('getMsgReadUserList', groupId, groupMsgId, currentUser)
294
+ }
295
+
296
+ async _getMsgReadUserList(groupId, groupMsgId, currentUser) {
297
+ return this.http.get(this.endpoints.getMsgReadUserList, { groupId, groupMsgId, currentUser })
298
+ }
299
+
300
+ /**
301
+ * 修改群基础信息(群主专用)
302
+ */
303
+ async updateGroupInfo(groupId, currentUser, groupNickname, remark, notice) {
304
+ return this._call('updateGroupInfo', groupId, currentUser, groupNickname, remark, notice)
305
+ }
306
+
307
+ async _updateGroupInfo(groupId, currentUser, groupNickname, remark, notice) {
308
+ return this.http.post(this.endpoints.updateGroupInfo, { groupId, currentUser, groupNickname, remark, notice })
309
+ }
310
+
311
+ /**
312
+ * 修改群成员专属昵称
313
+ */
314
+ async updateMemberNick(groupId, currentUser, targetUsername, memberNick) {
315
+ return this._call('updateMemberNick', groupId, currentUser, targetUsername, memberNick)
316
+ }
317
+
318
+ async _updateMemberNick(groupId, currentUser, targetUsername, memberNick) {
319
+ return this.http.post(this.endpoints.updateMemberNick, { groupId, currentUser, targetUsername, memberNick })
320
+ }
321
+
322
+ /**
323
+ * 群主解散/删除群聊
324
+ */
325
+ async deleteGroup(groupId, currentUser) {
326
+ return this._call('deleteGroup', groupId, currentUser)
327
+ }
328
+
329
+ async _deleteGroup(groupId, currentUser) {
330
+ return this.http.post(this.endpoints.deleteGroup, { groupId, currentUser })
331
+ }
332
+
333
+ /**
334
+ * 群主移除群成员
335
+ */
336
+ async removeGroupMember(groupId, currentUser, targetUsername) {
337
+ return this._call('removeGroupMember', groupId, currentUser, targetUsername)
338
+ }
339
+
340
+ async _removeGroupMember(groupId, currentUser, targetUsername) {
341
+ return this.http.post(this.endpoints.removeGroupMember, { groupId, currentUser, targetUsername })
342
+ }
343
+
344
+ /**
345
+ * 转让群主权限
346
+ */
347
+ async transferGroupOwner(groupId, currentUser, newOwnerUsername) {
348
+ return this._call('transferGroupOwner', groupId, currentUser, newOwnerUsername)
349
+ }
350
+
351
+ async _transferGroupOwner(groupId, currentUser, newOwnerUsername) {
352
+ return this.http.post(this.endpoints.transferGroupOwner, { groupId, currentUser, newOwnerUsername })
353
+ }
354
+
355
+ /**
356
+ * 标记单条群消息为已读
357
+ */
358
+ async readSingleGroupMsg(groupId, currentUser, groupMsgId) {
359
+ return this._call('readSingleGroupMsg', groupId, currentUser, groupMsgId)
360
+ }
361
+
362
+ async _readSingleGroupMsg(groupId, currentUser, groupMsgId) {
363
+ return this.http.post(this.endpoints.readSingleGroupMsg, { groupId, currentUser, groupMsgId })
364
+ }
365
+
366
+ /**
367
+ * 一键标记当前群全部未读消息为已读
368
+ */
369
+ async readAllGroupMsg(groupId, currentUser) {
370
+ return this._call('readAllGroupMsg', groupId, currentUser)
371
+ }
372
+
373
+ async _readAllGroupMsg(groupId, currentUser) {
374
+ return this.http.post(this.endpoints.readAllGroupMsg, { groupId, currentUser })
375
+ }
200
376
  }
201
377
 
202
378
  export default ChatApi
@@ -70,17 +70,33 @@ export class ChatWebSocket {
70
70
 
71
71
  /**
72
72
  * 发送消息
73
+ * @param {string} target - 目标用户或群ID
74
+ * @param {string} message - 消息内容
75
+ * @param {string} type - 消息类型
76
+ * @param {string} fileUrl - 文件地址
77
+ * @param {string} fileName - 文件名
78
+ * @param {number} fileSize - 文件大小
79
+ * @param {boolean} isGroup - 是否为群聊消息
73
80
  */
74
- send(to, message, type = 'text', fileUrl = '', fileName = '', fileSize = 0) {
81
+ send(target, message, type = 'text', fileUrl = '', fileName = '', fileSize = 0, isGroup = false) {
75
82
  if (this.isConnected()) {
76
- const data = JSON.stringify({
77
- to,
78
- msg: message,
79
- type,
80
- fileUrl,
81
- fileName,
82
- fileSize
83
- })
83
+ const data = isGroup
84
+ ? JSON.stringify({
85
+ toGroupId: target,
86
+ msg: message,
87
+ type,
88
+ fileUrl,
89
+ fileName,
90
+ fileSize
91
+ })
92
+ : JSON.stringify({
93
+ to: target,
94
+ msg: message,
95
+ type,
96
+ fileUrl,
97
+ fileName,
98
+ fileSize
99
+ })
84
100
  this.socket.send(data)
85
101
  return true
86
102
  }
package/src/index.js CHANGED
@@ -3,14 +3,11 @@ import './style.css'
3
3
 
4
4
  // 先导入组件用于 Vue 插件
5
5
  import ChatPanel from './components/ChatPanel.vue'
6
- import ChatWindow from './components/ChatWindow.vue'
7
6
  import AvatarCrop from './components/AvatarCrop.vue'
8
7
 
9
8
  // 导出组件 - 新的独立面板组件(推荐使用)
10
9
  export { ChatPanel }
11
10
 
12
- // 保留旧版弹窗组件,向后兼容
13
- export { ChatWindow }
14
11
 
15
12
  export { AvatarCrop }
16
13
 
@@ -32,7 +29,6 @@ export { HttpClient } from './core/request.js'
32
29
  export const VueChatKit = {
33
30
  install(app) {
34
31
  app.component('ChatPanel', ChatPanel)
35
- app.component('ChatWindow', ChatWindow)
36
32
  app.component('AvatarCrop', AvatarCrop)
37
33
  }
38
34
  }