Browse Source

灵活配置ip

蒋科 1 month ago
parent
commit
f9aea0b65c
5 changed files with 39 additions and 16 deletions
  1. 1 1
      common/request.js
  2. 4 1
      components/Navbar/Navbar.vue
  3. 5 2
      config.js
  4. 13 10
      pages/index/index.vue
  5. 16 2
      pages/login/index.vue

+ 1 - 1
common/request.js

@@ -41,7 +41,7 @@ export default {
 					reject(error);
 					reject(error);
 					if(error.errMsg.includes('timeout')){
 					if(error.errMsg.includes('timeout')){
 						uni.showToast({
 						uni.showToast({
-							title: '请求接口失败!',
+							title: '请求接口失败,请检查IP地址!',
 							icon: 'none',
 							icon: 'none',
 						})
 						})
 					}else{
 					}else{

+ 4 - 1
components/Navbar/Navbar.vue

@@ -122,7 +122,10 @@
 					content: "",
 					content: "",
 					success: function(res) {
 					success: function(res) {
 						if (res.confirm) {
 						if (res.confirm) {
-							that.$storage.clear(); //清除所有本地存储
+							// that.$storage.clear(); //清除所有本地存储
+							that.$storage.remove("users")
+							that.$storage.remove("token")
+							that.$store.commit("DELETEUSERS")
 							uni.navigateTo({
 							uni.navigateTo({
 								url: "../../pages/login/index"
 								url: "../../pages/login/index"
 							})
 							})

+ 5 - 2
config.js

@@ -1,8 +1,11 @@
+import storage from "./common/storage";
 export default {
 export default {
 	web_name: "智小狸",
 	web_name: "智小狸",
 	// uni_app_web_api_url: "http://10.12.22.137:8080/api", //后端统一接口路径
 	// uni_app_web_api_url: "http://10.12.22.137:8080/api", //后端统一接口路径
 	// web_socket_url:'ws://10.12.22.137:8080/ws/',
 	// 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: "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/':'',
 	debug: true
 	debug: true
 }
 }

+ 13 - 10
pages/index/index.vue

@@ -171,25 +171,28 @@
 				stateList: [],
 				stateList: [],
 				heartbeatTimer:null,
 				heartbeatTimer:null,
 				onMessageTime:null,
 				onMessageTime:null,
+				ws: null, //websuokit 链接器
 			}
 			}
 		},
 		},
 		mounted() {
 		mounted() {
 			this.onMessageTime = new Date();
 			this.onMessageTime = new Date();
 			this.InitWs()
 			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>3000){
+			// 		if(this.ws!=null){
+			// 			this.ws.close()
+			// 			this.ws=null
+			// 		}
+			// 	}
+			// },3000)
 			this.getDataView()
 			this.getDataView()
 		},
 		},
 		destroyed(){
 		destroyed(){
 			clearInterval(this.timer)
 			clearInterval(this.timer)
-			this.ws.close()
+			if(this.ws){
+				this.ws.close()
+			}
 		},
 		},
 		computed: {
 		computed: {
 			robotResult() {
 			robotResult() {

+ 16 - 2
pages/login/index.vue

@@ -12,6 +12,10 @@
 							<input class="psd_input" v-model="userInfo.passWord" :password="eye"></input>
 							<input class="psd_input" v-model="userInfo.passWord" :password="eye"></input>
 							<image :src="eye?Frame:browse" class='login_icon_eye' alt=""  @click="showpsd">
 							<image :src="eye?Frame:browse" class='login_icon_eye' alt=""  @click="showpsd">
 					</u-form-item>
 					</u-form-item>
+					<u-form-item prop="userInfo.name" class="label_left">
+						<image :src="user_img" class='login_icon' alt="">
+							<u--input v-model="addressIp"></u--input>
+					</u-form-item>
 				</u--form>
 				</u--form>
 				<u-button type="primary" text="登录" class="btn" @click="submit"></u-button>
 				<u-button type="primary" text="登录" class="btn" @click="submit"></u-button>
 			</view>
 			</view>
@@ -28,6 +32,7 @@
 	import lockon from "@/static/login_img/lock-on.png"
 	import lockon from "@/static/login_img/lock-on.png"
 	import user from "@/static/login_img/user.png"
 	import user from "@/static/login_img/user.png"
 	import browse from "@/static/login_img/browse.png"
 	import browse from "@/static/login_img/browse.png"
+	import config from "@/config";
 	export default {
 	export default {
 		name: "son",
 		name: "son",
 		data() {
 		data() {
@@ -43,7 +48,8 @@
 				},
 				},
 				eye: true,
 				eye: true,
 				popupType:'',
 				popupType:'',
-				popupMessage:''
+				popupMessage:'',
+				addressIp:this.$storage.getJson('addressIp')?this.$storage.getJson('addressIp'):'192.168.3.177:8080'
 			};
 			};
 		},
 		},
 		methods: {
 		methods: {
@@ -57,6 +63,13 @@
 				this.$refs.Exchangepopup.open()
 				this.$refs.Exchangepopup.open()
 			},
 			},
 			submit() {
 			submit() {
+				
+				config.uni_app_web_api_url='http://'+this.addressIp+'/api'
+				config.web_socket_url='ws://'+this.addressIp+'/ws/'
+				if(!this.addressIp){
+					this.ExchangeMessage('error', '请输入IP地址')
+					return 
+				}
 				this.$utils.showLoading('登录中')
 				this.$utils.showLoading('登录中')
 				if (this.userInfo.userAccount && this.userInfo.passWord) {
 				if (this.userInfo.userAccount && this.userInfo.passWord) {
 					this.$http.wxLogin(this.userInfo).then(res => {
 					this.$http.wxLogin(this.userInfo).then(res => {
@@ -64,6 +77,7 @@
 						if(res.code == 0){
 						if(res.code == 0){
 							this.$storage.setJson("token",res.data.token)
 							this.$storage.setJson("token",res.data.token)
 							this.$storage.setJson("userId",res.data.userId)
 							this.$storage.setJson("userId",res.data.userId)
+							this.$storage.setJson("addressIp",this.addressIp)
 							uni.navigateTo({
 							uni.navigateTo({
 								url: '/pages/home/index'
 								url: '/pages/home/index'
 							})
 							})
@@ -113,7 +127,7 @@
 
 
 			.u-form-item__body {
 			.u-form-item__body {
 				padding: 0px 0px;
 				padding: 0px 0px;
-				margin-bottom: 32px;
+				margin-bottom: 28px;
 			}
 			}
 
 
 			.u-form-item__body__right__content ,.psd_input{
 			.u-form-item__body__right__content ,.psd_input{