Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
foreign
/
customer-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cb2682db
authored
Jan 17, 2022
by
董文博
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'master' of
http://gitlab.corp.qinqinxiaobao.com:9880/uniplat/customer-service
parents
94eb5164
19a72930
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
13 additions
and
176 deletions
components/controller/chat-list.ts
hybrid-input/index.vue → components/hybrid-input.vue
components/image-preview.vue
components/message-input.vue
components/message-list.vue
components/message.vue
database/index.ts
store/index.ts
store/model.ts
components/controller/chat-list.ts
View file @
cb2682db
...
...
@@ -54,9 +54,6 @@ export default class ChatList extends Vue {
@
chatStore
.
Getter
(
ChatStore
.
STATE_CHAT_MSG_HISTORY
)
protected
readonly
historyMessage
!
:
ChatStore
.
STATE_CHAT_MSG_HISTORY
;
@
chatStore
.
Getter
(
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
)
protected
readonly
sendingMessages
!
:
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
;
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_CLEAR_CURRENT_CHAT_ID
)
protected
readonly
clearCurrentChatId
!
:
ChatStore
.
MUTATION_CLEAR_CURRENT_CHAT_ID
;
...
...
hybrid-input/index
.vue
→
components/hybrid-input
.vue
View file @
cb2682db
...
...
@@ -85,7 +85,7 @@
MESSAGE_FILE_EMPTY
,
MESSAGE_FILE_TOO_LARGE
,
MESSAGE_IMAGE_TOO_LARGE
,
}
from
".
./components
/message-item/file-controller"
;
}
from
"./message-item/file-controller"
;
import
{
EmojiItem
,
EmojiService
}
from
"../service/emoji"
;
import
{
ChatStore
}
from
"../store/model"
;
import
{
formatFileSize
}
from
"../utils"
;
...
...
components/image-preview.vue
View file @
cb2682db
...
...
@@ -8,7 +8,7 @@
width=
"90%"
top=
"60px"
>
<div
class=
"d-flex flex-column"
>
<div
class=
"d-flex flex-column"
v-if=
"value"
>
<div
class=
"d-flex justify-content-center align-items-start"
>
<img
v-if=
"file"
:src=
"file.url"
:style=
"imgStyle"
/>
<i
class=
"el-icon-close"
@
click=
"close"
></i>
...
...
components/message-input.vue
View file @
cb2682db
...
...
@@ -8,17 +8,13 @@
</
template
>
<
script
lang=
"ts"
>
import
{
Component
,
Ref
,
Vue
,
Watch
}
from
"vue-property-decorator"
;
import
ChatInput
,
{
isFileElement
,
isImageOrFile
,
}
from
"../hybrid-input/index.vue"
;
import
{
Message
,
MessageType
}
from
"../model"
;
import
ChatInput
,
{
isFileElement
,
isImageOrFile
}
from
"./hybrid-input.vue"
;
import
{
MessageType
}
from
"../model"
;
import
{
uploadFile
}
from
"../service/upload"
;
import
xim
from
"../xim/xim"
;
import
Chat
from
"../xim"
;
import
{
ChatStore
,
chatStore
}
from
"@/customer-service/store/model"
;
let
sendingMessageIndex
=
1
;
@
Component
({
components
:
{
ChatInput
}
})
export
default
class
MessageInput
extends
Vue
{
@
chatStore
.
State
(
ChatStore
.
STATE_CHAT_DIALOG_VISIBLE
)
...
...
@@ -39,15 +35,6 @@
@
chatStore
.
Getter
(
ChatStore
.
STATE_CHAT_SOURCE
)
private
readonly
source
!
:
ChatStore
.
STATE_CHAT_SOURCE
;
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_APPEND_SENDING_MESSAGE
)
private
readonly
appendSendingMessages
!
:
ChatStore
.
MUTATION_APPEND_SENDING_MESSAGE
;
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_FAILED_SENDING_MESSAGE
)
private
readonly
failedSendingMessage
!
:
ChatStore
.
MUTATION_FAILED_SENDING_MESSAGE
;
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_REMOVE_SENDING_MESSAGE
)
private
readonly
removeSendingMessages
!
:
ChatStore
.
MUTATION_REMOVE_SENDING_MESSAGE
;
@
Ref
(
"chat-input"
)
private
readonly
chatInput
!
:
ChatInput
;
...
...
@@ -128,7 +115,6 @@
size
:
number
;
};
if
(
src
)
{
const
index
=
this
.
sendSendingMessage
(
type
,
src
);
const
file
=
await
this
.
readBlobUrl2Base64
(
src
.
url
,
src
.
name
);
if
(
file
)
{
let
w
=
0
;
...
...
@@ -168,18 +154,11 @@
msgType
:
type
,
msg
:
JSON
.
stringify
(
msg
),
});
this
.
removeSendingMessages
(
index
);
URL
.
revokeObjectURL
(
src
.
url
);
return
index
;
}
else
{
this
.
setMsg2Failed
(
index
);
}
})
.
catch
((
e
)
=>
{
// eslint-disable-next-line no-console
console
.
error
(
e
);
this
.
setMsg2Failed
(
index
);
.
catch
(()
=>
{
Chat
.
error
(
"发送文件失败"
);
this
.
chatInput
&&
this
.
chatInput
.
updateUploadProgress
(
0
);
});
...
...
@@ -187,28 +166,6 @@
}
}
private
setMsg2Failed
(
index
:
number
)
{
this
.
failedSendingMessage
(
index
);
}
private
sendSendingMessage
(
type
:
string
,
msg
:
any
)
{
const
index
=
sendingMessageIndex
++
;
if
(
this
.
source
)
{
Object
.
assign
(
msg
,
{
source
:
this
.
source
,
eid
:
this
.
chatMyId
});
}
if
(
this
.
chatId
)
{
this
.
appendSendingMessages
({
id
:
-
index
,
chat_id
:
this
.
chatId
,
ts
:
Date
.
now
(),
type
,
msg
:
JSON
.
stringify
(
msg
),
}
as
Message
);
return
-
index
;
}
return
0
;
}
private
readBlobUrl2Base64
(
url
:
string
,
name
:
string
)
{
return
fetch
(
url
)
.
then
((
r
)
=>
r
.
blob
())
...
...
components/message-list.vue
View file @
cb2682db
...
...
@@ -17,8 +17,6 @@
{{
format2Time
(
item
.
ts
)
}}
</div>
<message
:is-sending-message=
"item.id
<
0
"
:failed=
"item.status === -1"
:key=
"item.id"
:data=
"item"
:shape=
"shape"
...
...
@@ -50,15 +48,13 @@
import
{
dbController
}
from
"../database"
;
import
{
getLastMessageId
}
from
"../store"
;
import
{
CustomerServiceEvent
}
from
"../event"
;
import
xim
from
"../xim/xim"
;
@
Component
({
components
:
{
message
,
ImagePreview
,
VideoPreview
}
})
export
default
class
MessageList
extends
Vue
{
@
chatStore
.
Getter
(
ChatStore
.
STATE_CHAT_MSG_HISTORY
)
private
readonly
historyMessage
!
:
ChatStore
.
STATE_CHAT_MSG_HISTORY
;
@
chatStore
.
Getter
(
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
)
private
readonly
sendingMessages
!
:
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
;
@
chatStore
.
State
(
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
)
private
readonly
chatId
!
:
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
;
...
...
@@ -77,9 +73,6 @@
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_CLEAR_FUNC_SCROLL_TO_BOTTOM
)
private
readonly
clearScrollToBottomFunc
!
:
ChatStore
.
MUTATION_CLEAR_FUNC_SCROLL_TO_BOTTOM
;
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_SAVE_FUNC_ON_NEW_MSG
)
private
readonly
onNewMessage
!
:
ChatStore
.
MUTATION_SAVE_FUNC_ON_NEW_MSG
;
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_CLEAR_FUNC_ON_NEW_MSG
)
private
readonly
clearNewMessage
!
:
ChatStore
.
MUTATION_CLEAR_FUNC_ON_NEW_MSG
;
...
...
@@ -93,22 +86,7 @@
private
shape
!
:
string
;
private
get
messages
()
{
if
(
this
.
historyMessage
)
{
if
(
this
.
sendingMessages
&&
this
.
sendingMessages
.
length
)
{
return
[...
this
.
historyMessage
,
...
this
.
sendingMessages
].
filter
(
(
i
)
=>
i
.
chat_id
===
this
.
chatId
&&
i
.
id
>
0
);
}
return
this
.
historyMessage
;
}
if
(
this
.
sendingMessages
&&
this
.
sendingMessages
.
length
)
{
return
this
.
sendingMessages
.
filter
(
(
i
)
=>
i
.
chat_id
===
this
.
chatId
&&
i
.
id
>
0
);
}
return
[];
return
this
.
historyMessage
||
[];
}
// 添加时间戳的最大间隔消息数
...
...
@@ -338,7 +316,8 @@
const
removingIds
:
number
[]
=
[];
for
(
const
item
of
data
)
{
if
(
item
.
type
===
MessageType
.
Withdraw
)
{
item
.
msg
&&
removingIds
.
push
(...
JSON
.
parse
(
item
.
msg
));
const
o
=
xim
.
withDrawMsgHandle
(
item
);
item
.
msg
&&
removingIds
.
push
(...
o
);
}
}
...
...
components/message.vue
View file @
cb2682db
...
...
@@ -99,13 +99,6 @@
>
</div>
<i
class=
"el-icon-warning text-danger"
v-if=
"failed"
title=
"发送失败"
></i>
<i
class=
"el-icon-loading"
v-else-if=
"isSendingMessage"
></i>
<span
class=
"withdraw"
v-if=
"showWithdraw"
@
click=
"withdraw"
>
撤回此消息
</span
>
...
...
@@ -247,12 +240,6 @@
@
Prop
({
type
:
Object
,
default
:
()
=>
Object
.
create
(
null
)
})
private
readonly
data
!
:
dto
.
Message
;
@
Prop
()
private
readonly
isSendingMessage
!
:
boolean
;
@
Prop
()
private
readonly
failed
!
:
boolean
;
@
Prop
({
default
:
"circle"
})
private
readonly
shape
!
:
string
;
...
...
@@ -371,10 +358,6 @@
}
private
get
isMyMessage
()
{
if
(
this
.
isSendingMessage
)
{
return
true
;
}
// 系统推送的消息或老用户(一般是客服,eid为负数),默认为客服发送
if
(
this
.
messageBody
&&
...
...
@@ -554,12 +537,6 @@
}
private
openFile
(
url
:
string
)
{
if
(
this
.
isSendingMessage
)
{
return
;
}
if
(
this
.
failed
)
{
return
;
}
const
copy
=
{
...
this
.
messageBody
.
msg
};
copy
.
url
=
url
;
this
.
$emit
(
"open"
,
{
type
:
this
.
messageType
,
msg
:
copy
});
...
...
database/index.ts
View file @
cb2682db
...
...
@@ -390,7 +390,7 @@ class ChatCacheDatabaseController {
}
public
removeMessage
(
chat
:
number
,
msgs
:
number
[])
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
return
new
Promise
<
void
>
((
resolve
)
=>
{
if
(
this
.
db
)
{
const
store
=
this
.
buildChatMessageStore
(
chat
);
let
count
=
0
;
...
...
store/index.ts
View file @
cb2682db
...
...
@@ -153,7 +153,6 @@ export default {
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID
]:
null
,
[
ChatStore
.
STATE_CHAT_CURRENT_USER_UID
]:
null
,
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
]:
null
,
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]:
[],
[
ChatStore
.
STATE_MY_CHAT_ROOM_LIST
]:
[],
[
ChatStore
.
STATE_SINGLE_CHAT
]:
null
,
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_VERSION
]:
null
,
...
...
@@ -277,7 +276,7 @@ export default {
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
if
(
!
chatId
)
return
;
state
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
]
=
Object
.
freeze
(
combineMessages
(
data
||
[],
old
,
chatId
)
combineMessages
(
old
,
data
||
[]
,
chatId
)
);
},
[
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_MEMBERS
](
...
...
@@ -325,58 +324,6 @@ export default {
[
ChatStore
.
MUTATION_CLEAR_FUNC_ON_NEW_MSG
](
state
)
{
state
[
ChatStore
.
STATE_FUNC_ON_NEW_MSG
]
=
()
=>
true
;
},
[
ChatStore
.
MUTATION_APPEND_SENDING_MESSAGE
]:
(
state
,
payload
:
ChatStore
.
STATE_CHAT_SENDING_MESSAGE
)
=>
{
const
current
=
state
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]
as
ChatStore
.
STATE_CHAT_SENDING_MESSAGE
[];
if
(
current
)
{
current
.
push
(
payload
);
const
chat
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
]
as
number
;
dbController
.
appendMessages
(
chat
,
[
payload
]);
}
preCacheImgs
([
payload
]).
then
(()
=>
{
setTimeout
(
()
=>
state
[
ChatStore
.
STATE_FUNC_SCROLL_TO_BOTTOM
](),
100
);
});
},
[
ChatStore
.
MUTATION_REMOVE_SENDING_MESSAGE
]:
(
state
,
payload
:
number
)
=>
{
const
current
=
state
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]
as
ChatStore
.
STATE_CHAT_SENDING_MESSAGE
[];
if
(
current
)
{
const
target
=
current
.
find
((
i
)
=>
i
.
id
===
payload
);
if
(
target
)
{
const
index
=
current
.
indexOf
(
target
);
current
.
splice
(
index
,
1
);
}
}
},
[
ChatStore
.
MUTATION_FAILED_SENDING_MESSAGE
]:
(
state
,
payload
:
number
)
=>
{
const
current
=
state
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]
as
ChatStore
.
STATE_CHAT_SENDING_MESSAGE
[];
if
(
current
)
{
const
target
=
current
.
find
((
i
)
=>
i
.
id
===
payload
);
if
(
target
)
{
target
.
status
=
-
1
;
}
state
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]
=
[...
current
];
}
},
[
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_INPUTING
]:
(
function
()
{
const
setTimeoutId
:
{
[
key
:
string
]:
number
}
=
{};
return
(
...
...
@@ -1180,9 +1127,6 @@ export default {
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
](
state
)
{
return
state
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
]
??
[];
},
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
](
state
)
{
return
state
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]
||
[];
},
[
ChatStore
.
STATE_CURRENT_CHAT_MEMBERS
](
state
)
{
return
state
[
ChatStore
.
STATE_CURRENT_CHAT_MEMBERS
]
??
[];
},
...
...
store/model.ts
View file @
cb2682db
...
...
@@ -25,11 +25,6 @@ export namespace ChatStore {
export
type
STATE_SINGLE_CHAT
=
ChatType
|
null
;
export
const
STATE_CHAT_MSG_HISTORY
=
"某个会话聊天记录"
;
export
type
STATE_CHAT_MSG_HISTORY
=
dto
.
MessageRequestResult
|
null
;
export
const
STATE_CHAT_SENDING_MESSAGES
=
"sendingMessages"
;
export
type
STATE_CHAT_SENDING_MESSAGES
=
dto
.
MessageRequestResult
|
null
;
export
type
STATE_CHAT_SENDING_MESSAGE
=
dto
.
Message
;
export
const
STATE_CHAT_CURRENT_CHAT_ID
=
"当前chat-id"
;
export
type
STATE_CHAT_CURRENT_CHAT_ID
=
number
;
export
const
STATE_CHAT_CURRENT_CHAT_VERSION
=
"当前chat的Uniplat version"
;
...
...
@@ -222,17 +217,6 @@ export namespace ChatStore {
export
const
MUTATION_CLEAR_FUNC_ON_NEW_MSG
=
"删除收到新消息后的方法"
;
export
type
MUTATION_CLEAR_FUNC_ON_NEW_MSG
=
()
=>
void
;
export
const
MUTATION_APPEND_SENDING_MESSAGE
=
"appendSendingMessage"
;
export
type
MUTATION_APPEND_SENDING_MESSAGE
=
(
payload
:
dto
.
Message
)
=>
void
;
export
const
MUTATION_REMOVE_SENDING_MESSAGE
=
"removeSendingMessage"
;
export
type
MUTATION_REMOVE_SENDING_MESSAGE
=
(
id
:
number
)
=>
void
;
export
const
MUTATION_FAILED_SENDING_MESSAGE
=
"failedSendingMessage"
;
export
type
MUTATION_FAILED_SENDING_MESSAGE
=
(
id
:
number
)
=>
void
;
export
const
MUTATION_SAVE_CURRENT_CHAT_INPUTING
=
"保存正在输入"
;
export
type
MUTATION_SAVE_CURRENT_CHAT_INPUTING
=
(
params
:
chatDto
.
NotifyMessage
...
...
@@ -394,7 +378,6 @@ export namespace ChatStore {
export
interface
ChatStoreState
{
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
]:
ChatStore
.
STATE_CHAT_MSG_HISTORY
;
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]:
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
;
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
]:
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
;
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID
]:
ChatStore
.
STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID
;
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_VERSION
]:
ChatStore
.
STATE_CHAT_CURRENT_CHAT_VERSION
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment