瀏覽代碼

websocket

lilei 4 年之前
父節點
當前提交
30d9e3875d
共有 3 個文件被更改,包括 9 次插入2 次删除
  1. 1 1
      App.vue
  2. 4 0
      pages/work/index/index.vue
  3. 4 1
      store/index.js

+ 1 - 1
App.vue

@@ -1,6 +1,6 @@
 <script>
 	// const uat_URL = 'http://md.test.zyucgj.com/saas/clz/' // 预发布
-	const uat_URL = 'http://192.168.16.105:8103/cw-wechat/' // 本地
+	const uat_URL = 'http://192.168.16.103:8103/cw-wechat/' // 本地
 	const pro_URL = 'https://car.zyucgj.com/saas/clz/'  // 生产
 	const buildType = 0 // 打包环境对应类型,1 生产 0 预发布
 	const buildURL = buildType ? pro_URL : uat_URL // 打包后实际对应的url

+ 4 - 0
pages/work/index/index.vue

@@ -180,6 +180,8 @@ export default {
 		washCarSuccess(){
 			this.status = "success";
 			this.resetLoadingStatus();
+			// 关闭socket
+			this.$store.commit("$closeWebsocket")
 			uni.showModal({
 			    title: '提示',
 			    content: '洗车已结束?',
@@ -223,6 +225,8 @@ export default {
 			this.showStop = false;
 			// 归位结束后
 			setTimeout(()=>{
+				// 关闭socket
+				this.$store.commit("$closeWebsocket")
 				uni.redirectTo({
 					url:"/pages/work/success/success"
 				})

+ 4 - 1
store/index.js

@@ -66,12 +66,14 @@ const store = new Vuex.Store({
 		// 创建通知消息websocket
 		$webSocket(state, params) {
 			let _this = this
-			let userInfo = state.vuex_userData
+			let token = getApp().globalData.token
 			let url = getApp().globalData.baseUrl
 			let wsBaseUrl = url.indexOf("https:")>=0 ? url.replace("https:","wss:") : url.replace("http:","ws:")
 			let wsUrl = wsBaseUrl + 'websocket/16546'
+			console.log(token,wsUrl)
 			// 开始连接
 			state.vuex_socket = uni.connectSocket({
+				header: {'X-AUTH-TOKEN':token},
 			    url: wsUrl, // ws 请求地址
 			    complete: ()=> {
 					console.log('连接complete回调!')
@@ -102,6 +104,7 @@ const store = new Vuex.Store({
 				console.log(state.vuex_socket.readyState)
 				if(state.vuex_socket.readyState != 1){
 					state.vuex_socket = uni.connectSocket({
+						header: {'X-AUTH-TOKEN':token},
 					    url: wsUrl, // ws 请求地址
 					    complete: ()=> {
 							console.log('连接complete回调!')