@aochuang/client-sdk 1.0.308 → 1.0.309
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.
|
@@ -15,38 +15,46 @@
|
|
|
15
15
|
<slot name="filter"></slot>
|
|
16
16
|
</template>
|
|
17
17
|
<template slot="chat" slot-scope="{ item, dir }">
|
|
18
|
-
<chat-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<
|
|
35
|
-
:
|
|
36
|
-
:update-chat-box-prop="updateProp"
|
|
37
|
-
></chat-panel-chat-status>
|
|
38
|
-
</template>
|
|
39
|
-
<template slot="chat-prefix" slot-scope="{ item }">
|
|
40
|
-
<template v-if="selectable && handleFilterSelectMessageMethod(item)">
|
|
41
|
-
<div class="sdk-wechat-chat-panel__checkbox">
|
|
42
|
-
<ui-checkbox :value="!!checkMsgMap[item[keyField]]" @input="handleMsgCheckboxChange(item, $event)"></ui-checkbox>
|
|
43
|
-
</div>
|
|
18
|
+
<div class="sdk-wechat-chat-panel__item">
|
|
19
|
+
<div
|
|
20
|
+
v-if="handleShowTimeDivider(item)"
|
|
21
|
+
class="sdk-wechat-chat-panel__time"
|
|
22
|
+
>
|
|
23
|
+
{{ formatMessageTime(parseMessageTime(item.wechatTime)) }}
|
|
24
|
+
</div>
|
|
25
|
+
<chat-panel-item
|
|
26
|
+
:item="item"
|
|
27
|
+
:dir="dir"
|
|
28
|
+
:fetch-user-method="fetchUserMethod"
|
|
29
|
+
:config="config"
|
|
30
|
+
:show-user-name="showUserName"
|
|
31
|
+
@user-avatar-click="handleUserAvatarClick"
|
|
32
|
+
@user-avatar-contextmenu="handleUserAvatarContextmenu"
|
|
33
|
+
>
|
|
34
|
+
<template slot="box-append">
|
|
35
|
+
<slot name="box-append" :item="item"></slot>
|
|
44
36
|
</template>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
<template slot="box-append-bottom" slot-scope="scope">
|
|
38
|
+
<slot name="box-append-bottom" :item="item" :hover="scope.hover"></slot>
|
|
39
|
+
</template>
|
|
40
|
+
<template slot="chat-append" slot-scope="{ item, updateProp }">
|
|
41
|
+
<chat-panel-chat-status
|
|
42
|
+
:data="item"
|
|
43
|
+
:update-chat-box-prop="updateProp"
|
|
44
|
+
></chat-panel-chat-status>
|
|
45
|
+
</template>
|
|
46
|
+
<template slot="chat-prefix" slot-scope="{ item }">
|
|
47
|
+
<template v-if="selectable && handleFilterSelectMessageMethod(item)">
|
|
48
|
+
<div class="sdk-wechat-chat-panel__checkbox">
|
|
49
|
+
<ui-checkbox :value="!!checkMsgMap[item[keyField]]" @input="handleMsgCheckboxChange(item, $event)"></ui-checkbox>
|
|
50
|
+
</div>
|
|
51
|
+
</template>
|
|
52
|
+
</template>
|
|
53
|
+
<template slot="quote-message-append" slot-scope="{ item, quoteMessageData }">
|
|
54
|
+
<slot name="chat-quote-message-append" :item="item" :quote-message-data="quoteMessageData"></slot>
|
|
55
|
+
</template>
|
|
56
|
+
</chat-panel-item>
|
|
57
|
+
</div>
|
|
50
58
|
</template>
|
|
51
59
|
<template slot="main">
|
|
52
60
|
<slot name="main"></slot>
|
|
@@ -60,6 +68,8 @@
|
|
|
60
68
|
import SdkChatPanel from '../chat-panel'
|
|
61
69
|
import ChatPanelItem from './chat-panel-item.vue'
|
|
62
70
|
import ChatPanelChatStatus from './chat-panel-chat-status/chat-panel-chat-status.vue'
|
|
71
|
+
import { formatDate } from '../../utils/date'
|
|
72
|
+
import { getPreviousMessage } from './util'
|
|
63
73
|
|
|
64
74
|
export default {
|
|
65
75
|
name: 'SdkWechatChatPanel',
|
|
@@ -147,6 +157,43 @@ export default {
|
|
|
147
157
|
}
|
|
148
158
|
},
|
|
149
159
|
methods: {
|
|
160
|
+
handleShowTimeDivider (item) {
|
|
161
|
+
if (!item || item.msgType === '_EMPTY_') {
|
|
162
|
+
return false
|
|
163
|
+
}
|
|
164
|
+
const currentTime = this.parseMessageTime(item.wechatTime)
|
|
165
|
+
if (currentTime === null) {
|
|
166
|
+
return false
|
|
167
|
+
}
|
|
168
|
+
const previousItem = getPreviousMessage(this.data, item)
|
|
169
|
+
if (!previousItem || previousItem.msgType === '_EMPTY_') {
|
|
170
|
+
return true
|
|
171
|
+
}
|
|
172
|
+
const previousTime = this.parseMessageTime(previousItem.wechatTime)
|
|
173
|
+
return previousTime === null || currentTime - previousTime >= 5 * 60 * 1000
|
|
174
|
+
},
|
|
175
|
+
parseMessageTime (value) {
|
|
176
|
+
if (value === null || value === undefined || value === '') {
|
|
177
|
+
return null
|
|
178
|
+
}
|
|
179
|
+
const date = new Date(typeof value === 'string' && /^[0-9]+$/.test(value) ? Number(value) : value)
|
|
180
|
+
const time = date.getTime()
|
|
181
|
+
return isNaN(time) ? null : time
|
|
182
|
+
},
|
|
183
|
+
formatMessageTime (time) {
|
|
184
|
+
const date = new Date(time)
|
|
185
|
+
const now = new Date()
|
|
186
|
+
const isToday = date.getFullYear() === now.getFullYear() &&
|
|
187
|
+
date.getMonth() === now.getMonth() &&
|
|
188
|
+
date.getDate() === now.getDate()
|
|
189
|
+
if (isToday) {
|
|
190
|
+
return formatDate(date, 'HH:MM')
|
|
191
|
+
}
|
|
192
|
+
if (date.getFullYear() === now.getFullYear()) {
|
|
193
|
+
return formatDate(date, 'mm-dd HH:MM')
|
|
194
|
+
}
|
|
195
|
+
return formatDate(date, 'YYYY-mm-dd HH:MM')
|
|
196
|
+
},
|
|
150
197
|
handleChatClassMethod () {
|
|
151
198
|
return {
|
|
152
199
|
'is-selectable': this.selectable
|
|
@@ -254,6 +301,31 @@ export default {
|
|
|
254
301
|
padding-left: 40px;
|
|
255
302
|
position: relative;
|
|
256
303
|
}
|
|
304
|
+
.sdk-chat-panel-box__date{
|
|
305
|
+
opacity: 0;
|
|
306
|
+
transition: opacity .2s;
|
|
307
|
+
}
|
|
308
|
+
.sdk-chat-panel-box:hover{
|
|
309
|
+
.sdk-chat-panel-box__date{
|
|
310
|
+
opacity: 1;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
.sdk-wechat-chat-panel__item{
|
|
315
|
+
width: 100%;
|
|
316
|
+
.sdk-wechat-chat-panel__time + .sdk-wechat-panel-item{
|
|
317
|
+
.sdk-wechat-chat-panel__checkbox{
|
|
318
|
+
transform: translateY(calc(-50% + 16px));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
.sdk-wechat-chat-panel__time{
|
|
323
|
+
padding: 8px 0 5px;
|
|
324
|
+
color: #999;
|
|
325
|
+
font-size: 12px;
|
|
326
|
+
line-height: 20px;
|
|
327
|
+
text-align: center;
|
|
328
|
+
user-select: none;
|
|
257
329
|
}
|
|
258
330
|
.sdk-wechat-chat-panel__checkbox{
|
|
259
331
|
position: absolute;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const DAY_MILLISECONDS = 24 * 60 * 60 * 1000
|
|
2
|
+
|
|
3
|
+
function parseTime (value) {
|
|
4
|
+
if (value === null || value === undefined || value === '') {
|
|
5
|
+
return null
|
|
6
|
+
}
|
|
7
|
+
const date = new Date(typeof value === 'string' && /^[0-9]+$/.test(value) ? Number(value) : value)
|
|
8
|
+
const time = date.getTime()
|
|
9
|
+
return isNaN(time) ? null : time
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getLastMessage (messages) {
|
|
13
|
+
if (!Array.isArray(messages) || !messages.length) {
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
return messages[messages.length - 1]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getPreviousGroupMessage (groups, currentKey) {
|
|
20
|
+
const keys = Object.keys(groups || {})
|
|
21
|
+
const currentIndex = keys.indexOf(String(currentKey))
|
|
22
|
+
for (let index = currentIndex - 1; index >= 0; index--) {
|
|
23
|
+
const message = getLastMessage(groups[keys[index]])
|
|
24
|
+
if (message) {
|
|
25
|
+
return message
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getPreviousMessage (data, message, timeField = 'wechatTime') {
|
|
31
|
+
if (!data || !message) {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(data)) {
|
|
35
|
+
const index = data.indexOf(message)
|
|
36
|
+
return index > 0 ? data[index - 1] : undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const time = parseTime(message[timeField])
|
|
40
|
+
if (time === null) {
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
const day = Math.floor(time / DAY_MILLISECONDS)
|
|
44
|
+
const milliseconds = time - day * DAY_MILLISECONDS
|
|
45
|
+
const dayData = data[day]
|
|
46
|
+
if (!dayData) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const messages = dayData[milliseconds]
|
|
51
|
+
if (Array.isArray(messages)) {
|
|
52
|
+
const messageIndex = messages.indexOf(message)
|
|
53
|
+
if (messageIndex > 0) {
|
|
54
|
+
return messages[messageIndex - 1]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const previousMessage = getPreviousGroupMessage(dayData, milliseconds)
|
|
59
|
+
if (previousMessage) {
|
|
60
|
+
return previousMessage
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const dayKeys = Object.keys(data)
|
|
64
|
+
const currentDayIndex = dayKeys.indexOf(String(day))
|
|
65
|
+
for (let index = currentDayIndex - 1; index >= 0; index--) {
|
|
66
|
+
const previousDay = data[dayKeys[index]]
|
|
67
|
+
const previousDayKeys = Object.keys(previousDay || {})
|
|
68
|
+
for (let groupIndex = previousDayKeys.length - 1; groupIndex >= 0; groupIndex--) {
|
|
69
|
+
const message = getLastMessage(previousDay[previousDayKeys[groupIndex]])
|
|
70
|
+
if (message) {
|
|
71
|
+
return message
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|