瀏覽代碼

提交代码呀~

release/210823_需求对对碰
王饶冀 3 年之前
父節點
當前提交
a87c2f32e4
共有 5 個檔案被更改,包括 158 行新增51 行删除
  1. 1
    1
      app.js
  2. 1
    1
      pages/msgModule/index.js
  3. 52
    30
      pages/msgModule/wechat2/wechat2.js
  4. 87
    17
      pages/msgModule/wechat2/wechat2.wxml
  5. 17
    2
      pages/msgModule/wechat2/wechat2.wxss

+ 1
- 1
app.js 查看文件

@@ -100,7 +100,7 @@ App({
})
},
// mangerUrl: 'http://test2.hhrchina.com',
mangerUrl: "http://192.168.18.216",
mangerUrl: "http://192.168.18.138",
// mangerUrl: "https://www.hhrchina.com",
// mangerUrlPath: "https://www.hhrchina.com",
})

+ 1
- 1
pages/msgModule/index.js 查看文件

@@ -73,8 +73,8 @@ Page({
el.lastContent = _data.chatRecord.content;
el.lastContentDate = $util.formatTime(new Date(_data.chatRecord.sendTime));
el.lastContentDate = el.lastContentDate.replaceAll('/', '-');
el.size += 1;
}
el.size += 1;
})
_this.setData({
msgData

+ 52
- 30
pages/msgModule/wechat2/wechat2.js 查看文件

@@ -50,12 +50,19 @@ Page({
productInfo: null,
// 发送框是否获取焦点
inputShowed: false,
// 是发送图片---用于阻止触发onhide
isSendImg: false,
// 发送图片url
mangerUrl: "",
},

/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.setData({
mangerUrl: app.mangerUrl + "/file/getPhotos.action?path="
})
const eventChannel = this.getOpenerEventChannel()
// 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据

@@ -129,17 +136,23 @@ Page({
list = _this.data.newsList;
let _data = JSON.parse(res.data);
_data.chatRecord = JSON.parse(_data.chatRecord);
console.log('--------------对方给你发消息拉 beg -------------')
console.log(_data);
console.log('--------------对方给你发消息拉 end -------------')
let msgData = {};
// type 0 自己 1 对方
if (_data.chatRecord.sender != _this.data.receiveMemberId) {
msgData.type = 1;
} else {
msgData.type = 0;
}
msgData.isRead = true;
msgData.message = _data.chatRecord.content;
list.push(msgData);
_this.setData({
newsList: list
})
_this.setMsgRead('newsList', _this.data.newsList, 0)
_this.scrollBottom()
},
)
@@ -160,6 +173,7 @@ Page({
var historyList = [...res.data.chatRecordList, ...this.data.historyList]
if (historyList && historyList.length > 0) {
historyList.forEach(item => {
// type 0 自己 1 对方
if (item.sender != sendMemberId) {
item.type = 0
} else {
@@ -190,7 +204,7 @@ Page({
}
}
// 说明没有一条是messageType == 1 的
if(tempArr.length < 1){
if (tempArr.length < 1) {
this.sendmsgApi("", 1);
}
} else {
@@ -198,6 +212,8 @@ Page({
}
}
}
// 设置消息已读
this.setMsgRead('historyList', this.data.historyList, 1)
// 页面进入滚动到底部
this.scrollBottom()
}).catch(err => {
@@ -273,14 +289,18 @@ Page({
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
// wx.closeSocket();
if (!this.data.isSendImg) {
wx.closeSocket();
}
},

/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
// wx.closeSocket();
if (!this.data.isSendImg) {
wx.closeSocket();
}
},

/**
@@ -313,11 +333,11 @@ Page({
let { sendMemberId, receiveMemberId, businessCommunicationDemandId } = this.data;
let transactionId = businessCommunicationDemandId;
if (!businessCommunicationDemandId) {
if(this.data.historyList.length > 0){
if (this.data.historyList.length > 0) {
transactionId = this.data.historyList[this.data.historyList.length - 1].transactionId;
}
}
if(!transactionId){
if (!transactionId) {
transactionId = "";
}
let params = {
@@ -326,7 +346,6 @@ Page({
transactionId, // 产品ID
content,
messageType: msgType,

};
$request.post('/businessCommunicationDemand/addChatRecord.action', params).then(res => {
console.log(`------------聊一聊保存记录-----------------`)
@@ -345,6 +364,7 @@ Page({
temp.date = temp.date.replaceAll('/', '-');
temp.messageType = msgType;
temp.transactionId = transactionId;
temp.isRead = false;
if (msgType == 1) {
temp.info = this.data.productInfo;
}
@@ -401,45 +421,47 @@ Page({
},
// 发送图片
upImg() {
this.setData({
isSendImg: true
})
wx.chooseImage({
count: 1,
success: (res) => {
console.log(res);
console.log(res.tempFilePaths[0], '拿到的URL');
wx.uploadFile({
filePath: res.tempFilePaths[0],
name: "file",
url: "/file/uploading.action?fileType=TinymceImg",
url: app.mangerUrl + "/file/uploading.action?fileType=TinymceImg",
success: (res2) => {
console.log(`上传之后的res2`,res2)
let data = JSON.parse(res2.data);
this.sendmsgApi(data.data, 2);
}
})
// /file/uploading.action?fileType=TinymceImg
},
complete: (res) => {
// 调用结束后要关闭isSendImg
this.setData({
isSendImg: false
})
}
})
},
// 公共聚焦方法,方法比较笨,但是过度效果平滑流畅
bottom: function () {

var that = this;

// 获取元素的高度
let query = wx.createSelectorQuery();
query.select('.news').boundingClientRect(rect => {
//获取到元素
let scrollTop = rect.height;
// 设置已读未读
setMsgRead(key, data, type) {
data.forEach(el => {
if (el.type == type) {
el.isRead = true;
}
})
if (key == 'historyList') {
this.setData({
scrollTop
historyList: data
})
}).exec();

console.log(this.data.scrollTop, 'hahah')

wx.pageScrollTo({
// scrollTop: this.data.scrollTop + 30,
scrollTop: 10000,
// duration: 0
})
} else {
this.setData({
newsList: data
})
}
},
})


+ 87
- 17
pages/msgModule/wechat2/wechat2.wxml 查看文件

@@ -6,66 +6,136 @@
<view wx:if="{{historyList.length > 0}}">
<view class="historyText">历史消息</view>
<block wx:for="{{historyList}}" wx:key="index">
<!-- 此处为other -->
<view wx:if="{{item.type==1 && item.messageType != 1}}" id="historyscrollid{{index}}">
<!-- 正常消息 左 -->
<view wx:if="{{item.type==1 && item.messageType == 0}}" id="historyscrollid{{index}}">
<view>
<text class='chat-time' style="display:none;">{{item.date}}</text>
</view>
<view class='other-record'>
<image class='other-head-img' src='{{item.senderHeadPortrait}}'></image>
<view class='other-record-content-triangle'></view>
<view class='other-record-content'>{{item.content}}</view>
<view class='other-record-content'>
{{item.content}}
<view class="msg-isRead left">{{ item.isRead ? '已读' : '未读' }}</view>
</view>
</view>
</view>
<!-- 此处为结尾 -->
<!-- 此处为own -->
<view id="historyscrollid{{index}}" wx:elif="{{item.type==0 && item.messageType != 1}}">
<!-- 正常消息 右 -->
<view id="historyscrollid{{index}}" wx:elif="{{item.type==0 && item.messageType == 0}}">
<view>
<text class='chat-time' style="display:none;">{{item.date}}</text>
</view>
<view class='own-record'>
<view class='own-record-content'>{{item.content}}</view>
<view class='own-record-content'>
{{item.content}}
<view class="msg-isRead right">
{{ item.isRead ? '已读' : '未读' }}
</view>
</view>
<view class='own-record-content-triangle'></view>
<image class='own-head-img' src='{{item.senderHeadPortrait}}'></image>
</view>
</view>
<!-- 发送图片 左 -->
<view wx:elif="{{item.type==1 && item.messageType == 2}}" id="historyscrollid{{index}}">
<view>
<text class='chat-time' style="display:none;">{{item.date}}</text>
</view>
<view class='other-record'>
<image class='other-head-img' src='{{item.senderHeadPortrait}}'></image>
<view class='other-record-content-triangle'></view>
<view class='other-record-content'>
<image class='content-img' src="{{ mangerUrl + item.content }}"></image>
<view class="msg-isRead left">{{ item.isRead ? '已读' : '未读' }}</view>
</view>
</view>
</view>
<!-- 发送图片 右 -->
<view id="historyscrollid{{index}}" wx:elif="{{item.type==0 && item.messageType == 2}}">
<view>
<text class='chat-time' style="display:none;">{{item.date}}</text>
</view>
<view class='own-record'>
<view class='own-record-content'>
<image class='content-img' src="{{ mangerUrl + item.content }}"></image>
<view class="msg-isRead right">
{{ item.isRead ? '已读' : '未读' }}
</view>
</view>
<view class='own-record-content-triangle'></view>
<image class='own-head-img' src='{{item.senderHeadPortrait}}'></image>
</view>
</view>
<!-- 由你发起沟通详情 -->
<view wx:else class="product-item-view" bindtap="goDetails" data-value="{{ item.transactionId }}">
<view class="content-view">
<view class="product-info-item">{{ item.object.info }}</view>
<view class="product-send-time">{{ item.date }} 由你发起沟通</view>
</view>
</view>
<!-- own结尾 -->
</block>
<view class="historyText" id="lastHistoryText">以上为历史消息</view>
</view>
<!-- 历史记录部分end -->
<view wx:if="{{ newsList.length == 0}}" id="scrollid0"></view>
<block wx:for="{{newsList}}" wx:key="index">
<!-- 此处为other -->
<view wx:if="{{item.type==1 && item.messageType != 1}}" id="scrollid{{index}}">
<!-- 正常消息 左 -->
<view wx:if="{{item.type==1 && item.messageType == 0}}" id="scrollid{{index}}">
<view>
<text class='chat-time' style="display:none;">{{item.date}}</text>
</view>
<view class='other-record'>
<image class='other-head-img' src='{{receivebaseInfo.avatar}}'></image>
<view class='other-record-content-triangle'></view>
<view class='other-record-content'>
{{item.message}}
<view class="msg-isRead left">{{ item.isRead ? '已读' : '未读' }}</view>
</view>
</view>
</view>
<!-- 正常消息 右 -->
<view id="scrollid{{index}}" wx:elif="{{item.type==0 && item.messageType == 0}}">
<view>
<text class='chat-time' style="display:none;">{{item.date}}</text>
</view>
<view class='own-record'>
<view class='own-record-content'>
{{item.message}}
<view class="msg-isRead right">{{ item.isRead ? '已读' : '未读' }}</view>
</view>
<view class='own-record-content-triangle'></view>
<image class='own-head-img' src='{{sendAvatar}}'></image>
</view>
</view>
<!-- 图片消息 左 -->
<view wx:if="{{item.type==1 && item.messageType == 2}}" id="scrollid{{index}}">
<view>
<text class='chat-time' style="display:none;">{{item.date}}</text>
</view>
<view class='other-record'>
<image class='other-head-img' src='{{receivebaseInfo.avatar}}'></image>
<view class='other-record-content-triangle'></view>
<view class='other-record-content'>{{item.message}}</view>
<view class='other-record-content'>
<image class='content-img' src="{{ mangerUrl + item.content }}"></image>
<view class="msg-isRead left">{{ item.isRead ? '已读' : '未读' }}</view>
</view>
</view>
</view>
<!-- 此处为结尾 -->
<!-- 此处为own -->
<view id="scrollid{{index}}" wx:elif="{{item.type==0 && item.messageType != 1}}">
<!-- 图片消息 右 -->
<view id="scrollid{{index}}" wx:elif="{{item.type==0 && item.messageType == 2}}">
<view>
<text class='chat-time' style="display:none;">{{item.date}}</text>
</view>
<view class='own-record'>
<view class='own-record-content'>{{item.message}}</view>
<view class='own-record-content'>
<image class='content-img' src="{{ mangerUrl + item.content }}"></image>
<view class="msg-isRead right">{{ item.isRead ? '已读' : '未读' }}</view>
</view>
<view class='own-record-content-triangle'></view>
<image class='own-head-img' src='{{sendAvatar}}'></image>
</view>
</view>
<!-- own结尾 -->
<!-- 由你发起沟通详情 -->
<view wx:else class="product-item-view" bindtap="goDetails" data-value="{{ item.transactionId }}">
<view class="content-view">
<view class="product-info-item">{{ item.info }}</view>
@@ -80,7 +150,7 @@
<view class="send-message">
<input class="chat-input" type="text" bindinput="bindChange" confirm-type="send" value='{{input}}' cursor-spacing="16px" hold-keyboard="{{true}}" placeholder="" bindconfirm="send" focus="{{inputShowed}}" />
<image class="expression-msg-img" src="/images/home/expression-msg-icon.png" bind:tap="emotionChange" />
<image class="img-msg-img" src="/images/home/img-msg-icon.png" bindtap="upImg"/>
<image class="img-msg-img" src="/images/home/img-msg-icon.png" bindtap="upImg" />
</view>
<view class="faces-view-dialog clearfix" wx:if="{{emotionVisible}}">
<view class="emotions-item fl" wx:for="{{connectemoji}}" wx:key="index" bindtap="addemotion" data-index="{{index}}">

+ 17
- 2
pages/msgModule/wechat2/wechat2.wxss 查看文件

@@ -190,7 +190,7 @@ page {
background-color: #fff;
box-shadow: -2px 9px 21px 0px
rgba(0, 0, 0, 0.05);
max-width: 180px;
max-width: 450rpx;
border-radius: 8px;
padding: 15rpx 20rpx;
text-align: left;
@@ -199,6 +199,7 @@ page {
box-sizing: border-box;
display: flex;
align-items:center; /*实现垂直居中*/
position: relative;
}
.other-record {
display: flex;
@@ -227,7 +228,7 @@ page {
background-color: #5e73e5;
box-shadow: -2px 9px 21px 0px
rgba(0, 0, 0, 0.05);
max-width: 180px;
max-width: 450rpx;
border-radius: 8px;
padding: 15rpx 20rpx;
color: #fff;
@@ -237,6 +238,7 @@ page {
box-sizing: border-box;
display: flex;
align-items:center; /*实现垂直居中*/
position: relative;
}
.own-record-content-triangle {
width: 0;
@@ -335,3 +337,16 @@ page {
width: 6.6%;
text-align: center;
}

.msg-isRead {
position: absolute;
font-size: 24rpx;
color: #b3bfcb;
bottom: -6rpx;
}
.msg-isRead.left {
right: -60rpx;
}
.msg-isRead.right {
left: -60rpx;
}

Loading…
取消
儲存