bayi пре 2 година
родитељ
комит
c52e6e5f28

+ 2 - 0
api/message.js

@@ -17,6 +17,8 @@ module.exports = {
   msgTopping: data => request('/v3/messageRecord/top', 'post', data),
   // 获取消息详情
   getMsgDet: data => request('/v3/messageRecord/single', 'get', data),
+  // 获取最新消息详情(聊天界面轮询
+  getNewMsgDet: data => request('/v3/messageRecord/newMessage', 'get', data),
   // 发送消息
   sendMsg: data => request('/v3/messageRecord', 'post', data),
 }

+ 53 - 20
pages/chat/index.js

@@ -1,13 +1,23 @@
 import {
   getMsgDet,
-  sendMsg
+  sendMsg,
+  getNewMsgDet
 } from "~/api/message"
+import {
+  createStoreBindings
+} from 'mobx-miniprogram-bindings'
+import {
+  store
+} from '~/store/index'
 const app = getApp()
 Page({
   data: {
     targetUid: '',
     value: '',
-    isIos: app.globalData.isIOS
+    list: [],
+    totalSize: 0,
+    isIos: app.globalData.isIOS,
+    uid: wx.getStorageSync('uid')
   },
   onLoad(options) {
     console.log(options);
@@ -17,37 +27,48 @@ Page({
     this.setData({
       targetUid: options.uid
     })
+    this.storeBindings = createStoreBindings(this, {
+      store,
+      fields: {
+        userInfo: 'userInfo'
+      },
+    })
+    this.storeBindings.updateStoreBindings()
     this.getMsgDet()
+    this.getNewMsgDet()
   },
   async getMsgDet() {
-    let list = await getMsgDet({
+    let data = await getMsgDet({
       senderUid: this.data.targetUid,
       pageNo: 1,
-      pageSize: 20
+      pageSize: 10
+    })
+    let {
+      list,
+      totalSize
+    } = data
+    this.setData({
+      list,
+      totalSize
+    })
+    console.log(data, this.data.userInfo);
+  },
+  async getNewMsgDet() {
+    let res = await getNewMsgDet({
+      senderUid: this.data.targetUid,
     })
-    console.log(list);
+    console.log(res);
   },
   async sendReply() {
     if (!this.data.value) {
       return
     }
     await sendMsg({
-      content: "1",
-      receiverUid: ""
-    })
-  },
-  bindKeyInput(e) {
-    this.setData({
-      value: e.detail.value
-    })
-  },
-  jumpUserInfo({
-    currentTarget
-  }) {
-    wx.navigateTo({
-      url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
+      content: this.data.value,
+      receiverUid: this.data.targetUid
     })
   },
+
   chooseImage() {
     wx.chooseImage({
       count: 1, // 可选择的图片数量
@@ -70,5 +91,17 @@ Page({
         console.log(res.data);
       }
     })
-  }
+  },
+  bindKeyInput(e) {
+    this.setData({
+      value: e.detail.value
+    })
+  },
+  jumpUserInfo({
+    currentTarget
+  }) {
+    wx.navigateTo({
+      url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
+    })
+  },
 })

+ 3 - 1
pages/chat/index.less

@@ -19,7 +19,6 @@
       }
 
       .message {
-        flex: 1;
         padding: 20rpx;
         box-sizing: border-box;
         font-size: 28rpx;
@@ -30,13 +29,16 @@
     }
 
     .someone {
+      justify-content: flex-start;
       .avatar {
         margin-right: 30rpx;
       }
     }
 
     .self {
+      justify-content: flex-end;
       .message {
+        display: inline-block;
         margin-right: 30rpx;
         background-color: #3DD076;
         color: white;

+ 10 - 8
pages/chat/index.wxml

@@ -1,13 +1,15 @@
 <view class="chat">
   <view class="content">
-    <view class="base someone" wx:for="{{2}}" wx:key="index">
-      <image src="/static/star.png" class="avatar" bindtap="jumpUserInfo" data-uid='{{index}}' />
-      <view class="message">获取系统信息。由于历史原因,wx.getSystemInfo 是异步的调用格式,但是是同步返回,需要异步获取系统信息请使用 wx.getSystemInfoAsync。</view>
-    </view>
-    <view class="base self" wx:for="{{2}}" wx:key="index">
-      <view class="message">获取系统信息。由于历史原因,wx.getSystemInfo 是异步的调用格式,但是是同步返回,需要异步获取系统信息请使用 wx.getSystemInfoAsync。</view>
-      <image src="/static/star.png" class="avatar" />
-    </view>
+    <block wx:for="{{list}}" wx:key="id">
+      <view class="base someone" wx:if="{{uid!=item.senderUid}}">
+        <image src="{{item.user.avatar}}" class="avatar" bindtap="jumpUserInfo" data-uid='{{item.uid}}' />
+        <view class="message">{{item.content}}</view>
+      </view>
+      <view class="base self" wx:else>
+        <view class="message">{{item.content}}</view>
+        <image src="{{userInfo.avatar}}" class="avatar" bindtap="jumpUserInfo" data-uid='{{item.uid}}' />
+      </view>
+    </block>
   </view>
   <view class="inputBox {{isIos?'iosPadding':''}}">
     <input class="input" bindinput="bindKeyInput" value="{{value}}" placeholder="我有话说..." />

+ 7 - 1
pages/chat/index.wxss

@@ -18,7 +18,6 @@
   background-color: #eeeeee;
 }
 .chat .content .base .message {
-  flex: 1;
   padding: 20rpx;
   box-sizing: border-box;
   font-size: 28rpx;
@@ -26,10 +25,17 @@
   border-radius: 14rpx;
   background-color: #F2F6FC;
 }
+.chat .content .someone {
+  justify-content: flex-start;
+}
 .chat .content .someone .avatar {
   margin-right: 30rpx;
 }
+.chat .content .self {
+  justify-content: flex-end;
+}
 .chat .content .self .message {
+  display: inline-block;
   margin-right: 30rpx;
   background-color: #3DD076;
   color: white;

+ 3 - 1
pages/comment/index.json

@@ -1,4 +1,6 @@
 {
-  "usingComponents": {},
+  "usingComponents": {
+    "emptyBg": "/components/empty/index"
+  },
   "navigationBarTitleText": "评论"
 }

+ 4 - 0
pages/comment/index.less

@@ -75,4 +75,8 @@
       }
     }
   }
+
+  .empty {
+    margin-top: 200rpx;
+  }
 }

+ 1 - 0
pages/comment/index.wxml

@@ -15,4 +15,5 @@
       <image src="{{item.userRead.coverImg}}" class="cover" />
     </view>
   </view>
+  <emptyBg wx:if="{{list.length==0}}" message='快去发布更多精彩作品吧!' />
 </view>

+ 3 - 0
pages/comment/index.wxss

@@ -64,3 +64,6 @@
   height: 84rpx;
   border-radius: 50%;
 }
+.commentPage .empty {
+  margin-top: 200rpx;
+}

+ 3 - 1
pages/like/index.json

@@ -1,4 +1,6 @@
 {
-  "usingComponents": {},
+  "usingComponents": {
+    "emptyBg": "/components/empty/index"
+  },
   "navigationBarTitleText": "点赞"
 }

+ 4 - 0
pages/like/index.less

@@ -65,4 +65,8 @@
       }
     }
   }
+
+  .empty {
+    margin-top: 200rpx;
+  }
 }

+ 1 - 0
pages/like/index.wxml

@@ -14,4 +14,5 @@
       <image src="{{item.userRead.coverImg}}" class="cover" />
     </view>
   </view>
+  <emptyBg wx:if="{{list.length==0}}" message='快去发布更多精彩作品吧!' />
 </view>

+ 3 - 0
pages/like/index.wxss

@@ -55,3 +55,6 @@
   height: 84rpx;
   border-radius: 50%;
 }
+.like .empty {
+  margin-top: 200rpx;
+}

+ 12 - 6
pages/message/index.js

@@ -16,7 +16,8 @@ Page({
     },
     menuH: 0,
     authorityMsg: {},
-    uid: ''
+    uid: '',
+    isTop: false
   },
   onLoad(options) {
     this.setData({
@@ -91,10 +92,11 @@ Page({
     } = currentTarget.dataset.item
     this.setData({
       targetId: receiverUid != this.data.uid ? receiverUid : senderUid,
+      isTop: currentTarget.dataset.top,
       menu: {
         show: true,
         top: hFlag ? touches[0].clientY : touches[0].clientY - menuH,
-        left: wFlag ? touches[0].clientX : touches[0].clientX - 135
+        left: wFlag ? touches[0].clientX : touches[0].clientX - 135,
       }
     })
   },
@@ -126,9 +128,13 @@ Page({
   jumpChat({
     currentTarget
   }) {
-    console.log(currentTarget.dataset);
-    /*  wx.navigateTo({
-       url: `/pages/${currentTarget.dataset.url}/index`,
-     }) */
+    let {
+      nickName,
+      eid,
+      uid
+    } = currentTarget.dataset.item.user
+    wx.navigateTo({
+      url: `/pages/chat/index?title=${nickName||eid}&uid=${uid}`,
+    })
   },
 })

+ 8 - 8
pages/message/index.wxml

@@ -39,12 +39,12 @@
         <view class="name">通知</view>
       </view>
       <view class="right">
-        <view class="date">2023-3-14</view>
+        <view class="date"></view>
         <view class="unread" wx:if="{{authorityMsg.messageCount>0}}">{{authorityMsg.messageCount}}</view>
       </view>
     </view>
-    <view class="base user" wx:for="{{authorityMsg.topList}}" wx:key="index" data-item='{{item}}'
-      bind:longpress="onLongPress" hover-class='pressHover' bindtap="jump">
+    <view class="base user" wx:for="{{authorityMsg.topList}}" wx:key="index" data-item='{{item}}' data-top="{{true}}"
+      bind:longpress="onLongPress" hover-class='pressHover' bindtap="jumpChat">
       <image src="{{item.user.avatar}}" class="avatar" />
       <view class="body">
         <view class="name textOver">{{item.user.nickName||item.user.eid}}</view>
@@ -54,11 +54,11 @@
       </view>
       <view class="right">
         <view class="date">{{filters.formatDate(item.gmtModified,5)}}</view>
-        <view class="unread">{{item.unReadCount}}</view>
+        <view class="unread" wx:if="{{item.unReadCount>0}}">{{item.unReadCount}}</view>
       </view>
     </view>
-    <view class="base user" wx:for="{{list}}" wx:key="id" data-item='{{item}}' bind:longpress="onLongPress"
-      hover-class='pressHover' bindtap="jump">
+    <view class="base user" wx:for="{{list}}" wx:key="id" data-item='{{item}}' data-top="{{false}}"
+      bind:longpress="onLongPress" hover-class='pressHover' bindtap="jumpChat">
       <image src="{{item.user.avatar}}" class="avatar" />
       <view class="body">
         <view class="name textOver">{{item.user.nickName||item.user.eid}}</view>
@@ -68,14 +68,14 @@
       </view>
       <view class="right">
         <view class="date">{{filters.formatDate(item.gmtModified,5)}}</view>
-        <view class="unread">{{item.unReadCount}}</view>
+        <view class="unread" wx:if="{{item.unReadCount>0}}">{{item.unReadCount}}</view>
       </view>
     </view>
   </view>
   <view class="menuBg" bind:touchstart="cancelMenu" wx:if="{{menu.show}}"></view>
   <view class="menu" style="display: {{menu.show?'block':'none'}}; top:{{menu.top}}px;left:{{menu.left}}px">
     <view class="menu-one" bindtap="msgTopping">
-      <image src="/static/istop.png" class="icon" /> 置顶该聊天
+      <image src="/static/istop.png" class="icon" />{{isTop?'取消置顶':'置顶该聊天'}}
     </view>
     <!--     <view bindtap="delMessage">
       <image src="/static/del.png" class="icon" />