Ver Fonte

灵活配置ip

蒋科 há 2 meses atrás
pai
commit
2cb859b5da
4 ficheiros alterados com 18 adições e 28 exclusões
  1. 2 2
      config.js
  2. 10 22
      pages/index/index.vue
  3. 6 4
      pages/login/index.vue
  4. BIN
      static/login_img/ip.png

+ 2 - 2
config.js

@@ -5,7 +5,7 @@ export default {
 	// web_socket_url:'ws://10.12.22.137:8080/ws/',
 	// uni_app_web_api_url: "http://192.168.3.177:8080/api",
 	// web_socket_url:'ws://192.168.3.177:8080/ws/',
-	uni_app_web_api_url:storage.getJson("addressIp")?'http://'+storage.getJson("addressIp")+'/api':'',
-	web_socket_url:storage.getJson("addressIp")?'ws://'+storage.getJson("addressIp")+'/ws/':'',
+	uni_app_web_api_url:storage.getJson("addressIp")?'http://'+storage.getJson("addressIp")+':8080/api':'',
+	web_socket_url:storage.getJson("addressIp")?'ws://'+storage.getJson("addressIp")+':8080/ws/':'',
 	debug: true
 }

+ 10 - 22
pages/index/index.vue

@@ -177,15 +177,15 @@
 		mounted() {
 			this.onMessageTime = new Date();
 			this.InitWs()
-			// this.heartbeatTimer = setInterval(()=>{
-			// 	let newDate = new Date();
-			// 	if(newDate-this.onMessageTime>3000){
-			// 		if(this.ws!=null){
-			// 			this.ws.close()
-			// 			this.ws=null
-			// 		}
-			// 	}
-			// },3000)
+			this.heartbeatTimer = setInterval(()=>{
+				let newDate = new Date();
+				if(newDate-this.onMessageTime>8000){
+					if(this.ws!=null){
+						this.ws.close()
+						this.ws=null
+					}
+				}
+			},8000)
 			this.getDataView()
 		},
 		destroyed(){
@@ -246,18 +246,6 @@
 					complete: () => {}
 				})
 				this.ws.onOpen(() => {
-					// let msg = {
-					// 	type: "subscribeExchange",
-					// 	payLoad: {
-					// 		exchangeNo: exchangeNo
-					// 	}
-					// }
-					// this.ws.send({
-					// 	data: JSON.stringify(msg)
-					// })
-					// uni.showLoading({
-					// 	title: '数据加载中...'
-					// });
 					console.log('websocket连接成功')
 					const wsMessage = {
 						type: 'page',
@@ -270,7 +258,7 @@
 				this.ws.onMessage((res) => {
 					this.onMessageTime = new Date();
 					let d = JSON.parse(res.data)
-					// console.log(d)
+					console.log(d)
 					this.stateList = d.stateList
 					this.robotState = d.robotState
 					uni.hideLoading()

+ 6 - 4
pages/login/index.vue

@@ -13,7 +13,7 @@
 							<image :src="eye?Frame:browse" class='login_icon_eye' alt=""  @click="showpsd">
 					</u-form-item>
 					<u-form-item prop="userInfo.name" class="label_left">
-						<image :src="user_img" class='login_icon' alt="">
+						<image :src="ip_img" class='login_icon' alt="">
 							<u--input v-model="addressIp"></u--input>
 					</u-form-item>
 				</u--form>
@@ -28,6 +28,7 @@
 </template>
 <script>
 	import login from "@/static/login_img/login.png"
+	import ip_img from "@/static/login_img/ip.png"
 	import Frame from "@/static/login_img/Frame.png"
 	import lockon from "@/static/login_img/lock-on.png"
 	import user from "@/static/login_img/user.png"
@@ -38,6 +39,7 @@
 		data() {
 			return {
 				login_img: login,
+				ip_img:ip_img,
 				browse: browse,
 				user_img: user,
 				lockon: lockon,
@@ -49,7 +51,7 @@
 				eye: true,
 				popupType:'',
 				popupMessage:'',
-				addressIp:this.$storage.getJson('addressIp')?this.$storage.getJson('addressIp'):'192.168.3.177:8080'
+				addressIp:this.$storage.getJson('addressIp')?this.$storage.getJson('addressIp'):'192.168.3.177'
 			};
 		},
 		methods: {
@@ -64,8 +66,8 @@
 			},
 			submit() {
 				
-				config.uni_app_web_api_url='http://'+this.addressIp+'/api'
-				config.web_socket_url='ws://'+this.addressIp+'/ws/'
+				config.uni_app_web_api_url='http://'+this.addressIp+':8080/api'
+				config.web_socket_url='ws://'+this.addressIp+':8080/ws/'
 				if(!this.addressIp){
 					this.ExchangeMessage('error', '请输入IP地址')
 					return 

BIN
static/login_img/ip.png