zsl-im-sdk 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ import http from '../../utils/http';
2
+
3
+ export const getOssConfig = async () => {
4
+ const res = await http.request('GET','/common/oss/config');
5
+ console.log('==getOssConfig== ',res);
6
+ return res;
7
+ }
@@ -0,0 +1,93 @@
1
+ import http from '../../utils/http';
2
+ import { IConversation } from '../../types/conversation.type';
3
+
4
+ // *
5
+ // * 获取会话列表
6
+ // * @param userId 查询参数
7
+ // * @returns 会话列表
8
+ //
9
+ export function getConversationsBuUserId(userId: string): Promise<Array<IConversation>> {
10
+ return http.request<Array<IConversation>>('POST','/conversations/byUserId', {
11
+ userId
12
+ })
13
+ }
14
+
15
+
16
+ /**
17
+ * 获取会话详情
18
+ * @param conversationId 会话ID
19
+ * @returns 会话详情
20
+ */
21
+ export const getConversationDetail = (conversationId: string) => {
22
+ return http.request<IConversation>('GET', `/conversation/${conversationId}`);
23
+ };
24
+
25
+ /**
26
+ * 删除会话
27
+ * @param conversationId 会话ID
28
+ * @returns 删除结果
29
+ */
30
+ export const deleteConversation = (conversationId: string) => {
31
+ return http.request('DELETE', `/conversation/${conversationId}`);
32
+ };
33
+
34
+ /**
35
+ * 标记会话已读
36
+ * @param conversationId 会话ID
37
+ * @returns 标记结果
38
+ */
39
+ export const markConversationRead = (conversationId: string) => {
40
+ return http.request('POST', `/conversation/${conversationId}/read`);
41
+ };
42
+
43
+ /**
44
+ * 清空会话未读计数
45
+ * @param conversationId 会话ID
46
+ * @returns 清空结果
47
+ */
48
+ export const clearConversationUnread = (conversationId: string) => {
49
+ return http.request('POST', `/conversation/${conversationId}/clear-unread`);
50
+ };
51
+
52
+ /**
53
+ * 创建单聊会话
54
+ * @param recipientId 接收者ID
55
+ * @returns 会话信息
56
+ */
57
+ export const createPrivateConversation = (recipientId: string) => {
58
+ return http.request<IConversation>('POST', '/conversation/private', {
59
+ data: { recipientId }
60
+ });
61
+ };
62
+
63
+ /**
64
+ * 创建群聊会话
65
+ * @param params 群聊参数
66
+ * @returns 会话信息
67
+ */
68
+ export const createGroupConversation = (params: {
69
+ name: string;
70
+ avatar?: string;
71
+ memberIds: Array<string | number>;
72
+ description?: string;
73
+ }) => {
74
+ return http.request<IConversation>('POST', '/conversation/group', {
75
+ data: params
76
+ });
77
+ };
78
+
79
+ /**
80
+ * 更新会话信息
81
+ * @param conversationId 会话ID
82
+ * @param params 更新参数
83
+ * @returns 更新结果
84
+ */
85
+ export const updateConversation = (conversationId: string, params: {
86
+ name?: string;
87
+ avatar?: string;
88
+ description?: string;
89
+ }) => {
90
+ return http.request<IConversation>('PUT', `/conversation/${conversationId}`, {
91
+ data: params
92
+ });
93
+ };
@@ -0,0 +1,18 @@
1
+ import http from '../utils/http';
2
+ import { IIMUserInfo } from '../types/im-user.type';
3
+
4
+
5
+
6
+ /**
7
+ * 消息已读
8
+ * @param conversationId 会话id
9
+ * @param lastReadMessageId 最后一条已读消息id
10
+ * @returns
11
+ */
12
+ export function userAuth(data: {
13
+ account: string,
14
+ token: string,
15
+ }): Promise<IIMUserInfo> {
16
+ return http.request<IIMUserInfo>('POST','/users/auth', data)
17
+ }
18
+
@@ -0,0 +1,51 @@
1
+ import http from "../../utils/http";
2
+ import type {
3
+ IMessage,
4
+ ISearchMessageRes,
5
+ } from "../../types/message-type.type";
6
+
7
+ /**
8
+ * 获取历史消息列表
9
+ * @param conversationId 会话id
10
+ * @param pageSize 每页数量
11
+ * @param lastMessageId 最后一条消息id
12
+ * @returns 历史消息列表
13
+ */
14
+ export async function getHistoryList(
15
+ conversationId: string,
16
+ pageSize: number,
17
+ lastMessageId: string,
18
+ ): Promise<Array<IMessage>> {
19
+ const res = await http.request<Array<IMessage>>("POST", "/messages/history", {
20
+ conversationId,
21
+ pageSize,
22
+ lastMessageId,
23
+ });
24
+
25
+ // return res || []
26
+
27
+ return res.sort((a: any, b: any) => Number(BigInt(b.id) - BigInt(a.id)));
28
+ }
29
+
30
+ /**
31
+ * 搜索消息
32
+ * @param userId 用户id
33
+ * @param keyword 搜索关键词
34
+ * @param page 页码
35
+ * @param size 每页数量
36
+ * @returns 搜索到的消息列表
37
+ */
38
+ export function searchMessage(data: {
39
+ conversationId: string;
40
+ keyword: string;
41
+ page: number;
42
+ size: number;
43
+ }): Promise<Array<ISearchMessageRes>> {
44
+ // return http.Post<Array<ISearchMessageRes>>('/messages/search', data)
45
+
46
+ return http.request<Array<ISearchMessageRes>>(
47
+ "POST",
48
+ "/messages/search",
49
+ data,
50
+ );
51
+ }
package/index.ts ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * ZSL IM SDK 核心入口
3
+ * 提供 IM 功能的核心能力:状态管理、WebSocket 连接、消息收发等
4
+ *
5
+ * @example
6
+ * // 在 main.js 中安装
7
+ * import { install } from '@zsl-im/sdk'
8
+ * Vue.use(install)
9
+ *
10
+ * // 在组件中使用
11
+ * this.$store.dispatch('login', { user, wsUrl, token })
12
+ * this.$store.dispatch('sendMessage', messageData)
13
+ */
14
+
15
+ import store, { install } from './store'
16
+ import { setBaseURL } from './utils/http'
17
+
18
+ // 增强 install 方法,支持配置
19
+ const originalInstall = install
20
+ export const installWithConfig = (vue: any, options: { baseURL?: string } = {}) => {
21
+ if (options.baseURL) {
22
+ setBaseURL(options.baseURL)
23
+ }
24
+ originalInstall(vue)
25
+ }
26
+
27
+ export type { IMessage, IUser, IState } from './store'
28
+ export { default as IM } from './websocket'
29
+ export * from './types'
30
+ export * from './api/common/common.api'
31
+ export * from './api/conversation/conversation.api'
32
+ export * from './api/message/message.api'
33
+ export * from './api/im-login'
34
+
35
+ export { store, installWithConfig as install }
36
+ export default store
package/jsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "paths": {
5
+ "@/*": ["./*"],
6
+ "@zsl-im-sdk": ["zsl-im-sdk"],
7
+ "@zsl-im-sdk/*": ["zsl-im-sdk/*"]
8
+ }
9
+ },
10
+ "include": [
11
+ "**/*"
12
+ ],
13
+ "exclude": ["node_modules", "unpackage", "dist"]
14
+ }
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "zsl-im-sdk",
3
+ "version": "1.0.0",
4
+ "description": "IM 即时通讯 SDK 核心包",
5
+ "main": "index.ts",
6
+ "types": "types.ts",
7
+ "keywords": [
8
+ "im",
9
+ "websocket",
10
+ "chat",
11
+ "vuex",
12
+ "instant-messaging"
13
+ ],
14
+ "author": "ZSL",
15
+ "license": "MIT",
16
+ "peerDependencies": {
17
+ "vue": "^2.6.0",
18
+ "vuex": "^3.0.0",
19
+ "ali-oss": "^6.23.0"
20
+ }
21
+ }