ck110 hai 2 semanas
pai
achega
952a227f3d

+ 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: {

+ 63 - 5
common/websocketUtil.js

@@ -1,4 +1,21 @@
 class websocketUtil {
+	var is_open_socket = false;
+	var socketStatus = 0 //避免重复连接 0 无连接 1-9连接中 10 已连接
+	var url = '';
+	var data = '';
+	var uuid = '';
+	var timeout = 10000;
+	var heartbeatInterval = null;
+	var reconnectTimeOut = null;
+	var reconnectNum = 0 //重连次数
+	var msgQueue = []
+	var socketTask = null //ws对象
+	var netIsConnected = false
+	var netType = 'none'
+
+	var autoFlag = true
+
+
 	constructor(url, uuid) {
 		this.is_open_socket = false; //避免重复连接
 		this.url = url; //地址
@@ -9,13 +26,38 @@ 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();
+		// }
 	}
 	generateSeq() {
 		return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
@@ -91,7 +133,7 @@ class websocketUtil {
 			seq: that.generateSeq(),
 			cmd: "login",
 			data: {
-				"skey": that.uuid,
+				"uuid": that.uuid,
 				"appId": 101
 			}
 		});
@@ -99,13 +141,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}"`);
+				}
+			}
+
 		});
 	}
 	//开启心跳检测

+ 1 - 12
pages.json

@@ -393,18 +393,7 @@
 				"navigationStyle": "custom",
 				"navigationBarTitleText": "燃料中心",
 				"navigationBarBackgroundColor": "#161616",
-				"navigationBarTextStyle": "white",
-				
-				"app-plus": {
-					"titleNView": {
-						"buttons": [{
-							"fontSize": "15px",
-							"color": "#fff",
-							"text": "记录"
-						}]
-					}
-					
-				}
+				"navigationBarTextStyle": "white"
 			}
 		}, {
 			"path": "pages/w3/miningRecord",

+ 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
 					}
 				});

+ 7 - 3
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>
@@ -192,7 +192,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];
@@ -224,7 +228,7 @@
 			},
 			previewOpen(imgs1, index) {
 				this.imgs = imgs1.split("|");
-				this.$nextTick(()=>{
+				this.$nextTick(() => {
 					this.$refs.previewImage.open(index)
 				}) // 传入当前选中的图片地址或序号
 				return; //如需测试和uni原生预览差别可注释这两行