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
b707d4d5
authored
Oct 11, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
unread
parent
fea0bdc8
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
9 deletions
components/controller/chat-list.ts
components/controller/index.ts
components/message-list.vue
database/index.ts
store/index.ts
store/model.ts
xim/xim.ts
components/controller/chat-list.ts
View file @
b707d4d5
...
...
@@ -18,7 +18,7 @@ export default class ChatList extends Vue {
protected
readonly
chatList
!
:
ChatStore
.
STATE_MY_CHAT_ROOM_LIST
;
@
chatStore
.
State
(
ChatStore
.
STATE_CHAT_USERNAME
)
protected
readonly
userNames
!
:
ChatStore
.
STATE_CHAT_USERNAME
|
any
;
protected
readonly
userNames
!
:
ChatStore
.
STATE_CHAT_USERNAME
;
@
chatStore
.
Action
(
ChatStore
.
ACTION_SAVE_CURRENT_CHAT_ID_VERSION
)
protected
readonly
saveChatId
!
:
ChatStore
.
ACTION_SAVE_CURRENT_CHAT_ID_VERSION
;
...
...
@@ -41,9 +41,12 @@ export default class ChatList extends Vue {
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_HIDE_CHAT
)
protected
readonly
hideChat
!
:
ChatStore
.
MUTATION_HIDE_CHAT
;
@
chatStore
.
Action
(
ChatStore
.
ACTION_UPDATE_CHAT
)
protected
readonly
updateChat
!
:
ChatStore
.
ACTION_UPDATE_CHAT
;
protected
parseMesage
(
data
:
ChatItem
)
{
if
(
data
.
last_msg_sender
&&
data
.
last_msg_sender
!==
"0"
)
{
if
(
this
.
userNames
[
data
.
last_msg_sender
]
===
undefined
)
{
if
(
!
this
.
userNames
[
data
.
last_msg_sender
]
)
{
this
.
updateUserName
({
id
:
data
.
last_msg_sender
,
name
:
""
});
this
.
sdk
.
model
(
"user"
)
...
...
components/controller/index.ts
View file @
b707d4d5
...
...
@@ -3,8 +3,8 @@ import { MessageType } from "@/customer-service/model";
export
function
parserMessage
(
type
:
string
,
rawMsg
:
string
)
{
if
(
!
type
)
return
""
;
if
(
!
rawMsg
)
return
""
;
const
msg
=
JSON
.
parse
(
rawMsg
);
if
(
type
===
MessageType
.
Text
)
{
const
msg
=
JSON
.
parse
(
rawMsg
);
return
msg
.
text
;
}
else
if
(
type
===
MessageType
.
Image
)
{
return
`[图片]`
;
...
...
components/message-list.vue
View file @
b707d4d5
...
...
@@ -197,7 +197,7 @@ export default class MessageList extends Vue {
this
.
scollWrapper
.
addEventListener
(
"scroll"
,
this
.
handleScroll
);
this
.
saveScrollToBottomFunc
(
this
.
scrollToNewMsg
);
this
.
scrollToNewMsg
();
this
.
scroll2End
(
200
);
setTimeout
(()
=>
this
.
scroll2End
(
200
)
);
}
public
beforeDestroy
()
{
...
...
database/index.ts
View file @
b707d4d5
import
{
Chat
,
Message
}
from
"./../xim/models/chat"
;
import
{
MessageHandled
}
from
"../model"
;
import
{
ChatStore
}
from
"../store/model"
;
class
ChatCacheDatabaseController
{
private
db
!
:
IDBDatabase
;
...
...
@@ -61,7 +62,7 @@ class ChatCacheDatabaseController {
const
setupDb
=
()
=>
{
const
db
=
that
.
messageDatabases
.
get
(
k
);
try
{
that
.
buildTables
(
db
!
,
this
.
chatMessageKey
,
"id"
);
that
.
buildTables
(
db
,
this
.
chatMessageKey
,
"id"
);
}
catch
(
e
)
{
console
.
error
(
e
);
}
...
...
@@ -118,6 +119,35 @@ class ChatCacheDatabaseController {
}
}
public
updateChat
(
p
:
ChatStore
.
ChatUpdateParameter
)
{
return
new
Promise
<
void
>
((
resolve
)
=>
{
if
(
this
.
db
)
{
const
store
=
this
.
buildStore
(
this
.
chatListKey
);
const
t
=
store
.
get
(
p
.
chat
);
t
.
onsuccess
=
(
r
)
=>
{
const
chat
=
(
r
.
target
as
any
).
result
as
Chat
;
if
(
chat
)
{
chat
.
eid
=
p
.
eid
;
p
.
ts
&&
(
chat
.
last_msg_ts
=
p
.
ts
);
p
.
eid
&&
(
chat
.
last_msg_sender
=
p
.
eid
);
p
.
type
&&
(
chat
.
last_msg_type
=
p
.
type
);
p
.
msg
&&
(
chat
.
last_msg_content
=
p
.
msg
);
p
.
unread
&&
chat
.
unread_msg_count
++
;
if
(
p
.
unread
===
0
)
{
chat
.
unread_msg_count
=
0
;
}
const
u
=
store
.
put
(
chat
,
chat
.
id
);
u
.
onsuccess
=
()
=>
resolve
();
u
.
onerror
=
()
=>
resolve
();
}
else
{
resolve
();
}
};
t
.
onerror
=
()
=>
resolve
();
}
});
}
public
getChatList
()
{
return
new
Promise
<
Chat
[]
>
((
resolve
)
=>
{
if
(
!
this
.
db
)
{
...
...
@@ -156,9 +186,7 @@ class ChatCacheDatabaseController {
this
.
setupChatMessageDatabase
(
chat
).
finally
(()
=>
{
const
store
=
this
.
buildChatMessageStore
(
chat
);
const
r
=
store
.
getAll
();
r
.
onsuccess
=
(
o
)
=>
{
resolve
((
o
.
target
as
any
).
result
);
};
r
.
onsuccess
=
(
o
)
=>
resolve
((
o
.
target
as
any
).
result
);
r
.
onerror
=
()
=>
resolve
([]);
});
});
...
...
store/index.ts
View file @
b707d4d5
...
...
@@ -861,6 +861,14 @@ export default {
}
}
},
[
ChatStore
.
ACTION_UPDATE_CHAT
]:
(
{
dispatch
},
p
:
ChatStore
.
ChatUpdateParameter
)
=>
{
dbController
.
updateChat
(
p
)
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_MY_CHAT_LIST
));
},
},
getters
:
{
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
](
state
)
{
...
...
store/model.ts
View file @
b707d4d5
...
...
@@ -48,7 +48,7 @@ export namespace ChatStore {
export
type
STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID
=
string
|
null
;
export
const
STATE_CHAT_USERNAME
=
"会话用户id-name"
;
export
type
STATE_CHAT_USERNAME
=
{
[
key
:
string
]:
string
}
|
{}
;
export
type
STATE_CHAT_USERNAME
=
{
[
key
:
string
]:
string
};
export
const
STATE_CHAT_MY_ID
=
"聊天窗口显示在右边那个人的id"
;
export
type
STATE_CHAT_MY_ID
=
string
|
null
;
...
...
@@ -90,8 +90,10 @@ export namespace ChatStore {
/* mutation */
export
const
MUTATION_SHOW_CHAT
=
"打开会话弹窗"
;
export
type
MUTATION_SHOW_CHAT
=
()
=>
void
;
export
const
MUTATION_HIDE_CHAT
=
"关闭会话弹窗"
;
export
type
MUTATION_HIDE_CHAT
=
()
=>
void
;
export
const
MUTATION_SAVE_CHAT_LIST
=
"保存我的会话列表"
;
export
type
MUTATION_SAVE_CHAT_LIST
=
(
list
:
STATE_MY_CHAT_ROOM_LIST
...
...
@@ -335,6 +337,18 @@ export namespace ChatStore {
id
:
number
;
value
:
dto
.
MessageHandled
;
})
=>
void
;
export
interface
ChatUpdateParameter
{
chat
:
number
;
type
?:
dto
.
MessageType
;
msg
?:
string
;
ts
?:
number
;
eid
?:
string
;
unread
?:
number
;
}
export
const
ACTION_UPDATE_CHAT
=
"更新会话信息"
;
export
type
ACTION_UPDATE_CHAT
=
(
p
:
ChatUpdateParameter
)
=>
void
;
}
export
interface
ChatStoreState
{
...
...
xim/xim.ts
View file @
b707d4d5
...
...
@@ -393,6 +393,11 @@ export class Xim {
private
debug
(
message
:
any
,
...
params
:
any
[])
{
ChatLoggerService
.
logger
?.
debug
(
message
,
params
);
}
public
registerOnMessage
(
vue
:
Vue
,
action
:
(
e
:
Message
)
=>
void
)
{
this
.
on
(
"msg"
,
action
);
vue
.
$once
(
"hook:beforeDestroy"
,
()
=>
this
.
off
(
"msg"
,
action
));
}
}
const
ximInstance
=
new
Xim
();
...
...
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