@aochuang/client-sdk 1.0.308 → 1.0.310
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/components/chat-panel/chat-panel-box.vue +1 -1
- package/components/chat-panel/chat-panel-chat.vue +1 -1
- package/components/chat-panel/chat-panel-chats.vue +28 -23
- package/components/chat-panel/chat-panel.vue +3 -0
- package/components/wechat-chat-panel/chat-panel.vue +105 -31
- package/components/wechat-chat-panel/util.js +75 -0
- package/package.json +1 -1
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
<div class="sdk-chat-panel-box__foot-row" v-if="inner_foot_vnode">
|
|
36
36
|
<component :is="inner_foot_vnode"></component>
|
|
37
37
|
</div>
|
|
38
|
-
<div class="sdk-chat-panel-box__foot-row" v-if="$slots.foot">
|
|
38
|
+
<div class="sdk-chat-panel-box__foot-row" v-if="$slots.foot || $scopedSlots.foot">
|
|
39
39
|
<slot name="foot"></slot>
|
|
40
40
|
</div>
|
|
41
41
|
<div class="sdk-chat-panel-box__foot-row is-last">
|
|
@@ -18,31 +18,35 @@
|
|
|
18
18
|
@range="handleIncrementRangeMore"
|
|
19
19
|
></chat-panel-increment>
|
|
20
20
|
<template v-if="dataType === 'array'">
|
|
21
|
-
<
|
|
21
|
+
<template
|
|
22
22
|
v-for="item in data"
|
|
23
|
-
:key="'chat_' + item[keyField]"
|
|
24
|
-
:dir="handleisSenderMethod(item) ? 'right' : 'left'"
|
|
25
|
-
:class="handleChatClassMethod(item)"
|
|
26
|
-
:id="item[keyField]"
|
|
27
|
-
:item="item"
|
|
28
|
-
:render-control="renderControl"
|
|
29
|
-
:fetch-user-method="fetchUserMethod"
|
|
30
|
-
:ref="'chat_' + item[keyField]"
|
|
31
|
-
:show-context-btn="showContextBtn"
|
|
32
|
-
:msg-time-field="msgTimeField"
|
|
33
|
-
@view-context="handleViewContextClick(item)"
|
|
34
|
-
@contextmenu="handleChatContextMenu(item, $event)"
|
|
35
23
|
>
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
24
|
+
<slot name="chat-before" :item="item"></slot>
|
|
25
|
+
<chat-panel-chat
|
|
26
|
+
:key="'chat_' + item[keyField]"
|
|
27
|
+
:dir="handleisSenderMethod(item) ? 'right' : 'left'"
|
|
28
|
+
:class="handleChatClassMethod(item)"
|
|
29
|
+
:id="item[keyField]"
|
|
30
|
+
:item="item"
|
|
31
|
+
:render-control="renderControl"
|
|
32
|
+
:fetch-user-method="fetchUserMethod"
|
|
33
|
+
:ref="'chat_' + item[keyField]"
|
|
34
|
+
:show-context-btn="showContextBtn"
|
|
35
|
+
:msg-time-field="msgTimeField"
|
|
36
|
+
@view-context="handleViewContextClick(item)"
|
|
37
|
+
@contextmenu="handleChatContextMenu(item, $event)"
|
|
38
|
+
>
|
|
39
|
+
<template slot="chat" slot-scope="scope">
|
|
40
|
+
<slot name="chat" v-bind="scope"></slot>
|
|
41
|
+
</template>
|
|
42
|
+
<template slot-scope="scope" slot="chat-foot">
|
|
43
|
+
<slot name="chat-foot" v-bind="scope"></slot>
|
|
44
|
+
</template>
|
|
45
|
+
<template slot-scope="scope" slot="chat-append">
|
|
46
|
+
<slot name="chat-append" v-bind="scope"></slot>
|
|
47
|
+
</template>
|
|
48
|
+
</chat-panel-chat>
|
|
49
|
+
</template>
|
|
46
50
|
</template>
|
|
47
51
|
<template v-else>
|
|
48
52
|
<template v-for="day in data">
|
|
@@ -52,6 +56,7 @@
|
|
|
52
56
|
<template
|
|
53
57
|
v-for="item in milliseconds"
|
|
54
58
|
>
|
|
59
|
+
<slot name="chat-before" :item="item"></slot>
|
|
55
60
|
<chat-panel-chat
|
|
56
61
|
:key="'chat_' + item[keyField]"
|
|
57
62
|
:dir="handleisSenderMethod(item) ? 'right' : 'left'"
|
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
@view-context="handleChatsViewContext"
|
|
32
32
|
@chat-contextmenu="handleChatContext"
|
|
33
33
|
>
|
|
34
|
+
<template slot="chat-before" slot-scope="scope">
|
|
35
|
+
<slot name="chat-before" v-bind="scope"></slot>
|
|
36
|
+
</template>
|
|
34
37
|
<template slot="chat" slot-scope="scope">
|
|
35
38
|
<slot name="chat" v-bind="scope"></slot>
|
|
36
39
|
</template>
|
|
@@ -14,39 +14,49 @@
|
|
|
14
14
|
<template slot="filter">
|
|
15
15
|
<slot name="filter"></slot>
|
|
16
16
|
</template>
|
|
17
|
-
<template slot="chat" slot-scope="{ item
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
:fetch-user-method="fetchUserMethod"
|
|
22
|
-
:config="config"
|
|
23
|
-
:show-user-name="showUserName"
|
|
24
|
-
@user-avatar-click="handleUserAvatarClick"
|
|
25
|
-
@user-avatar-contextmenu="handleUserAvatarContextmenu"
|
|
17
|
+
<template slot="chat-before" slot-scope="{ item }">
|
|
18
|
+
<div
|
|
19
|
+
v-if="handleShowTimeDivider(item)"
|
|
20
|
+
class="sdk-wechat-chat-panel__time"
|
|
26
21
|
>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
22
|
+
{{ formatMessageTime(parseMessageTime(item.wechatTime)) }}
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
<template slot="chat" slot-scope="{ item, dir }">
|
|
26
|
+
<div class="sdk-wechat-chat-panel__item">
|
|
27
|
+
<chat-panel-item
|
|
28
|
+
:item="item"
|
|
29
|
+
:dir="dir"
|
|
30
|
+
:fetch-user-method="fetchUserMethod"
|
|
31
|
+
:config="config"
|
|
32
|
+
:show-user-name="showUserName"
|
|
33
|
+
@user-avatar-click="handleUserAvatarClick"
|
|
34
|
+
@user-avatar-contextmenu="handleUserAvatarContextmenu"
|
|
35
|
+
>
|
|
36
|
+
<template slot="box-append">
|
|
37
|
+
<slot name="box-append" :item="item"></slot>
|
|
38
|
+
</template>
|
|
39
|
+
<template slot="box-append-bottom" slot-scope="scope">
|
|
40
|
+
<slot name="box-append-bottom" :item="item" :hover="scope.hover"></slot>
|
|
41
|
+
</template>
|
|
42
|
+
<template slot="chat-append" slot-scope="{ item, updateProp }">
|
|
43
|
+
<chat-panel-chat-status
|
|
44
|
+
:data="item"
|
|
45
|
+
:update-chat-box-prop="updateProp"
|
|
46
|
+
></chat-panel-chat-status>
|
|
47
|
+
</template>
|
|
48
|
+
<template slot="chat-prefix" slot-scope="{ item }">
|
|
49
|
+
<template v-if="selectable && handleFilterSelectMessageMethod(item)">
|
|
50
|
+
<div class="sdk-wechat-chat-panel__checkbox">
|
|
51
|
+
<ui-checkbox :value="!!checkMsgMap[item[keyField]]" @input="handleMsgCheckboxChange(item, $event)"></ui-checkbox>
|
|
52
|
+
</div>
|
|
53
|
+
</template>
|
|
44
54
|
</template>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
</
|
|
49
|
-
</
|
|
55
|
+
<template slot="quote-message-append" slot-scope="{ item, quoteMessageData }">
|
|
56
|
+
<slot name="chat-quote-message-append" :item="item" :quote-message-data="quoteMessageData"></slot>
|
|
57
|
+
</template>
|
|
58
|
+
</chat-panel-item>
|
|
59
|
+
</div>
|
|
50
60
|
</template>
|
|
51
61
|
<template slot="main">
|
|
52
62
|
<slot name="main"></slot>
|
|
@@ -60,6 +70,8 @@
|
|
|
60
70
|
import SdkChatPanel from '../chat-panel'
|
|
61
71
|
import ChatPanelItem from './chat-panel-item.vue'
|
|
62
72
|
import ChatPanelChatStatus from './chat-panel-chat-status/chat-panel-chat-status.vue'
|
|
73
|
+
import { formatDate } from '../../utils/date'
|
|
74
|
+
import { getPreviousMessage } from './util'
|
|
63
75
|
|
|
64
76
|
export default {
|
|
65
77
|
name: 'SdkWechatChatPanel',
|
|
@@ -147,6 +159,43 @@ export default {
|
|
|
147
159
|
}
|
|
148
160
|
},
|
|
149
161
|
methods: {
|
|
162
|
+
handleShowTimeDivider (item) {
|
|
163
|
+
if (!item || item.msgType === '_EMPTY_') {
|
|
164
|
+
return false
|
|
165
|
+
}
|
|
166
|
+
const currentTime = this.parseMessageTime(item.wechatTime)
|
|
167
|
+
if (currentTime === null) {
|
|
168
|
+
return false
|
|
169
|
+
}
|
|
170
|
+
const previousItem = getPreviousMessage(this.data, item)
|
|
171
|
+
if (!previousItem || previousItem.msgType === '_EMPTY_') {
|
|
172
|
+
return true
|
|
173
|
+
}
|
|
174
|
+
const previousTime = this.parseMessageTime(previousItem.wechatTime)
|
|
175
|
+
return previousTime === null || currentTime - previousTime >= 5 * 60 * 1000
|
|
176
|
+
},
|
|
177
|
+
parseMessageTime (value) {
|
|
178
|
+
if (value === null || value === undefined || value === '') {
|
|
179
|
+
return null
|
|
180
|
+
}
|
|
181
|
+
const date = new Date(typeof value === 'string' && /^[0-9]+$/.test(value) ? Number(value) : value)
|
|
182
|
+
const time = date.getTime()
|
|
183
|
+
return isNaN(time) ? null : time
|
|
184
|
+
},
|
|
185
|
+
formatMessageTime (time) {
|
|
186
|
+
const date = new Date(time)
|
|
187
|
+
const now = new Date()
|
|
188
|
+
const isToday = date.getFullYear() === now.getFullYear() &&
|
|
189
|
+
date.getMonth() === now.getMonth() &&
|
|
190
|
+
date.getDate() === now.getDate()
|
|
191
|
+
if (isToday) {
|
|
192
|
+
return formatDate(date, 'HH:MM')
|
|
193
|
+
}
|
|
194
|
+
if (date.getFullYear() === now.getFullYear()) {
|
|
195
|
+
return formatDate(date, 'mm-dd HH:MM')
|
|
196
|
+
}
|
|
197
|
+
return formatDate(date, 'YYYY-mm-dd HH:MM')
|
|
198
|
+
},
|
|
150
199
|
handleChatClassMethod () {
|
|
151
200
|
return {
|
|
152
201
|
'is-selectable': this.selectable
|
|
@@ -254,6 +303,31 @@ export default {
|
|
|
254
303
|
padding-left: 40px;
|
|
255
304
|
position: relative;
|
|
256
305
|
}
|
|
306
|
+
.sdk-chat-panel-box__date{
|
|
307
|
+
opacity: 0;
|
|
308
|
+
transition: opacity .2s;
|
|
309
|
+
}
|
|
310
|
+
.sdk-chat-panel-box:hover{
|
|
311
|
+
.sdk-chat-panel-box__date{
|
|
312
|
+
opacity: 1;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
.sdk-wechat-chat-panel__item{
|
|
317
|
+
width: 100%;
|
|
318
|
+
.sdk-wechat-chat-panel__time + .sdk-wechat-panel-item{
|
|
319
|
+
.sdk-wechat-chat-panel__checkbox{
|
|
320
|
+
transform: translateY(calc(-50% + 16px));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
.sdk-wechat-chat-panel__time{
|
|
325
|
+
padding: 8px 0 5px;
|
|
326
|
+
color: #999;
|
|
327
|
+
font-size: 12px;
|
|
328
|
+
line-height: 20px;
|
|
329
|
+
text-align: center;
|
|
330
|
+
user-select: none;
|
|
257
331
|
}
|
|
258
332
|
.sdk-wechat-chat-panel__checkbox{
|
|
259
333
|
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
|
+
}
|