im-ui-mobile 0.0.30 → 0.0.32

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.
Files changed (44) hide show
  1. package/index.js +27 -2
  2. package/libs/index.ts +7 -0
  3. package/package.json +1 -1
  4. package/types/index.d.ts +82 -2
  5. package/types/libs/index.d.ts +204 -0
  6. package/types/utils/auth.d.ts +7 -0
  7. package/types/utils/datetime.d.ts +9 -36
  8. package/types/utils/dom.d.ts +11 -0
  9. package/types/utils/emoji.d.ts +8 -0
  10. package/types/utils/enums.d.ts +73 -0
  11. package/types/utils/env.d.ts +11 -0
  12. package/types/utils/messageType.d.ts +35 -0
  13. package/types/utils/recorderApp.d.ts +8 -0
  14. package/types/utils/recorderH5.d.ts +8 -0
  15. package/types/utils/requester.d.ts +17 -0
  16. package/types/utils/url.d.ts +5 -0
  17. package/types/utils/useDynamicRefs.d.ts +9 -0
  18. package/types/utils/websocket.d.ts +35 -0
  19. package/utils/auth.js +32 -0
  20. package/utils/dom.js +148 -0
  21. package/utils/{htmlEscape.ts → dom.ts} +1 -1
  22. package/utils/emoji.js +193 -0
  23. package/utils/enums.js +76 -0
  24. package/utils/eventBus.js +191 -0
  25. package/utils/messageType.js +130 -0
  26. package/utils/recorderApp.js +297 -0
  27. package/utils/recorderH5.js +374 -0
  28. package/utils/recorderH5.ts +0 -30
  29. package/utils/requester.js +84 -0
  30. package/utils/requester.ts +88 -0
  31. package/utils/url.js +23 -0
  32. package/utils/useDynamicRefs.js +31 -0
  33. package/utils/websocket.js +230 -0
  34. package/utils/eventBus/EventBusImpl.ts +0 -183
  35. package/utils/eventBus/EventCallback.ts +0 -2
  36. package/utils/eventBus/GlobalEventCallback.ts +0 -2
  37. package/utils/eventBus/IEventBus.ts +0 -11
  38. package/utils/eventBus/IEventListener.ts +0 -5
  39. package/utils/eventBus/index.ts +0 -6
  40. package/utils/index.ts +0 -15
  41. package/utils/request.ts +0 -82
  42. package/utils/requestx.ts +0 -92
  43. /package/utils/{datetime-ts-txt → datetime.ts} +0 -0
  44. /package/utils/{emotion.ts → emoji.ts} +0 -0
package/index.js CHANGED
@@ -13,8 +13,33 @@ const install = (app) => {
13
13
  })
14
14
  }
15
15
 
16
- import datetime from './utils/datetime.js'
17
- export { datetime }
16
+ import eventBus from "./utils/eventBus.js";
17
+ import * as auth from "./utils/auth.js";
18
+ import datetime from "./utils/datetime.js";
19
+ import Emoji from "./utils/emoji.js";
20
+ import * as dom from "./utils/dom.js";
21
+ import messageType from "./utils/messageType.js";
22
+ import * as recorderApp from "./utils/recorderApp.js";
23
+ import * as recorderH5 from "./utils/recorderH5.js";
24
+ import Requester from "./utils/requester.js";
25
+ import * as url from "./utils/url.js";
26
+ import { useDynamicRefs } from "./utils/useDynamicRefs.js";
27
+ import webSocketManager from "./utils/websocket.js";
28
+
29
+
30
+ export {
31
+ eventBus,
32
+ datetime,
33
+ Emoji,
34
+ dom,
35
+ messageType,
36
+ recorderApp,
37
+ recorderH5,
38
+ Requester,
39
+ url,
40
+ useDynamicRefs,
41
+ webSocketManager
42
+ }
18
43
 
19
44
  export default {
20
45
  install
package/libs/index.ts CHANGED
@@ -220,4 +220,11 @@ export interface UserInfo {
220
220
  sex?: number
221
221
  online?: boolean
222
222
  [key: string]: any
223
+ }
224
+
225
+ export interface Response<T> {
226
+ code: number
227
+ message: string
228
+ result: T
229
+ success: boolean
223
230
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "im-ui-mobile",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "description": "A Vue3.0 + typescript instant messaging component library for Uniapp",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/types/index.d.ts CHANGED
@@ -1,9 +1,89 @@
1
1
  /// <reference path="./components.d.ts" />
2
2
 
3
- import datetime from "../utils/datetime"
3
+ import eventBus from "./utils/eventBus";
4
+ import * as auth from "./utils/auth";
5
+ import datetime from "./utils/datetime";
6
+ import Emoji from "./utils/emoji";
7
+ import { MESSAGE_TYPE, RTC_STATE, TERMINAL_TYPE, MESSAGE_STATUS } from "./utils/enums";
8
+ import env from "./utils/env";
9
+ import * as dom from "./utils/dom";
10
+ import messageType from "./utils/messageType";
11
+ import * as recorderApp from "./utils/recorderApp";
12
+ import * as recorderH5 from "./utils/recorderH5";
13
+ import Requester from "./utils/requester";
14
+ import * as url from "./utils/url";
15
+ import { useDynamicRefs } from "./utils/useDynamicRefs";
16
+ import webSocketManager from "./utils/websocket";
17
+ import {
18
+ // 枚举类型
19
+ RTC_STATE,
20
+ MESSAGE_TYPE,
21
+ } from './libs';
22
+ import type {
23
+ // 类型常量
24
+ RtcMode,
25
+ RtcInfo,
26
+ Chat,
27
+ Message,
28
+ Friend,
29
+ OnlineTerminal,
30
+ MenuItem,
31
+ WebRTCMessage,
32
+ GroupMember,
33
+ Group,
34
+ UploadImageResponse,
35
+ SubmitItem,
36
+ ImageItem,
37
+ FileItem,
38
+ ApiResponse,
39
+ RecorderError,
40
+ UploadRecorderFileResponse,
41
+ UploadRecorderFileResult,
42
+ RecorderFile,
43
+ UserInfo,
44
+ Response
45
+ } from './libs';
4
46
 
5
47
  declare module 'im-ui-mobile' {
6
48
  export function install(): void
7
49
 
8
- export { datetime }
50
+ export {
51
+ eventBus,
52
+ datetime,
53
+ Emoji,
54
+ MESSAGE_TYPE, RTC_STATE, TERMINAL_TYPE, MESSAGE_STATUS,
55
+ dom,
56
+ messageType,
57
+ Requester,
58
+ url,
59
+ useDynamicRefs,
60
+ webSocketManager,
61
+
62
+ // 枚举类型
63
+ RTC_STATE,
64
+ MESSAGE_TYPE,
65
+
66
+ // 类型常量
67
+ RtcMode,
68
+ RtcInfo,
69
+ Chat,
70
+ Message,
71
+ Friend,
72
+ OnlineTerminal,
73
+ MenuItem,
74
+ WebRTCMessage,
75
+ GroupMember,
76
+ Group,
77
+ UploadImageResponse,
78
+ SubmitItem,
79
+ ImageItem,
80
+ FileItem,
81
+ ApiResponse,
82
+ RecorderError,
83
+ UploadRecorderFileResponse,
84
+ UploadRecorderFileResult,
85
+ RecorderFile,
86
+ UserInfo,
87
+ Response
88
+ }
9
89
  }
@@ -0,0 +1,204 @@
1
+ import type { RTC_STATE, MESSAGE_TYPE } from '../utils/enums';
2
+ /**
3
+ * 通话模式类型
4
+ */
5
+ export type RtcMode = 'audio' | 'video' | 'voice';
6
+ /**
7
+ * RTC 信息接口
8
+ */
9
+ export interface RtcInfo {
10
+ friend: Friend;
11
+ mode: RtcMode;
12
+ state: RTC_STATE;
13
+ isHost?: boolean;
14
+ }
15
+ /**
16
+ * 聊天
17
+ */
18
+ export interface Chat {
19
+ id?: string | number;
20
+ targetId: number;
21
+ type: 'PRIVATE' | 'GROUP';
22
+ showName: string;
23
+ headImage: string;
24
+ isDnd: boolean;
25
+ lastContent: string;
26
+ lastSendTime?: number;
27
+ unreadCount: number;
28
+ hotMinIdx: number;
29
+ readedMessageIdx: number;
30
+ messages: Message[];
31
+ atMe: boolean;
32
+ atAll: boolean;
33
+ stored: boolean;
34
+ delete: boolean;
35
+ lastTimeTip?: number;
36
+ sendNickName?: string;
37
+ }
38
+ /**
39
+ * 消息
40
+ */
41
+ export interface Message {
42
+ id?: number;
43
+ tmpId?: number;
44
+ type: number;
45
+ content: string;
46
+ sendTime?: number;
47
+ selfSend?: boolean;
48
+ status?: number;
49
+ sendNickName?: string;
50
+ atUserIds?: number[];
51
+ sendId?: number;
52
+ recvId?: number;
53
+ groupId?: number;
54
+ receipt?: boolean;
55
+ receiptOk?: boolean;
56
+ readedCount?: number;
57
+ quoteMessage?: Message;
58
+ fileId?: string;
59
+ }
60
+ /**
61
+ * 好友信息接口
62
+ */
63
+ export interface Friend {
64
+ id: number;
65
+ nickName: string;
66
+ headImage?: string;
67
+ online: boolean;
68
+ onlineWeb: boolean;
69
+ onlineApp: boolean;
70
+ isDnd: boolean;
71
+ deleted?: boolean;
72
+ remarkName?: string;
73
+ gender?: number;
74
+ signature?: string;
75
+ remarkNickName?: string;
76
+ showNickName?: string;
77
+ [key: string]: any;
78
+ }
79
+ /**
80
+ * 在线终端信息接口
81
+ */
82
+ export interface OnlineTerminal {
83
+ userId: string | number;
84
+ terminals: number[];
85
+ }
86
+ /**
87
+ * 菜单项
88
+ */
89
+ export interface MenuItem {
90
+ key: string;
91
+ name: string;
92
+ icon?: string;
93
+ color?: string;
94
+ [key: string]: any;
95
+ }
96
+ export interface WebRTCMessage {
97
+ type: number;
98
+ content: string;
99
+ sendId: number;
100
+ selfSend?: boolean;
101
+ }
102
+ export interface GroupMember {
103
+ id?: number;
104
+ userId: number;
105
+ showNickName: string;
106
+ headImage?: string;
107
+ quit?: boolean;
108
+ [key: string]: any;
109
+ }
110
+ /**
111
+ * 群组信息接口
112
+ */
113
+ export interface Group {
114
+ id: number;
115
+ ownerId: number;
116
+ isBanned?: boolean;
117
+ reason?: string;
118
+ name: string;
119
+ headImage: string;
120
+ isDnd: boolean;
121
+ quit?: boolean;
122
+ topMessage?: string;
123
+ memberCount?: number;
124
+ createTime?: number;
125
+ showGroupName: string;
126
+ headImageThumb?: string;
127
+ remarkGroupName?: string;
128
+ remarkNickName?: string;
129
+ notice?: string;
130
+ [key: string]: any;
131
+ }
132
+ /**
133
+ * 上传图片相应数据
134
+ */
135
+ export interface UploadImageResponse {
136
+ originUrl: string;
137
+ thumbUrl: string;
138
+ [key: string]: any;
139
+ }
140
+ /**
141
+ * 发送消息项
142
+ */
143
+ export interface SubmitItem {
144
+ type: MESSAGE_TYPE;
145
+ content: string | ImageItem | FileItem;
146
+ atUserIds?: number[];
147
+ }
148
+ export interface ImageItem {
149
+ fileId: number;
150
+ file: File;
151
+ url: string;
152
+ }
153
+ export interface FileItem {
154
+ fileId: number;
155
+ file: File;
156
+ }
157
+ export interface ApiResponse<T = any> {
158
+ data?: T;
159
+ code?: number;
160
+ message?: string;
161
+ success?: boolean;
162
+ timestamp?: number;
163
+ path?: string;
164
+ }
165
+ export interface RecorderError {
166
+ errMsg: string;
167
+ }
168
+ export interface UploadRecorderFileResponse {
169
+ code: number;
170
+ data: string;
171
+ message?: string;
172
+ }
173
+ export interface UploadRecorderFileResult {
174
+ duration: number;
175
+ url: string;
176
+ }
177
+ export interface RecorderFile {
178
+ tempFilePath: string;
179
+ }
180
+ /**
181
+ * 用户信息接口
182
+ */
183
+ export interface UserInfo {
184
+ id: number;
185
+ nickName: string;
186
+ headImage: string;
187
+ headImageThumb?: string;
188
+ email?: string;
189
+ phone?: string;
190
+ gender?: number;
191
+ signature?: string;
192
+ isBanned?: boolean;
193
+ reason?: string;
194
+ userName?: string;
195
+ sex?: number;
196
+ online?: boolean;
197
+ [key: string]: any;
198
+ }
199
+ export interface Response<T> {
200
+ code: number;
201
+ message: string;
202
+ result: T;
203
+ success: boolean;
204
+ }
@@ -0,0 +1,7 @@
1
+ export declare const setToken: (value: string) => void;
2
+ export declare const getToken: () => string;
3
+ export declare const setRefreshToken: (value: string) => void;
4
+ export declare const getRefreshToken: () => string;
5
+ export declare const clearToken: () => void;
6
+ export declare const setAuth: (data: any) => void;
7
+ export declare const isAuthed: () => boolean;
@@ -1,36 +1,9 @@
1
- /**
2
- * 日期时间工具模块
3
- */
4
- declare const datetime: {
5
- /**
6
- * 将时间戳转换为相对时间文本
7
- */
8
- toTimeText: (timeStamp: number | string | Date, simple?: boolean) => string;
9
-
10
- /**
11
- * 判断日期是否是昨天
12
- */
13
- isYesterday: (date: Date) => boolean;
14
-
15
- /**
16
- * 判断日期是否在今年
17
- */
18
- isYear: (date: Date) => boolean;
19
-
20
- /**
21
- * 格式化日期时间为字符串
22
- */
23
- formatDateTime: (date: string | Date) => string;
24
-
25
- /**
26
- * 获取更精确的相对时间描述
27
- */
28
- toPreciseTimeText: (timeStamp: number | string | Date) => string;
29
-
30
- /**
31
- * 获取聊天界面常用的时间显示格式
32
- */
33
- toChatTimeText: (timeStamp: number | string | Date) => string;
34
- };
35
-
36
- export default datetime;
1
+ declare const _default: {
2
+ toTimeText: (timeStamp: string | number | Date, simple?: boolean | undefined) => string;
3
+ toPreciseTimeText: (timeStamp: string | number | Date) => string;
4
+ toChatTimeText: (timeStamp: string | number | Date) => string;
5
+ isYestday: (date: Date) => boolean;
6
+ isYear: (date: Date) => boolean;
7
+ formatDateTime: (date: string | Date) => string;
8
+ };
9
+ export default _default;
@@ -0,0 +1,11 @@
1
+ declare const _default: {
2
+ html2Escape: (text: string) => string;
3
+ htmlEscape: (text: string) => string;
4
+ htmlUnescape: (text: string) => string;
5
+ escapeAttribute: (value: string) => string;
6
+ escapeTextContent: (text: string) => string;
7
+ hasHtmlSpecialChars: (text: string) => boolean;
8
+ setSafeHTML: (element: HTMLElement, html: string) => void;
9
+ safeHTML: (strings: TemplateStringsArray, ...values: any[]) => string;
10
+ };
11
+ export default _default;
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ containEmoji: (content: string) => boolean;
3
+ emoTextList: string[];
4
+ transform: (content: string, extClass?: string) => string;
5
+ textToPath: (emoText: string) => string;
6
+ pathToText: (path: string) => string;
7
+ };
8
+ export default _default;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * 消息类型枚举
3
+ */
4
+ export declare enum MESSAGE_TYPE {
5
+ TEXT = 0,
6
+ IMAGE = 1,
7
+ FILE = 2,
8
+ AUDIO = 3,
9
+ VIDEO = 4,
10
+ RECALL = 10,
11
+ READED = 11,
12
+ RECEIPT = 12,
13
+ TIP_TIME = 20,
14
+ TIP_TEXT = 21,
15
+ LOADING = 30,
16
+ ACT_RT_VOICE = 40,
17
+ ACT_RT_VIDEO = 41,
18
+ USER_BANNED = 50,
19
+ FRIEND_NEW = 80,
20
+ FRIEND_DEL = 81,
21
+ FRIEND_DND = 82,
22
+ GROUP_NEW = 90,
23
+ GROUP_DEL = 91,
24
+ GROUP_DND = 92,
25
+ RTC_CALL_VOICE = 100,
26
+ RTC_CALL_VIDEO = 101,
27
+ RTC_ACCEPT = 102,
28
+ RTC_REJECT = 103,
29
+ RTC_CANCEL = 104,
30
+ RTC_FAILED = 105,
31
+ RTC_HANDUP = 106,
32
+ RTC_CANDIDATE = 107,
33
+ RTC_GROUP_SETUP = 200,
34
+ RTC_GROUP_ACCEPT = 201,
35
+ RTC_GROUP_REJECT = 202,
36
+ RTC_GROUP_FAILED = 203,
37
+ RTC_GROUP_CANCEL = 204,
38
+ RTC_GROUP_QUIT = 205,
39
+ RTC_GROUP_INVITE = 206,
40
+ RTC_GROUP_JOIN = 207,
41
+ RTC_GROUP_OFFER = 208,
42
+ RTC_GROUP_ANSWER = 209,
43
+ RTC_GROUP_CANDIDATE = 210,
44
+ RTC_GROUP_DEVICE = 211
45
+ }
46
+ /**
47
+ * RTC 状态枚举
48
+ */
49
+ export declare enum RTC_STATE {
50
+ FREE = 0,// 空闲,可以被呼叫
51
+ WAIT_CALL = 1,// 呼叫后等待
52
+ WAIT_ACCEPT = 2,// 被呼叫后等待
53
+ ACCEPTED = 3,// 已接受聊天,等待建立连接
54
+ CHATING = 4
55
+ }
56
+ /**
57
+ * 终端类型枚举
58
+ */
59
+ export declare enum TERMINAL_TYPE {
60
+ WEB = 0,
61
+ APP = 1
62
+ }
63
+ /**
64
+ * 消息状态枚举
65
+ */
66
+ export declare enum MESSAGE_STATUS {
67
+ FAILED = -2,// 发送失败
68
+ SENDING = -1,// 发送中(消息没到服务器)
69
+ PENDING = 0,// 未送达(消息已到服务器,但对方没收到)
70
+ DELIVERED = 1,// 已送达(对方已收到,但是未读消息)
71
+ RECALL = 2,// 已撤回
72
+ READED = 3
73
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 环境变量类
3
+ * Created by Joncky 2025.08.15
4
+ */
5
+ declare class Env {
6
+ static EmojiUrl: string;
7
+ static AuthApiUrl: string;
8
+ static BaseApiUrl: string;
9
+ static WebSocketUrl: string;
10
+ }
11
+ export default Env;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 消息类型枚举
3
+ * 消息类型范围
4
+ */
5
+ export declare enum MessageTypeRange {
6
+ NORMAL_MIN = 0,
7
+ NORMAL_MAX = 9,
8
+ STATUS_MIN = 10,
9
+ STATUS_MAX = 19,
10
+ TIP_MIN = 20,
11
+ TIP_MAX = 29,
12
+ ACTION_MIN = 40,
13
+ ACTION_MAX = 49,
14
+ RTC_PRIVATE_MIN = 100,
15
+ RTC_PRIVATE_MAX = 199,
16
+ RTC_GROUP_MIN = 200,
17
+ RTC_GROUP_MAX = 299
18
+ }
19
+ declare const _default: {
20
+ isNormal: (type: number) => boolean;
21
+ isStatus: (type: number) => boolean;
22
+ isTip: (type: number) => boolean;
23
+ isAction: (type: number) => boolean;
24
+ isRtcPrivate: (type: number) => boolean;
25
+ isRtcGroup: (type: number) => boolean;
26
+ getMessageCategory: (type: number) => string;
27
+ isValidMessageType: (type: number) => boolean;
28
+ getMessageTypeRanges: () => {
29
+ category: string;
30
+ min: number;
31
+ max: number;
32
+ description: string;
33
+ }[];
34
+ };
35
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import type { UploadRecorderFileResult } from '../libs';
2
+ declare const _default: {
3
+ checkIsEnable: () => boolean;
4
+ start: () => Promise<void>;
5
+ close: () => void;
6
+ upload: () => Promise<UploadRecorderFileResult>;
7
+ };
8
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import type { UploadRecorderFileResult } from '../libs';
2
+ declare const _default: {
3
+ checkIsEnable: () => boolean;
4
+ start: () => Promise<void>;
5
+ close: () => void;
6
+ upload: () => Promise<UploadRecorderFileResult>;
7
+ };
8
+ export default _default;
@@ -0,0 +1,17 @@
1
+ /// <reference types="@dcloudio/types" />
2
+ /// <reference types="@dcloudio/types" />
3
+ import type { Response } from '../libs/index';
4
+ export default class Requester {
5
+ private baseURL;
6
+ private options;
7
+ private timeout;
8
+ private headers;
9
+ private accessToken;
10
+ constructor(baseURL: string, timeout?: number, options?: Partial<UniApp.RequestOptions>);
11
+ setToken(token: string): void;
12
+ request<T = any>(options: Partial<UniApp.RequestOptions>): Promise<Response<T>>;
13
+ get<T = any>(url: string, data?: any, options?: Partial<UniApp.RequestOptions>): Promise<Response<T>>;
14
+ post<T = any>(url: string, data?: any, options?: Partial<UniApp.RequestOptions>): Promise<Response<T>>;
15
+ put<T = any>(url: string, data?: any, options?: Partial<UniApp.RequestOptions>): Promise<Response<T>>;
16
+ delete<T = any>(url: string, data?: any, options?: Partial<UniApp.RequestOptions>): Promise<Response<T>>;
17
+ }
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ containUrl: (content: string) => boolean;
3
+ replaceURLWithHTMLLinks: (content: string, color?: string) => string;
4
+ };
5
+ export default _default;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 使用动态Refs(组合式函数)
3
+ */
4
+ export declare function useDynamicRefs<T = any>(): {
5
+ refs: import("vue").Ref<Map<string, import("@vue/reactivity").UnwrapRefSimple<T>> & Omit<Map<string, T>, keyof Map<any, any>>, Map<string, T> | (Map<string, import("@vue/reactivity").UnwrapRefSimple<T>> & Omit<Map<string, T>, keyof Map<any, any>>)>;
6
+ setRef: (key: string) => (el: T) => void;
7
+ getRef: (key: string) => T | undefined;
8
+ getAllRefs: () => Map<string, import("@vue/reactivity").UnwrapRefSimple<T>> & Omit<Map<string, T>, keyof Map<any, any>>;
9
+ };
@@ -0,0 +1,35 @@
1
+ type MessageCallback = (cmd: number, data: any) => void;
2
+ type CloseCallback = (res: any) => void;
3
+ type ConnectCallback = () => void;
4
+ declare class WebSocketManager {
5
+ private messageCallBack;
6
+ private closeCallBack;
7
+ private connectCallBack;
8
+ private isConnect;
9
+ private reconnectTimer;
10
+ private lastConnectTime;
11
+ private socketTask;
12
+ private heartCheckTimeout;
13
+ private heartCheckTimer;
14
+ private startHeartCheck;
15
+ private resetHeartCheck;
16
+ private clearHeartCheck;
17
+ connect(wsurl: string, token: string): void;
18
+ private setupSocketEvents;
19
+ private handleMessage;
20
+ private handleClose;
21
+ reconnect(wsurl: string, token: string): void;
22
+ private scheduleReconnect;
23
+ close(code?: number): void;
24
+ sendMessage(message: string): void;
25
+ onConnect(callback: ConnectCallback): void;
26
+ onMessage(callback: MessageCallback): void;
27
+ onClose(callback: CloseCallback): void;
28
+ getIsConnect(): boolean;
29
+ getLastConnectTime(): Date;
30
+ setHeartCheckTimeout(timeout: number): void;
31
+ destroy(): void;
32
+ }
33
+ declare const webSocketManager: WebSocketManager;
34
+ export { webSocketManager, WebSocketManager };
35
+ export default webSocketManager;
package/utils/auth.js ADDED
@@ -0,0 +1,32 @@
1
+ export const setToken = (value) => {
2
+ uni.setStorageSync("accessToken", value);
3
+ };
4
+
5
+ export const getToken = () => {
6
+ return uni.getStorageSync("accessToken") || "";
7
+ };
8
+
9
+ export const setRefreshToken = (value) => {
10
+ uni.setStorageSync("refreshToken", value);
11
+ };
12
+
13
+ export const getRefreshToken = () => {
14
+ return uni.getStorageSync("refreshToken") || "";
15
+ };
16
+
17
+ export const clearToken = () => {
18
+ uni.removeStorageSync("accessToken");
19
+ uni.removeStorageSync("refreshToken");
20
+ };
21
+
22
+ export const setAuth = (data) => {
23
+ setToken(data.accessToken)
24
+ setRefreshToken(data.refreshToken)
25
+ uni.setStorageSync('expired', +new Date() + Number(data.expiresIn) * 60 * 60)
26
+ }
27
+
28
+ export const isAuthed = () => {
29
+ const expired = uni.getStorageSync('expired')
30
+ const token = getToken()
31
+ return !(!expired || expired < +new Date() || !token)
32
+ }