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
8d36ee61
authored
Oct 26, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
会话控制
parent
3347be3d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
76 additions
and
23 deletions
components/chat-room.vue
components/chat-title.vue
components/message-input.vue
components/message-item/file-controller.ts
components/message-list.vue
hybrid-input/index.vue
store/index.ts
store/model.ts
components/chat-room.vue
View file @
8d36ee61
This diff is collapsed.
Click to expand it.
components/chat-title.vue
View file @
8d36ee61
This diff is collapsed.
Click to expand it.
components/message-input.vue
View file @
8d36ee61
...
@@ -128,7 +128,7 @@
...
@@ -128,7 +128,7 @@
};
};
img
.
remove
();
img
.
remove
();
}
}
uploadFile
(
file
)
return
uploadFile
(
file
)
.
then
((
r
)
=>
{
.
then
((
r
)
=>
{
if
(
r
)
{
if
(
r
)
{
const
msg
=
{
const
msg
=
{
...
@@ -150,6 +150,7 @@
...
@@ -150,6 +150,7 @@
});
});
this
.
removeSendingMessages
(
index
);
this
.
removeSendingMessages
(
index
);
URL
.
revokeObjectURL
(
src
.
url
);
URL
.
revokeObjectURL
(
src
.
url
);
return
index
;
}
else
{
}
else
{
this
.
setMsg2Failed
(
index
);
this
.
setMsg2Failed
(
index
);
}
}
...
...
components/message-item/file-controller.ts
View file @
8d36ee61
...
@@ -196,6 +196,7 @@ export const MAX_IMAGE_SIZE = 5 * 1024 * 1024;
...
@@ -196,6 +196,7 @@ export const MAX_IMAGE_SIZE = 5 * 1024 * 1024;
export
const
MAX_IMAGE_SIZE_STRING
=
"5MB"
;
export
const
MAX_IMAGE_SIZE_STRING
=
"5MB"
;
export
const
MESSAGE_IMAGE_TOO_LARGE
=
`您发送的图片大小超过
${
MAX_IMAGE_SIZE_STRING
}
。`
;
export
const
MESSAGE_IMAGE_TOO_LARGE
=
`您发送的图片大小超过
${
MAX_IMAGE_SIZE_STRING
}
。`
;
export
const
MESSAGE_FILE_EMPTY
=
"不能发送空文件。"
;
export
const
MESSAGE_FILE_EMPTY
=
"不能发送空文件。"
;
export
const
ERROR_IMAGE
=
"发送的不是图片"
;
/**
/**
* 最大文件大小
* 最大文件大小
...
...
components/message-list.vue
View file @
8d36ee61
...
@@ -69,9 +69,6 @@
...
@@ -69,9 +69,6 @@
@
chatStore
.
Action
(
ChatStore
.
ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID
)
@
chatStore
.
Action
(
ChatStore
.
ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID
)
private
readonly
getNextPageMsg
!
:
ChatStore
.
ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID
;
private
readonly
getNextPageMsg
!
:
ChatStore
.
ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID
;
@
chatStore
.
Action
(
ChatStore
.
ACTION_CLEAR_CURRENT_CHAT_DATA
)
private
readonly
clearChatId
!
:
ChatStore
.
ACTION_CLEAR_CURRENT_CHAT_DATA
;
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_SAVE_FUNC_SCROLL_TO_BOTTOM
)
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_SAVE_FUNC_SCROLL_TO_BOTTOM
)
private
readonly
saveScrollToBottomFunc
!
:
ChatStore
.
MUTATION_SAVE_FUNC_SCROLL_TO_BOTTOM
;
private
readonly
saveScrollToBottomFunc
!
:
ChatStore
.
MUTATION_SAVE_FUNC_SCROLL_TO_BOTTOM
;
...
@@ -87,6 +84,9 @@
...
@@ -87,6 +84,9 @@
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_WITHDRAW
)
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_WITHDRAW
)
private
readonly
executeWithDraw
!
:
ChatStore
.
MUTATION_WITHDRAW
;
private
readonly
executeWithDraw
!
:
ChatStore
.
MUTATION_WITHDRAW
;
@
chatStore
.
Action
(
ChatStore
.
ACTION_SET_CHAT_ERROR
)
private
readonly
setError
!
:
ChatStore
.
ACTION_SET_CHAT_ERROR
;
@
Prop
({
default
:
"circle"
})
@
Prop
({
default
:
"circle"
})
private
shape
!
:
string
;
private
shape
!
:
string
;
...
@@ -148,6 +148,14 @@
...
@@ -148,6 +148,14 @@
}
}
}
}
@
Watch
(
"chatId"
)
private
onChatChanged
(
o
:
number
,
n
:
number
)
{
o
&&
n
&&
this
.
messages
.
length
?
this
.
fetchNewMsg
()
:
setTimeout
(()
=>
this
.
fetchNewMsg
(),
300
);
this
.
scroll2End
(
this
.
messages
.
length
?
0
:
100
);
}
private
raiseFileOpen
(
value
:
boolean
)
{
private
raiseFileOpen
(
value
:
boolean
)
{
this
.
$emit
(
"file-open"
,
value
);
this
.
$emit
(
"file-open"
,
value
);
}
}
...
@@ -204,7 +212,6 @@
...
@@ -204,7 +212,6 @@
this
.
scollWrapper
.
removeEventListener
(
"scroll"
,
this
.
handleScroll
);
this
.
scollWrapper
.
removeEventListener
(
"scroll"
,
this
.
handleScroll
);
this
.
clearScrollToBottomFunc
();
this
.
clearScrollToBottomFunc
();
this
.
clearNewMessage
();
this
.
clearNewMessage
();
// this.clearChatId();
}
}
public
scroll2End
(
delay
?:
number
)
{
public
scroll2End
(
delay
?:
number
)
{
...
@@ -325,13 +332,25 @@
...
@@ -325,13 +332,25 @@
if
(
msg
.
length
===
0
)
return
;
if
(
msg
.
length
===
0
)
return
;
this
.
startLoadingNew
();
this
.
startLoadingNew
();
const
msgId
=
getLastMessageId
(
msg
);
const
msgId
=
getLastMessageId
(
msg
);
const
data
=
await
this
.
getNextPageMsg
(
msgId
);
return
this
.
getNextPageMsg
(
msgId
)
if
(
data
.
length
===
0
)
{
.
then
((
data
)
=>
{
// eslint-disable-next-line no-console
if
(
data
.
length
===
0
)
{
console
.
log
(
"没有更多新消息了"
);
// eslint-disable-next-line no-console
}
console
.
log
(
"没有更多新消息了"
);
this
.
$emit
(
"next-page"
,
msgId
);
}
this
.
endLoadingNew
();
this
.
$emit
(
"next-page"
,
msgId
);
this
.
endLoadingNew
();
})
.
catch
((
e
)
=>
{
if
(
e
&&
e
.
message
&&
(
e
.
message
as
string
).
includes
(
"sql: no rows in result set"
)
)
{
this
.
setError
(
this
.
chatId
);
}
})
.
finally
(()
=>
this
.
endLoadingNew
());
}
}
private
format2Time
(
time
:
number
)
{
private
format2Time
(
time
:
number
)
{
...
...
hybrid-input/index.vue
View file @
8d36ee61
...
@@ -18,9 +18,17 @@
...
@@ -18,9 +18,17 @@
src=
"@/customer-service/imgs/pic.png"
src=
"@/customer-service/imgs/pic.png"
/>
/>
</label>
</label>
<!--
<label
for=
"chat-upload-file"
:title=
"tip4File"
@
click=
"allowLoadFile"
>
<label
<img
class=
"tool-bar-icon"
src=
"@/customer-service/imgs/file.png"
/>
for=
"chat-upload-file"
</label>
-->
:title=
"tip4File"
@
click=
"allowLoadFile"
v-if=
"enableFileSelection"
>
<img
class=
"tool-bar-icon"
src=
"@/customer-service/imgs/file.png"
/>
</label>
<input
<input
@
change=
"onChange"
@
change=
"onChange"
...
@@ -63,6 +71,7 @@
...
@@ -63,6 +71,7 @@
import
{
Component
,
Ref
,
Vue
,
Watch
}
from
"vue-property-decorator"
;
import
{
Component
,
Ref
,
Vue
,
Watch
}
from
"vue-property-decorator"
;
import
{
namespace
}
from
"vuex-class"
;
import
{
namespace
}
from
"vuex-class"
;
import
{
import
{
ERROR_IMAGE
,
getFileType
,
getFileType
,
getSvg
,
getSvg
,
MAX_FILE_SIZE
,
MAX_FILE_SIZE
,
...
@@ -130,6 +139,8 @@
...
@@ -130,6 +139,8 @@
private
tip4Image
=
`发送图片(最大
${
MAX_IMAGE_SIZE_STRING
}
)`
;
private
tip4Image
=
`发送图片(最大
${
MAX_IMAGE_SIZE_STRING
}
)`
;
private
tip4File
=
`发送文件(最大
${
MAX_FILE_SIZE_STRING
}
)`
;
private
tip4File
=
`发送文件(最大
${
MAX_FILE_SIZE_STRING
}
)`
;
private
enableFileSelection
=
false
;
private
emoji
:
EmojiItem
[]
=
[];
private
emoji
:
EmojiItem
[]
=
[];
@
Watch
(
"chatId"
)
@
Watch
(
"chatId"
)
...
@@ -489,6 +500,15 @@
...
@@ -489,6 +500,15 @@
this
.
$emit
(
"error"
,
MESSAGE_FILE_EMPTY
);
this
.
$emit
(
"error"
,
MESSAGE_FILE_EMPTY
);
return
;
return
;
}
}
if
(
this
.
enableFileSelection
&&
file
.
size
>=
MAX_FILE_SIZE
)
{
this
.
$emit
(
"error"
,
MESSAGE_FILE_TOO_LARGE
);
return
;
}
if
(
this
.
isImage
(
file
))
{
if
(
this
.
isImage
(
file
))
{
if
(
file
.
size
>=
MAX_IMAGE_SIZE
)
{
if
(
file
.
size
>=
MAX_IMAGE_SIZE
)
{
this
.
$emit
(
"error"
,
MESSAGE_IMAGE_TOO_LARGE
);
this
.
$emit
(
"error"
,
MESSAGE_IMAGE_TOO_LARGE
);
...
@@ -496,11 +516,11 @@
...
@@ -496,11 +516,11 @@
}
}
html
+=
this
.
buildImageHtml
(
file
);
html
+=
this
.
buildImageHtml
(
file
);
}
else
{
}
else
{
if
(
file
.
size
>=
MAX_FILE_SIZE
)
{
if
(
this
.
enableFileSelection
)
{
this
.
$emit
(
"error"
,
MESSAGE_FILE_TOO_LARGE
);
html
+=
this
.
buildFileHtml
(
file
);
return
;
}
else
{
return
this
.
$emit
(
"error"
,
ERROR_IMAGE
);
}
}
html
+=
this
.
buildFileHtml
(
file
);
}
}
}
}
...
...
store/index.ts
View file @
8d36ee61
...
@@ -31,7 +31,7 @@ function uniqueMessages(
...
@@ -31,7 +31,7 @@ function uniqueMessages(
messages
:
NonNullable
<
ChatStore
.
STATE_CHAT_MSG_HISTORY
>
messages
:
NonNullable
<
ChatStore
.
STATE_CHAT_MSG_HISTORY
>
)
{
)
{
const
arr
=
[...
messages
];
const
arr
=
[...
messages
];
return
unique
(
arr
,
function
(
item
,
all
)
{
return
unique
(
arr
,
function
(
item
,
all
)
{
return
all
.
findIndex
((
k
)
=>
k
.
id
===
item
.
id
);
return
all
.
findIndex
((
k
)
=>
k
.
id
===
item
.
id
);
});
});
}
}
...
@@ -119,6 +119,7 @@ export default {
...
@@ -119,6 +119,7 @@ export default {
[
ChatStore
.
STATE_CHAT_DIALOG_VISIBLE
]:
false
,
[
ChatStore
.
STATE_CHAT_DIALOG_VISIBLE
]:
false
,
[
ChatStore
.
STATE_CHAT_DIALOG_IS_SINGLE
]:
false
,
[
ChatStore
.
STATE_CHAT_DIALOG_IS_SINGLE
]:
false
,
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
]:
false
,
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_MEMBER
]:
false
,
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_ERROR
]:
null
,
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID
]:
null
,
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID
]:
null
,
[
ChatStore
.
STATE_CHAT_CURRENT_USER_UID
]:
null
,
[
ChatStore
.
STATE_CHAT_CURRENT_USER_UID
]:
null
,
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
]:
null
,
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
]:
null
,
...
@@ -326,7 +327,7 @@ export default {
...
@@ -326,7 +327,7 @@ export default {
state
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]
=
[...
current
];
state
[
ChatStore
.
STATE_CHAT_SENDING_MESSAGES
]
=
[...
current
];
}
}
},
},
[
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_INPUTING
]:
(
function
()
{
[
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_INPUTING
]:
(
function
()
{
const
setTimeoutId
:
{
[
key
:
string
]:
number
}
=
{};
const
setTimeoutId
:
{
[
key
:
string
]:
number
}
=
{};
return
(
return
(
state
:
ChatStoreState
,
state
:
ChatStoreState
,
...
@@ -683,13 +684,15 @@ export default {
...
@@ -683,13 +684,15 @@ export default {
);
);
commit
(
ChatStore
.
MUTATION_INITING_CHAT_DONE
);
commit
(
ChatStore
.
MUTATION_INITING_CHAT_DONE
);
commit
(
ChatStore
.
MUTATION_SCROLL_TO_BOTTOM
);
commit
(
ChatStore
.
MUTATION_SCROLL_TO_BOTTOM
);
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_ERROR
]
=
null
;
},
},
async
[
ChatStore
.
ACTION_CLEAR_CURRENT_CHAT_DATA
]({
commit
})
{
async
[
ChatStore
.
ACTION_CLEAR_CURRENT_CHAT_DATA
]({
commit
,
state
})
{
commit
(
ChatStore
.
MUTATION_CLEAR_CURRENT_CHAT_ID
);
commit
(
ChatStore
.
MUTATION_CLEAR_CURRENT_CHAT_ID
);
commit
(
ChatStore
.
MUTATION_CLEAR_MYSELF_ID
);
commit
(
ChatStore
.
MUTATION_CLEAR_MYSELF_ID
);
commit
(
ChatStore
.
MUTATION_CLEAR_CHAT_MSG_HISTORY
);
commit
(
ChatStore
.
MUTATION_CLEAR_CHAT_MSG_HISTORY
);
commit
(
ChatStore
.
MUTATION_CLEAR_CHAT_TITLE
);
commit
(
ChatStore
.
MUTATION_CLEAR_CHAT_TITLE
);
commit
(
ChatStore
.
MUTATION_CLEAR_CURRENT_CHAT_MEMBERS
);
commit
(
ChatStore
.
MUTATION_CLEAR_CURRENT_CHAT_MEMBERS
);
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_ERROR
]
=
null
;
},
},
async
[
ChatStore
.
ACTION_GET_CHAT_MEMBERS
]({
commit
,
state
})
{
async
[
ChatStore
.
ACTION_GET_CHAT_MEMBERS
]({
commit
,
state
})
{
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
...
@@ -729,7 +732,7 @@ export default {
...
@@ -729,7 +732,7 @@ export default {
}
}
commit
(
commit
(
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_MEMBERS
,
ChatStore
.
MUTATION_SAVE_CURRENT_CHAT_MEMBERS
,
unique
(
newChatMembers
,
function
(
item
,
all
)
{
unique
(
newChatMembers
,
function
(
item
,
all
)
{
return
all
.
findIndex
((
k
)
=>
k
.
eid
===
item
.
eid
);
return
all
.
findIndex
((
k
)
=>
k
.
eid
===
item
.
eid
);
})
})
);
);
...
@@ -916,6 +919,9 @@ export default {
...
@@ -916,6 +919,9 @@ export default {
.
updateChat
(
p
)
.
updateChat
(
p
)
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_MY_CHAT_LIST
));
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_MY_CHAT_LIST
));
},
},
[
ChatStore
.
ACTION_SET_CHAT_ERROR
]:
({
state
},
chat
:
number
)
=>
{
state
[
ChatStore
.
STATE_CHAT_CURRENT_IS_CHAT_ERROR
]
=
chat
;
},
},
},
getters
:
{
getters
:
{
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
](
state
)
{
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
](
state
)
{
...
...
store/model.ts
View file @
8d36ee61
...
@@ -44,6 +44,9 @@ export namespace ChatStore {
...
@@ -44,6 +44,9 @@ export namespace ChatStore {
"当前用户类型状态,25-普通用户,92-客服"
;
"当前用户类型状态,25-普通用户,92-客服"
;
export
type
STATE_CHAT_CURRENT_USER_TYPE
=
string
|
null
;
export
type
STATE_CHAT_CURRENT_USER_TYPE
=
string
|
null
;
export
const
STATE_CHAT_CURRENT_IS_CHAT_ERROR
=
"当前会话是否错误"
;
export
type
STATE_CHAT_CURRENT_IS_CHAT_ERROR
=
number
|
null
;
export
const
STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID
=
"当前chat的Uniplat id"
;
export
const
STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID
=
"当前chat的Uniplat id"
;
export
type
STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID
=
string
|
null
;
export
type
STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID
=
string
|
null
;
...
@@ -344,6 +347,9 @@ export namespace ChatStore {
...
@@ -344,6 +347,9 @@ export namespace ChatStore {
value
:
dto
.
MessageHandled
;
value
:
dto
.
MessageHandled
;
})
=>
void
;
})
=>
void
;
export
const
ACTION_SET_CHAT_ERROR
=
"标记会话关键性错误"
;
export
type
ACTION_SET_CHAT_ERROR
=
(
chat
:
number
)
=>
void
;
export
interface
ChatUpdateParameter
{
export
interface
ChatUpdateParameter
{
chat
:
number
;
chat
:
number
;
type
?:
dto
.
MessageType
;
type
?:
dto
.
MessageType
;
...
...
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