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
Hide 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 {
...
@@ -18,7 +18,7 @@ export default class ChatList extends Vue {
protected
readonly
chatList
!
:
ChatStore
.
STATE_MY_CHAT_ROOM_LIST
;
protected
readonly
chatList
!
:
ChatStore
.
STATE_MY_CHAT_ROOM_LIST
;
@
chatStore
.
State
(
ChatStore
.
STATE_CHAT_USERNAME
)
@
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
)
@
chatStore
.
Action
(
ChatStore
.
ACTION_SAVE_CURRENT_CHAT_ID_VERSION
)
protected
readonly
saveChatId
!
:
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 {
...
@@ -41,9 +41,12 @@ export default class ChatList extends Vue {
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_HIDE_CHAT
)
@
chatStore
.
Mutation
(
ChatStore
.
MUTATION_HIDE_CHAT
)
protected
readonly
hideChat
!
:
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
)
{
protected
parseMesage
(
data
:
ChatItem
)
{
if
(
data
.
last_msg_sender
&&
data
.
last_msg_sender
!==
"0"
)
{
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
.
updateUserName
({
id
:
data
.
last_msg_sender
,
name
:
""
});
this
.
sdk
this
.
sdk
.
model
(
"user"
)
.
model
(
"user"
)
...
...
components/controller/index.ts
View file @
b707d4d5
...
@@ -3,8 +3,8 @@ import { MessageType } from "@/customer-service/model";
...
@@ -3,8 +3,8 @@ import { MessageType } from "@/customer-service/model";
export
function
parserMessage
(
type
:
string
,
rawMsg
:
string
)
{
export
function
parserMessage
(
type
:
string
,
rawMsg
:
string
)
{
if
(
!
type
)
return
""
;
if
(
!
type
)
return
""
;
if
(
!
rawMsg
)
return
""
;
if
(
!
rawMsg
)
return
""
;
const
msg
=
JSON
.
parse
(
rawMsg
);
if
(
type
===
MessageType
.
Text
)
{
if
(
type
===
MessageType
.
Text
)
{
const
msg
=
JSON
.
parse
(
rawMsg
);
return
msg
.
text
;
return
msg
.
text
;
}
else
if
(
type
===
MessageType
.
Image
)
{
}
else
if
(
type
===
MessageType
.
Image
)
{
return
`[图片]`
;
return
`[图片]`
;
...
...
components/message-list.vue
View file @
b707d4d5
...
@@ -197,7 +197,7 @@ export default class MessageList extends Vue {
...
@@ -197,7 +197,7 @@ export default class MessageList extends Vue {
this
.
scollWrapper
.
addEventListener
(
"scroll"
,
this
.
handleScroll
);
this
.
scollWrapper
.
addEventListener
(
"scroll"
,
this
.
handleScroll
);
this
.
saveScrollToBottomFunc
(
this
.
scrollToNewMsg
);
this
.
saveScrollToBottomFunc
(
this
.
scrollToNewMsg
);
this
.
scrollToNewMsg
();
this
.
scrollToNewMsg
();
this
.
scroll2End
(
200
);
setTimeout
(()
=>
this
.
scroll2End
(
200
)
);
}
}
public
beforeDestroy
()
{
public
beforeDestroy
()
{
...
...
database/index.ts
View file @
b707d4d5
import
{
Chat
,
Message
}
from
"./../xim/models/chat"
;
import
{
Chat
,
Message
}
from
"./../xim/models/chat"
;
import
{
MessageHandled
}
from
"../model"
;
import
{
MessageHandled
}
from
"../model"
;
import
{
ChatStore
}
from
"../store/model"
;
class
ChatCacheDatabaseController
{
class
ChatCacheDatabaseController
{
private
db
!
:
IDBDatabase
;
private
db
!
:
IDBDatabase
;
...
@@ -61,7 +62,7 @@ class ChatCacheDatabaseController {
...
@@ -61,7 +62,7 @@ class ChatCacheDatabaseController {
const
setupDb
=
()
=>
{
const
setupDb
=
()
=>
{
const
db
=
that
.
messageDatabases
.
get
(
k
);
const
db
=
that
.
messageDatabases
.
get
(
k
);
try
{
try
{
that
.
buildTables
(
db
!
,
this
.
chatMessageKey
,
"id"
);
that
.
buildTables
(
db
,
this
.
chatMessageKey
,
"id"
);
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
error
(
e
);
console
.
error
(
e
);
}
}
...
@@ -118,6 +119,35 @@ class ChatCacheDatabaseController {
...
@@ -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
()
{
public
getChatList
()
{
return
new
Promise
<
Chat
[]
>
((
resolve
)
=>
{
return
new
Promise
<
Chat
[]
>
((
resolve
)
=>
{
if
(
!
this
.
db
)
{
if
(
!
this
.
db
)
{
...
@@ -156,9 +186,7 @@ class ChatCacheDatabaseController {
...
@@ -156,9 +186,7 @@ class ChatCacheDatabaseController {
this
.
setupChatMessageDatabase
(
chat
).
finally
(()
=>
{
this
.
setupChatMessageDatabase
(
chat
).
finally
(()
=>
{
const
store
=
this
.
buildChatMessageStore
(
chat
);
const
store
=
this
.
buildChatMessageStore
(
chat
);
const
r
=
store
.
getAll
();
const
r
=
store
.
getAll
();
r
.
onsuccess
=
(
o
)
=>
{
r
.
onsuccess
=
(
o
)
=>
resolve
((
o
.
target
as
any
).
result
);
resolve
((
o
.
target
as
any
).
result
);
};
r
.
onerror
=
()
=>
resolve
([]);
r
.
onerror
=
()
=>
resolve
([]);
});
});
});
});
...
...
store/index.ts
View file @
b707d4d5
...
@@ -861,6 +861,14 @@ export default {
...
@@ -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
:
{
getters
:
{
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
](
state
)
{
[
ChatStore
.
STATE_CHAT_MSG_HISTORY
](
state
)
{
...
...
store/model.ts
View file @
b707d4d5
...
@@ -48,7 +48,7 @@ export namespace ChatStore {
...
@@ -48,7 +48,7 @@ export namespace ChatStore {
export
type
STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID
=
string
|
null
;
export
type
STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID
=
string
|
null
;
export
const
STATE_CHAT_USERNAME
=
"会话用户id-name"
;
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
const
STATE_CHAT_MY_ID
=
"聊天窗口显示在右边那个人的id"
;
export
type
STATE_CHAT_MY_ID
=
string
|
null
;
export
type
STATE_CHAT_MY_ID
=
string
|
null
;
...
@@ -90,8 +90,10 @@ export namespace ChatStore {
...
@@ -90,8 +90,10 @@ export namespace ChatStore {
/* mutation */
/* mutation */
export
const
MUTATION_SHOW_CHAT
=
"打开会话弹窗"
;
export
const
MUTATION_SHOW_CHAT
=
"打开会话弹窗"
;
export
type
MUTATION_SHOW_CHAT
=
()
=>
void
;
export
type
MUTATION_SHOW_CHAT
=
()
=>
void
;
export
const
MUTATION_HIDE_CHAT
=
"关闭会话弹窗"
;
export
const
MUTATION_HIDE_CHAT
=
"关闭会话弹窗"
;
export
type
MUTATION_HIDE_CHAT
=
()
=>
void
;
export
type
MUTATION_HIDE_CHAT
=
()
=>
void
;
export
const
MUTATION_SAVE_CHAT_LIST
=
"保存我的会话列表"
;
export
const
MUTATION_SAVE_CHAT_LIST
=
"保存我的会话列表"
;
export
type
MUTATION_SAVE_CHAT_LIST
=
(
export
type
MUTATION_SAVE_CHAT_LIST
=
(
list
:
STATE_MY_CHAT_ROOM_LIST
list
:
STATE_MY_CHAT_ROOM_LIST
...
@@ -335,6 +337,18 @@ export namespace ChatStore {
...
@@ -335,6 +337,18 @@ export namespace ChatStore {
id
:
number
;
id
:
number
;
value
:
dto
.
MessageHandled
;
value
:
dto
.
MessageHandled
;
})
=>
void
;
})
=>
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
{
export
interface
ChatStoreState
{
...
...
xim/xim.ts
View file @
b707d4d5
...
@@ -393,6 +393,11 @@ export class Xim {
...
@@ -393,6 +393,11 @@ export class Xim {
private
debug
(
message
:
any
,
...
params
:
any
[])
{
private
debug
(
message
:
any
,
...
params
:
any
[])
{
ChatLoggerService
.
logger
?.
debug
(
message
,
params
);
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
();
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