|
@@ -1,5 +1,5 @@
|
|
|
|
|
|
-const {getUserInfoList,getChattingRecord} = require('../../API/appraise')
|
|
+const {getUserInfoList,getChattingRecord,getGoodsInfo,setWsConnect} = require('../../API/appraise')
|
|
import messageMap from '../../utils/util'
|
|
import messageMap from '../../utils/util'
|
|
var socketMsgQueue = {
|
|
var socketMsgQueue = {
|
|
from: wx.getStorageSync('uid'),
|
|
from: wx.getStorageSync('uid'),
|
|
@@ -17,6 +17,14 @@ var getChattingRecordOption = {
|
|
uid:wx.getStorageSync('uid'),
|
|
uid:wx.getStorageSync('uid'),
|
|
target:''
|
|
target:''
|
|
}
|
|
}
|
|
|
|
+var getGoodsInfoOption = {
|
|
|
|
+ id:'',
|
|
|
|
+ uid:'',
|
|
|
|
+ date:''
|
|
|
|
+}
|
|
|
|
+var setWsConnectOption = {
|
|
|
|
+ uid: wx.getStorageSync('uid')
|
|
|
|
+}
|
|
Page({
|
|
Page({
|
|
|
|
|
|
|
|
|
|
@@ -26,9 +34,9 @@ Page({
|
|
toUid:'',
|
|
toUid:'',
|
|
goodsId:'',
|
|
goodsId:'',
|
|
goods: {
|
|
goods: {
|
|
- pic:'',
|
|
+ pic:'https://img.js.design/assets/img/6229b69ff89eeaf3b7fd1919.jpg',
|
|
- name:'',
|
|
+ name:'粉色',
|
|
- price:''
|
|
+ price:20
|
|
},
|
|
},
|
|
|
|
|
|
login: {
|
|
login: {
|
|
@@ -41,7 +49,8 @@ Page({
|
|
nickname:'daisy',
|
|
nickname:'daisy',
|
|
avatar: 'http://192.168.31.30:8084/pics/1698753512AiD8PaNrvqsDb1493fda534929a5b5d05f80a8cf3d16.jpg',
|
|
avatar: 'http://192.168.31.30:8084/pics/1698753512AiD8PaNrvqsDb1493fda534929a5b5d05f80a8cf3d16.jpg',
|
|
message: '你好',
|
|
message: '你好',
|
|
- type: 'text'
|
|
+ type: 'text',
|
|
|
|
+ time: '11-8 20:52'
|
|
},
|
|
},
|
|
{
|
|
{
|
|
to: '7385700531999608832',
|
|
to: '7385700531999608832',
|
|
@@ -49,7 +58,8 @@ Page({
|
|
nickname:'无情的敲代码机器人',
|
|
nickname:'无情的敲代码机器人',
|
|
avatar: 'http://192.168.31.30:8084/pics/1699175056BvtgC8vv8gSzd85dedb14362dc3a251c6c85705ec495.jpg',
|
|
avatar: 'http://192.168.31.30:8084/pics/1699175056BvtgC8vv8gSzd85dedb14362dc3a251c6c85705ec495.jpg',
|
|
message: '你好',
|
|
message: '你好',
|
|
- type: 'text'
|
|
+ type: 'text',
|
|
|
|
+ time: '11-8 20:52'
|
|
}
|
|
}
|
|
]
|
|
]
|
|
|
|
|
|
@@ -60,16 +70,75 @@ Page({
|
|
* 生命周期函数--监听页面加载
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
*/
|
|
onLoad(options) {
|
|
onLoad(options) {
|
|
|
|
+
|
|
this.data.toUid = options.toUid;
|
|
this.data.toUid = options.toUid;
|
|
this.data.goodsId = options.goodsId;
|
|
this.data.goodsId = options.goodsId;
|
|
getChattingRecordOption.target = this.data.toUid;
|
|
getChattingRecordOption.target = this.data.toUid;
|
|
- getChattingRecord(getChattingRecordOption).then((res)=>{
|
|
+ let time = new Date().getTime();
|
|
|
|
+ getGoodsInfoOption = {
|
|
|
|
+ id:this.data.goodsId,
|
|
|
|
+ uid:wx.getStorageSync('uid'),
|
|
|
|
+ date:time
|
|
|
|
+ }
|
|
|
|
+ getGoodsInfo(getGoodsInfoOption).then((res)=>{
|
|
|
|
+ console.log(res);
|
|
|
|
+ const good = res.data.data;
|
|
|
|
+ console.log(good);
|
|
|
|
+ }).catch((err)=>{
|
|
|
|
+ console.log(err);
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ getUserInfoListOption.data.uid = [this.data.toUid];
|
|
|
|
+ getUserInfoList(getUserInfoListOption).then((res)=> {
|
|
console.log(res);
|
|
console.log(res);
|
|
- const receiveMessage = res.data.data;
|
|
+ const {users} = res.data.data;
|
|
-
|
|
+ wx.setStorageSync('anotherNickName', users[0].name);
|
|
|
|
+ wx.setStorageSync('anotherAvatar', users[0].avatar);
|
|
}).catch((err)=>{
|
|
}).catch((err)=>{
|
|
console.log(err);
|
|
console.log(err);
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+ setWsConnect(setWsConnectOption).then((res)=> {
|
|
|
|
+ console.log(res);
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ wx.onSocketMessage((result) => {
|
|
|
|
+ console.log("服务器的数据返回", result);
|
|
|
|
+ const res = JSON.parse(result.data);
|
|
|
|
+ if(res.msgType == 1){
|
|
|
|
+
|
|
|
|
+ let date = new Date();
|
|
|
|
+ let month = date.getMonth() + 1;
|
|
|
|
+ let day = date.getDate();
|
|
|
|
+ let hour = date.getHours();
|
|
|
|
+ let minu = date.getMinutes();
|
|
|
|
+ let now1 = month < 10 ? '0' + month : month;
|
|
|
|
+ let now2 = day < 10 ? '0' + day : day;
|
|
|
|
+
|
|
|
|
+ if(res.from == this.data.toUid){
|
|
|
|
+ let msg = {
|
|
|
|
+ from: res.from,
|
|
|
|
+ to:res.to,
|
|
|
|
+ message: res.content,
|
|
|
|
+ type: 'text',
|
|
|
|
+ time: now1 + '-' + now2 + ' ' + hour + ':' + minu,
|
|
|
|
+ nickname: wx.getStorageSync('anotherNiakName'),
|
|
|
|
+ avatar: wx.getStorageSync('anotherAvatar')
|
|
|
|
+ }
|
|
|
|
+ console.log(msg);
|
|
|
|
+ this.setData({
|
|
|
|
+ chatList: list.concat(msg)
|
|
|
|
+ }, () => {
|
|
|
|
+ that.scrollToBottom();
|
|
|
|
+ that.setData({
|
|
|
|
+ content: ''
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+
|
|
this.scrollToBottom();
|
|
this.scrollToBottom();
|
|
},
|
|
},
|
|
|
|
|
|
@@ -77,12 +146,7 @@ Page({
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
*/
|
|
onReady() {
|
|
onReady() {
|
|
- getUserInfoListOption.data.uid = [wx.getStorageSync('uid'),this.data.toUid];
|
|
+
|
|
- getUserInfoList(getUserInfoListOption).then((res)=> {
|
|
|
|
- console.log(res);
|
|
|
|
- }).catch((err)=>{
|
|
|
|
- console.log(err);
|
|
|
|
- })
|
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
@@ -134,25 +198,25 @@ Page({
|
|
},
|
|
},
|
|
|
|
|
|
sendClick() {
|
|
sendClick() {
|
|
- var that = this;
|
|
+ let that = this;
|
|
- var list = this.data.chatList;
|
|
+ let list = this.data.chatList;
|
|
|
|
|
|
- var date = new Date();
|
|
+ let date = new Date();
|
|
- var month = date.getMonth() + 1;
|
|
+ let month = date.getMonth() + 1;
|
|
- var day = date.getDate();
|
|
+ let day = date.getDate();
|
|
- var hour = date.getHours();
|
|
+ let hour = date.getHours();
|
|
- var minu = date.getMinutes();
|
|
+ let minu = date.getMinutes();
|
|
- var now1 = month < 10 ? '0' + month : month;
|
|
+ let now1 = month < 10 ? '0' + month : month;
|
|
- var now2 = day < 10 ? '0' + day : day;
|
|
+ let now2 = day < 10 ? '0' + day : day;
|
|
|
|
|
|
- var msg = {
|
|
+ let msg = {
|
|
from: wx.getStorageSync('uid'),
|
|
from: wx.getStorageSync('uid'),
|
|
to: this.data.toUid,
|
|
to: this.data.toUid,
|
|
nickname: wx.getStorageSync('nickName'),
|
|
nickname: wx.getStorageSync('nickName'),
|
|
avatar: wx.getStorageSync('avatarUrl'),
|
|
avatar: wx.getStorageSync('avatarUrl'),
|
|
message: this.data.content,
|
|
message: this.data.content,
|
|
type: 'text',
|
|
type: 'text',
|
|
- date: now1 + '-' + now2 + ' ' + hour + ':' + minu
|
|
+ time: now1 + '-' + now2 + ' ' + hour + ':' + minu
|
|
}
|
|
}
|
|
console.log(msg);
|
|
console.log(msg);
|
|
this.setData({
|
|
this.setData({
|
|
@@ -163,19 +227,22 @@ Page({
|
|
content: ''
|
|
content: ''
|
|
})
|
|
})
|
|
})
|
|
})
|
|
- var socketMsg = socketMsgQueue;
|
|
+ let socketMsg = socketMsgQueue;
|
|
socketMsg.msgType = 1;
|
|
socketMsg.msgType = 1;
|
|
socketMsg.content = this.data.content;
|
|
socketMsg.content = this.data.content;
|
|
socketMsg.to = this.data.toUid;
|
|
socketMsg.to = this.data.toUid;
|
|
console.log(this.data.toUid);
|
|
console.log(this.data.toUid);
|
|
- var time = new Date().getTime();
|
|
+ let time = new Date().getTime();
|
|
console.log(time);
|
|
console.log(time);
|
|
socketMsg.time = time;
|
|
socketMsg.time = time;
|
|
console.log(socketMsg);
|
|
console.log(socketMsg);
|
|
wx.sendSocketMessage({
|
|
wx.sendSocketMessage({
|
|
data: JSON.stringify(socketMsg),
|
|
data: JSON.stringify(socketMsg),
|
|
})
|
|
})
|
|
- },
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
scrollToBottom() {
|
|
scrollToBottom() {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|