mdm-im-v3 1.4.1 → 1.4.3
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 +7 -0
- package/README.md +19 -16
- package/dist/core.es.js +4 -2
- package/dist/{index-CKBF2vQ0.js → index-CeZkCy7e.js} +1687 -1684
- package/dist/index.es.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -63,12 +63,11 @@ const handleLogin = () => {
|
|
|
63
63
|
|
|
64
64
|
```js
|
|
65
65
|
// ========== 步骤1:core/index.js — 应用入口处登录 IM ==========
|
|
66
|
-
import {
|
|
67
|
-
|
|
68
|
-
const chatStore = useChatStore()
|
|
66
|
+
import { watch } from 'vue'
|
|
67
|
+
import { useMessage } from 'mdm-im-v3/core'
|
|
69
68
|
|
|
70
|
-
// 传入配置参数,自动保存到 store
|
|
71
|
-
const { initIMSDK, getUnReadMessageCount } = useMessage({
|
|
69
|
+
// 传入配置参数,自动保存到 store;同时解构出 loginStatus 用于监控
|
|
70
|
+
const { initIMSDK, getUnReadMessageCount, loginStatus, messageStore } = useMessage({
|
|
72
71
|
userID: 'your-account', // 用户 ID,必填
|
|
73
72
|
nickname: 'your-name', // 用户昵称
|
|
74
73
|
faceURL: '', // 用户头像
|
|
@@ -83,16 +82,13 @@ const { initIMSDK, getUnReadMessageCount } = useMessage({
|
|
|
83
82
|
// 初始化并登录
|
|
84
83
|
await initIMSDK()
|
|
85
84
|
|
|
86
|
-
//
|
|
87
|
-
watch(
|
|
88
|
-
()
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// 从服务端获取未读消息总数
|
|
92
|
-
getUnReadMessageCount(true)
|
|
93
|
-
}
|
|
85
|
+
// 监控 IM 登录状态,登录成功后获取未读数
|
|
86
|
+
watch(loginStatus, status => {
|
|
87
|
+
if (status === 3) {
|
|
88
|
+
// 从服务端获取未读消息总数
|
|
89
|
+
getUnReadMessageCount(true)
|
|
94
90
|
}
|
|
95
|
-
)
|
|
91
|
+
})
|
|
96
92
|
```
|
|
97
93
|
|
|
98
94
|
```vue
|
|
@@ -199,7 +195,7 @@ chatRef.value.inviteUser('group-id-xxx', ['user1', 'user2'])
|
|
|
199
195
|
|
|
200
196
|
## `useMessage` API
|
|
201
197
|
|
|
202
|
-
从 `mdm-im-v3/core` 导入,用于手动管理 IM
|
|
198
|
+
从 `mdm-im-v3/core` 导入,用于手动管理 IM 生命周期。该模块同时导出 `useMessage` 和 `useChatStore`:
|
|
203
199
|
|
|
204
200
|
```js
|
|
205
201
|
import { useMessage, useChatStore } from 'mdm-im-v3/core'
|
|
@@ -240,6 +236,8 @@ const { initIMSDK, clearInstance, getUnReadMessageCount, setConversationMsgAsRea
|
|
|
240
236
|
|
|
241
237
|
| 方法/属性 | 说明 |
|
|
242
238
|
|-----------|------|
|
|
239
|
+
| `messageStore` | Pinia store 实例(`useChatStore()`),可直接访问所有 state/getters/actions |
|
|
240
|
+
| `loginStatus` | IM 登录状态的 `computed` 引用,便于外部 `watch` 监控。值:1-未登录,2-登录中,3-已登录 |
|
|
243
241
|
| `initIMSDK()` | 初始化 SDK → 绑定所有 OpenIM 事件 → 登录。需先在 store 中设置 userID、imToken、apiUrl 等。返回 `Promise<void>`。 |
|
|
244
242
|
| `clearInstance(bool)` | 解绑事件 → 登出 → 清除 SDK 实例。传入 `true` 时同时清空会话列表和 `window.imInstance`。 |
|
|
245
243
|
| `getUnReadMessageCount(fromServer?)` | 获取未读消息总数。`fromServer=true` 从服务端获取,默认从本地会话列表累计。 |
|
|
@@ -250,7 +248,12 @@ const { initIMSDK, clearInstance, getUnReadMessageCount, setConversationMsgAsRea
|
|
|
250
248
|
|
|
251
249
|
## ChatStore
|
|
252
250
|
|
|
253
|
-
|
|
251
|
+
从 `mdm-im-v3/core` 导入 `useChatStore` 后调用获取,是 Pinia store(id: `'chatMessage'`),**已开启 localStorage 持久化**,持久化字段包括:`userID`、`nickname`、`faceURL`、`platformID`、`apiUrl`、`wsUrl`、`tenantID`(`imToken` 和 `satoken` 仅保存在 Pinia 内存中,不持久化到本地存储)。
|
|
252
|
+
|
|
253
|
+
```js
|
|
254
|
+
import { useChatStore } from 'mdm-im-v3/core'
|
|
255
|
+
const chatStore = useChatStore()
|
|
256
|
+
```
|
|
254
257
|
|
|
255
258
|
### 常用 State
|
|
256
259
|
|
package/dist/core.es.js
CHANGED