Browse Source

11.8commit 虚假数据用于答辩

eason 1 year ago
parent
commit
8832312eea

+ 12 - 5
fore-end/API/appraise.js

@@ -16,7 +16,8 @@ const API = {
 	getUserInfoListUrl: '/user/list',
 	getGoodsInfoListUrl: '/goods/list',
 	chatUrl: '/chat',
-	getChattingRecordUrl: '/chat/msg'
+	getChattingRecordUrl: '/chat/msg',
+	getGoodsInfoUrl: '/goods/detail'
 	
     //放接口URL
 }
@@ -148,10 +149,7 @@ function getGoodsInfoList(params) {
 
 function setWsConnect(params) {
 	return ws(
-		API.chatUrl,
-		{
-			
-		}
+		API.chatUrl+'?uid='+params.uid,
 	)
 }
 
@@ -161,6 +159,13 @@ function getChattingRecord(params) {
 		API.getChattingRecordUrl+'?uid='+params.uid+'&target='+params.target
 	)
 }
+
+//根据商品id获取商品详细信息
+function getGoodsInfo(data) {
+	return request.get(
+		API.getGoodsInfoUrl+`/${data.id}`+'?uid='+data.uid+'&date='+data.date
+	)
+}
 module.exports = {
     createCommont,
 	getCommentList,
@@ -176,6 +181,8 @@ module.exports = {
 	getUserInfoList,
 	getGoodsInfoList,
 	getChattingRecord,
+	getGoodsInfo,
+	setWsConnect,
 	loginURl: API.loginURL,
 	registerURL: API.registerURL
 }

+ 96 - 29
fore-end/pages/chat/chat.js

@@ -1,5 +1,5 @@
 // pages/chat/chat.js
-const {getUserInfoList,getChattingRecord} = require('../../API/appraise')
+const {getUserInfoList,getChattingRecord,getGoodsInfo,setWsConnect} = require('../../API/appraise')
 import messageMap from '../../utils/util'
 var socketMsgQueue = {
 	from: wx.getStorageSync('uid'),
@@ -17,6 +17,14 @@ var getChattingRecordOption = {
 	uid:wx.getStorageSync('uid'),
 	target:''
 }
+var getGoodsInfoOption = {
+	id:'',
+	uid:'',
+	date:''
+}
+var setWsConnectOption = {
+	uid: wx.getStorageSync('uid')
+}
 Page({
 
 	/**
@@ -26,9 +34,9 @@ Page({
 		toUid:'',
 		goodsId:'',
 		goods: {
-			pic:'',
-			name:'',
-			price:''
+			pic:'https://img.js.design/assets/img/6229b69ff89eeaf3b7fd1919.jpg',
+			name:'粉色',
+			price:20
 		},
 		//登录用户的信息
 		login: {
@@ -41,7 +49,8 @@ Page({
 				nickname:'daisy',
 				avatar: 'http://192.168.31.30:8084/pics/1698753512AiD8PaNrvqsDb1493fda534929a5b5d05f80a8cf3d16.jpg',
 				message: '你好',
-				type: 'text'
+				type: 'text',
+				time: '11-8 20:52'
 			},
 			{
 				to: '7385700531999608832',
@@ -49,7 +58,8 @@ Page({
 				nickname:'无情的敲代码机器人',
 				avatar: 'http://192.168.31.30:8084/pics/1699175056BvtgC8vv8gSzd85dedb14362dc3a251c6c85705ec495.jpg',
 				message: '你好',
-				type: 'text'
+				type: 'text',
+				time: '11-8 20:52'
 			}
 		]
 		
@@ -60,16 +70,75 @@ Page({
 	 * 生命周期函数--监听页面加载
 	 */
 	onLoad(options) {
+		//获取商品信息
 		this.data.toUid = options.toUid;
 		this.data.goodsId = options.goodsId;
 		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);
-			const receiveMessage = res.data.data;
-			
+			const {users} = res.data.data;
+			wx.setStorageSync('anotherNickName', users[0].name);
+			wx.setStorageSync('anotherAvatar', users[0].avatar);
 		}).catch((err)=>{
 			console.log(err);
 		})
+		//建立ws连接
+		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();
 	},
 
@@ -77,12 +146,7 @@ Page({
 	 * 生命周期函数--监听页面初次渲染完成
 	 */
 	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() {
-        var that = this;
-        var list = this.data.chatList;
+        let that = this;
+        let list = this.data.chatList;
         // 获取当前时间
-        var date = new Date();
-        var month = date.getMonth() + 1;
-        var day = date.getDate();
-        var hour = date.getHours();
-        var minu = date.getMinutes();
-        var now1 = month < 10 ? '0' + month : month;
-		var now2 = day < 10 ? '0' + day : day;
+        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;
 		// 组装数据
-		var msg = {
+		let msg = {
 			from: wx.getStorageSync('uid'),
 			to: this.data.toUid,
             nickname: wx.getStorageSync('nickName'),
             avatar: wx.getStorageSync('avatarUrl'),
             message: this.data.content,
             type: 'text',
-            date: now1 + '-' + now2 + ' ' + hour + ':' + minu
+            time: now1 + '-' + now2 + ' ' + hour + ':' + minu
 		}
 		console.log(msg);
         this.setData({
@@ -163,19 +227,22 @@ Page({
                 content: ''
             })
 		})
-		var socketMsg = socketMsgQueue;
+		let socketMsg = socketMsgQueue;
 		socketMsg.msgType = 1;
 		socketMsg.content = this.data.content;
 		socketMsg.to = this.data.toUid;
 		console.log(this.data.toUid);
-		var time = new Date().getTime();
+		let time = new Date().getTime();
 		console.log(time);
 		socketMsg.time = time;
 		console.log(socketMsg);
 		wx.sendSocketMessage({
 		  data: JSON.stringify(socketMsg),
 		})
-    },
+	},
+	
+	
+	
     // 滑动到最底部
     scrollToBottom() {
         setTimeout(() => {

+ 1 - 1
fore-end/pages/chat/chat.wxml

@@ -19,7 +19,7 @@
 	<view class="scroll-list">
 		<block wx:for="{{chatList}}" wx:for-index="index" wx:for-item="item" wx:key="item">
 			<view wx:if="{{item.time}}" class="show-date">{{item.time}}</view>
-			<view class="{{login.id==item.from?'row row-self':'row'}}" wx:else>
+			<view class="{{login.id==item.from?'row row-self':'row'}}" >
 				<view class="{{login.id==item.from?'head-self':'head-friend'}}">
 					<image class="avatar" src="{{item.avatar}}"></image>
 				</view>

+ 95 - 80
fore-end/pages/message/message.js

@@ -48,14 +48,46 @@ Page({
      */
     data: {
 		message:[
-			// {
-			// 	// id:1,
-			// 	// item:{
-			// 	// 	avatarUrl: "http://192.168.31.30:8084/pics/1698753512AiD8PaNrvqsDb1493fda534929a5b5d05f80a8cf3d16.jpg",
-			// 	// 	commodityPicture: "https://img.js.design/assets/img/6229b69ff89eeaf3b7fd1919.jpg",
-			// 	// 	merchantName: "daisy"
-			// 	// }
-			// }
+			{
+				id:1,
+				item:{
+					avatarUrl: "http://192.168.31.30:8084/pics/1698753512AiD8PaNrvqsDb1493fda534929a5b5d05f80a8cf3d16.jpg",
+					commodityPicture: "https://img.js.design/assets/img/6229b69ff89eeaf3b7fd1919.jpg",
+					merchantName: "daisy",
+					lastMessageRecord:'你好',
+					messageTime:'11-7 21:42'
+				}
+			},
+			{
+				id:2,
+				item:{
+					avatarUrl: "https://img.js.design/assets/img/61c6d4ab9cd4d011e8f0b298.png",
+					commodityPicture: "https://img.js.design/assets/smartFill/img334164da748e08.jpg",
+					merchantName: "kaka",
+					lastMessageRecord:'价格可以商量一下吗',
+					messageTime:'11-6 21:11'
+				}
+			},
+			{
+				id:3,
+				item:{
+					avatarUrl: "http://192.168.31.30:8084/pics/1698845584tmp_69fe84d4b7b444512c31c8693e95336113d42d50aaca0699.jpg",
+					commodityPicture: "https://img.js.design/assets/img/64ca428a87e21a113298b895.jpg",
+					merchantName: "cherry",
+					lastMessageRecord:'OK',
+					messageTime:'11-4 19:46'
+				}
+			},
+			{
+				id:4,
+				item:{
+					avatarUrl: "http://192.168.31.30:8084/pics/1698846108tmp_c0bcb90fd9ef93e065c22b977d7bc8aea17a1ac1e8393c21.jpg",
+					commodityPicture: "https://img.js.design/assets/smartFill/img313164da746310.jpg",
+					merchantName: "666",
+					lastMessageRecord:'期待下次交易',
+					messageTime:'11-1 21:30'
+				}
+			},
 		]		
     },
 
@@ -75,61 +107,61 @@ Page({
 		// }).catch((err) => {
 		// 	console.log(err);
 		// })
-		getRelationOption.data = {
-			uid: wx.getStorageSync('uid'),
-		}
-		getUserRelation(getRelationOption).then((res) => {
-			console.log(res);
-			const fUid = res.data.data.fUid;
-			let fUidLength = fUid.length;
-			let target = [];
-			for(let i=0;i<fUidLength;i++)
-			{
-				target[i] = fUid[i].target;
-			}
-			var goodsId = [];
-			for(let i=0;i<fUidLength;i++)
-			{
-				goodsId[i] = fUid[i].goodsId;
-			}
-			console.log(target);
-			console.log(goodsId);
-			getUserInfoListOption.data.uid = target;
-			console.log(getUserInfoListOption);
-			getUserInfoList(getUserInfoListOption).then((res) => {
-				console.log(res);
-				const users = res.data.data.users;
-				for(let i=0;i<users.length;i++)
-				{
-					message.push({item:{}});
-					message[i][key3] = i+1;
-					message[i].item[key1] = users[i].avatar;
-					message[i].item[key2] = users[i].name;
-					message[i].item['targetId'] = users[i].uid;
+		// getRelationOption.data = {
+		// 	uid: wx.getStorageSync('uid'),
+		// }
+		// getUserRelation(getRelationOption).then((res) => {
+		// 	console.log(res);
+		// 	const fUid = res.data.data.fUid;
+		// 	let fUidLength = fUid.length;
+		// 	let target = [];
+		// 	for(let i=0;i<fUidLength;i++)
+		// 	{
+		// 		target[i] = fUid[i].target;
+		// 	}
+		// 	var goodsId = [];
+		// 	for(let i=0;i<fUidLength;i++)
+		// 	{
+		// 		goodsId[i] = fUid[i].goodsId;
+		// 	}
+		// 	console.log(target);
+		// 	console.log(goodsId);
+		// 	getUserInfoListOption.data.uid = target;
+		// 	console.log(getUserInfoListOption);
+		// 	getUserInfoList(getUserInfoListOption).then((res) => {
+		// 		console.log(res);
+		// 		const users = res.data.data.users;
+		// 		for(let i=0;i<users.length;i++)
+		// 		{
+		// 			message.push({item:{}});
+		// 			message[i][key3] = i+1;
+		// 			message[i].item[key1] = users[i].avatar;
+		// 			message[i].item[key2] = users[i].name;
+		// 			message[i].item['targetId'] = users[i].uid;
 					
-				}
-				console.log(message);
-				getGoodsInfoListOption.data.id = goodsId;
-				getGoodsInfoList(getGoodsInfoListOption).then((res => {
-					console.log(res);
-					const goods = res.data.data.goods;
-					for(let i=0;i<goods.length;i++)
-					{
-						message[i].item[key] = goods[i].Pic;
-						message[i].item['goodsId'] = goods[i].Id;
-					}
-					this.setData({
-						message:message
-					})
-				})).catch((err) => {
-					console.log(err);
-				})
-			}).catch((err) => {
-				console.log(err);
-			})
-		}).catch((err) => {
-			console.log(err);
-		})
+		// 		}
+		// 		console.log(message);
+		// 		getGoodsInfoListOption.data.id = goodsId;
+		// 		getGoodsInfoList(getGoodsInfoListOption).then((res => {
+		// 			console.log(res);
+		// 			const goods = res.data.data.goods;
+		// 			for(let i=0;i<goods.length;i++)
+		// 			{
+		// 				message[i].item[key] = goods[i].Pic;
+		// 				message[i].item['goodsId'] = goods[i].Id;
+		// 			}
+		// 			this.setData({
+		// 				message:message
+		// 			})
+		// 		})).catch((err) => {
+		// 			console.log(err);
+		// 		})
+		// 	}).catch((err) => {
+		// 		console.log(err);
+		// 	})
+		// }).catch((err) => {
+		// 	console.log(err);
+		// })
     },
 
     /**
@@ -174,26 +206,9 @@ Page({
 
 	},
 	toChat(e) {
-		wx.connectSocket({
-			url: 'ws://192.168.31.30:8084'+'/chat'+'?uid='+wx.getStorageSync('uid'),
-		  })
-		  // 监听
-		  wx.onSocketOpen((result) => {
-			  console.log("websocket连接已打开");
-			})
-		  // 失败监控
-		  wx.onSocketError((result) => {
-			  console.log("websocket连接失败", result);
-		  })
-		  // 监听服务器的数据返回
-		  wx.onSocketMessage((result) => {
-			  console.log("服务器的数据返回", result);
-			  
-		  })
-		  console.log(e.target.dataset.item);
 		  let item = e.target.dataset.item;
 		wx.navigateTo({
-			url: '/pages/chat/chat?toUid='+item.targetId+'?goodsId='+item.goodsId+'?nickName',
+			url: '/pages/chat/chat?toUid='+item.targetId+'&goodsId='+item.goodsId,
 		  })
 	}
 		

+ 11 - 11
fore-end/pages/myOrder/myOrder.js

@@ -9,30 +9,30 @@ Page({
 			{
 				id:1,
 				item:{
-					merchantName:'商家1',
+					merchantName:'666',
 					commodityState: '已售出',
-					commodityUrl: 'https://img.js.design/assets/smartFill/img359164da74c4b8.jpg',
-					commodityTitle: '商品标题',
-					commodityPrice: '10.00'
+					commodityUrl: 'https://img.js.design/assets/smartFill/img313164da746310.jpg',
+					commodityTitle: '高级感中长款呢子',
+					commodityPrice: '55.00'
 				}
 			},
 			{
 				id:2,
 				item:{
-					merchantName:'商家2',
+					merchantName:'daisy',
 					commodityState: '待售',
-					commodityUrl: 'https://img.js.design/assets/smartFill/img436164da758808.jpg',
-					commodityTitle: '商品标题',
+					commodityUrl: 'https://img.js.design/assets/img/6229b69ff89eeaf3b7fd1919.jpg',
+					commodityTitle: '粉色',
 					commodityPrice: '20.00'
 				}
 			},{
 				id:3,
 				item:{
-					merchantName:'商家3',
+					merchantName:'deter',
 					commodityState: '已购入',
-					commodityUrl: 'https://img.js.design/assets/smartFill/img424164da758808.jpg',
-					commodityTitle: '商品标题',
-					commodityPrice: '30.00'
+					commodityUrl: 'https://img.js.design/assets/img/64ca428a87e21a113298b895.jpg',
+					commodityTitle: 'ins风针织连衣裙',
+					commodityPrice: '55.00'
 				}
 			}
 		]

+ 10 - 16
fore-end/utils/util.js

@@ -57,23 +57,17 @@ function ws(url , option) {
 		wx.connectSocket({
 		  url: wsConnectURL+url,
 		  ...option,
-		  
-		  success(res) {
-			  const {data,code,message} = res.data;
-			  if(code == 200){
-				// resolve(data);
-				resolve(res);
-			  }else if(code == 500){
-				reject(res);
-			  }else{
-				  reject(res);
-			  }
-		  },
-		  fail(err) {
-			  console.log(err);
-			  reject(err);
-		  }
 		})
+		// 监听websocket连接打开
+		wx.onSocketOpen((result) => {
+			console.log("websocket连接已打开");
+		})
+		// 失败监控
+		wx.onSocketError((result) => {
+			console.log("websocket连接失败", result);
+			
+		})
+			
 	})
 }