1
0

3 Ревизии 415b4bfea0 ... 976d9f7393

Автор SHA1 Съобщение Дата
  ck110 976d9f7393 Merge branch 'master' of http://150.158.33.144:3000/lalalashen/MeetMateApp преди 2 седмици
  ck110 8efdce9ac9 Merge branch 'master' of http://150.158.33.144:3000/lalalashen/MeetMateApp преди 2 седмици
  ck110 952a227f3d 完善socket преди 2 седмици
променени са 8 файла, в които са добавени 158 реда и са изтрити 25 реда
  1. 3 0
      App.vue
  2. 107 16
      common/websocketUtil.js
  3. 2 2
      manifest.json
  4. 3 0
      pages/chat/components/member.vue
  5. 8 2
      pages/chat/detail.vue
  6. 1 1
      pages/chat/message.vue
  7. 6 2
      pages/index/peopleHome.vue
  8. 28 2
      pages/my/myArticle.vue

+ 3 - 0
App.vue

@@ -68,6 +68,9 @@
 		},
 		onHide: function() {
 			console.log('App Hide');
+			if (this.globalData.socket != null) {
+				this.globalData.socket.stop();
+			}
 		},
 		onAppBackground() {},
 		methods: {

+ 107 - 16
common/websocketUtil.js

@@ -1,4 +1,21 @@
 class websocketUtil {
+	is_open_socket = false;
+	socketStatus = 0 //避免重复连接 0 无连接 1-9连接中 10 已连接
+	url = '';
+	data = '';
+	uuid = '';
+	timeout = 10000;
+	heartbeatInterval = null;
+	reconnectTimeOut = null;
+	reconnectNum = 0 //重连次数
+	msgQueue = []
+	socketTask = null //ws对象
+	netIsConnected = false
+	netType = 'none'
+
+	autoFlag = true
+
+
 	constructor(url, uuid) {
 		this.is_open_socket = false; //避免重复连接
 		this.url = url; //地址
@@ -9,13 +26,82 @@ class websocketUtil {
 		this.heartbeatInterval = null; //检测服务器端是否还活着
 		this.reconnectTimeOut = null; //重连之后多久再次重连
 
+		// 监听网络状态变化
+		let that = this;
+		uni.onNetworkStatusChange((res) => {
+			console.log('WebSocket NetStatus', res.isConnected);
+			console.log('WebSocket NetStatus', res.networkType);
+			that.netIsConnected = res.isConnected
+			that.netType = res.networkType
+			that.reconnectNum = 0
+			if (that.autoFlag) this.reconnect()
+		});
 		try {
-			return this.connectSocketInit()
+			uni.getNetworkType({
+				success: (res) => {
+					console.log('WebSocket getNetworkType', res.networkType);
+					that.netType = res.networkType;
+					that.netIsConnected = true;
+
+					that.reconnect();
+				}
+			});
+			// 有return ,则构造方法返回return的对象,没有,则返回new的对象
+			// return this.hhh
 		} catch (e) {
-			console.log('catch');
-			this.is_open_socket = false
-			this.reconnect();
+			console.log('连接初始化失败', e);
 		}
+		// try {
+		// 	return this.connectSocketInit()
+		// } catch (e) {
+		// 	console.log('catch');
+		// 	this.is_open_socket = false
+		// 	this.reconnect();
+		// }
+	}
+	//重新连接
+	reconnect() {
+		// 失败重连频率
+		const reconnect_time = [3000, 3000, 3000, 3000, 10000, 10000, 10000, 20000, 20000, 50000]
+		// 自身巡检频率
+		let reconnect_timeout = 30000
+		//停止发送心跳
+		this.heartbeatInterval && clearInterval(this.heartbeatInterval)
+		if (this.socketStatus < 10) {
+			// 失败重连
+			if (this.reconnectNum > 50) return;
+			if (this.reconnectNum < this.reconnect_time.length) {
+				reconnect_timeout = reconnect_time[this.reconnectNum]
+			} else {
+				reconnect_timeout = reconnect_time[this.reconnect_time.length - 1]
+			}
+
+			console.log("uniWebsocket 重新连接", this.socketStatus, this.reconnectNum, this.reconnect_timeout)
+
+			this.reconnectNum = this.reconnectNum + 1
+
+			this.reconnectTimeOut = setTimeout(() => {
+				// 连接创建
+				this.connectSocketInit();
+				this.reconnect()
+			}, reconnect_timeout)
+
+			return;
+		}
+		console.log("uniWebsocket 自身巡检", socketStatus, reconnectNum, reconnect_timeout)
+
+		// 自身巡检循环
+		this.reconnectTimeOut = setTimeout(() => {
+			// 连接创建
+			this.connectSocketInit();
+			this.reconnect()
+		}, reconnect_timeout)
+		//如果不是人为关闭的话,进行重连
+		// if (!this.is_open_socket) {
+		// 	this.reconnectTimeOut = setTimeout(() => {
+		// 		this.connectSocketInit();
+		// 	}, 3000)
+		// }
 	}
 	generateSeq() {
 		return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
@@ -91,7 +177,7 @@ class websocketUtil {
 			seq: that.generateSeq(),
 			cmd: "login",
 			data: {
-				"skey": that.uuid,
+				"uuid": that.uuid,
 				"appId": 101
 			}
 		});
@@ -99,13 +185,29 @@ class websocketUtil {
 
 	//发送消息
 	send(value) {
+		console.log("send-content:", value);
 		value.seq = this.generateSeq();
 		// 注:只有连接正常打开中 ,才能正常成功发送消息
+		let that = this;
 		this.socketTask.send({
 			data: JSON.stringify(value),
 			async success() {
 				// console.log("消息发送成功");
 			},
+			fail(e) {
+				console.log("send-err:", e);
+				// {"errMsg":"sendSocketMessage:fail WebSocket is not connected"}  at common/websocketUtil.js:111
+				if (e.errMsg.includes("fail WebSocket") || e.errMsg.includes("not connected")) {
+					uni.closeSocket();
+					that.reconnect();
+					console.log('is now reconnect');
+					// console.log(`"${str}" 包含 "${substr}"`);
+				} else {
+					console.log('errMsg', e.errMsg)
+					// console.log(`"${str}" 不包含 "${substr}"`);
+				}
+			}
+
 		});
 	}
 	//开启心跳检测
@@ -139,17 +241,6 @@ class websocketUtil {
 	stop() {
 		uni.closeSocket();
 	}
-	//重新连接
-	reconnect() {
-		//停止发送心跳
-		clearInterval(this.heartbeatInterval)
-		//如果不是人为关闭的话,进行重连
-		if (!this.is_open_socket) {
-			this.reconnectTimeOut = setTimeout(() => {
-				this.connectSocketInit();
-			}, 3000)
-		}
-	}
 	//外部获取消息
 	getMessage(callback) {
 		this.socketTask.onMessage((res) => {

+ 2 - 2
manifest.json

@@ -2,8 +2,8 @@
 	"name": "遇见玛特",
 	"appid": "__UNI__A59181F",
 	"description": "",
-	"versionName": "1.1.2",
-	"versionCode": 112,
+	"versionName": "1.1.3",
+	"versionCode": 113,
 	"transformPx": false,
 	/* 5+App特有相关 hfhz-mrro-iqmv-igdl storygarden2024@outlook.com*/
 	"app-plus": {

+ 3 - 0
pages/chat/components/member.vue

@@ -75,6 +75,9 @@
 			closeTA() {
 				// this.$refs.member.open(this.userID);
 				this.$refs.popup.close();
+			},
+			viewMore() {
+
 			},
 			async open(id) {
 				this.groupID = id;

+ 8 - 2
pages/chat/detail.vue

@@ -232,6 +232,7 @@
 					}
 					// console.log("res-cmd", resdata.cmd);
 				});
+				console.log("detail-addgroup1");
 				that.addGroup();
 			}
 			uni.$on('updateGroup', this.addGroup)
@@ -282,10 +283,16 @@
 				getApp().globalData.socket.send({
 					cmd: "addGroup",
 					data: {
-						"skey": that.skey,
+						"uuid": getApp().globalData.uuid,
 						"appId": 101,
 						"userId": getApp().globalData.userId,
 						"groupId": that.conversationID
+					},
+					success() {
+						console.log("addGroup-succ", "ok");
+					},
+					fail(e) {
+						console.log("addGroup-err", e);
 					}
 				});
 			},
@@ -617,7 +624,6 @@
 							'content-type': 'application/json' //自定义请求头信息
 						},
 						success: (res) => {
-							console.log("this.skey", this.skey);
 							console.log("----", res.data);
 							if (res.data.success == "yes") {
 								if (res.data.conversation_id != "") {

+ 1 - 1
pages/chat/message.vue

@@ -172,7 +172,7 @@
 				getApp().globalData.socket.send({
 					cmd: "login",
 					data: {
-						"skey": this.skey,
+						"uuid": getApp().globalData.uuid,
 						"appId": 101
 					}
 				});

+ 6 - 2
pages/index/peopleHome.vue

@@ -134,7 +134,7 @@
 					</view>
 					<text class="right">
 						<block v-if="item.status == 1">
-							<view class="btn_submit" @click="onLinqu">邀请助力</view>
+							<view class="btn_submit" @click="onLinqu(item)">邀请助力</view>
 						</block>
 						<block v-if="item.status == 2">
 							<view class="state">待发货</view>
@@ -191,7 +191,11 @@
 			this.loadWishData();
 		},
 		methods: {
-			onLinqu(){},
+			onLinqu(item) {
+				uni.navigateTo({
+					url: '/pages/my/wishHelp?id=' + item.myid,
+				})
+			},
 			selPhoto(item, sel) {
 				this.selImg = sel;
 				this.home_image = this.image_list[sel];

+ 28 - 2
pages/my/myArticle.vue

@@ -167,7 +167,33 @@
 					animation: 0
 				}).then((res) => {
 
-				
+					uni.request({
+						url: this.$apiHost + '/Article/doAct',
+						data: {
+							uuid: getApp().globalData.uuid,
+							act: 'del',
+							id: article.id
+						},
+						header: {
+							"content-type": "application/json",
+							'sign': getApp().globalData.headerSign
+						},
+						success: (res) => {
+							uni.showToast({
+								title: res.data.str,
+								icon: 'none'
+							});
+							if (res.data.success == 'yes') {
+								this.loadData();
+							}
+						},
+						complete: (com) => {
+							// uni.hideLoading();
+						},
+						fail: (e) => {
+							console.log("----e:", e);
+						}
+					});
 
 				})
 			},
@@ -195,7 +221,7 @@
 				// var param = e.currentTarget.dataset.src;
 				// console.log(param);
 				// this.imgs = ['../../static/home/avator.png', '../../static/me/sex_2.png', '../../static/home/avator.png'];
-				setTimeout(()=>this.$refs.previewImage.open(index),0)// 传入当前选中的图片地址或序号
+				setTimeout(() => this.$refs.previewImage.open(index), 0) // 传入当前选中的图片地址或序号
 				return; //如需测试和uni原生预览差别可注释这两行
 			},
 			//长按事件