Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
施宇
/
icsalesProgram
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
e1cec561
authored
Aug 06, 2019
by
施宇
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
32121
parent
9292c60e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
105 deletions
app.js
pages/tab/message/message.js
utils/chat.js
utils/util.js
app.js
View file @
e1cec561
...
...
@@ -45,9 +45,9 @@ App({
success
(
res
)
{
if
(
res
.
data
)
{
//
wx.switchTab({
//
url: '/pages/tab/home/home'
//
});
wx
.
switchTab
({
url
:
'/pages/tab/home/home'
});
}
}
...
...
@@ -59,9 +59,9 @@ App({
success
(
res
)
{
if
(
res
.
authSetting
[
'scope.userInfo'
])
{
// 已经授权
//
wx.switchTab({
//
url: '/pages/tab/home/home'
//
})
wx
.
switchTab
({
url
:
'/pages/tab/home/home'
})
}
}
});
...
...
pages/tab/message/message.js
View file @
e1cec561
...
...
@@ -25,7 +25,7 @@ Page({
//监听未读消息数
disp
.
on
(
"em.xmpp.unreadspot"
,
function
(
message
)
{
if
(
getApp
().
globalData
.
customerNum
!=
my
)
{
me
.
getCustom
()
me
.
getCustom
()
;
}
me
.
setData
({
arr
:
me
.
getChatList
(),
...
...
@@ -81,23 +81,26 @@ Page({
let
member
=
wx
.
getStorageSync
(
"member"
);
let
myName
=
wx
.
getStorageSync
(
"myUsername"
);
for
(
let
i
=
0
;
i
<
member
.
length
;
i
++
)
{
let
newChatMsgs
=
wx
.
getStorageSync
(
member
[
i
]
+
myName
)
||
[];
let
historyChatMsgs
=
wx
.
getStorageSync
(
"rendered_"
+
member
[
i
]
+
myName
)
||
[];
let
curChatMsgs
=
historyChatMsgs
.
concat
(
newChatMsgs
);
if
(
curChatMsgs
.
length
)
{
let
lastChatMsg
=
curChatMsgs
[
curChatMsgs
.
length
-
1
];
lastChatMsg
.
unReadCount
=
newChatMsgs
.
length
;
if
(
lastChatMsg
.
unReadCount
>
99
)
{
lastChatMsg
.
unReadCount
=
"99+"
;
if
(
member
[
i
]
!==
getApp
().
globalData
.
customerNum
){
let
newChatMsgs
=
wx
.
getStorageSync
(
member
[
i
]
+
myName
)
||
[];
let
historyChatMsgs
=
wx
.
getStorageSync
(
"rendered_"
+
member
[
i
]
+
myName
)
||
[];
let
curChatMsgs
=
historyChatMsgs
.
concat
(
newChatMsgs
);
if
(
curChatMsgs
.
length
)
{
let
lastChatMsg
=
curChatMsgs
[
curChatMsgs
.
length
-
1
];
lastChatMsg
.
unReadCount
=
newChatMsgs
.
length
;
if
(
lastChatMsg
.
unReadCount
>
99
)
{
lastChatMsg
.
unReadCount
=
"99+"
;
}
let
dateArr
=
lastChatMsg
.
time
.
split
(
' '
)[
0
].
split
(
'-'
)
let
timeArr
=
lastChatMsg
.
time
.
split
(
' '
)[
1
].
split
(
':'
)
let
month
=
dateArr
[
2
]
<
10
?
'0'
+
dateArr
[
2
]
:
dateArr
[
2
]
lastChatMsg
.
dateTimeNum
=
`
${
dateArr
[
1
]}${
month
}${
timeArr
[
0
]}${
timeArr
[
1
]}${
timeArr
[
2
]}
`
lastChatMsg
.
time
=
`
${
dateArr
[
1
]}
月
${
dateArr
[
2
]}
日
${
timeArr
[
0
]}
时
${
timeArr
[
1
]}
分`
array
.
push
(
lastChatMsg
);
}
let
dateArr
=
lastChatMsg
.
time
.
split
(
' '
)[
0
].
split
(
'-'
)
let
timeArr
=
lastChatMsg
.
time
.
split
(
' '
)[
1
].
split
(
':'
)
let
month
=
dateArr
[
2
]
<
10
?
'0'
+
dateArr
[
2
]
:
dateArr
[
2
]
lastChatMsg
.
dateTimeNum
=
`
${
dateArr
[
1
]}${
month
}${
timeArr
[
0
]}${
timeArr
[
1
]}${
timeArr
[
2
]}
`
lastChatMsg
.
time
=
`
${
dateArr
[
1
]}
月
${
dateArr
[
2
]}
日
${
timeArr
[
0
]}
时
${
timeArr
[
1
]}
分`
array
.
push
(
lastChatMsg
);
}
}
}
array
.
sort
((
a
,
b
)
=>
{
return
b
.
dateTimeNum
-
a
.
dateTimeNum
})
...
...
utils/chat.js
View file @
e1cec561
...
...
@@ -26,7 +26,7 @@ let conn = {
const
calcUnReadSpot
=
(
message
)
=>
{
let
myName
=
wx
.
getStorageSync
(
"myUsername"
);
let
allMembers
=
wx
.
getStorageSync
(
"member"
)
||
[];
//好友
let
count
=
allMembers
.
reduce
(
function
(
result
,
curMember
,
idx
)
{
let
count
=
allMembers
.
reduce
(
function
(
result
,
curMember
,
idx
)
{
let
chatMsgs
=
wx
.
getStorageSync
(
curMember
.
toLowerCase
()
+
myName
.
toLowerCase
())
||
[];
return
result
+
chatMsgs
.
length
;
},
0
);
...
...
@@ -47,7 +47,7 @@ const getImUser = () => {
let
token
=
wx
.
getStorageSync
(
'access_token'
)
||
''
getData
(
apis
.
authme
,
'get'
,
{
"token"
:
token
,
},
function
(
res
)
{
},
function
(
res
)
{
if
(
res
.
err_code
==
0
)
{
wx
.
setStorageSync
(
'user_id'
,
res
.
data
.
user_id
+
''
);
wx
.
setStorageSync
(
'avatar'
,
res
.
data
.
avatar
);
...
...
@@ -104,8 +104,10 @@ const webimListen = () => {
onTextMessage
(
message
)
{
if
(
message
)
{
if
(
onMessageError
(
message
))
{
if
(
getApp
().
globalData
.
customerNum
!=
m
essage
.
from
)
{
if
(
getApp
().
globalData
.
customerNum
!=
m
y
)
{
getApp
().
addChatMemberStorage
(
message
.
from
);
}
else
{
getApp
().
addChatMember
(
message
.
from
);
}
msgStorage
.
saveReceiveMsg
(
message
,
msgType
.
TEXT
);
}
...
...
@@ -117,8 +119,10 @@ const webimListen = () => {
onEmojiMessage
(
message
)
{
if
(
message
)
{
if
(
onMessageError
(
message
))
{
if
(
getApp
().
globalData
.
customerNum
!=
m
essage
.
from
)
{
if
(
getApp
().
globalData
.
customerNum
!=
m
y
)
{
getApp
().
addChatMemberStorage
(
message
.
from
);
}
else
{
getApp
().
addChatMember
(
message
.
from
);
}
msgStorage
.
saveReceiveMsg
(
message
,
msgType
.
EMOJI
);
}
...
...
@@ -128,8 +132,10 @@ const webimListen = () => {
onPictureMessage
(
message
)
{
if
(
message
)
{
if
(
onMessageError
(
message
))
{
if
(
getApp
().
globalData
.
customerNum
!=
m
essage
.
from
)
{
if
(
getApp
().
globalData
.
customerNum
!=
m
y
)
{
getApp
().
addChatMemberStorage
(
message
.
from
);
}
else
{
getApp
().
addChatMember
(
message
.
from
);
}
msgStorage
.
saveReceiveMsg
(
message
,
msgType
.
IMAGE
);
}
...
...
@@ -142,7 +148,7 @@ const webimListen = () => {
wx
.
showModal
({
title
:
'提示'
,
content
:
'您的聊天账号被迫下线!'
,
showCancel
:
false
showCancel
:
false
})
}
else
{
wx
.
showModal
({
...
...
utils/util.js
View file @
e1cec561
//数据请求(get,post)
const
getData
=
(
url
,
type
,
param
,
callBack
,
loading
,
isheader
,
istoken
)
=>
{
wx
.
showNavigationBarLoading
();
var
token
,
header
;
//获取token
token
=
wx
.
getStorageSync
(
'access_token'
);
//参数字段追加来源字段,token字段
if
(
istoken
)
{
var
params
=
Object
.
assign
({},
param
,
{
source
:
1
,
token
:
token
});
}
else
{
var
params
=
Object
.
assign
({},
param
,
{
source
:
1
});
}
//是否启用loading加载效果
if
(
loading
)
{
wx
.
showLoading
();
}
//是否启用请求头token
if
(
isheader
)
{
header
=
{
"Content-Type"
:
"applciation/json"
,
"Authorization"
:
'Bearer '
+
token
}
}
else
{
header
=
{
"Content-Type"
:
"applciation/json"
}
}
wx
.
request
({
url
:
url
,
data
:
params
,
header
:
header
,
method
:
type
,
success
:
(
res
)
=>
{
//处理token失效的情况
if
(
res
.
data
.
hasOwnProperty
(
'data'
))
{
if
(
res
.
data
.
data
.
err_code
===
501
||
res
.
data
.
data
.
errcode
===
501
)
{
wx
.
navigateTo
({
url
:
'/pages/person/login/index'
});
}
else
{
typeof
callBack
==
"function"
&&
callBack
(
res
.
data
,
""
);
}
}
else
{
typeof
callBack
==
"function"
&&
callBack
(
res
.
data
,
""
);
}
wx
.
hideNavigationBarLoading
();
if
(
loading
)
{
wx
.
hideLoading
();
}
},
fail
:
(
err
)
=>
{
typeof
callBack
==
"function"
&&
callBack
(
null
,
err
.
errMsg
);
console
.
log
(
err
);
wx
.
hideNavigationBarLoading
();
if
(
loading
)
{
wx
.
hideLoading
();
}
}
})
wx
.
showNavigationBarLoading
();
var
token
,
header
;
...
...
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