Commit b8e4016cc46af6a93ba9cb71263494d3bdaf4780

Authored by liangqingchun
1 parent 27df54ec86

群聊

Showing 11 changed files with 186 additions and 65 deletions

littleApp_child/app.js View file @ b8e4016
... ... @@ -116,7 +116,7 @@
116 116 from: message.from,
117 117 to: message.to
118 118 },
119   - username: '',
  119 + username: message.from,
120 120 yourname: message.from,
121 121 msg: {
122 122 type: 'txt',
... ... @@ -134,6 +134,7 @@
134 134 data: that.globalData.unrederMsg[messageFrom + myName],
135 135 success: function () {
136 136 console.log('setStorage success')
  137 + disp.fire("em.xmpp.unreadspot", message);
137 138 }
138 139 })
139 140 console.log('消息打印',messageFrom + myName,that.globalData.unrederMsg[messageFrom + myName])
... ... @@ -167,7 +168,7 @@
167 168 from: message.from,
168 169 to: message.to
169 170 },
170   - username: '',
  171 + username: message.from,
171 172 yourname: message.from,
172 173 msg: {
173 174 type: 'img',
... ... @@ -186,6 +187,7 @@
186 187 data: that.globalData.unrederMsg[messageFrom + myName],
187 188 success: function () {
188 189 console.log('setStorage success')
  190 + disp.fire("em.xmpp.unreadspot", message);
189 191 }
190 192 })
191 193 }
... ... @@ -210,7 +212,7 @@
210 212 from: message.from,
211 213 to: message.to
212 214 },
213   - username: '',
  215 + username: message.from,
214 216 yourname: message.from,
215 217 msg: {
216 218 type: 'audio',
... ... @@ -231,6 +233,7 @@
231 233 data: that.globalData.unrederMsg[messageFrom+ myName],
232 234 success: function () {
233 235 console.log('setStorage success')
  236 + disp.fire("em.xmpp.unreadspot", message);
234 237 }
235 238 })
236 239 }
littleApp_child/pages/chatroom/chatroom.js View file @ b8e4016
... ... @@ -45,6 +45,7 @@
45 45 kfName:'',
46 46 memberHxName:'',
47 47 memberName:'',
  48 + unTotleReadCount:0,
48 49 chatMsg: [],
49 50 username:'',
50 51 bubbles:false,
... ... @@ -62,7 +63,7 @@
62 63 */
63 64 onLoad: function (options) {
64 65 let self=this;
65   - console.log(options)
  66 + var options=JSON.parse(options.username)
66 67 networkUtil._post(api.addBabyChatroom,{doctorId:options.doctorId},function(res){
67 68 console.log(res)
68 69 self.setData({
69 70  
... ... @@ -74,14 +75,14 @@
74 75 kfName:res.data.data.kfName,
75 76 memberHxName:res.data.data.memberHxName,
76 77 memberName:res.data.data.memberName,
77   - username:'150346790928385'
  78 + username:res.data.data.chatroomId
78 79 })
79 80  
80 81 self.initChat()
81 82 },function(res){
82 83  
83 84 },'application/json')
84   -
  85 + self.initChat()
85 86 disp.on('em.xmpp.error.sendMsgErr', function(err) {
86 87 curMsgMid = err.data.mid
87 88 isFail = true
... ... @@ -431,7 +432,7 @@
431 432 from: msg.from,
432 433 to: msg.to
433 434 },
434   - username: '',
  435 + username: msg.from,
435 436 yourname: msg.from,
436 437 msg: {
437 438 type: type,
... ... @@ -551,7 +552,7 @@
551 552 },
552 553 onRender(){
553 554 wx.pageScrollTo({
554   - scrollTop: 5000,
  555 + scrollTop: 50000,
555 556 duration: 300,
556 557 success: function(){console.log('滚动成功')},
557 558 fail: function(){console.log('滚动失败')}
... ... @@ -879,6 +880,8 @@
879 880 var id = WebIM.conn.getUniqueId();
880 881 var msg = new WebIM.message(msgType.AUDIO, id);
881 882 var dataObj = JSON.parse(res.data);
  883 + msg.from = myName;
  884 +
882 885 // 接收消息对象
883 886 msg.set({
884 887 apiUrl: WebIM.config.apiURL,
... ... @@ -913,7 +916,7 @@
913 916 from: msg.from,
914 917 to: msg.to
915 918 },
916   - username: '',
  919 + username: msg.from,
917 920 yourname: msg.from,
918 921 msg: {
919 922 type: 'audio',
littleApp_child/pages/chatroom/chatroom.wxml View file @ b8e4016
... ... @@ -14,8 +14,9 @@
14 14 <view class="user">
15 15 <text>{{ item.username===doctorHxName?doctorName:item.username===kfHxName?kfName:item.username===memberHxName?memberName:'' }}</text>
16 16 </view>
17   - <image wx:if="{{item.style == 'self'}}" class="avatar" src="https://img1.healthbaby.com.cn/FpMYI-aoXUyTONfNN5IGw3Jr-n_z?imageView2/0/w/200"/>
18   - <image wx:if="{{item.style == ''}}" class="avatar" src="../../source/default_doctor_icon.png"/>
  17 + <image wx:if="{{item.username==memberHxName}}" class="avatar" src="https://img1.healthbaby.com.cn/FpMYI-aoXUyTONfNN5IGw3Jr-n_z?imageView2/0/w/200"/>
  18 + <image wx:if="{{item.username==doctorHxName}}" class="avatar" src="../../source/default_doctor_icon.png"/>
  19 + <image wx:if="{{item.username==kfHxName}}" class="avatar" src="../../source/kefu.png"/>
19 20 <view class="msg">
20 21 <image
21 22 class="err {{(item.style == 'self' && item.isFail) ? 'show' : 'hide'}}"
littleApp_child/pages/doctorLists/doctorLists.js View file @ b8e4016
... ... @@ -3,6 +3,10 @@
3 3 var networkUtil = require('../../utils/network_util.js')
4 4 var api = require('../../utils/apiFile.js')
5 5  
  6 +//即时通讯工具类
  7 +let disp = require("../../utils/broadcast");
  8 +var WebIM = require("../../utils/WebIM")["default"];
  9 +
6 10 Page({
7 11  
8 12 /**
9 13  
... ... @@ -10,12 +14,22 @@
10 14 */
11 15 data: {
12 16 list: [],
  17 + chatList:[],
13 18 hospitalName: "",
14 19 hospitalId: "",
15 20 hostitalprice: 0,
16 21 totalPrize: 0, //总价
17 22 ids: '', //服务id
18 23 doctorIds: '', //选中的医生id
  24 + memberId:'',
  25 + serviceId:'',
  26 + doctorHxName:'',
  27 + doctorName:'',
  28 + kfHxName:'',
  29 + kfName:'',
  30 + memberHxName:'',
  31 + memberName:'',
  32 + username:'',
19 33 hospitalList: [],
20 34 count: 1500,
21 35 isShowToast: false,
22 36  
... ... @@ -29,11 +43,12 @@
29 43 * 生命周期函数--监听页面加载
30 44 */
31 45 onLoad: function (options) {
32   - console.log(options)
  46 + var option=JSON.parse(options.username)
  47 + console.log(option)
33 48 var that = this;
34 49 that.setData({
35   - memberId:options.memberId,
36   - serviceId:options.serviceId,
  50 + memberId:option.memberId,
  51 + serviceId:option.serviceId,
37 52 })
38 53 networkUtil.showLoading();
39 54 networkUtil._get(api.getWxDoctors,{},function(res){
40 55  
... ... @@ -49,11 +64,25 @@
49 64 that.setData({
50 65 hospitalList:hospitals,
51 66 hospitalName:hospitals[0].name,
52   - list:hospitals[0].data
  67 + list:that.getChatList(hospitals[0].data)
53 68 })
54 69 },function(){
55 70  
56 71 })
  72 + //监听未读消息数
  73 + disp.on("em.xmpp.unreadspot", function(message){
  74 + that.setData({
  75 + list: that.getChatList(that.data.list),
  76 + });
  77 + console.log(that.data.unTotleReadCount)
  78 + if(that.data.unTotleReadCount >= 1){
  79 + wx.vibrateLong({
  80 + success:function() {
  81 + console.log('震动调取成功')
  82 + },
  83 + })
  84 + }
  85 + });
57 86 },
58 87  
59 88 /**
60 89  
61 90  
... ... @@ -106,37 +135,39 @@
106 135 },
107 136 chat(e){
108 137 var self=this;
109   - var doctorId = e.target.dataset.doctorid;
  138 + var doctorId = e.currentTarget.dataset.doctorid;
110 139 console.log(doctorId)
111 140 networkUtil._post(api.addBabyChatroom,{doctorId:doctorId},function(res){
112   - console.log(res)
113   - self.setData({
114   - doctorHxName:res.data.data.doctorHxName,
115   - doctorName:res.data.data.doctorName,
116   - kfHxName:res.data.data.kfHxName,
117   - kfName:res.data.data.kfName,
118   - memberHxName:res.data.data.memberHxName,
119   - memberName:res.data.data.memberName,
120   - username:'150346790928385'
121   - })
  141 + if(res.data.errorcode==0){
  142 + self.data.unTotleReadCount = 0;
  143 + console.log(res)
  144 + var nameList={
  145 + doctorHxName:res.data.data.doctorHxName,
  146 + doctorName:res.data.data.doctorName,
  147 + kfHxName:res.data.data.kfHxName,
  148 + kfName:res.data.data.kfName,
  149 + memberHxName:res.data.data.memberHxName,
  150 + memberName:res.data.data.memberName,
  151 + username:res.data.data.chatroomId,
  152 + doctorId:doctorId
  153 + }
  154 + console.log(nameList)
  155 +
  156 + console.log(self.data.unTotleReadCount)
  157 + if(self.data.unTotleReadCount >= 1){
  158 + wx.vibrateLong({
  159 + success:function() {
  160 + console.log('震动调取成功')
  161 + },
  162 + })
  163 + }
  164 + wx.redirectTo({
  165 + url: '../chatroom/chatroom?username='+ JSON.stringify(nameList),
  166 + })
  167 + }
122 168 },function(res){
123 169  
124 170 },'application/json')
125   - var nameList={
126   - memberId:self.memberId,
127   - serviceId:self.serviceId,
128   - doctorHxName:self.doctorHxName,
129   - doctorName:self.doctorName,
130   - kfHxName:self.kfHxName,
131   - kfName:self.kfName,
132   - memberHxName:self.memberHxName,
133   - memberName:self.memberName,
134   - doctorId:self.doctorId
135   - }
136   - console.log(nameList)
137   - wx.navigateTo({
138   - url: '../chatroom/chatroom?username='+ JSON.stringify(nameList),
139   - })
140 171 },
141 172 godoctor: function(e) {
142 173 var doctorId = e.currentTarget.dataset.doctorid;
... ... @@ -186,7 +217,7 @@
186 217 self.setData({
187 218 hospitalName: hospitalName,
188 219 index: e.detail.value,
189   - list:doctors
  220 + list:self.getChatList(doctors)
190 221 })
191 222 //self.getDoctorsFromServer()
192 223 },
... ... @@ -268,5 +299,28 @@
268 299  
269 300 })
270 301 },
  302 +
  303 + getChatList(data){
  304 + console.log(111)
  305 + var member = data || this.data.list;
  306 + var myName = wx.getStorageSync("hxName");
  307 + for(let i = 0; i < member.length; i++){
  308 + console.log(member[i].chartroomId,myName)
  309 + //let newChatMsgs = wx.getStorageSync('150455922524161' + myName) || [];
  310 + //let historyChatMsgs = wx.getStorageSync("rendered_" + '150455922524161' + myName) || [];
  311 + let newChatMsgs = wx.getStorageSync(member[i].chartroomId + myName) || [];
  312 + let historyChatMsgs = wx.getStorageSync("rendered_" + member[i].chartroomId + myName) || [];
  313 + let curChatMsgs = historyChatMsgs.concat(newChatMsgs);
  314 + let item = member[i];
  315 + if(curChatMsgs.length){
  316 + item.unReadCount = newChatMsgs.length;
  317 + if(item.unReadCount > 99) {
  318 + item.unReadCount = "99+";
  319 + }
  320 + this.data.unTotleReadCount += item.unReadCount
  321 + }
  322 + }
  323 + return member;
  324 + }
271 325 })
littleApp_child/pages/doctorLists/doctorLists.wxml View file @ b8e4016
... ... @@ -29,14 +29,14 @@
29 29 <view class='service_name'>专家咨询</view>
30 30 </view>
31 31 <view class='divider'></view>
32   - <view class='item' wx:for="{{list}}" bindtap="chat" data-doctorId="{{item.doctorId}}">
  32 + <view class='item' wx:for="{{list}}" bindtap="chat" data-doctorId="{{item.id}}" >
33 33 <view class='icon_name_view'>
34 34 <image class='icon' src="{{item.doctorImage.medium.length>0 ?item.doctorImage.medium:'../../source/default_doctor_icon.png'}}"></image>
35 35 <view bindtap='godoctor' data-doctorId="{{item.id}}" data-doctor="{{item}}">
36 36 <view class='name_text'>{{item.name}}<text class="job_text">{{item.positional}}</text></view>
37 37 <view class="description_text">专家介绍</view>
38 38 </view>
39   -
  39 + <view class="massage_box_txt" wx:if="{{item.unReadCount > 0}}">{{item.unReadCount}}</view>
40 40 </view>
41 41 <view style='height:10px'></view>
42 42 <view class='divider' hidden='{{index==list[index].item.length}}'></view>
littleApp_child/pages/doctorLists/doctorLists.wxss View file @ b8e4016
... ... @@ -15,7 +15,19 @@
15 15 padding-right: 15px;
16 16 padding-top: 15px;
17 17 }
18   -
  18 +.massage_box_txt{
  19 + float:right;
  20 + width: 50rpx;
  21 + height: 50rpx;
  22 + text-align: center;
  23 + border-radius: 50%;
  24 + background-color: indianred;
  25 + font-size: 15px;
  26 + color: #fff;
  27 + position: absolute;
  28 + right:20px;
  29 + top:10px;
  30 +}
19 31 .top_content_view {
20 32 background: #fff;
21 33 border: 1px solid #d8dbd2;
... ... @@ -95,6 +107,7 @@
95 107 .icon_name_view {
96 108 display: flex;
97 109 padding-left: 15px;
  110 + position: relative;
98 111 }
99 112  
100 113 .icon {
littleApp_child/pages/home/home.js View file @ b8e4016
... ... @@ -13,6 +13,7 @@
13 13  
14 14 //聊天控件
15 15 let WebIM = wx.WebIM = require("../../utils/WebIM.js").default;
  16 +let disp = require("../../utils/broadcast");
16 17  
17 18 var timeCount = 60;
18 19 var timer;
... ... @@ -32,6 +33,7 @@
32 33 item_small: 0,
33 34 // 首页类型 1登录 2用户首页 3欢迎页
34 35 pageType: 0,
  36 + unTotleReadCount:0,
35 37 time: '0s',
36 38 list: [],
37 39 userInfo: '',
38 40  
39 41  
... ... @@ -83,10 +85,15 @@
83 85 riskDise:false
84 86 },
85 87 /*---------生命周期--------*/
86   - onLoad: function() {
  88 + onLoad: function(options) {
87 89 this.calculatePageSize()
  90 +
88 91 // 网络监听
89 92 this.networkStatusChange()
  93 + var that = this
  94 + disp.on("em.xmpp.unreadspot", function(){
  95 + that.getUnreaderMsgNum()
  96 + })
90 97 if (app.globalData.token == null || app.globalData.token == ''||wx.getStorageSync("access_token") == null||!wx.getStorageSync("access_token")) {
91 98 this.welcomePage()
92 99 } else {
... ... @@ -115,6 +122,7 @@
115 122 if (wx.getStorageSync("access_token") != null&&wx.getStorageSync("access_token")) {
116 123 console.log(wx.getStorageSync("access_token"))
117 124 this.connectWebIM()
  125 +
118 126 }
119 127 if (app.globalData.token.length > 0 && this.data.pageType != 2) {
120 128 this.getUserInfo()
... ... @@ -126,6 +134,7 @@
126 134 if (!app.globalData.token && this.data.pageType != 1) {
127 135 this.welcomePage()
128 136 }
  137 + this.getUnreaderMsgNum()
129 138 },
130 139 onUnload: function() {
131 140 // 移除监听
... ... @@ -805,8 +814,7 @@
805 814 },
806 815 //专家咨询
807 816 consultation(){
808   - console.log(this.data.userData)
809   - if(this.data.userData.disStatus == 0){
  817 + if(this.data.riskGuide){
810 818 var my = wx.getStorageSync('hxName')
811 819 var nameList = {
812 820 myName: my,
813 821  
... ... @@ -818,22 +826,47 @@
818 826 wx.navigateTo({
819 827 url: '../doctorLists/doctorLists?username='+ JSON.stringify(nameList),
820 828 })
821   - }else if(this.data.userData.disStatus == 1){
822   - var my = wx.getStorageSync('hxName')
823   - var serviceId = this.data.userData.disData.serviceId;
824   - var nameList = {
825   - myName: my,
826   - your: this.data.userData.disData.doctorHxName,
827   - serviceId:serviceId,
828   - memberId:this.data.userData.disData.memberId,
829   - doctorId:this.data.userData.disData.doctorId
830   - }
831   - wx.setStorageSync('serviceId',serviceId)
832   - console.log(nameList)
833   - wx.navigateTo({
834   - url: '../doctorLists/doctorLists?username='+ JSON.stringify(nameList),
  829 + }else{
  830 + wx.showModal({
  831 + title: '温馨提示',
  832 + content: '您还没有开通该项服务哦',
  833 + confirmText: '立即开通',
  834 + success: function(res) {
  835 + if (res.confirm) {
  836 + wx.navigateTo({
  837 + url: '../vipService/vipService',
  838 + })
  839 + }
  840 + }
835 841 })
836 842 }
837   -},
  843 + },
  844 + // 获取未读总数
  845 + getUnreaderMsgNum(){
  846 + var that = this
  847 + var num = 0
  848 + var myName = wx.getStorageSync("hxName");
  849 + WebIM.conn.listRooms({
  850 + success: function(rooms){
  851 + console.log(rooms)
  852 + rooms.map((item) => {
  853 + wx.getStorage({
  854 + key: item.roomId + myName,
  855 + success (res) {
  856 + var unreadMas =res.data
  857 + if(unreadMas){
  858 + num += unreadMas.length;
  859 + }
  860 + console.log(num)
  861 + that.setData({unTotleReadCount:num})
  862 + }
  863 + })
  864 + })
  865 + },
  866 + error: function(){
  867 +
  868 + }
  869 + })
  870 + }
838 871 })
littleApp_child/pages/home/home.wxml View file @ b8e4016
... ... @@ -101,6 +101,7 @@
101 101 <view class="foundation_item_small_text">眼保健记录</view>
102 102 </navigator>
103 103 <navigator class="foundation_item_small" bindtap="consultation">
  104 + <view class="unreadCount" wx:if="{{unTotleReadCount>0}}">{{unTotleReadCount}}</view>
104 105 <image src="../../source/icon_consult@2x.png" style="{{item_small}}" class="foundation_item_small_image"></image>
105 106 <view class="foundation_item_small_text">专家咨询</view>
106 107 </navigator>
littleApp_child/pages/home/home.wxss View file @ b8e4016
... ... @@ -11,7 +11,19 @@
11 11 background: #48C17B;
12 12 position: relative;
13 13 }
14   -
  14 +.unreadCount{
  15 + width: 46rpx;
  16 + height: 46rpx;
  17 + text-align: center;
  18 + border-radius: 50%;
  19 + background-color: indianred;
  20 + z-index: 10;
  21 + font-size: 15px;
  22 + color: #fff;
  23 + position: absolute;
  24 + right:10px;
  25 + top:0px;
  26 +}
15 27 .promptText {
16 28 background: #f4879b;
17 29 font: bold;
... ... @@ -203,6 +215,7 @@
203 215 flex-direction: column;
204 216 align-items: center;
205 217 justify-content: center;
  218 + position: relative;
206 219 }
207 220  
208 221 .foundation_item_small_image {
littleApp_child/source/kefu.png View file @ b8e4016

11.3 KB

littleApp_child/utils/apiFile.js View file @ b8e4016
... ... @@ -106,6 +106,6 @@
106 106 //膳食报告详情
107 107 querybabyAppDiet:'baby/querybabyAppDiet',
108 108 //群聊
109   - addBabyChatroom:'/baby/addBabyChatroom'
  109 + addBabyChatroom:'/baby/addBabyChatroom',
110 110 }