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
60f42551
authored
Aug 05, 2019
by
施宇
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
111
parent
25e6e733
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
499 additions
and
442 deletions
app.js
components/chat/chat.js
components/chat/chat.wxml
components/chat/inputbar/suit/main/main.js
components/chat/msglist/msglist.js
components/chat/msglist/msglist.wxml
components/swipedelete/swipedelete.js
components/swipedelete/swipedelete.wxml
components/swipedelete/swipedelete.wxss
pages/detail/chat/index.js
pages/search/result/index.js
pages/search/result/index.wxml
pages/tab/message/message.js
pages/tab/message/message.wxml
utils/chat.js
app.js
View file @
60f42551
const
WebIM
=
require
(
"utils/WebIM"
)[
"default"
];
// let msgStorage = require("components/chat/msgstorage");
// let msgType = require("components/chat/msgtype");
// let disp = require("utils/broadcast");
let
chat
=
require
(
'utils/chat.js'
);
import
{
getData
}
from
'./utils/util.js'
;
import
{
apis
}
from
'./utils/api.js'
;
// function calcUnReadSpot(message) {
// let myName = wx.getStorageSync("myUsername");
// let allMembers = wx.getStorageSync("member") || []; //好友
// let count = allMembers.reduce(function (result, curMember, idx) {
// let chatMsgs = wx.getStorageSync(curMember.toLowerCase() + myName.toLowerCase()) || [];
// return result + chatMsgs.length;
// }, 0);
// getApp().globalData.unReadMessageNum = count;
// disp.fire("em.xmpp.unreadspot", message);
// }
// function onMessageError(err) {
// if (err.type === "error") {
// wx.showToast({
// title: err.errorText
// });
// return false;
// }
// return true;
// }
// function addMember(id) {
// let member = wx.getStorageSync("member") || [];
// let index = member.indexOf(id);
// if (index == -1) {
// member.push(id)
// }
// wx.setStorage({
// key: "member",
// data: member
// });
// }
App
({
globalData
:
{
unReadMessageNum
:
0
,
token
:
wx
.
getStorageSync
(
'access_token'
),
token
:
wx
.
getStorageSync
(
'access_token'
),
isIPX
:
false
,
//是否为iphone X
customerNum
:
"18664936975
"
,
customerName
:
"IC业务助手
"
customerNum
:
"001
"
,
customerName
:
"IC助手客服
"
},
// conn: {
// closed: false,
// curOpenOpt: {},
// open(opt) {
// // /* wx.showLoading({
// // title: '正在初始化客户端...',
// // mask: true
// // }) */
// this.curOpenOpt = opt;
// WebIM.conn.open(opt);
// this.closed = false;
// },
// reopen() {
// if (this.closed) {
// WebIM.conn.open(this.curOpenOpt);
// this.closed = false;
// }
// }
// },
getImUser
:
chat
.
getImUser
,
addChatMember
:
function
(
id
)
{
let
token
=
wx
.
getStorageSync
(
'access_token'
)
||
''
let
member
=
wx
.
getStorageSync
(
"member"
)
||
[];
let
index
=
member
.
indexOf
(
id
);
if
(
index
==
-
1
)
{
member
.
push
(
id
)
}
wx
.
setStorage
({
key
:
"member"
,
data
:
member
});
let
token
=
wx
.
getStorageSync
(
'access_token'
)
||
''
;
this
.
addChatMemberStorage
(
id
);
getData
(
apis
.
addrecord
,
'GET'
,
{
"token"
:
token
,
"user_id"
:
id
...
...
@@ -87,6 +25,17 @@ App({
}
},
false
);
},
addChatMemberStorage
:
function
(
id
)
{
let
member
=
wx
.
getStorageSync
(
"member"
)
||
[];
let
index
=
member
.
indexOf
(
id
);
if
(
index
==
-
1
)
{
member
.
push
(
id
)
}
wx
.
setStorage
({
key
:
"member"
,
data
:
member
});
},
onLaunch
()
{
let
me
=
this
;
...
...
@@ -94,7 +43,7 @@ App({
wx
.
getStorage
({
key
:
'access_token'
,
success
(
res
)
{
if
(
res
.
data
)
{
if
(
res
.
data
)
{
wx
.
switchTab
({
url
:
'/pages/tab/home/home'
...
...
@@ -116,68 +65,8 @@ App({
}
}
})
this
.
getImUser
()
// wx.setStorage({
// key: "myUsername",
// data: '7a2765fc7caa5e512a6d1270bcf98bf0'
// });
// this.conn.open({
// apiUrl: WebIM.config.apiURL,
// user: '7a2765fc7caa5e512a6d1270bcf98bf0',
// pwd: 'ic_55028838',
// appKey: WebIM.config.appkey
// });
this
.
getImUser
();
chat
.
webimListen
();
// WebIM.conn.listen({
// onOpened(message) {
// },
// onReconnect() {
// wx.showToast({
// title: "重连中...",
// duration: 2000
// });
// },
// onSocketConnected() {
// /* wx.showToast({
// title: "socket连接成功",
// duration: 2000
// }); */
// },
// onClosed() {
// wx.showToast({
// title: "网络已断开",
// icon: 'none',
// duration: 2000
// });
// me.conn.closed = true;
// WebIM.conn.close();
// },
// onCmdMessage(message) {
// },
// onTextMessage(message) {
// chat.addMember(message.from)
// if (message) {
// if (chat.onMessageError(message)) {
// msgStorage.saveReceiveMsg(message, msgType.TEXT);
// }
// chat.calcUnReadSpot(message);
// }
// },
// onPictureMessage(message) {
// },
// // 各种异常
// onError(error) {
// console.log(error)
// },
// });
this
.
checkIsIPhoneX
();
},
checkIsIPhoneX
:
function
()
{
...
...
components/chat/chat.js
View file @
60f42551
...
...
@@ -30,9 +30,8 @@ Component({
saveSendMsg
(
evt
){
msgStorage
.
saveMsg
(
evt
.
detail
.
msg
,
evt
.
detail
.
type
);
if
(
evt
.
detail
.
type
!==
'cmd'
){
if
((
evt
.
detail
.
type
!==
'cmd'
)
&&
(
!
evt
.
detail
.
customer
)
){
this
.
data
.
__comps__
.
inputbar
.
cancelEmoji
();
}
}
},
...
...
components/chat/chat.wxml
View file @
60f42551
<view class="main">
<chat-suit-audio
id="chat-suit-audio"
username="{{ username }}"
chatType="{{ chatType }}"
bind:newAudioMsg="saveSendMsg"></chat-suit-audio>
<chat-msglist
id="chat-msglist"
username="{{ username }}"
...
...
components/chat/inputbar/suit/main/main.js
View file @
60f42551
...
...
@@ -51,6 +51,10 @@ Component({
sendMessage
()
{
let
me
=
this
;
let
customer
=
wx
.
getStorageSync
(
'customer'
)
||
''
;
if
(
customer
)
{
wx
.
removeStorageSync
(
'customer'
);
}
String
.
prototype
.
trim
=
function
()
{
return
this
.
replace
(
/
(
^
\s
*
)
|
(\s
*$
)
/g
,
''
);
}
...
...
@@ -90,6 +94,7 @@ Component({
"newTextMsg"
,
{
msg
:
msg
,
type
:
msgType
.
TEXT
,
customer
:
customer
?
true
:
false
},
{
bubbles
:
true
,
composed
:
true
...
...
@@ -126,16 +131,14 @@ Component({
success
:
function
()
{
console
.
log
(
'发送模板成功'
)
console
.
log
(
me
.
data
.
username
.
your
)
getApp
().
addChatMember
(
me
.
data
.
username
.
your
)
//
getApp().addChatMember(me.data.username.your)
disp
.
fire
(
'em.chat.sendSuccess'
,
id
);
},
fail
:
function
()
{
console
.
log
(
'发送模板失败'
);
}
});
console
.
log
(
msg
.
body
)
getApp
().
addChatMember
(
me
.
data
.
username
.
your
)
WebIM
.
conn
.
send
(
msg
.
body
);
this
.
triggerEvent
(
"newTextMsg"
,
{
...
...
@@ -162,14 +165,19 @@ Component({
detached
()
{
},
ready
()
{
let
template
=
wx
.
getStorageSync
(
'template'
)
||
''
;
if
(
!
template
)
{
return
}
else
{
let
customer
=
wx
.
getStorageSync
(
'customer'
)
||
''
;
if
(
template
)
{
this
.
setData
({
template
:
template
});
wx
.
removeStorageSync
(
'template'
);
this
.
sendCmd
();
};
if
(
customer
){
this
.
setData
({
userMessage
:
customer
});
this
.
sendMessage
();
}
},
});
\ No newline at end of file
components/chat/msglist/msglist.js
View file @
60f42551
This diff is collapsed.
Click to expand it.
components/chat/msglist/msglist.wxml
View file @
60f42551
...
...
@@ -17,7 +17,7 @@
<view class="cmd-text">品牌:</view>
<view class="cmd-value">{{ item.ext.brand }}</view>
</view>
<view class="cmd-com">
<view class="cmd-com">
<view class="cmd-text">数量:</view>
<view class="cmd-value">{{ item.ext.num }}</view>
</view>
...
...
@@ -38,7 +38,12 @@
<view scroll-y="true" class="{{ view }} wrap {{isIPX?'scroll_view_X': ''}}" bind:tap="onTap" scroll-into-view="{{ toView }}">
<view class="message" wx:for="{{ chatMsg }}" wx:key="{{ item.mid }}" id="{{ item.mid }}">
<view class="{{ item.style }}">
<image class="avatar" src="{{item.ext.img?item.ext.img:'/res/images/imgs/s.png'}}" />
<block wx:if="{{item.yourname == customerNum}}">
<image class="avatar" src="/res/images/imgs/timg.jpg" />
</block>
<block wx:else>
<image class="avatar" src="{{item.ext.img?item.ext.img:'/res/images/imgs/s.png'}}" />
</block>
<view class="msg {{item.msg.type=='cmd'?'cmd-msg':''}}">
<image class="err {{(item.style == 'self' && item.isFail) ? 'show' : 'hide'}}" src="../../../images/msgerr.png" />
<view wx:if="{{ item.msg.type == 'img'}}">
...
...
components/swipedelete/swipedelete.js
View file @
60f42551
...
...
@@ -14,7 +14,13 @@ Component({
this
.
setData
({
translateX
:
0
})
this
.
triggerEvent
(
'deleteChatItem'
,
{},
{
bubbles
:
true
})
this
.
triggerEvent
(
'deleteChatItem'
)
},
deleteChat
:
function
(
e
)
{
this
.
setData
({
translateX
:
0
})
this
.
triggerEvent
(
'deleteChat'
)
},
/**
* 滑动删除事件-滑动开始
...
...
@@ -41,11 +47,11 @@ Component({
})
}
}
else
{
// 左滑 显示删除
if
(
Math
.
abs
(
this
.
data
.
translateX
)
>=
16
0
)
{
if
(
Math
.
abs
(
this
.
data
.
translateX
)
>=
32
0
)
{
return
}
else
{
this
.
setData
({
translateX
:
-
16
0
translateX
:
-
32
0
})
}
}
...
...
components/swipedelete/swipedelete.wxml
View file @
60f42551
<view class='swipedelete-wrapper' bindtouchmove='touchMoveHandler' bindtouchstart='touchStartHandler' style="transform:translateX({{translateX}}rpx)">
<slot></slot>
<view class='swipedelete-btn' bindtap='deleteItem'>删除</view>
<view class='swipedelete-btn' bindtap='deleteItem'>拉入黑名单</view>
<view class='delete-btn' bindtap='deleteChat'>删除聊天</view>
</view>
\ No newline at end of file
components/swipedelete/swipedelete.wxss
View file @
60f42551
...
...
@@ -4,21 +4,24 @@
position: relative;
}
.swipedelete-btn {
/*
position:absolute;
top:0;
right:-180rpx
;
text-align:center
;
background: #f00
;
color:#fff
;
width:160rpx
;
height:100%
;
position:absolute;
right: -320rpx;
top:0
;
background-color:#F03737
;
width:160rpx
;
height:100%
;
text-align:center
;
color: #fff
;
display:flex;
align-items:center;
justify-content:center;
align-items:center;*/
font-size: 24rpx;
}
.delete-btn{
position:absolute;
right: -160rpx;
top:0;
background-color:#
D0021B
;
background-color:#
8A9299
;
width:160rpx;
height:100%;
text-align:center;
...
...
@@ -26,4 +29,5 @@
display:flex;
align-items:center;
justify-content:center;
font-size: 24rpx;
}
\ No newline at end of file
pages/detail/chat/index.js
View file @
60f42551
...
...
@@ -13,9 +13,16 @@ Page({
let
username
=
JSON
.
parse
(
options
.
username
);
this
.
setData
({
username
:
username
});
console
.
log
(
username
)
wx
.
setNavigationBarTitle
({
title
:
username
.
title
});
if
(
getApp
().
globalData
.
customerNum
==
username
.
your
){
wx
.
setNavigationBarTitle
({
title
:
'IC助手客服'
});
}
else
{
wx
.
setNavigationBarTitle
({
title
:
username
.
title
});
}
},
onUnload
()
{
...
...
pages/search/result/index.js
View file @
60f42551
...
...
@@ -217,5 +217,26 @@ Page({
wx
.
navigateTo
({
url
:
"/pages/form/good/index"
})
}
},
sendCustomer
:
function
()
{
let
my
=
wx
.
getStorageSync
(
"myUsername"
);
let
companyName
=
wx
.
getStorageSync
(
"company_name"
);
let
userId
=
wx
.
getStorageSync
(
"user_id"
);
let
avatar
=
wx
.
getStorageSync
(
"avatar"
);
let
queryObj
=
{
myName
:
my
,
your
:
getApp
().
globalData
.
customerNum
,
name
:
getApp
().
globalData
.
customerName
,
name1
:
companyName
,
id
:
userId
,
touserid
:
''
,
title
:
getApp
().
globalData
.
customerName
,
img
:
''
,
img1
:
avatar
};
wx
.
setStorageSync
(
'customer'
,
this
.
data
.
confirmKey
);
wx
.
navigateTo
({
url
:
"/pages/detail/chat/index?username="
+
JSON
.
stringify
(
queryObj
)
})
},
})
\ No newline at end of file
pages/search/result/index.wxml
View file @
60f42551
...
...
@@ -44,7 +44,7 @@
</view>
</view>
<view class="concat_custom" wx:if="{{priceList&&priceList.length==0&&tabIndex == 2}}">
<text class="icon iconfont iconiconxiantiaoshouji11"></text>
<text>联系客服帮您找</text>
<text class="icon iconfont iconiconxiantiaoshouji11"
bindtap="sendCustomer"
></text>
<text
bindtap="sendCustomer"
>联系客服帮您找</text>
</view>
</view>
\ No newline at end of file
pages/tab/message/message.js
View file @
60f42551
// pages/tab/message/message.js
let
disp
=
require
(
"../../../utils/broadcast"
);
var
WebIM
=
require
(
"../../../utils/WebIM"
)[
"default"
];
let
WebIM
=
require
(
"../../../utils/WebIM"
)[
"default"
];
Page
({
/**
...
...
@@ -8,24 +8,70 @@ Page({
*/
data
:
{
unReadSpotNum
:
0
,
arr
:
[],
userId
:
""
,
customer
:{}
arr
:
null
,
userId
:
""
,
customer
:
{},
isCustomer
:
true
,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad
:
function
(
options
)
{
onLoad
:
function
(
options
)
{
let
me
=
this
;
let
my
=
wx
.
getStorageSync
(
"myUsername"
);
//监听未读消息数
disp
.
on
(
"em.xmpp.unreadspot"
,
function
(
message
)
{
disp
.
on
(
"em.xmpp.unreadspot"
,
function
(
message
)
{
if
(
getApp
().
globalData
.
customerNum
!=
my
)
{
me
.
getCustom
()
}
me
.
setData
({
arr
:
me
.
getChatList
(),
unReadSpotNum
:
getApp
().
globalData
.
unReadMessageNum
>
99
?
'99+'
:
getApp
().
globalData
.
unReadMessageNum
,
});
});
},
getCustom
:
function
()
{
let
my
=
wx
.
getStorageSync
(
"myUsername"
);
let
companyName
=
wx
.
getStorageSync
(
"company_name"
)
||
''
;
let
userId
=
wx
.
getStorageSync
(
"user_id"
)
||
''
;
let
avatar
=
wx
.
getStorageSync
(
"avatar"
)
||
''
;
let
newChatMsgs
=
wx
.
getStorageSync
(
getApp
().
globalData
.
customerNum
+
my
)
||
[];
let
historyChatMsgs
=
wx
.
getStorageSync
(
"rendered_"
+
getApp
().
globalData
.
customerNum
+
my
)
||
[];
let
curChatMsgs
=
historyChatMsgs
.
concat
(
newChatMsgs
);
if
(
curChatMsgs
.
length
)
{
let
lastChatMsg
=
curChatMsgs
[
curChatMsgs
.
length
-
1
];
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
.
time
=
`
${
dateArr
[
1
]}
月
${
dateArr
[
2
]}
日
${
timeArr
[
0
]}
时
${
timeArr
[
1
]}
分`
;
lastChatMsg
.
unReadCount
=
newChatMsgs
.
length
;
if
(
lastChatMsg
.
unReadCount
>
99
)
{
lastChatMsg
.
unReadCount
=
"99+"
;
}
this
.
setData
({
customer
:
lastChatMsg
})
}
else
{
this
.
setData
({
customer
:
{
username
:
getApp
().
globalData
.
customerNum
,
ext
:
{
name
:
getApp
().
globalData
.
customerName
,
name1
:
companyName
,
id
:
userId
,
touserid
:
''
,
img
:
''
,
img1
:
avatar
},
name
:
getApp
().
globalData
.
customerName
,
unReadCount
:
0
}
})
}
},
getChatList
()
{
let
array
=
[];
let
member
=
wx
.
getStorageSync
(
"member"
);
...
...
@@ -55,33 +101,31 @@ Page({
return
array
;
},
into_singleChatRoom
:
function
(
detail
)
{
var
my
=
wx
.
getStorageSync
(
"myUsername"
);
console
.
log
(
detail
)
var
nameList
=
{
into_singleChatRoom
:
function
(
detail
)
{
let
my
=
wx
.
getStorageSync
(
"myUsername"
);
let
nameList
=
{
myName
:
my
,
your
:
detail
.
username
,
name
:
detail
.
ext
.
name
,
name1
:
detail
.
ext
.
name1
,
id
:
detail
.
ext
.
id
,
touserid
:
detail
.
ext
.
touserid
,
name
:
detail
.
ext
.
name
,
name1
:
detail
.
ext
.
name1
,
id
:
detail
.
ext
.
id
,
touserid
:
detail
.
ext
.
touserid
,
title
:
detail
.
name
,
img
:
detail
.
ext
.
img
,
img1
:
detail
.
ext
.
img1
img
:
detail
.
ext
.
img
,
img1
:
detail
.
ext
.
img1
};
console
.
log
(
JSON
.
stringify
(
nameList
))
wx
.
navigateTo
({
url
:
"/pages/detail/chat/index?username="
+
JSON
.
stringify
(
nameList
)
});
},
into_chatRoom
:
function
(
event
)
{
into_chatRoom
:
function
(
event
)
{
let
detail
=
event
.
currentTarget
.
dataset
.
item
;
this
.
into_singleChatRoom
(
detail
)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady
:
function
()
{
onReady
:
function
()
{
},
...
...
@@ -89,40 +133,21 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow
:
function
()
{
onShow
:
function
()
{
let
my
=
wx
.
getStorageSync
(
"myUsername"
);
let
companyName
=
wx
.
getStorageSync
(
"company_name"
)
||
''
;
let
userId
=
wx
.
getStorageSync
(
"user_id"
)
||
''
;
let
avatar
=
wx
.
getStorageSync
(
"avatar"
)
||
''
;
let
customerKey
=
'rendered_'
+
getApp
().
globalData
.
customerNum
+
my
let
customer
=
wx
.
getStorageSync
(
customerKey
)
||
''
;
if
(
customer
){
if
(
getApp
().
globalData
.
customerNum
!=
my
)
{
this
.
getCustom
();
this
.
setData
({
customer
:
customer
[
customer
.
length
-
1
]
isCustomer
:
false
})
console
.
log
(
this
.
data
.
customer
)
}
else
{
}
else
{
this
.
setData
({
customer
:
{
username
:
getApp
().
globalData
.
customerNum
,
ext
:{
name
:
getApp
().
globalData
.
customerName
,
name1
:
companyName
,
id
:
userId
,
touserid
:
''
,
img
:
''
,
img1
:
avatar
},
name
:
getApp
().
globalData
.
customerName
,
}
isCustomer
:
true
})
}
this
.
setData
({
arr
:
this
.
getChatList
(),
userId
:
wx
.
getStorageSync
(
'user_id'
),
userId
:
wx
.
getStorageSync
(
'user_id'
),
unReadSpotNum
:
getApp
().
globalData
.
unReadMessageNum
>
99
?
'99+'
:
getApp
().
globalData
.
unReadMessageNum
,
});
},
...
...
@@ -130,35 +155,102 @@ Page({
/**
* 生命周期函数--监听页面隐藏
*/
onHide
:
function
()
{
onHide
:
function
()
{
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload
:
function
()
{
onUnload
:
function
()
{
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh
:
function
()
{
onPullDownRefresh
:
function
()
{
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom
:
function
()
{
onReachBottom
:
function
()
{
},
/**
* 用户点击右上角分享
*/
onShareAppMessage
:
function
()
{
onShareAppMessage
:
function
()
{
},
deleteChatItem
:
function
(
e
)
{
//拉黑
this
.
del_chat
(
e
,
2
)
},
deleteChat
:
function
(
e
)
{
//删除记录
this
.
del_chat
(
e
,
1
)
},
del_chat
:
function
(
event
,
type
)
{
let
detail
=
event
.
currentTarget
.
dataset
.
item
;
let
your
=
detail
.
username
;
let
myName
=
wx
.
getStorageSync
(
"myUsername"
);
let
currentPage
=
getCurrentPages
();
let
title
=
type
==
1
?
'是否删除记录'
:
'是否加入黑名单?'
wx
.
showModal
({
title
:
title
,
confirmText
:
"确定"
,
success
:
function
(
res
)
{
if
(
res
.
confirm
)
{
if
(
type
==
1
)
{
let
member
=
wx
.
getStorageSync
(
'member'
);
let
index
=
member
.
indexOf
(
your
);
member
.
splice
(
index
,
1
);
wx
.
setStorageSync
(
'member'
,
member
)
wx
.
removeStorageSync
(
your
+
myName
);
wx
.
removeStorageSync
(
"rendered_"
+
your
+
myName
);
if
(
currentPage
[
0
])
{
currentPage
[
0
].
onShow
();
}
disp
.
fire
(
"em.chat.session.remove"
);
}
else
{
let
list
=
{
your
:
{
jid
:
WebIM
.
config
.
appkey
+
'_'
+
your
+
'@easemob.com'
,
name
:
your
,
order
:
1
,
},
};
WebIM
.
conn
.
addToBlackList
({
list
:
list
,
type
:
'jid'
,
success
:
function
()
{
let
member
=
wx
.
getStorageSync
(
'member'
);
let
index
=
member
.
indexOf
(
your
);
member
.
splice
(
index
,
1
);
wx
.
setStorageSync
(
'member'
,
member
)
wx
.
removeStorageSync
(
your
+
myName
);
wx
.
removeStorageSync
(
"rendered_"
+
your
+
myName
);
if
(
currentPage
[
0
])
{
currentPage
[
0
].
onShow
();
}
disp
.
fire
(
"em.chat.session.remove"
);
},
error
:
function
()
{
wx
.
showToast
({
title
:
'加入黑名单失败'
,
icon
:
'none'
,
duration
:
2000
});
}
});
}
}
}
},
fail
:
function
(
err
)
{}
});
},
})
\ No newline at end of file
pages/tab/message/message.wxml
View file @
60f42551
<!--pages/tab/message/message.wxml-->
<scroll-view scroll-y="true" class="message-view">
<
!-- <view class="nodata" wx:if="{{arr.length == 0
}}">
<
view class="nodata" wx:if="{{arr.length==0&&isCustomer
}}">
<image src="/res/images/imgs/nomessage.png" class="img"></image>
<view class="h3 bold">暂无询价消息</view>
</view>
-->
<view class="message-content">
</view>
<view class="message-content"
wx:if="{{!isCustomer||arr.length}}"
>
<view class="tip row bothSide verCenter">
<view class="tip-left">
<text class="icon iconfont iconiconxiantiaoshouji12 tip-icon"></text>
...
...
@@ -13,42 +13,42 @@
<text class="icon iconfont iconiconxiantiaoshouji13 close-icon"></text>
</view>
<view class="message-list">
<view catchtap="into_chatRoom" data-item="{{c
ustomer}}">
<view class="message-item px-hr-bottom row bothSide nowrap">
<view class="message-l row ellipsis">
<image src="/res/images/imgs/timg.jpg" class="message-avar"></image>
<view class="message-l-view ellipsis">
<view class="message-c bold ellipsis">IC助手客服</view>
<view class="message-t ellipsis" wx:if="{{ customer.msg.data[0].data }}">{{ customer.msg.data[0].data }}</view>
<view class="message-t ellipsis" wx:if="{{customer.msg.type == 'img' }}">[图片]</view>
<view catchtap="into_chatRoom" data-item="{{customer}}" wx:if="{{!isC
ustomer}}">
<view class="message-item px-hr-bottom row bothSide nowrap">
<view class="message-l row ellipsis">
<image src="/res/images/imgs/timg.jpg" class="message-avar"></image>
<view class="message-l-view ellipsis">
<view class="message-c bold ellipsis">IC助手客服</view>
<view class="message-t ellipsis" wx:if="{{ customer.msg.data[0].data }}">{{ customer.msg.data[0].data }}</view>
<view class="message-t ellipsis" wx:if="{{customer.msg.type == 'img' }}">[图片]</view>
<view class="message-t ellipsis" wx:if="{{customer.msg.type == 'cmd' }}">{{customer.ext.type}} {{customer.ext.price}}</view>
</view>
</view>
</view>
<view class="message-r">
<view class="message-r-t">{{customer.time}}</view>
<view class="message-r-n" wx:if="{{ customer.unReadCount > 0 || customer.unReadCount == '99+' }}">{{ customer.unReadCount }}</view>
</view>
</view>
</view>
<view wx:for="{{ arr }}" wx:key="index" catchtap="into_chatRoom" data-item="{{ item }}">
<swipe-delete>
<view class="message-item px-hr-bottom row bothSide nowrap">
<view class="message-l row ellipsis">
<image src="{{item.img?item.img:'/res/images/imgs/s.png'}}" class="message-avar"></image>
<view class="message-l-view ellipsis">
<view class="message-c bold ellipsis">{{ item.name||'--' }}</view>
<view class="message-t ellipsis" wx:if="{{ item.msg.data[0].data }}">{{ item.msg.data[0].data }}</view>
<view class="message-t ellipsis" wx:if="{{item.msg.type == 'img' }}">[图片]</view>
<view class="message-t ellipsis" wx:if="{{item.msg.type == 'cmd' }}">{{item.ext.type}} {{item.ext.price}}</view>
<view class="message-r">
<view class="message-r-t">{{customer.time}}</view>
<view class="message-r-n" wx:if="{{ customer.unReadCount > 0 || customer.unReadCount == '99+' }}">{{ customer.unReadCount }}</view>
</view>
</view>
<view class="message-r">
<view class="message-r-t">{{item.time}}</view>
<view class="message-r-n" wx:if="{{ item.unReadCount > 0 || item.unReadCount == '99+' }}">{{ item.unReadCount }}</view>
</view>
</view>
</swipe-delete>
</view>
</view>
<view wx:for="{{ arr }}" wx:key="index" wx:if="{{arr}}">
<swipe-delete binddeleteChatItem="deleteChatItem" data-item="{{ item }}" binddeleteChat="deleteChat">
<view class="message-item px-hr-bottom row bothSide nowrap" catchtap="into_chatRoom" data-item="{{ item }}">
<view class="message-l row ellipsis">
<image src="{{item.img?item.img:'/res/images/imgs/s.png'}}" class="message-avar"></image>
<view class="message-l-view ellipsis">
<view class="message-c bold ellipsis">{{ item.name||'--' }}</view>
<view class="message-t ellipsis" wx:if="{{ item.msg.data[0].data }}">{{ item.msg.data[0].data }}</view>
<view class="message-t ellipsis" wx:if="{{item.msg.type == 'img' }}">[图片]</view>
<view class="message-t ellipsis" wx:if="{{item.msg.type == 'cmd' }}">{{item.ext.type}} {{item.ext.price}}</view>
</view>
</view>
<view class="message-r">
<view class="message-r-t">{{item.time}}</view>
<view class="message-r-n" wx:if="{{ item.unReadCount > 0 || item.unReadCount == '99+' }}">{{ item.unReadCount }}</view>
</view>
</view>
</swipe-delete>
</view>
</view>
</view>
</scroll-view>
\ No newline at end of file
utils/chat.js
View file @
60f42551
import
{
getData
}
from
'../utils/util.js'
;
import
{
apis
}
from
'../utils/api.js'
;
import
{
getData
}
from
'../utils/util.js'
;
import
{
apis
}
from
'../utils/api.js'
;
const
WebIM
=
require
(
"./WebIM"
)[
"default"
];
let
msgStorage
=
require
(
"../components/chat/msgstorage"
);
let
msgType
=
require
(
"../components/chat/msgtype"
);
...
...
@@ -26,9 +30,8 @@ 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
);
getApp
().
globalData
.
unReadMessageNum
=
count
;
...
...
@@ -48,9 +51,9 @@ 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
(
'user_id'
,
res
.
data
.
user_id
+
''
);
wx
.
setStorageSync
(
'avatar'
,
res
.
data
.
avatar
);
wx
.
setStorageSync
(
'company_name'
,
res
.
data
.
company_name
);
wx
.
setStorageSync
(
"myUsername"
,
res
.
data
.
im_username
);
...
...
@@ -67,9 +70,10 @@ const getImUser = () => {
},
false
)
};
const
webimListen
=
()
=>
{
let
my
=
wx
.
getStorageSync
(
'myUsername'
)
||
''
;
WebIM
.
conn
.
listen
({
onOpened
(
message
)
{
WebIM
.
conn
.
setPresence
();
},
onReconnect
()
{
wx
.
showToast
({
...
...
@@ -93,19 +97,22 @@ const webimListen = () => {
WebIM
.
conn
.
close
();
},
onCmdMessage
(
message
)
{
getApp
().
addChatMember
(
message
.
from
)
if
(
message
)
{
if
(
onMessageError
(
message
))
{
getApp
().
addChatMember
(
message
.
from
);
msgStorage
.
saveReceiveMsg
(
message
,
msgType
.
CMD
);
}
calcUnReadSpot
(
message
);
}
},
onTextMessage
(
message
)
{
console
.
log
(
'接受信息'
)
if
(
message
)
{
if
(
onMessageError
(
message
))
{
if
(
getApp
().
globalData
.
customerNum
!=
message
.
from
)
{
getApp
().
addChatMember
(
message
.
from
);
}
msgStorage
.
saveReceiveMsg
(
message
,
msgType
.
TEXT
);
// console.log(111)
}
calcUnReadSpot
(
message
);
}
...
...
@@ -116,6 +123,9 @@ const webimListen = () => {
console
.
log
(
"onEmojiMessage"
,
message
);
if
(
message
)
{
if
(
onMessageError
(
message
))
{
if
(
getApp
().
globalData
.
customerNum
!=
message
.
from
)
{
getApp
().
addChatMember
(
message
.
from
);
}
msgStorage
.
saveReceiveMsg
(
message
,
msgType
.
EMOJI
);
}
calcUnReadSpot
(
message
);
...
...
@@ -125,6 +135,9 @@ const webimListen = () => {
console
.
log
(
"onPictureMessage"
,
message
);
if
(
message
)
{
if
(
onMessageError
(
message
))
{
if
(
getApp
().
globalData
.
customerNum
!=
message
.
from
)
{
getApp
().
addChatMember
(
message
.
from
);
}
msgStorage
.
saveReceiveMsg
(
message
,
msgType
.
IMAGE
);
}
calcUnReadSpot
(
message
);
...
...
@@ -137,8 +150,6 @@ const webimListen = () => {
});
};
module
.
exports
=
{
// calcUnReadSpot: calcUnReadSpot,
// onMessageError: onMessageError,
webimListen
:
webimListen
,
conn
:
conn
,
getImUser
:
getImUser
...
...
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