im-ui-mobile 0.0.24 → 0.0.26

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/index.js CHANGED
@@ -13,9 +13,8 @@ const install = (app) => {
13
13
  })
14
14
  }
15
15
 
16
- import datetime from './utils/datetime.ts'
17
- export * from './libs/index.ts'
18
- export {datetime}
16
+ import datetime from './utils/datetime.js'
17
+ export { datetime }
19
18
 
20
19
  export default {
21
20
  install
package/libs/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type { RTC_STATE, MESSAGE_TYPE } from '../utils/enums'
2
2
 
3
- export * from './user'
4
- export * from './recorder'
3
+
5
4
 
6
5
  /**
7
6
  * 通话模式类型
@@ -179,4 +178,46 @@ export interface ApiResponse<T = any> {
179
178
  success?: boolean
180
179
  timestamp?: number
181
180
  path?: string
181
+ }
182
+
183
+ // -----------------------------
184
+ // Recorder
185
+ // -----------------------------
186
+ export interface RecorderError {
187
+ errMsg: string;
188
+ }
189
+
190
+ export interface UploadRecorderFileResponse {
191
+ code: number;
192
+ data: string;
193
+ message?: string;
194
+ }
195
+
196
+ export interface UploadRecorderFileResult {
197
+ duration: number;
198
+ url: string;
199
+ }
200
+
201
+ export interface RecorderFile {
202
+ tempFilePath: string;
203
+ }
204
+
205
+ /**
206
+ * 用户信息接口
207
+ */
208
+ export interface UserInfo {
209
+ id: number
210
+ nickName: string
211
+ headImage: string
212
+ headImageThumb?: string
213
+ email?: string
214
+ phone?: string
215
+ gender?: number
216
+ signature?: string
217
+ isBanned?: boolean
218
+ reason?: string
219
+ userName?: string
220
+ sex?: number
221
+ online?: boolean
222
+ [key: string]: any
182
223
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "im-ui-mobile",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
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,4 +1,39 @@
1
1
  /// <reference path="./components.d.ts" />
2
2
  declare module 'im-ui-mobile' {
3
3
  export function install(): void
4
+
5
+ /**
6
+ * 日期时间工具模块
7
+ */
8
+ export const datetime: {
9
+ /**
10
+ * 将时间戳转换为相对时间文本
11
+ */
12
+ toTimeText: (timeStamp: number | string | Date, simple?: boolean) => string;
13
+
14
+ /**
15
+ * 判断日期是否是昨天
16
+ */
17
+ isYesterday: (date: Date) => boolean;
18
+
19
+ /**
20
+ * 判断日期是否在今年
21
+ */
22
+ isYear: (date: Date) => boolean;
23
+
24
+ /**
25
+ * 格式化日期时间为字符串
26
+ */
27
+ formatDateTime: (date: string | Date) => string;
28
+
29
+ /**
30
+ * 获取更精确的相对时间描述
31
+ */
32
+ toPreciseTimeText: (timeStamp: number | string | Date) => string;
33
+
34
+ /**
35
+ * 获取聊天界面常用的时间显示格式
36
+ */
37
+ toChatTimeText: (timeStamp: number | string | Date) => string;
38
+ };
4
39
  }
@@ -0,0 +1,153 @@
1
+ // 日期时间工具函数
2
+
3
+ /**
4
+ * 将时间戳转换为相对时间文本
5
+ * @param {number|string|Date} timeStamp - 时间戳
6
+ * @param {boolean} simple - 是否使用简单格式
7
+ * @returns {string} 格式化后的时间文本
8
+ */
9
+ const toTimeText = (timeStamp, simple) => {
10
+ const dateTime = new Date(timeStamp);
11
+ const currentTime = Date.now(); // 当前时间戳
12
+ const timeDiff = currentTime - dateTime.getTime(); // 与当前时间误差
13
+ let timeText = '';
14
+
15
+ if (timeDiff <= 60000) { // 一分钟内
16
+ timeText = '刚刚';
17
+ } else if (timeDiff > 60000 && timeDiff < 3600000) {
18
+ // 1小时内
19
+ timeText = Math.floor(timeDiff / 60000) + '分钟前';
20
+ } else if (timeDiff >= 3600000 && timeDiff < 86400000 && !isYesterday(dateTime)) {
21
+ // 今日
22
+ timeText = formatDateTime(dateTime).substr(11, 5);
23
+ } else if (isYesterday(dateTime)) {
24
+ // 昨天
25
+ timeText = '昨天' + formatDateTime(dateTime).substr(11, 5);
26
+ } else if (isYear(dateTime)) {
27
+ // 今年
28
+ timeText = formatDateTime(dateTime).substr(5, simple ? 5 : 14);
29
+ } else {
30
+ // 不属于今年
31
+ timeText = formatDateTime(dateTime);
32
+ if (simple) {
33
+ timeText = timeText.substr(2, 8);
34
+ }
35
+ }
36
+ return timeText;
37
+ }
38
+
39
+ /**
40
+ * 判断日期是否是昨天
41
+ * @param {Date} date - 日期对象
42
+ * @returns {boolean} 是否是昨天
43
+ */
44
+ const isYesterday = (date) => {
45
+ const yesterday = new Date(Date.now() - 1000 * 60 * 60 * 24);
46
+ return yesterday.getFullYear() === date.getFullYear() &&
47
+ yesterday.getMonth() === date.getMonth() &&
48
+ yesterday.getDate() === date.getDate();
49
+ }
50
+
51
+ /**
52
+ * 判断日期是否在今年
53
+ * @param {Date} date - 日期对象
54
+ * @returns {boolean} 是否在今年
55
+ */
56
+ const isYear = (date) => {
57
+ return date.getFullYear() === new Date().getFullYear();
58
+ }
59
+
60
+ /**
61
+ * 格式化日期时间为字符串
62
+ * @param {string|Date} date - 日期对象或字符串
63
+ * @returns {string} 格式化后的日期时间字符串
64
+ */
65
+ const formatDateTime = (date) => {
66
+ if (date === '' || !date) {
67
+ return '';
68
+ }
69
+
70
+ const dateObject = new Date(date);
71
+
72
+ // 检查日期是否有效
73
+ if (isNaN(dateObject.getTime())) {
74
+ return '';
75
+ }
76
+
77
+ const y = dateObject.getFullYear();
78
+ const m = dateObject.getMonth() + 1;
79
+ const month = m < 10 ? ('0' + m) : m;
80
+ const d = dateObject.getDate();
81
+ const day = d < 10 ? ('0' + d) : d;
82
+ const h = dateObject.getHours();
83
+ const hour = h < 10 ? ('0' + h) : h;
84
+ const minute = dateObject.getMinutes();
85
+ const min = minute < 10 ? ('0' + minute) : minute;
86
+ const second = dateObject.getSeconds();
87
+ const sec = second < 10 ? ('0' + second) : second;
88
+
89
+ return `${y}/${month}/${day} ${hour}:${min}:${sec}`;
90
+ }
91
+
92
+ /**
93
+ * 获取更精确的相对时间描述
94
+ * @param {number|string|Date} timeStamp - 时间戳
95
+ * @returns {string} 精确的相对时间文本
96
+ */
97
+ const toPreciseTimeText = (timeStamp) => {
98
+ const dateTime = new Date(timeStamp);
99
+ const currentTime = Date.now();
100
+ const timeDiff = currentTime - dateTime.getTime();
101
+
102
+ if (timeDiff < 60000) {
103
+ return `${Math.floor(timeDiff / 1000)}秒前`;
104
+ } else if (timeDiff < 3600000) {
105
+ const minutes = Math.floor(timeDiff / 60000);
106
+ return `${minutes}分钟前`;
107
+ } else if (timeDiff < 86400000) {
108
+ const hours = Math.floor(timeDiff / 3600000);
109
+ return `${hours}小时前`;
110
+ } else if (timeDiff < 604800000) {
111
+ const days = Math.floor(timeDiff / 86400000);
112
+ return `${days}天前`;
113
+ } else {
114
+ return formatDateTime(dateTime);
115
+ }
116
+ }
117
+
118
+ /**
119
+ * 获取聊天界面常用的时间显示格式
120
+ * @param {number|string|Date} timeStamp - 时间戳
121
+ * @returns {string} 聊天时间显示文本
122
+ */
123
+ const toChatTimeText = (timeStamp) => {
124
+ const dateTime = new Date(timeStamp);
125
+ const currentTime = Date.now();
126
+ const timeDiff = currentTime - dateTime.getTime();
127
+
128
+ // 今天内的消息
129
+ if (timeDiff < 86400000 && !isYesterday(dateTime)) {
130
+ return formatDateTime(dateTime).substr(11, 5);
131
+ }
132
+ // 昨天的消息
133
+ else if (isYesterday(dateTime)) {
134
+ return '昨天 ' + formatDateTime(dateTime).substr(11, 5);
135
+ }
136
+ // 今年内的消息
137
+ else if (isYear(dateTime)) {
138
+ return formatDateTime(dateTime).substr(5, 5); // MM/dd
139
+ }
140
+ // 往年的消息
141
+ else {
142
+ return formatDateTime(dateTime).substr(2, 8); // yy/MM/dd
143
+ }
144
+ }
145
+
146
+ export default {
147
+ toTimeText,
148
+ toPreciseTimeText,
149
+ toChatTimeText,
150
+ isYesterday,
151
+ isYear,
152
+ formatDateTime
153
+ };
package/libs/recorder.ts DELETED
@@ -1,21 +0,0 @@
1
- // -----------------------------
2
- // Recorder
3
- // -----------------------------
4
- export interface RecorderError {
5
- errMsg: string;
6
- }
7
-
8
- export interface UploadRecorderFileResponse {
9
- code: number;
10
- data: string;
11
- message?: string;
12
- }
13
-
14
- export interface UploadRecorderFileResult {
15
- duration: number;
16
- url: string;
17
- }
18
-
19
- export interface RecorderFile {
20
- tempFilePath: string;
21
- }
package/libs/user.ts DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * 用户信息接口
3
- */
4
- export interface UserInfo {
5
- id: number
6
- nickName: string
7
- headImage: string
8
- headImageThumb?: string
9
- email?: string
10
- phone?: string
11
- gender?: number
12
- signature?: string
13
- isBanned?: boolean
14
- reason?: string
15
- userName?: string
16
- sex?: number
17
- online?: boolean
18
- [key: string]: any
19
- }