浏览代码

即时通信功能优化

shilin 4 年之前
父节点
当前提交
21434babee
共有 3 个文件被更改,包括 327 次插入112 次删除
  1. 2 2
      common/store.js
  2. 266 59
      components/login/Login.vue
  3. 59 51
      components/mine/addressBook/InitializeThe.vue

+ 2 - 2
common/store.js

@@ -5,10 +5,10 @@ Vue.use(Vuex)
 
 const store = new Vuex.Store({
     state: {
-		wholeSituationBackStageIp:'117.78.18.24',//117.78.18.24
+		wholeSituationBackStageIp:'192.168.0.91',//117.78.18.24
 		wholeSituationBackStagePort:'9988',
 		
-		GlobalLocalIp:'117.78.18.24',//192.168.1.102
+		GlobalLocalIp:'192.168.0.91',//192.168.1.102
 		GlobalLocalPort:'9987',
 		
 		windpowerstationNameToId:{},

+ 266 - 59
components/login/Login.vue

@@ -1,6 +1,7 @@
 <template>
 	<view>
-		<view v-show="accountIsShow">
+		
+		<view v-if="accountIsShow">
 			<view class="title">账号密码登录</view>
 			<view class="usernameAndPassword">
 				<view class="usernameContent">
@@ -21,7 +22,7 @@
 				点击登录,即代表已阅读并同意<a href="#">隐私政策</a>和<a href="#">用户协议</a>
 			</view>
 		</view>
-		<view v-show="phoneIsShow">
+		<view v-if="phoneIsShow">
 			<view class="title">手机验证码登录</view>
 			<view class="usernameAndPassword">
 				<view class="phoneContent">
@@ -41,11 +42,17 @@
 				点击登录,即代表已阅读并同意<a href="#">隐私政策</a>和<a href="#">用户协议</a>
 			</view>
 		</view>
+		
+			
+		<initial ref="mywebview"></initial> 
+
 	</view>
 </template>
 
 <script>
+
 	export default {
+
 		data: function() {
 			return {
 				passwordShow: true,
@@ -76,7 +83,7 @@
 			};
 		},
 		created() {
-
+			uni.setStorageSync('im_show','0');
 			this.windowWidth = uni.getSystemInfoSync().windowWidth;
 			this.windowHeight = uni.getSystemInfoSync().windowHeight;
 			//console.log(this.windowWidth);
@@ -97,6 +104,12 @@
 			this.getUsernamePassword();
 		},
 		computed: {
+			sisStageIp: function() {
+				return this.$store.state.wholeSituationBackStageIp;
+			},
+			sisStagePort: function() {
+				return this.$store.state.wholeSituationBackStagePort;
+			},
 			backStageIp: function() {
 				return this.$store.state.wholeSituationBackStageIp;
 			},
@@ -114,9 +127,14 @@
 			}
 		},
 		methods: {
+			
 			showPass(e) {
 				this.passwordShow = e;
 			},
+			destroyUseWebViews() {
+				this.$refs.mywebview.destroyUseWebViews();
+				
+			},
 			usernameInput(e) {
 				if (e.detail.value != "") {
 					this.usernameFlag = true;
@@ -249,76 +267,264 @@
 						title: "请先用密码登录!"
 					});
 				}
-			},
-			getUsernamePassword: function() {
-				this.lastUserName = uni.getStorageSync('gyeeusername');
-				this.lastPassWord = uni.getStorageSync('gyeepassword');
-				if (this.lastUserName != '' && this.lastPassWord != '') {
-					uni.switchTab({
-						url: '/pages/index/Index'
+			},getFingerPrintPassword: function() {
+				let _this = this;
+				if (uni.getStorageSync('fingerPrintname') != '' && uni.getStorageSync('fingerPrintpassword') != '') {
+				
+					uni.setStorageSync('gyeeusername', uni.getStorageSync('fingerPrintname'));
+					uni.setStorageSync('gyeepassword', uni.getStorageSync('fingerPrintpassword'));
+					uni.setStorageSync('userid', uni.getStorageSync('fingerPrintuserid'));
+					
+					
+					this.username = uni.getStorageSync('gyeeusername');
+					this.password = uni.getStorageSync('gyeepassword');
+					uni.request({
+						url: 'http://' + this.backStageIp + ':' + this.backStagePort + '/GyeeuserController/login?username=' + this.username +
+							'&password=' + this.password,
+						data: {},
+						method: 'GET',
+						success: function(res) {
+							//console.log(res.data);
+							_this.userid = res.data.data;
+					
+					
+							uni.setStorageSync('userid', _this.userid);
+							uni.setStorageSync('fingerPrintuserid', _this.userid);
+							//sessionStorage.setItem('userid',_this.userid);
+							if (res.data.code == 200) {
+					
+								
+								_this.dataprocessing.viewUserid();
+								_this.dataprocessing.monitoringAuthority();
+								
+						
+								_this.createUserOnline();
+								_this.setUsernamePassword();
+								_this.loginFalg = true;
+								_this.lastUserName = _this.username;
+								_this.lastPassWord = _this.password;
+								uni.switchTab({
+									url: '/pages/index/Index'
+								});
+							} else {
+								uni.showModal({
+									content: '用户名密码输入错误,请核对'
+								});
+								_this.username = '';
+								_this.password = '';
+							}
+						},
+						fail: () => {
+							_this.tips = '网络错误,小程序端请检查合法域名';
+						}
 					});
+
 				}
+				
 			},
+			// getUsernamePassword: function() {
+			// 	this.lastUserName = uni.getStorageSync('gyeeusername');
+			// 	this.lastPassWord = uni.getStorageSync('gyeepassword');
+				
+			// 	this.createUserOnline();
+				
+			// 	if (this.lastUserName != '' && this.lastPassWord != '') {
+			// 		uni.switchTab({
+			// 			url: '/pages/index/Index'
+			// 		});
+			// 	}
+			// },
 			removeUsernamePassword: function() {
 				uni.removeStorageSync('gyeeusername');
 				uni.removeStorageSync('gyeepassword');
 				//uni.removeStorageSync('userid');
+			},getUsernamePassword: function() {
+					let _this = this;
+				 	this.username = uni.getStorageSync('gyeeusername');
+				 	this.password = uni.getStorageSync('gyeepassword');
+					if(this.username!="" && this.password!="")
+					{
+						uni.request({
+							url: 'http://' + this.backStageIp + ':' + this.backStagePort + '/GyeeuserController/login?username=' + this.username +
+								'&password=' + this.password,
+							data: {},
+							method: 'GET',
+							success: function(res) {
+								//console.log(res.data);
+								_this.userid = res.data.data;
+						
+						
+								uni.setStorageSync('userid', _this.userid);
+								uni.setStorageSync('fingerPrintuserid', _this.userid);
+								//sessionStorage.setItem('userid',_this.userid);
+								if (res.data.code == 200) {
+						
+									
+									_this.dataprocessing.viewUserid();
+									_this.dataprocessing.monitoringAuthority();
+									
+									// let plusDrawerList = uni.getStorageSync('plusList');
+									
+									// _this.dataprocessing.putWindPowerStationId(plusDrawerList[0].windId);
+									// _this.dataprocessing.putWindPowerStationName(plusDrawerList[0].name);
+									
+									// if(_this.dataprocessing.getWindPowerStationId()=='')
+									// {
+									// 	//debugger
+									// 	_this.dataprocessing.putWindPowerStationId(_this.$store.state.default_wpid);
+									// }
+						
+									// if(_this.dataprocessing.getWindPowerStationName()=='')
+									// {
+									// 	//debugger
+									// 	_this.dataprocessing.putWindPowerStationName(_this.$store.state.default_wpname);
+									// }
+									_this.createUserOnline();
+									_this.setUsernamePassword();
+									_this.loginFalg = true;
+									_this.lastUserName = _this.username;
+									_this.lastPassWord = _this.password;
+									uni.switchTab({
+										url: '/pages/index/Index'
+									});
+								} else {
+									uni.showModal({
+										content: '用户名密码输入错误,请核对'
+									});
+									_this.username = '';
+									_this.password = '';
+								}
+							},
+							fail: () => {
+								_this.tips = '网络错误,小程序端请检查合法域名';
+							},
+							
+							});
+					}
+				
+				
 			},
+			
 			login: function() {
 				let _this = this;
-				uni.request({
-					url: 'http://' + this.backStageIp + ':' + this.backStagePort + '/GyeeuserController/login?username=' + this.username +
-						'&password=' + this.password,
-					data: {},
-					method: 'GET',
-					success: function(res) {
-						//console.log(res.data);
-						_this.userid = res.data.data;
-
-
-						uni.setStorageSync('userid', _this.userid);
-						uni.setStorageSync('fingerPrintuserid', _this.userid);
-						//sessionStorage.setItem('userid',_this.userid);
-						if (res.data.code == 200) {
-
-							
-							_this.dataprocessing.viewUserid();
-							_this.dataprocessing.monitoringAuthority();
-							
-							// let plusDrawerList = uni.getStorageSync('plusList');
+				
+				if(this.username!="" && this.password!="")
+				{
+					uni.request({
+						url: 'http://' + this.backStageIp + ':' + this.backStagePort + '/GyeeuserController/login?username=' + this.username +
+							'&password=' + this.password,
+						data: {},
+						method: 'GET',
+						success: function(res) {
+							//console.log(res.data);
+							_this.userid = res.data.data;
+					
+					
+							uni.setStorageSync('userid', _this.userid);
+							uni.setStorageSync('fingerPrintuserid', _this.userid);
+							//sessionStorage.setItem('userid',_this.userid);
+							if (res.data.code == 200) {
+					
+								
+								_this.dataprocessing.viewUserid();
+								_this.dataprocessing.monitoringAuthority();
+								
+								// let plusDrawerList = uni.getStorageSync('plusList');
+								
+								// _this.dataprocessing.putWindPowerStationId(plusDrawerList[0].windId);
+								// _this.dataprocessing.putWindPowerStationName(plusDrawerList[0].name);
+								
+								// if(_this.dataprocessing.getWindPowerStationId()=='')
+								// {
+								// 	//debugger
+								// 	_this.dataprocessing.putWindPowerStationId(_this.$store.state.default_wpid);
+								// }
+					
+								// if(_this.dataprocessing.getWindPowerStationName()=='')
+								// {
+								// 	//debugger
+								// 	_this.dataprocessing.putWindPowerStationName(_this.$store.state.default_wpname);
+								// }
+								_this.createUserOnline();
+								_this.setUsernamePassword();
+								_this.loginFalg = true;
+								_this.lastUserName = _this.username;
+								_this.lastPassWord = _this.password;
+								uni.switchTab({
+									url: '/pages/index/Index'
+								});
+							} else {
+								uni.showModal({
+									content: '用户名密码输入错误,请核对'
+								});
+								_this.username = '';
+								_this.password = '';
+							}
+						},
+						fail: () => {
+							_this.tips = '网络错误,小程序端请检查合法域名';
+						},
+					});
+				}else
+				{
+					uni.showToast({
+					    title: "用户名和密码不能为空!",
+					    icon: "none"
+					})
+				}
+				
+			
+			},
+			async createUserOnline() {
+				let _this = this;
+	
+				let userid=uni.getStorageSync('userid');
+				// 创建一个this.socketTask对象【发送、接收、关闭socket都由这个对象操作】
+				_this.socketTask_getUserList = uni.connectSocket({
+					// 【非常重要】必须确保你的服务器是成功的,如果是手机测试千万别使用ws://127.0.0.1:9099【特别容易犯的错误】
+					url: 'ws://' + _this.sisStageIp + ':' + _this.sisStagePort + '/websocket/pageNumber_4/functionNumber_5/'+userid,
+					success(data) {
+						console.log(data);
+					}
+				});
+				/* let windpowerstationid = uni.getStorageSync('windpowerstationName'); */
+				// 消息的发送和接收必须在正常连接打开中,才能发送或接收【否则会失败】
+				_this.socketTask_getUserList.onOpen(res => {
+					console.log('WebSocket连接正常打开中...!');
+					_this.is_open_socket = true;
+
+					// 注:只有连接正常打开中 ,才能正常收到消息
+					_this.socketTask_getUserList.onMessage(res => {
+						/* _this.windpowerstationdetail.getUserList = JSON.parse(res.data); */
+						_this.lastUserName = uni.getStorageSync('gyeeusername');
+						_this.userid = uni.getStorageSync('userid');
+						let templist=JSON.parse(res.data);
+						
+						if(templist!=null && templist!=undefined)
+						{
+							uni.showToast({
+							    title: "同名用户登录,当前用户下线!",
+							    icon: "none"
+							})
 							
-							// _this.dataprocessing.putWindPowerStationId(plusDrawerList[0].windId);
-							// _this.dataprocessing.putWindPowerStationName(plusDrawerList[0].name);
+				
 							
-							// if(_this.dataprocessing.getWindPowerStationId()=='')
-							// {
-							// 	//debugger
-							// 	_this.dataprocessing.putWindPowerStationId(_this.$store.state.default_wpid);
-							// }
-
-							// if(_this.dataprocessing.getWindPowerStationName()=='')
-							// {
-							// 	//debugger
-							// 	_this.dataprocessing.putWindPowerStationName(_this.$store.state.default_wpname);
-							// }
-							_this.setUsernamePassword();
-							_this.loginFalg = true;
-							_this.lastUserName = _this.username;
-							_this.lastPassWord = _this.password;
-							uni.switchTab({
-								url: '/pages/index/Index'
-							});
-						} else {
-							uni.showModal({
-								content: '用户名密码输入错误,请核对'
+							//plus.runtime.quit();
+							//#ifdef H5
+							_this.destroyUseWebViews();
+							uni.navigateTo({
+							    url: '/components/login/Login'
 							});
-							_this.username = '';
-							_this.password = '';
+							 //#endif
+							//#ifdef APP-PLUS
+							setTimeout(function() {
+							        plus.runtime.quit()
+							       }, 1000);//如果是首页的onload调用时需要延时一下,二级页面无需延时,可直接获取
+							 //#endif
 						}
-					},
-					fail: () => {
-						_this.tips = '网络错误,小程序端请检查合法域名';
-					}
+						//_this.userList = JSON.parse(res.data);
+						
+					});
 				});
 			},
 			checkIsSoterEnrolledInDeviceFingerPrint() {
@@ -337,6 +543,7 @@
 									//_this.setUsernamePassword();
 									//_this.loginFalg = true;
 									//_this.getUser()
+									_this.createUserOnline();
 									_this.getFingerPrintPassword();
 								} else {
 									uni.showToast({

+ 59 - 51
components/mine/addressBook/InitializeThe.vue

@@ -32,7 +32,7 @@
 			let _this = this;
 			setInterval(function() {
 			        _this.onlineUserMap();
-			       }, 6000);//如果是首页的onload调用时需要延时一下,二级页面无需延时,可直接获取
+			       }, 5000);//如果是首页的onload调用时需要延时一下,二级页面无需延时,可直接获取
 			
 		},
 		computed: {
@@ -53,7 +53,11 @@
 			},
 		},
 		methods: {
-	
+			
+			destroyUseWebViews() {
+				wv=null;
+			
+			},
 			getUserList() {
 
 				let im_show =uni.getStorageSync('im_show');
@@ -67,6 +71,7 @@
 						data: {},
 						method: 'GET',
 						success: function(res) {
+							//#ifdef APP-PLUS
 							_this.userList = [];
 
 							for (var i = 0; i < res.data.length; i++) {
@@ -96,11 +101,11 @@
 									webView.hide();
 
 									wv.push(webView)
-
+									
 								}
-
+							
 							};
-
+							//#endif
 
 						},
 						fail: () => {
@@ -112,6 +117,7 @@
 					
 				}else
 				{
+					//#ifdef APP-PLUS
 					var pages = getCurrentPages();
 					var page = pages[pages.length - 1];
 					var currentWebview = page.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
@@ -124,6 +130,7 @@
 						currentWebview.append(webView); //一定要append到当前的页面里!!!才能跟随当前页面一起做动画,一起关闭
 						
 					}
+					//#endif
 				}
 
 
@@ -131,68 +138,68 @@
 			async onlineUserMap() {
 
 
-					let _this = this;
-					let url='https://' + _this.backStageIp + ':' + _this.backStagePort + '/websocket/usercontroller/onlineUserList';
-					uni.request({
-						url: url,
-						data: {},
-						method: 'GET',
-						sslVerify: false,
-						success: function(res) {
+			// 		let _this = this;
+			// 		let url='https://' + _this.backStageIp + ':' + _this.backStagePort + '/websocket/usercontroller/onlineUserList';
+			// 		uni.request({
+			// 			url: url,
+			// 			data: {},
+			// 			method: 'GET',
+			// 			sslVerify: false,
+			// 			success: function(res) {
 			
-						_this.userid = uni.getStorageSync('userid');
+			// 			_this.userid = uni.getStorageSync('userid');
 						
 
 						
-						let onlineList=[];
+			// 			let onlineList=[];
 						
-							for (var i = 0; i < res.data.length; i++) {
+			// 				for (var i = 0; i < res.data.length; i++) {
 								
-								if(res.data[i].id==_this.userid)
-								{
-									onlineList=res.data[i].userlist;
-									break;
-								}
-							}
+			// 					if(res.data[i].id==_this.userid)
+			// 					{
+			// 						onlineList=res.data[i].userlist;
+			// 						break;
+			// 					}
+			// 				}
 						
-							var pages = getCurrentPages();
-							var page = pages[pages.length - 1];
-							var currentWebview = page.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
+			// 				var pages = getCurrentPages();
+			// 				var page = pages[pages.length - 1];
+			// 				var currentWebview = page.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
 							
-							for (var i = 0; i < wv.length; i++) {
+			// 				for (var i = 0; i < wv.length; i++) {
 								
-								let status=true;
+			// 					let status=true;
 								
-								if(onlineList.length==0)
-								{
-									status=false;
-								}else{
-									for (var j = 0; j < onlineList.length; j++) {
+			// 					if(onlineList.length==0)
+			// 					{
+			// 						status=false;
+			// 					}else{
+			// 						for (var j = 0; j < onlineList.length; j++) {
 										
-										if (wv[i].id == "webview" + onlineList[j]) {
-											status=false;
-											break;
-										}
-									}
-								}
+			// 							if (wv[i].id == "webview" + onlineList[j]) {
+			// 								status=false;
+			// 								break;
+			// 							}
+			// 						}
+			// 					}
 					
 								
-								if(status)
-								{
-									let url=wv[i].getURL();
-									wv[i].loadURL(url);
-								}
+			// 					if(status)
+			// 					{
+			// 						let url=wv[i].getURL();
+			// 						wv[i].loadURL(url);
+			// 					}
 								
-							}
+			// 				}
 							
 
-						},
-						fail: function(res) {
-							_this.tips = '网络错误,小程序端请检查合法域名';
-						},
-					});
+			// 			},
+			// 			fail: function(res) {
+			// 				_this.tips = '网络错误,小程序端请检查合法域名';
+			// 			},
+			// 		});
 					
-					 uni.setStorageSync('im_show','0');
+			// 		 uni.setStorageSync('im_show','0');
 					
 			},
 			async onlineMonitor() {
@@ -295,7 +302,8 @@
 					}
 				}
 
-			}
+			},
+			
 
 		}
 	}