im-ui-mobile 0.0.2 → 0.0.4

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 (32) hide show
  1. package/package.json +2 -3
  2. package/src/index.ts +38 -0
  3. package/dist/index.d.ts +0 -1
  4. package/dist/index.js +0 -694
  5. package/dist/style.css +0 -1
  6. /package/{dist → src}/components/chat-box/index.vue +0 -0
  7. /package/{dist → src}/components/chat-item/index.vue +0 -0
  8. /package/{dist → src}/components/chat-message-item/index.vue +0 -0
  9. /package/{dist → src}/types/index.ts +0 -0
  10. /package/{dist → src}/types/recorder.ts +0 -0
  11. /package/{dist → src}/types/user.ts +0 -0
  12. /package/{dist → src}/utils/auth.ts +0 -0
  13. /package/{dist → src}/utils/datetime.ts +0 -0
  14. /package/{dist → src}/utils/emotion.ts +0 -0
  15. /package/{dist → src}/utils/enums.ts +0 -0
  16. /package/{dist → src}/utils/env.ts +0 -0
  17. /package/{dist → src}/utils/eventBus/EventBusImpl.ts +0 -0
  18. /package/{dist → src}/utils/eventBus/EventCallback.ts +0 -0
  19. /package/{dist → src}/utils/eventBus/GlobalEventCallback.ts +0 -0
  20. /package/{dist → src}/utils/eventBus/IEventBus.ts +0 -0
  21. /package/{dist → src}/utils/eventBus/IEventListener.ts +0 -0
  22. /package/{dist → src}/utils/eventBus/index.ts +0 -0
  23. /package/{dist → src}/utils/htmlEscape.ts +0 -0
  24. /package/{dist → src}/utils/index.ts +0 -0
  25. /package/{dist → src}/utils/messageType.ts +0 -0
  26. /package/{dist → src}/utils/recorderApp.ts +0 -0
  27. /package/{dist → src}/utils/recorderH5.ts +0 -0
  28. /package/{dist → src}/utils/request.ts +0 -0
  29. /package/{dist → src}/utils/requestx.ts +0 -0
  30. /package/{dist → src}/utils/url.ts +0 -0
  31. /package/{dist → src}/utils/useDynamicRefs.ts +0 -0
  32. /package/{dist → src}/utils/websocket.ts +0 -0
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "im-ui-mobile",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "A Uniapp instant messaging component library based on Vue3.0+typescript",
5
5
  "main": "index.ts",
6
6
  "module": "dist/im-ui-mobile.es.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "files": [
9
- "dist",
10
- "components"
9
+ "src"
11
10
  ],
12
11
  "scripts": {
13
12
  "build": "vite build",
package/src/index.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { App } from 'vue'
2
+ import ChatItem from './components/chat-item/index.vue'
3
+ import ChatMessageItem from './components/chat-message-item/index.vue'
4
+ import ChatBox from './components/chat-box/index.vue'
5
+
6
+ // 导出类型
7
+ export * from './types'
8
+
9
+ // 导出工具函数
10
+ export * from './utils'
11
+
12
+ // 重要:为组件添加名称,以支持开发环境
13
+ ChatItem.name = 'ChatItem'
14
+ ChatMessageItem.name = 'ChatMessageItem'
15
+ ChatBox.name = 'ChatBox'
16
+
17
+ const components = [
18
+ ChatItem,
19
+ ChatMessageItem,
20
+ ChatBox
21
+ ]
22
+
23
+ const install = (app: App): void => {
24
+ components.forEach(component => {
25
+ app.component(component.name || '', component)
26
+ })
27
+ }
28
+
29
+ export {
30
+ ChatItem,
31
+ ChatMessageItem,
32
+ ChatBox,
33
+ install
34
+ }
35
+
36
+ export default {
37
+ install
38
+ }
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './index'
package/dist/index.js DELETED
@@ -1,694 +0,0 @@
1
- var w = Object.defineProperty;
2
- var $ = (e, t, s) => t in e ? w(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
- var c = (e, t, s) => ($(e, typeof t != "symbol" ? t + "" : t, s), s);
4
- import { defineComponent as g, openBlock as l, createElementBlock as u, normalizeClass as I, createElementVNode as o, toDisplayString as f, createCommentVNode as C, ref as v, watch as F, onMounted as V, renderSlot as p, Fragment as H, renderList as W, createBlock as X, withDirectives as z, vModelText as q, nextTick as J } from "vue";
5
- const A = { class: "u-im-chat-item__avatar" }, Q = ["src"], K = { class: "u-im-chat-item__content" }, Z = { class: "u-im-chat-item__header" }, j = { class: "u-im-chat-item__name" }, P = { class: "u-im-chat-item__time" }, G = { class: "u-im-chat-item__message" }, M = { class: "u-im-chat-item__text" }, Y = ["value"], E = /* @__PURE__ */ g({
6
- __name: "index",
7
- props: {
8
- type: { default: "default" },
9
- avatar: { default: "" },
10
- name: {},
11
- time: {},
12
- lastMessage: {},
13
- unreadCount: { default: 0 }
14
- },
15
- emits: ["click"],
16
- setup(e, { emit: t }) {
17
- const s = t, n = (i) => {
18
- s("click", i);
19
- };
20
- return (i, a) => (l(), u("div", {
21
- class: I(["u-im-chat-item", [`u-im-chat-item--${e.type}`]]),
22
- onClick: n
23
- }, [
24
- o("div", A, [
25
- o("u-avatar", {
26
- src: e.avatar,
27
- size: "40"
28
- }, null, 8, Q)
29
- ]),
30
- o("div", K, [
31
- o("div", Z, [
32
- o("span", j, f(e.name), 1),
33
- o("span", P, f(e.time), 1)
34
- ]),
35
- o("div", G, [
36
- o("span", M, f(e.lastMessage), 1),
37
- e.unreadCount > 0 ? (l(), u("u-badge", {
38
- key: 0,
39
- value: e.unreadCount,
40
- max: "99",
41
- class: "u-im-chat-item__badge"
42
- }, null, 8, Y)) : C("", !0)
43
- ])
44
- ])
45
- ], 2));
46
- }
47
- });
48
- const D = (e, t) => {
49
- const s = e.__vccOpts || e;
50
- for (const [n, i] of t)
51
- s[n] = i;
52
- return s;
53
- }, U = /* @__PURE__ */ D(E, [["__scopeId", "data-v-a0bce79a"]]), S = {
54
- key: 0,
55
- class: "u-im-message-item__avatar"
56
- }, ee = ["src"], te = { class: "u-im-message-item__content" }, se = {
57
- key: 0,
58
- class: "u-im-message-item__text"
59
- }, ne = {
60
- key: 1,
61
- class: "u-im-message-item__image"
62
- }, ie = ["src"], oe = {
63
- key: 2,
64
- class: "u-im-message-item__voice"
65
- }, ae = { class: "u-im-message-item__duration" }, ce = {
66
- key: 0,
67
- class: "u-im-message-item__status"
68
- }, re = {
69
- key: 0,
70
- name: "loading",
71
- size: "16",
72
- color: "#909399"
73
- }, le = {
74
- key: 1,
75
- name: "checkmark",
76
- size: "16",
77
- color: "#67C23A"
78
- }, ue = {
79
- key: 2,
80
- name: "close",
81
- size: "16",
82
- color: "#F56C6C"
83
- }, he = /* @__PURE__ */ g({
84
- __name: "index",
85
- props: {
86
- position: { default: "left" },
87
- type: { default: "text" },
88
- content: {},
89
- avatar: {},
90
- showAvatar: { type: Boolean, default: !0 },
91
- status: { default: "success" },
92
- duration: { default: 0 }
93
- },
94
- setup(e) {
95
- return (t, s) => (l(), u("div", {
96
- class: I(["u-im-message-item", [`u-im-message-item--${e.position}`]])
97
- }, [
98
- e.showAvatar ? (l(), u("div", S, [
99
- o("u-avatar", {
100
- src: e.avatar,
101
- size: "32"
102
- }, null, 8, ee)
103
- ])) : C("", !0),
104
- o("div", te, [
105
- o("div", {
106
- class: I(["u-im-message-item__bubble", [`u-im-message-item__bubble--${e.type}`]])
107
- }, [
108
- e.type === "text" ? (l(), u("div", se, f(e.content), 1)) : e.type === "image" ? (l(), u("div", ne, [
109
- o("u-image", {
110
- src: e.content,
111
- width: "200",
112
- height: "150",
113
- mode: "aspectFill"
114
- }, null, 8, ie)
115
- ])) : e.type === "voice" ? (l(), u("div", oe, [
116
- s[0] || (s[0] = o("u-icon", {
117
- name: "play-circle",
118
- size: "20"
119
- }, null, -1)),
120
- o("span", ae, f(e.duration) + "''", 1)
121
- ])) : C("", !0)
122
- ], 2),
123
- e.position === "right" ? (l(), u("div", ce, [
124
- e.status === "sending" ? (l(), u("u-icon", re)) : e.status === "success" ? (l(), u("u-icon", le)) : e.status === "failed" ? (l(), u("u-icon", ue)) : C("", !0)
125
- ])) : C("", !0)
126
- ])
127
- ], 2));
128
- }
129
- });
130
- const O = /* @__PURE__ */ D(he, [["__scopeId", "data-v-66e9b9aa"]]), de = { class: "u-im-chat-box" }, me = { class: "u-im-chat-box__header" }, Ce = { class: "u-im-chat-box__title" }, _e = { class: "u-im-chat-box__actions" }, fe = {
131
- key: 0,
132
- class: "u-im-chat-box__loading"
133
- }, ke = { class: "u-im-chat-box__input" }, Re = { class: "u-im-chat-box__tools" }, Ie = { class: "u-im-chat-box__textarea" }, ve = ["placeholder", "maxlength"], ge = /* @__PURE__ */ g({
134
- __name: "index",
135
- props: {
136
- title: { default: "聊天" },
137
- messages: { default: () => [] },
138
- placeholder: { default: "请输入消息..." },
139
- maxlength: { default: 1e3 },
140
- loading: { type: Boolean, default: !1 }
141
- },
142
- emits: ["send", "loadMore"],
143
- setup(e, { emit: t }) {
144
- const s = e, n = t, i = v(""), a = v(), h = () => {
145
- i.value.trim() && (n("send", i.value.trim()), i.value = "");
146
- }, R = (d, m) => {
147
- if (m === 0)
148
- return !0;
149
- const r = s.messages[m - 1];
150
- return !!(r.position !== d.position || r.avatar !== d.avatar || d.timestamp && r.timestamp && d.timestamp - r.timestamp > 3e5);
151
- }, L = () => {
152
- J(() => {
153
- a.value && (a.value.scrollTop = a.value.scrollHeight);
154
- });
155
- };
156
- return F(() => s.messages, () => {
157
- L();
158
- }, { deep: !0 }), V(() => {
159
- L();
160
- }), (d, m) => (l(), u("div", de, [
161
- o("div", me, [
162
- o("div", Ce, f(e.title), 1),
163
- o("div", _e, [
164
- p(d.$slots, "header-actions", {}, void 0, !0)
165
- ])
166
- ]),
167
- o("div", {
168
- class: "u-im-chat-box__messages",
169
- ref_key: "messagesRef",
170
- ref: a
171
- }, [
172
- e.loading ? (l(), u("div", fe, [...m[1] || (m[1] = [
173
- o("u-loading-icon", { size: "24" }, null, -1)
174
- ])])) : C("", !0),
175
- (l(!0), u(H, null, W(e.messages, (r, N) => (l(), X(O, {
176
- key: r.id || N,
177
- position: r.position,
178
- type: r.type,
179
- content: r.content,
180
- avatar: r.avatar,
181
- "show-avatar": R(r, N),
182
- status: r.status,
183
- duration: r.duration
184
- }, null, 8, ["position", "type", "content", "avatar", "show-avatar", "status", "duration"]))), 128))
185
- ], 512),
186
- o("div", ke, [
187
- o("div", Re, [
188
- p(d.$slots, "input-tools", {}, void 0, !0)
189
- ]),
190
- o("div", Ie, [
191
- z(o("u-textarea", {
192
- "onUpdate:modelValue": m[0] || (m[0] = (r) => i.value = r),
193
- placeholder: e.placeholder,
194
- maxlength: e.maxlength,
195
- "auto-height": !0,
196
- onConfirm: h
197
- }, null, 40, ve), [
198
- [q, i.value]
199
- ])
200
- ]),
201
- o("div", { class: "u-im-chat-box__send" }, [
202
- o("u-button", {
203
- type: "primary",
204
- size: "small",
205
- onClick: h
206
- }, "发送")
207
- ])
208
- ])
209
- ]));
210
- }
211
- });
212
- const x = /* @__PURE__ */ D(ge, [["__scopeId", "data-v-d331769d"]]);
213
- class De {
214
- constructor() {
215
- c(this, "events", /* @__PURE__ */ new Map());
216
- c(this, "globalListeners", []);
217
- }
218
- /**
219
- * 监听特定事件
220
- * @param eventName 事件名称
221
- * @param callback 回调函数
222
- */
223
- on(t, s) {
224
- this.events.has(t) || this.events.set(t, []), this.events.get(t).push({ callback: s });
225
- }
226
- /**
227
- * 监听所有事件
228
- * @param callback 全局回调函数
229
- */
230
- onAll(t) {
231
- this.globalListeners.push(t);
232
- }
233
- /**
234
- * 一次性监听特定事件
235
- * @param eventName 事件名称
236
- * @param callback 回调函数
237
- */
238
- once(t, s) {
239
- this.events.has(t) || this.events.set(t, []), this.events.get(t).push({ callback: s, once: !0 });
240
- }
241
- /**
242
- * 触发事件
243
- * @param eventName 事件名称
244
- * @param data 事件数据
245
- */
246
- emit(t, s) {
247
- const n = this.events.get(t);
248
- if (n) {
249
- const i = [], a = [];
250
- n.forEach((h) => {
251
- h.once ? i.push(h) : a.push(h);
252
- }), n.forEach((h) => {
253
- try {
254
- h.callback(s);
255
- } catch (R) {
256
- console.error(`Error executing listener for event "${t}":`, R);
257
- }
258
- }), i.length > 0 && this.events.set(t, a);
259
- }
260
- this.globalListeners.forEach((i) => {
261
- try {
262
- i(t, s);
263
- } catch (a) {
264
- console.error(`Error executing global listener for event "${t}":`, a);
265
- }
266
- });
267
- }
268
- /**
269
- * 移除事件监听器
270
- * @param eventName 事件名称
271
- * @param callback 要移除的回调函数(不传则移除所有监听器)
272
- */
273
- off(t, s) {
274
- if (this.events.has(t))
275
- if (!s)
276
- this.events.delete(t);
277
- else {
278
- const i = this.events.get(t).filter((a) => a.callback !== s);
279
- i.length === 0 ? this.events.delete(t) : this.events.set(t, i);
280
- }
281
- }
282
- /**
283
- * 移除所有事件监听器
284
- */
285
- offAll() {
286
- this.events.clear(), this.globalListeners = [];
287
- }
288
- /**
289
- * 移除全局监听器
290
- * @param callback 要移除的全局回调函数
291
- */
292
- offAllListener(t) {
293
- t ? this.globalListeners = this.globalListeners.filter((s) => s !== t) : this.globalListeners = [];
294
- }
295
- /**
296
- * 获取事件监听器数量
297
- * @param eventName 事件名称(不传则返回所有事件的总数)
298
- */
299
- getEventCount(t) {
300
- var n;
301
- if (t)
302
- return ((n = this.events.get(t)) == null ? void 0 : n.length) || 0;
303
- let s = 0;
304
- return this.events.forEach((i) => {
305
- s += i.length;
306
- }), s;
307
- }
308
- /**
309
- * 检查是否存在特定事件的监听器
310
- * @param eventName 事件名称
311
- */
312
- hasEvent(t) {
313
- return this.events.has(t) && this.events.get(t).length > 0;
314
- }
315
- /**
316
- * 获取所有已注册的事件名称
317
- */
318
- getEventNames() {
319
- return Array.from(this.events.keys());
320
- }
321
- /**
322
- * 清空所有事件(包括全局监听器)
323
- */
324
- clear() {
325
- this.offAll();
326
- }
327
- /**
328
- * 销毁事件总线实例
329
- */
330
- destroy() {
331
- this.clear(), this.events.clear(), this.globalListeners.length = 0;
332
- }
333
- }
334
- const We = new De(), Oe = (e) => {
335
- uni.setStorageSync("accessToken", e);
336
- }, b = () => uni.getStorageSync("accessToken") || "", Le = (e) => {
337
- uni.setStorageSync("refreshToken", e);
338
- }, Xe = () => uni.getStorageSync("refreshToken") || "", Ne = () => {
339
- uni.removeStorageSync("accessToken"), uni.removeStorageSync("refreshToken");
340
- }, ze = (e) => {
341
- Oe(e.accessToken), Le(e.refreshToken), uni.setStorageSync("expired", +/* @__PURE__ */ new Date() + Number(e.expiresIn) * 60 * 60);
342
- }, qe = () => {
343
- const e = uni.getStorageSync("expired"), t = b();
344
- return !(!e || e < +/* @__PURE__ */ new Date() || !t);
345
- };
346
- class _ {
347
- }
348
- // 表情包路径
349
- c(_, "EmojiUrl", "/static/emoji/"), c(_, "AuthApiUrl", "http://192.168.31.33:5002"), c(_, "BaseApiUrl", "http://192.168.31.33:8888"), c(_, "WebSocketUrl", "ws://192.168.31.33:8878/im");
350
- var pe = /* @__PURE__ */ ((e) => (e[e.TEXT = 0] = "TEXT", e[e.IMAGE = 1] = "IMAGE", e[e.FILE = 2] = "FILE", e[e.AUDIO = 3] = "AUDIO", e[e.VIDEO = 4] = "VIDEO", e[e.RECALL = 10] = "RECALL", e[e.READED = 11] = "READED", e[e.RECEIPT = 12] = "RECEIPT", e[e.TIP_TIME = 20] = "TIP_TIME", e[e.TIP_TEXT = 21] = "TIP_TEXT", e[e.LOADING = 30] = "LOADING", e[e.ACT_RT_VOICE = 40] = "ACT_RT_VOICE", e[e.ACT_RT_VIDEO = 41] = "ACT_RT_VIDEO", e[e.USER_BANNED = 50] = "USER_BANNED", e[e.FRIEND_NEW = 80] = "FRIEND_NEW", e[e.FRIEND_DEL = 81] = "FRIEND_DEL", e[e.FRIEND_DND = 82] = "FRIEND_DND", e[e.GROUP_NEW = 90] = "GROUP_NEW", e[e.GROUP_DEL = 91] = "GROUP_DEL", e[e.GROUP_DND = 92] = "GROUP_DND", e[e.RTC_CALL_VOICE = 100] = "RTC_CALL_VOICE", e[e.RTC_CALL_VIDEO = 101] = "RTC_CALL_VIDEO", e[e.RTC_ACCEPT = 102] = "RTC_ACCEPT", e[e.RTC_REJECT = 103] = "RTC_REJECT", e[e.RTC_CANCEL = 104] = "RTC_CANCEL", e[e.RTC_FAILED = 105] = "RTC_FAILED", e[e.RTC_HANDUP = 106] = "RTC_HANDUP", e[e.RTC_CANDIDATE = 107] = "RTC_CANDIDATE", e[e.RTC_GROUP_SETUP = 200] = "RTC_GROUP_SETUP", e[e.RTC_GROUP_ACCEPT = 201] = "RTC_GROUP_ACCEPT", e[e.RTC_GROUP_REJECT = 202] = "RTC_GROUP_REJECT", e[e.RTC_GROUP_FAILED = 203] = "RTC_GROUP_FAILED", e[e.RTC_GROUP_CANCEL = 204] = "RTC_GROUP_CANCEL", e[e.RTC_GROUP_QUIT = 205] = "RTC_GROUP_QUIT", e[e.RTC_GROUP_INVITE = 206] = "RTC_GROUP_INVITE", e[e.RTC_GROUP_JOIN = 207] = "RTC_GROUP_JOIN", e[e.RTC_GROUP_OFFER = 208] = "RTC_GROUP_OFFER", e[e.RTC_GROUP_ANSWER = 209] = "RTC_GROUP_ANSWER", e[e.RTC_GROUP_CANDIDATE = 210] = "RTC_GROUP_CANDIDATE", e[e.RTC_GROUP_DEVICE = 211] = "RTC_GROUP_DEVICE", e))(pe || {}), Ue = /* @__PURE__ */ ((e) => (e[e.FREE = 0] = "FREE", e[e.WAIT_CALL = 1] = "WAIT_CALL", e[e.WAIT_ACCEPT = 2] = "WAIT_ACCEPT", e[e.ACCEPTED = 3] = "ACCEPTED", e[e.CHATING = 4] = "CHATING", e))(Ue || {}), xe = /* @__PURE__ */ ((e) => (e[e.WEB = 0] = "WEB", e[e.APP = 1] = "APP", e))(xe || {}), be = /* @__PURE__ */ ((e) => (e[e.FAILED = -2] = "FAILED", e[e.SENDING = -1] = "SENDING", e[e.PENDING = 0] = "PENDING", e[e.DELIVERED = 1] = "DELIVERED", e[e.RECALL = 2] = "RECALL", e[e.READED = 3] = "READED", e))(be || {});
351
- const T = {
352
- "<": "&lt;",
353
- ">": "&gt;",
354
- "&": "&amp;",
355
- '"': "&quot;",
356
- "'": "&#39;",
357
- "`": "&#96;"
358
- }, Te = {
359
- "&lt;": "<",
360
- "&gt;": ">",
361
- "&amp;": "&",
362
- "&quot;": '"',
363
- "&#39;": "'",
364
- "&#96;": "`"
365
- }, Je = (e) => e ? e.replace(/[<>&"']/g, (t) => T[t] || t) : "", y = (e) => {
366
- if (!e)
367
- return "";
368
- const t = /[<>&"'`]/g;
369
- return e.replace(t, (s) => T[s] || s);
370
- }, Ae = (e) => {
371
- if (!e)
372
- return "";
373
- const t = /&(lt|gt|amp|quot|#39|#96);/g;
374
- return e.replace(t, (s) => Te[s] || s);
375
- }, Qe = (e) => e ? e.replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;") : "", Ke = (e) => e ? e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;") : "", Ze = (e) => e ? /[<>&"']/.test(e) : !1, je = (e, t) => {
376
- e && (e.innerHTML = y(t));
377
- }, Pe = (e, ...t) => {
378
- let s = "";
379
- for (let n = 0; n < e.length; n++)
380
- s += e[n], n < t.length && (s += y(String(t[n])));
381
- return s;
382
- };
383
- var ye = /* @__PURE__ */ ((e) => (e[e.NORMAL_MIN = 0] = "NORMAL_MIN", e[e.NORMAL_MAX = 9] = "NORMAL_MAX", e[e.STATUS_MIN = 10] = "STATUS_MIN", e[e.STATUS_MAX = 19] = "STATUS_MAX", e[e.TIP_MIN = 20] = "TIP_MIN", e[e.TIP_MAX = 29] = "TIP_MAX", e[e.ACTION_MIN = 40] = "ACTION_MIN", e[e.ACTION_MAX = 49] = "ACTION_MAX", e[e.RTC_PRIVATE_MIN = 100] = "RTC_PRIVATE_MIN", e[e.RTC_PRIVATE_MAX = 199] = "RTC_PRIVATE_MAX", e[e.RTC_GROUP_MIN = 200] = "RTC_GROUP_MIN", e[e.RTC_GROUP_MAX = 299] = "RTC_GROUP_MAX", e))(ye || {});
384
- uni.getRecorderManager();
385
- const B = {
386
- invoke(e) {
387
- const t = b(), s = uni.getStorageSync("expired");
388
- !e.url.startsWith("http") && !e.url.startsWith("https") && (e.url.includes("login") || e.url.includes("Token") ? e.url = _.AuthApiUrl + e.url : e.url = _.BaseApiUrl + e.url), e.timeout = 1e4, e.header = {
389
- ...e.header,
390
- "Content-Type": "application/json",
391
- Authorization: `Bearer ${t}`,
392
- AccessToken: t
393
- }, t && s && s > +/* @__PURE__ */ new Date() && (e.header.Authorization = "Bearer " + t);
394
- }
395
- };
396
- uni.addInterceptor("request", B);
397
- uni.addInterceptor("uploadFile", B);
398
- const k = (e) => new Promise((t, s) => {
399
- uni.request({
400
- ...e,
401
- success(n) {
402
- n.data.code >= 200 && n.data.code < 300 ? t(n.data) : n.data.code === 401 ? (uni.showToast({
403
- icon: "none",
404
- title: "请先登录"
405
- }), setTimeout(() => {
406
- Ne(), uni.removeStorageSync("expired"), uni.removeStorageSync("user"), uni.setStorageSync("keepLoggedIn", !1), s(n);
407
- }, 1e3)) : (uni.showToast({
408
- icon: "none",
409
- title: n.data.message || "请求错误"
410
- }), console.error("请求错误", n), s(n));
411
- },
412
- fail(n) {
413
- uni.showToast({
414
- icon: "none",
415
- title: "请求失败"
416
- }), s(n);
417
- }
418
- });
419
- });
420
- class Be {
421
- constructor() {
422
- /**
423
- * GET 请求
424
- */
425
- c(this, "get", (t, s, n) => k({
426
- url: t,
427
- method: "GET",
428
- data: s,
429
- ...n
430
- }));
431
- /**
432
- * POST 请求
433
- */
434
- c(this, "post", (t, s, n) => k({
435
- url: t,
436
- method: "POST",
437
- data: s,
438
- ...n
439
- }));
440
- /**
441
- * PUT 请求
442
- */
443
- c(this, "put", (t, s, n) => k({
444
- url: t,
445
- method: "PUT",
446
- data: s,
447
- ...n
448
- }));
449
- /**
450
- * DELETE 请求
451
- */
452
- c(this, "delete", (t, s, n) => k({
453
- url: t,
454
- method: "DELETE",
455
- data: s,
456
- ...n
457
- }));
458
- /**
459
- * 上传文件
460
- */
461
- c(this, "uploadFile", (t) => new Promise((s, n) => {
462
- uni.uploadFile({
463
- ...t,
464
- success: (i) => {
465
- try {
466
- const a = JSON.parse(i.data);
467
- if (a.code >= 200 && a.code < 300) {
468
- s(a);
469
- return;
470
- }
471
- if (a.code === 401) {
472
- n(new Error("未授权访问"));
473
- return;
474
- }
475
- n(new Error(a.message || "上传失败"));
476
- } catch (a) {
477
- console.error(a), n(new Error("解析响应数据失败"));
478
- }
479
- },
480
- fail: (i) => {
481
- n(i);
482
- }
483
- });
484
- }));
485
- }
486
- }
487
- const Ge = new Be();
488
- function Me() {
489
- const e = v(/* @__PURE__ */ new Map());
490
- return {
491
- refs: e,
492
- setRef: (i) => (a) => {
493
- a ? e.value.set(i, a) : e.value.delete(i);
494
- },
495
- getRef: (i) => e.value.get(i),
496
- getAllRefs: () => e.value
497
- };
498
- }
499
- class we {
500
- constructor() {
501
- // 私有属性
502
- // private accessToken: string = "";
503
- c(this, "messageCallBack", null);
504
- c(this, "closeCallBack", null);
505
- c(this, "connectCallBack", null);
506
- c(this, "isConnect", !1);
507
- c(this, "reconnectTimer", null);
508
- c(this, "lastConnectTime", /* @__PURE__ */ new Date());
509
- c(this, "socketTask", null);
510
- // 心跳配置
511
- c(this, "heartCheckTimeout", 2e4);
512
- c(this, "heartCheckTimer", null);
513
- }
514
- // 私有方法 - 心跳相关
515
- startHeartCheck() {
516
- if (!this.isConnect || !this.socketTask)
517
- return;
518
- const t = {
519
- cmd: 1,
520
- data: {}
521
- };
522
- this.sendMessage(JSON.stringify(t));
523
- }
524
- resetHeartCheck() {
525
- this.clearHeartCheck(), this.heartCheckTimer = setTimeout(() => {
526
- this.startHeartCheck();
527
- }, this.heartCheckTimeout);
528
- }
529
- clearHeartCheck() {
530
- this.heartCheckTimer && (clearTimeout(this.heartCheckTimer), this.heartCheckTimer = null);
531
- }
532
- // 连接 WebSocket
533
- connect(t, s) {
534
- this.isConnect || (this.lastConnectTime = /* @__PURE__ */ new Date(), this.socketTask = uni.connectSocket({
535
- url: t,
536
- fail: (n) => {
537
- console.error("WebSocket连接失败:", n), console.log("10秒后重连..."), this.scheduleReconnect(t, s);
538
- }
539
- }), this.setupSocketEvents(t, s));
540
- }
541
- // 设置 WebSocket 事件监听
542
- setupSocketEvents(t, s) {
543
- this.socketTask && (this.socketTask.onOpen((n) => {
544
- this.isConnect = !0;
545
- const i = {
546
- cmd: 0,
547
- data: { accessToken: s }
548
- };
549
- this.sendMessage(JSON.stringify(i));
550
- }), this.socketTask.onMessage((n) => {
551
- try {
552
- const i = JSON.parse(n.data);
553
- this.handleMessage(i);
554
- } catch (i) {
555
- console.error("消息解析失败:", i);
556
- }
557
- }), this.socketTask.onClose((n) => {
558
- this.handleClose(n);
559
- }), this.socketTask.onError((n) => {
560
- console.error("WebSocket错误:", n), this.handleClose(n);
561
- }));
562
- }
563
- // 处理接收到的消息
564
- handleMessage(t) {
565
- var s, n;
566
- switch (t.cmd) {
567
- case 0:
568
- this.resetHeartCheck(), (s = this.connectCallBack) == null || s.call(this);
569
- break;
570
- case 1:
571
- this.resetHeartCheck();
572
- break;
573
- default:
574
- (n = this.messageCallBack) == null || n.call(this, t.cmd, t.data);
575
- break;
576
- }
577
- }
578
- // 处理连接关闭
579
- handleClose(t) {
580
- var s;
581
- this.isConnect = !1, this.clearHeartCheck(), (s = this.closeCallBack) == null || s.call(this, t);
582
- }
583
- // 重新连接
584
- reconnect(t, s) {
585
- if (console.log("尝试重新连接"), this.isConnect)
586
- return;
587
- const n = (/* @__PURE__ */ new Date()).getTime() - this.lastConnectTime.getTime(), i = n < 1e4 ? 1e4 - n : 0;
588
- this.reconnectTimer && clearTimeout(this.reconnectTimer), this.reconnectTimer = setTimeout(() => {
589
- this.connect(t, s);
590
- }, i);
591
- }
592
- // 安排重新连接
593
- scheduleReconnect(t, s) {
594
- setTimeout(() => {
595
- this.reconnect(t, s);
596
- }, 1e4);
597
- }
598
- // 关闭连接
599
- close(t = 1e3) {
600
- !this.isConnect || !this.socketTask || (this.clearHeartCheck(), this.socketTask.close({
601
- code: t,
602
- complete: (s) => {
603
- this.isConnect = !1;
604
- },
605
- fail: (s) => {
606
- console.error("关闭WebSocket连接失败", s);
607
- }
608
- }));
609
- }
610
- // 发送消息
611
- sendMessage(t) {
612
- if (!this.isConnect || !this.socketTask) {
613
- console.warn("WebSocket未连接,无法发送消息");
614
- return;
615
- }
616
- this.socketTask.send({ data: t });
617
- }
618
- // 注册连接成功回调
619
- onConnect(t) {
620
- this.connectCallBack = t;
621
- }
622
- // 注册消息接收回调
623
- onMessage(t) {
624
- this.messageCallBack = t;
625
- }
626
- // 注册连接关闭回调
627
- onClose(t) {
628
- this.closeCallBack = t;
629
- }
630
- // 获取连接状态
631
- getIsConnect() {
632
- return this.isConnect;
633
- }
634
- // 获取最后连接时间
635
- getLastConnectTime() {
636
- return this.lastConnectTime;
637
- }
638
- // 设置心跳间隔
639
- setHeartCheckTimeout(t) {
640
- this.heartCheckTimeout = t;
641
- }
642
- // 销毁实例
643
- destroy() {
644
- this.close(), this.clearHeartCheck(), this.reconnectTimer && (clearTimeout(this.reconnectTimer), this.reconnectTimer = null), this.messageCallBack = null, this.closeCallBack = null, this.connectCallBack = null, this.socketTask = null;
645
- }
646
- }
647
- const Ye = new we();
648
- U.name = "ChatItem";
649
- O.name = "ChatMessageItem";
650
- x.name = "ChatBox";
651
- const $e = [
652
- U,
653
- O,
654
- x
655
- ], Fe = (e) => {
656
- $e.forEach((t) => {
657
- e.component(t.name || "", t);
658
- });
659
- }, Ee = {
660
- install: Fe
661
- };
662
- export {
663
- x as ChatBox,
664
- U as ChatItem,
665
- O as ChatMessageItem,
666
- be as MESSAGE_STATUS,
667
- pe as MESSAGE_TYPE,
668
- ye as MessageTypeRange,
669
- Ue as RTC_STATE,
670
- xe as TERMINAL_TYPE,
671
- we as WebSocketManager,
672
- Ne as clearToken,
673
- Ee as default,
674
- Qe as escapeAttribute,
675
- Ke as escapeTextContent,
676
- We as eventBus,
677
- Xe as getRefreshToken,
678
- b as getToken,
679
- Ze as hasHtmlSpecialChars,
680
- Je as html2Escape,
681
- y as htmlEscape,
682
- Ae as htmlUnescape,
683
- Fe as install,
684
- qe as isAuthed,
685
- k as request,
686
- Ge as requestx,
687
- Pe as safeHTML,
688
- ze as setAuth,
689
- Le as setRefreshToken,
690
- je as setSafeHTML,
691
- Oe as setToken,
692
- Me as useDynamicRefs,
693
- Ye as webSocketManager
694
- };
package/dist/style.css DELETED
@@ -1 +0,0 @@
1
- .u-im-chat-item[data-v-a0bce79a]{display:flex;padding:12px 16px;cursor:pointer;transition:background-color .3s}.u-im-chat-item[data-v-a0bce79a]:hover{background-color:#f5f7fa}.u-im-chat-item__avatar[data-v-a0bce79a]{margin-right:12px}.u-im-chat-item__content[data-v-a0bce79a]{flex:1;min-width:0}.u-im-chat-item__header[data-v-a0bce79a]{display:flex;justify-content:space-between;align-items:center;margin-bottom:4px}.u-im-chat-item__name[data-v-a0bce79a]{font-size:16px;font-weight:500;color:#303133}.u-im-chat-item__time[data-v-a0bce79a]{font-size:12px;color:#909399}.u-im-chat-item__message[data-v-a0bce79a]{display:flex;justify-content:space-between;align-items:center}.u-im-chat-item__text[data-v-a0bce79a]{font-size:14px;color:#606266;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1}.u-im-chat-item__badge[data-v-a0bce79a]{margin-left:8px}.u-im-message-item[data-v-66e9b9aa]{display:flex;margin-bottom:16px}.u-im-message-item--left[data-v-66e9b9aa]{justify-content:flex-start}.u-im-message-item--right[data-v-66e9b9aa]{justify-content:flex-end}.u-im-message-item--right .u-im-message-item__content[data-v-66e9b9aa]{flex-direction:row-reverse}.u-im-message-item__avatar[data-v-66e9b9aa]{margin:0 8px;align-self:flex-end}.u-im-message-item__content[data-v-66e9b9aa]{display:flex;align-items:flex-end;max-width:70%}.u-im-message-item__bubble[data-v-66e9b9aa]{padding:8px 12px;border-radius:8px;position:relative}.u-im-message-item__bubble--text[data-v-66e9b9aa]{background-color:#f0f2f5;color:#303133}.u-im-message-item--right .u-im-message-item__bubble--text[data-v-66e9b9aa]{background-color:#409eff;color:#fff}.u-im-message-item__image[data-v-66e9b9aa]{border-radius:4px;overflow:hidden}.u-im-message-item__voice[data-v-66e9b9aa]{display:flex;align-items:center;gap:8px;padding:8px 16px;background-color:#f0f2f5;border-radius:16px}.u-im-message-item--right .u-im-message-item__voice[data-v-66e9b9aa]{background-color:#409eff;color:#fff}.u-im-message-item__duration[data-v-66e9b9aa]{font-size:12px}.u-im-message-item__status[data-v-66e9b9aa]{margin:0 4px;display:flex;align-items:center}.u-im-chat-box[data-v-d331769d]{display:flex;flex-direction:column;height:600px;border:1px solid #e4e7ed;border-radius:8px;overflow:hidden}.u-im-chat-box__header[data-v-d331769d]{display:flex;justify-content:space-between;align-items:center;padding:12px 16px;background-color:#f5f7fa;border-bottom:1px solid #e4e7ed}.u-im-chat-box__title[data-v-d331769d]{font-size:16px;font-weight:500;color:#303133}.u-im-chat-box__messages[data-v-d331769d]{flex:1;padding:16px;overflow-y:auto;background-color:#fafafa}.u-im-chat-box__loading[data-v-d331769d]{display:flex;justify-content:center;padding:16px}.u-im-chat-box__input[data-v-d331769d]{border-top:1px solid #e4e7ed;background-color:#fff}.u-im-chat-box__tools[data-v-d331769d]{padding:8px 16px;border-bottom:1px solid #e4e7ed}.u-im-chat-box__textarea[data-v-d331769d]{padding:12px 16px}.u-im-chat-box__send[data-v-d331769d]{padding:0 16px 12px;text-align:right}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes