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
dc8f7637
authored
Oct 15, 2021
by
Sixong.Zhu
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
性能优化,缓存处理
parent
5b0e1790
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
65 deletions
components/msg-shortcut.vue
hybrid-input/index.vue
service/emoji.ts
store/index.ts
utils/chat-info.ts
components/msg-shortcut.vue
View file @
dc8f7637
...
@@ -117,6 +117,8 @@ interface Reply {
...
@@ -117,6 +117,8 @@ interface Reply {
const
ReplyModelName
=
"uniplat_chat_reply"
;
const
ReplyModelName
=
"uniplat_chat_reply"
;
let
cacheReply
:
Reply
[]
=
[];
@
Component
({
components
:
{}
})
@
Component
({
components
:
{}
})
export
default
class
MsgShortCut
extends
Vue
{
export
default
class
MsgShortCut
extends
Vue
{
@
chatStore
.
Action
(
ChatStore
.
ACTION_SEND_MESSAGE
)
@
chatStore
.
Action
(
ChatStore
.
ACTION_SEND_MESSAGE
)
...
@@ -138,18 +140,21 @@ export default class MsgShortCut extends Vue {
...
@@ -138,18 +140,21 @@ export default class MsgShortCut extends Vue {
private
editingItem
:
{
[
key
:
string
]:
boolean
}
=
{};
private
editingItem
:
{
[
key
:
string
]:
boolean
}
=
{};
private
editingItemContent
:
{
[
key
:
string
]:
string
}
=
{};
private
editingItemContent
:
{
[
key
:
string
]:
string
}
=
{};
async
mounted
()
{
mounted
()
{
await
this
.
getReplyList
();
this
.
getReplyList
();
}
}
private
async
getReplyList
()
{
private
async
getReplyList
()
{
this
.
replyList
=
await
this
.
sdk
if
(
cacheReply
&&
cacheReply
.
length
)
{
return
(
this
.
replyList
=
cacheReply
);
}
cacheReply
=
this
.
replyList
=
await
this
.
sdk
.
domainService
(
"uniplat_base"
,
"chat.chat"
,
"reply"
)
.
domainService
(
"uniplat_base"
,
"chat.chat"
,
"reply"
)
.
request
(
"get"
);
.
request
(
"get"
);
}
}
@
buttonThrottle
()
@
buttonThrottle
()
private
sendMsg
(
reply
:
Reply
)
{
private
async
sendMsg
(
reply
:
Reply
)
{
return
this
.
_sendMsg
({
return
this
.
_sendMsg
({
msgType
:
MessageType
.
Text
,
msgType
:
MessageType
.
Text
,
msg
:
JSON
.
stringify
({
text
:
reply
.
content
,
source
:
this
.
source
}),
msg
:
JSON
.
stringify
({
text
:
reply
.
content
,
source
:
this
.
source
}),
...
@@ -263,6 +268,7 @@ export default class MsgShortCut extends Vue {
...
@@ -263,6 +268,7 @@ export default class MsgShortCut extends Vue {
}
}
}
}
</
script
>
</
script
>
<
style
lang=
"less"
scoped
>
<
style
lang=
"less"
scoped
>
.shortcut
{
.shortcut
{
position
:
relative
;
position
:
relative
;
...
...
hybrid-input/index.vue
View file @
dc8f7637
...
@@ -73,7 +73,7 @@ import {
...
@@ -73,7 +73,7 @@ import {
MESSAGE_FILE_TOO_LARGE
,
MESSAGE_FILE_TOO_LARGE
,
MESSAGE_IMAGE_TOO_LARGE
,
MESSAGE_IMAGE_TOO_LARGE
,
}
from
"../components/message-item/file-controller"
;
}
from
"../components/message-item/file-controller"
;
import
{
EmojiService
}
from
"../service/emoji"
;
import
{
Emoji
Item
,
Emoji
Service
}
from
"../service/emoji"
;
import
{
ChatStore
}
from
"../store/model"
;
import
{
ChatStore
}
from
"../store/model"
;
import
{
formatFileSize
}
from
"../utils"
;
import
{
formatFileSize
}
from
"../utils"
;
...
@@ -130,7 +130,7 @@ export default class Input extends Vue {
...
@@ -130,7 +130,7 @@ export default class Input extends Vue {
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
emoji
:
{
name
:
string
;
emoji_chars
:
string
;
code
:
string
}
[]
=
[];
private
emoji
:
EmojiItem
[]
=
[];
@
Watch
(
"chatId"
)
@
Watch
(
"chatId"
)
private
onChatIdChanged
(
v
:
number
,
old
:
number
)
{
private
onChatIdChanged
(
v
:
number
,
old
:
number
)
{
...
...
service/emoji.ts
View file @
dc8f7637
import
{
TokenStringGetter
}
from
"../model"
;
import
{
TokenStringGetter
}
from
"../model"
;
import
{
invokeGet
}
from
"./request"
;
import
{
invokeGet
}
from
"./request"
;
export
interface
EmojiItem
{
code
:
string
;
name
:
string
;
emoji_chars
:
string
;
}
export
interface
EmojiResult
{
type
:
string
;
list
:
EmojiItem
[];
}
let
cacheEmoji
:
EmojiResult
|
null
=
null
;
export
class
EmojiService
{
export
class
EmojiService
{
private
static
ready
=
false
private
static
ready
=
false
;
private
static
token
:
TokenStringGetter
private
static
token
:
TokenStringGetter
;
private
static
beforeReadyCacheAction
:
Function
[]
=
[]
private
static
beforeReadyCacheAction
:
Function
[]
=
[]
;
private
url
=
""
private
url
=
""
;
public
constructor
()
{
public
constructor
()
{
this
.
url
=
this
.
url
=
...
@@ -16,15 +28,14 @@ export class EmojiService {
...
@@ -16,15 +28,14 @@ export class EmojiService {
}
}
public
async
getEmoji
()
{
public
async
getEmoji
()
{
if
(
cacheEmoji
)
{
return
Promise
.
resolve
(
cacheEmoji
);
}
const
token
=
await
EmojiService
.
token
();
const
token
=
await
EmojiService
.
token
();
return
invokeGet
<
{
return
invokeGet
<
EmojiResult
>
(
type
:
string
;
`
${
this
.
url
}
/v1/emoji/list?type=chat`
,
list
:
{
token
code
:
string
;
).
then
((
o
)
=>
(
cacheEmoji
=
o
));
name
:
string
;
emoji_chars
:
string
;
}[];
}
>
(
`
${
this
.
url
}
/v1/emoji/list?type=chat`
,
token
);
}
}
public
static
onReady
(
callback
:
()
=>
void
)
{
public
static
onReady
(
callback
:
()
=>
void
)
{
...
...
store/index.ts
View file @
dc8f7637
...
@@ -3,7 +3,6 @@ import { Module } from "vuex";
...
@@ -3,7 +3,6 @@ import { Module } from "vuex";
import
{
dbController
}
from
"../database"
;
import
{
dbController
}
from
"../database"
;
import
{
import
{
ChatMember
,
ChatMember
,
MessageType
,
ServiceType
,
ServiceType
,
MessageHandled
,
MessageHandled
,
RawChatItem
,
RawChatItem
,
...
@@ -33,7 +32,7 @@ function uniqueMessages(
...
@@ -33,7 +32,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
);
});
});
}
}
...
@@ -317,7 +316,7 @@ export default {
...
@@ -317,7 +316,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
,
...
@@ -419,12 +418,6 @@ export default {
...
@@ -419,12 +418,6 @@ export default {
items
.
forEach
((
i
)
=>
(
sum
+=
i
.
unread_msg_count
));
items
.
forEach
((
i
)
=>
(
sum
+=
i
.
unread_msg_count
));
state
[
ChatStore
.
STATE_CURRENT_UNREAD_MESSAGE_COUNT
]
=
sum
;
state
[
ChatStore
.
STATE_CURRENT_UNREAD_MESSAGE_COUNT
]
=
sum
;
},
},
// async [ChatStore.ACTION_JOIN_CHAT](
// { commit },
// chatId: Parameters<ChatStore.ACTION_JOIN_CHAT>[0]
// ) {
// // return await XimService.getInstance().joinChat(chatId)
// },
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES
]({
state
,
commit
})
{
async
[
ChatStore
.
ACTION_GET_CHAT_MESSAGES
]({
state
,
commit
})
{
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
const
chatId
=
state
[
ChatStore
.
STATE_CHAT_CURRENT_CHAT_ID
];
if
(
chatId
==
null
)
return
;
if
(
chatId
==
null
)
return
;
...
@@ -721,7 +714,7 @@ export default {
...
@@ -721,7 +714,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
);
})
})
);
);
...
@@ -756,9 +749,11 @@ export default {
...
@@ -756,9 +749,11 @@ export default {
const
{
model_name
,
obj_id
}
=
currentChat
;
const
{
model_name
,
obj_id
}
=
currentChat
;
if
(
model_name
==
null
)
return
;
if
(
model_name
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
await
sdk
().
model
(
model_name
).
chat
(
obj_id
,
orgId
()).
startChat
();
return
await
sdk
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
500
));
.
model
(
model_name
)
await
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
);
.
chat
(
obj_id
,
orgId
())
.
startChat
()
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
},
async
[
ChatStore
.
ACTION_CHAT_FINISH_RECEPTION
]({
getters
,
dispatch
})
{
async
[
ChatStore
.
ACTION_CHAT_FINISH_RECEPTION
]({
getters
,
dispatch
})
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
...
@@ -766,9 +761,11 @@ export default {
...
@@ -766,9 +761,11 @@ export default {
const
{
model_name
,
obj_id
}
=
currentChat
;
const
{
model_name
,
obj_id
}
=
currentChat
;
if
(
model_name
==
null
)
return
;
if
(
model_name
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
await
sdk
().
model
(
model_name
).
chat
(
obj_id
,
orgId
()).
finishChat
();
return
await
sdk
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
500
));
.
model
(
model_name
)
await
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
);
.
chat
(
obj_id
,
orgId
())
.
finishChat
()
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
},
async
[
ChatStore
.
ACTION_CHAT_USER_EXIT
]({
getters
,
dispatch
})
{
async
[
ChatStore
.
ACTION_CHAT_USER_EXIT
]({
getters
,
dispatch
})
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
...
@@ -776,9 +773,11 @@ export default {
...
@@ -776,9 +773,11 @@ export default {
const
{
model_name
,
obj_id
}
=
currentChat
;
const
{
model_name
,
obj_id
}
=
currentChat
;
if
(
model_name
==
null
)
return
;
if
(
model_name
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
await
sdk
().
model
(
model_name
).
chat
(
obj_id
,
orgId
()).
userExitChat
();
return
await
sdk
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
500
));
.
model
(
model_name
)
await
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
);
.
chat
(
obj_id
,
orgId
())
.
userExitChat
()
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
},
async
[
ChatStore
.
ACTION_CHAT_CS_EXIT
]({
getters
,
dispatch
})
{
async
[
ChatStore
.
ACTION_CHAT_CS_EXIT
]({
getters
,
dispatch
})
{
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
const
currentChat
=
getters
[
ChatStore
.
GETTER_CURRENT_CURRENT_CHAT
];
...
@@ -786,9 +785,11 @@ export default {
...
@@ -786,9 +785,11 @@ export default {
const
{
model_name
,
obj_id
}
=
currentChat
;
const
{
model_name
,
obj_id
}
=
currentChat
;
if
(
model_name
==
null
)
return
;
if
(
model_name
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
await
sdk
().
model
(
model_name
).
chat
(
obj_id
,
orgId
()).
csExitChat
();
return
await
sdk
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
500
));
.
model
(
model_name
)
await
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
);
.
chat
(
obj_id
,
orgId
())
.
csExitChat
()
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
},
},
async
[
ChatStore
.
ACTION_CHAT_ADD_MEMBERS
](
async
[
ChatStore
.
ACTION_CHAT_ADD_MEMBERS
](
{
getters
,
dispatch
},
{
getters
,
dispatch
},
...
@@ -799,12 +800,11 @@ export default {
...
@@ -799,12 +800,11 @@ export default {
const
{
model_name
,
obj_id
}
=
currentChat
;
const
{
model_name
,
obj_id
}
=
currentChat
;
if
(
model_name
==
null
)
return
;
if
(
model_name
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
await
sdk
()
return
await
sdk
()
.
model
(
model_name
)
.
model
(
model_name
)
.
chat
(
obj_id
,
orgId
())
.
chat
(
obj_id
,
orgId
())
.
addMember
(
uids
.
map
((
id
)
=>
Number
(
id
)));
.
addMember
(
uids
.
map
((
id
)
=>
Number
(
id
)))
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
500
));
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
await
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
);
},
},
async
[
ChatStore
.
ACTION_CHAT_REMOVE_MEMBER
](
async
[
ChatStore
.
ACTION_CHAT_REMOVE_MEMBER
](
{
getters
,
dispatch
},
{
getters
,
dispatch
},
...
@@ -815,12 +815,11 @@ export default {
...
@@ -815,12 +815,11 @@ export default {
const
{
model_name
,
obj_id
}
=
currentChat
;
const
{
model_name
,
obj_id
}
=
currentChat
;
if
(
model_name
==
null
)
return
;
if
(
model_name
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
await
sdk
()
return
await
sdk
()
.
model
(
model_name
)
.
model
(
model_name
)
.
chat
(
obj_id
,
orgId
())
.
chat
(
obj_id
,
orgId
())
.
removeMember
(
uids
.
map
((
id
)
=>
Number
(
id
)));
.
removeMember
(
uids
.
map
((
id
)
=>
Number
(
id
)))
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
500
));
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
await
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
);
},
},
async
[
ChatStore
.
ACTION_CHAT_ADD_CS
](
async
[
ChatStore
.
ACTION_CHAT_ADD_CS
](
{
getters
,
dispatch
},
{
getters
,
dispatch
},
...
@@ -831,12 +830,11 @@ export default {
...
@@ -831,12 +830,11 @@ export default {
const
{
model_name
,
obj_id
}
=
currentChat
;
const
{
model_name
,
obj_id
}
=
currentChat
;
if
(
model_name
==
null
)
return
;
if
(
model_name
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
await
sdk
()
return
await
sdk
()
.
model
(
model_name
)
.
model
(
model_name
)
.
chat
(
obj_id
,
orgId
())
.
chat
(
obj_id
,
orgId
())
.
addCs
(
uids
.
map
((
id
)
=>
Number
(
id
)));
.
addCs
(
uids
.
map
((
id
)
=>
Number
(
id
)))
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
500
));
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
await
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
);
},
},
async
[
ChatStore
.
ACTION_CHAT_REMOVE_CS
](
async
[
ChatStore
.
ACTION_CHAT_REMOVE_CS
](
{
getters
,
dispatch
},
{
getters
,
dispatch
},
...
@@ -847,12 +845,11 @@ export default {
...
@@ -847,12 +845,11 @@ export default {
const
{
model_name
,
obj_id
}
=
currentChat
;
const
{
model_name
,
obj_id
}
=
currentChat
;
if
(
model_name
==
null
)
return
;
if
(
model_name
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
if
(
obj_id
==
null
)
return
;
await
sdk
()
return
await
sdk
()
.
model
(
model_name
)
.
model
(
model_name
)
.
chat
(
obj_id
,
orgId
())
.
chat
(
obj_id
,
orgId
())
.
removeCs
(
uids
.
map
((
id
)
=>
Number
(
id
)));
.
removeCs
(
uids
.
map
((
id
)
=>
Number
(
id
)))
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
500
));
.
finally
(()
=>
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
));
await
dispatch
(
ChatStore
.
ACTION_GET_CHAT_MEMBERS
);
},
},
[
ChatStore
.
ACTION_SET_HANDLED
](
[
ChatStore
.
ACTION_SET_HANDLED
](
{
state
},
{
state
},
...
...
utils/chat-info.ts
View file @
dc8f7637
...
@@ -3,24 +3,34 @@ import Chat from "../xim";
...
@@ -3,24 +3,34 @@ import Chat from "../xim";
export
type
ChatInfo
=
{
export
type
ChatInfo
=
{
[
eid
:
string
]:
any
;
[
eid
:
string
]:
any
;
};
};
const
chatInfo
:
ChatInfo
=
{};
const
chatInfo
:
ChatInfo
=
{};
export
const
getChatModel
=
()
=>
chatInfo
;
export
const
getChatModel
=
()
=>
chatInfo
;
export
async
function
getChatModelInfo
(
modelName
:
string
,
id
:
string
,
detailname
?:
string
)
{
export
async
function
getChatModelInfo
(
if
(
chatInfo
[
id
]
!=
null
)
{
modelName
:
string
,
return
{
id
:
string
|
number
,
uniplatId
:
chatInfo
[
id
].
row
.
UniplatChatId
.
value
,
detailname
?:
string
chat_id
:
+
chatInfo
[
id
].
row
.
UniplatImChatId
.
value
,
)
{
uniplat_version
:
0
,
if
(
chatInfo
[
id
])
{
};
return
Promise
.
resolve
({
uniplatId
:
chatInfo
[
id
].
row
.
UniplatChatId
.
value
,
chat_id
:
+
chatInfo
[
id
].
row
.
UniplatImChatId
.
value
,
uniplat_version
:
0
,
data
:
chatInfo
[
id
],
});
}
}
const
info
=
await
Chat
.
getSdk
().
model
(
modelName
).
detail
(
id
,
detailname
).
query
();
const
info
=
await
Chat
.
getSdk
()
.
model
(
modelName
)
.
detail
(
id
+
""
,
detailname
)
.
query
();
const
data
=
info
;
const
data
=
info
;
chatInfo
[
id
]
=
data
;
chatInfo
[
id
]
=
data
;
return
{
return
{
uniplatId
:
info
.
row
.
UniplatChatId
.
value
,
uniplatId
:
info
.
row
.
UniplatChatId
.
value
,
chat_id
:
Number
(
info
.
row
.
UniplatImChatId
.
value
),
chat_id
:
Number
(
info
.
row
.
UniplatImChatId
.
value
),
uniplat_version
:
0
,
uniplat_version
:
0
,
data
,
};
};
}
}
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