Browse Source

修复审核bug

chenjj 2 days ago
parent
commit
639d432d11
8 changed files with 141 additions and 41 deletions
  1. 12 13
      App.vue
  2. 4 2
      config.js
  3. 4 3
      main.js
  4. 2 1
      pages.json
  5. 21 18
      store/modules/user.ts
  6. 6 4
      utils/WebSocketManager.js
  7. 37 0
      utils/shareMixin.js
  8. 55 0
      utils/soketMixin.js

+ 12 - 13
App.vue

@@ -9,8 +9,7 @@ export default {
 	},
 	onLaunch: function () {
 		//develop:开发版 trial:体验版  release:正式版
-		console.log('App Launch',uni.getAccountInfoSync().miniProgram.envVersion)
-		console.log("App Launch");
+		// console.log('App Launch',uni.getAccountInfoSync().miniProgram.envVersion)
 		uni.loadFontFace({
 			family: "uicon-iconfont",
 			source: 'url("https://at.alicdn.com/t/font_2225171_8kdcwk4po24.ttf")',
@@ -23,19 +22,19 @@ export default {
 			},
 		});
 	},
-	onShow: function () {
-		//设置默认角色
-		//  uni.setStorageSync('userType', 1);
-		console.log('App Show')
-	},
-	onHide: function () {
-		console.log('App Hide')
-	},
-	onMounted() {
+	// onShow: function () {
+	// 	//设置默认角色
+	// 	//  uni.setStorageSync('userType', 1);
+	// 	console.log('App Show')
+	// },
+	// onHide: function () {
+	// 	console.log('App Hide')
+	// },
+	// onMounted() {
 
-		console.log("TCL: onMounted -> onMounted", onMounted)
+	// 	console.log("TCL: onMounted -> onMounted", onMounted)
 
-	},
+	// },
 }
 
 </script>

+ 4 - 2
config.js

@@ -1,8 +1,10 @@
 const base_url = {
-  develop:'http://192.168.100.128:9527',//开发版 
+  // develop:'http://192.168.100.128:9527',//开发版 
   // develop: 'http://192.168.100.139:9527', //嵘哥
+  // develop: 'https://yongc.top/prod-api',//体验版
+  develop: 'https://goldshulin.com/prod-api',//体验版
 
-  trial: 'https://zybooks.tech/prod-api',//体验版
+  trial: 'https://yongc.top/prod-api',//体验版
   release: 'https://goldshulin.com/prod-api',//正式版
 }
 

+ 4 - 3
main.js

@@ -2,7 +2,8 @@ import App from './App.vue'
 import plugins from './plugins'
 import uviewPlus from 'uview-plus'
 import store from './store/index.ts'
-
+import shareMixin from '@/utils/shareMixin'
+import soketMixin from '@/utils/soketMixin'
 
 import { createSSRApp } from 'vue'
 export function createApp() {
@@ -10,8 +11,8 @@ export function createApp() {
   app.use(uviewPlus)
   app.use(plugins)
   app.use(store)
-
-
+  app.mixin(shareMixin)
+  app.mixin(soketMixin)
 
   return {
     app

+ 2 - 1
pages.json

@@ -410,7 +410,8 @@
 	},
 	"globalStyle": {
 		"navigationBarTextStyle": "black",
-		"navigationBarBackgroundColor": "#FFFFFF"
+		"navigationBarBackgroundColor": "#FFFFFF",
+		"enableShareAppMessage":true
 	},
 	"plugins": {
 	},

+ 21 - 18
store/modules/user.ts

@@ -133,24 +133,24 @@ const user: Module<UserState, UserState> = {
 
 
 
-          if (this.wsManager) {
-            this.wsManager.closeConnection();
-          } else {
-            //获取账户时,连接soket 
-            const ms = new WebSocketManager(res.user.userId);
-            // 设置消息回调
-            ms.onMessage(data => {
-              console.log("处理消息逻辑", data.data)
-              // 处理消息逻辑
-              if (data.type === 'msgUnreadCount') {
-                commit('SET_MESSAGECOUNT', data.data);
-              }
-            });
-            // 建立连接
-            ms.connect();
-            commit('SET_MESSAGE', ms)
-
-          }
+          // if (this.wsManager) {
+          //   this.wsManager.closeConnection();
+          // } else {
+          //   //获取账户时,连接soket 
+          //   const ms = new WebSocketManager(res.user.userId);
+          //   // 设置消息回调
+          //   ms.onMessage(data => {
+          //     console.log("处理消息逻辑", data.data)
+          //     // 处理消息逻辑
+          //     if (data.type === 'msgUnreadCount') {
+          //       commit('SET_MESSAGECOUNT', data.data);
+          //     }
+          //   });
+          //   // 建立连接
+          //   ms.connect();
+          //   commit('SET_MESSAGE', ms)
+
+          // }
 
 
           resolve(res)
@@ -182,6 +182,9 @@ const user: Module<UserState, UserState> = {
     handleMessageCount({ commit, state }, count) {
       commit('SET_MESSAGECOUNT', count);
     },
+    handleSoket({ commit, state }, ms) {
+      commit('SET_MESSAGE', ms);
+    },
     handlerAddress({ commit, state }, address) {
       commit('SET_ADDRESSINFO', address);
     },

+ 6 - 4
utils/WebSocketManager.js

@@ -17,7 +17,8 @@ class WebSocketManager {
         this.reconnectTimer = null;
         this.isConnecting = false;
         this.onMessageCallback = null;
-
+        this.connectCount = 0;//重连次数
+        
     }
 
     /**
@@ -75,12 +76,13 @@ class WebSocketManager {
 
         this.socketTask.onError(err => {
             console.error('WebSocket 发生错误:', err);
+   
         });
 
         this.socketTask.onClose(() => {
             console.log('WebSocket 已关闭');
             this.stopHeartbeat();
-            this.reconnect(); // 自动重连
+            this.connectCount <= 3 && this.reconnect();
         });
     }
 
@@ -118,6 +120,7 @@ class WebSocketManager {
         clearTimeout(this.reconnectTimer);
         this.reconnectTimer = setTimeout(() => {
             console.log('尝试重新连接...');
+            this.connectCount = this.connectCount +1;
             this.connect();
         }, 3000);
     }
@@ -142,10 +145,9 @@ class WebSocketManager {
      */
     closeConnection() {
         console.log('主动关闭连接',this.socketTask);
-        
         this.socketTask.close();
         this.socketTask = null;
-        // this.stopHeartbeat();
+        this.stopHeartbeat();
     }
 
     /**

+ 37 - 0
utils/shareMixin.js

@@ -0,0 +1,37 @@
+import { onLaunch, onShow, onHide, onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app";
+export default {
+  data() {
+    return {
+      // 可全局覆盖的默认参数
+      shareConfig: {
+        title: '金邻助家-着力打造全国居家服务行业标准和建立综合信用评价体系',
+        // path: `/pages/login?scene=${uni.getStorageSync('userType')}:${uni.getStorageSync('userId')}`,
+        path:'/pages/index',
+        // imageUrl: '/static/serverImg/mine/user.png',
+        imageUrl:''
+      }
+    }
+  },
+ 
+  onLaunch:function () { 
+    uni.showShareMenu({
+      withShareTicket: true,
+      menus: ['shareAppMessage', 'shareTimeline']
+    })
+  },
+  onShareAppMessage() {
+    return {
+      title: this.shareConfig.title,
+      path: this.shareConfig.path,
+      imageUrl: this.shareConfig.imageUrl
+    }
+  },
+  onShareTimeline() {
+    return {
+      title: this.shareConfig.title,
+      // query: `scene=${uni.getStorageSync('userType')}:${uni.getStorageSync('userId')}`,
+      query:``,
+      imageUrl: this.shareConfig.imageUrl
+    }
+  }
+}

+ 55 - 0
utils/soketMixin.js

@@ -0,0 +1,55 @@
+import WebSocketManager from '@/utils/WebSocketManager.js';
+import store from '@/store'
+import { getToken } from '@/utils/auth'
+export default {
+  data() {
+    return {
+    //   userId: store.state.user.userId,
+    //   ws: store.state.user.wsManager
+    }
+  },
+  onShow: function () {
+    console.log('App-Show^^')
+    uni.$u.debounce(this.connectSoket(), 500)
+  },
+  onHide: function () {
+    console.log('App-Hide^^')
+    this.closeSoket();
+  },
+  onLaunch:function () { 
+    console.log('App-onLaunch^^')
+    uni.$u.debounce(this.connectSoket(), 500)
+  },
+  onExit: function () { 
+    console.log('App onExit^^')
+  },
+
+  methods: {
+    connectSoket(){
+        const ws = store.state.user.wsManager;
+        const userId = uni.getStorageSync('userId');
+        const token = getToken();
+        // console.log('connectSoket------------>',!ws , userId,!ws && userId);
+
+          if (!ws && userId && token) {
+            console.log('connectSoket-----+++------->',!ws , userId,!ws && userId);
+            // 获取账户时,连接soket 
+            const ms = new WebSocketManager(userId);
+            // 设置消息回调
+            ms.onMessage(data => {
+              console.log("处理消息逻辑", data.data)
+              // 处理消息逻辑
+              if (data.type === 'msgUnreadCount') {
+                store.dispatch('handleMessageCount',data.data);
+              }
+            });
+            // 建立连接
+            ms.connect();
+            store.dispatch('handleSoket',ms);
+          }
+    },
+    closeSoket(){
+        console.log('closeSoket',store);
+    }
+  }
+}