瀏覽代碼

fix:冲突修改

jiayubo 3 月之前
父節點
當前提交
888dbc07ae

+ 14 - 25
App.vue

@@ -1,41 +1,30 @@
 <script>
-// import WebSocketManager from '@/utils/WebSocketManager.js';
 import { watch } from 'vue';
 import store from '@/store'
 import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
+import soketMixin from '@/utils/soketMixin'
 export default {
 	data: {
 		userId: uni.getStorageSync('userId') //读取本地存储
 	},
+	mixins: [soketMixin],
 	onLaunch: function () {
 		//develop:开发版 trial:体验版  release:正式版
-		console.log('App Launch',uni.getAccountInfoSync().miniProgram.envVersion)
-		console.log("App Launch");
-		uni.loadFontFace({
-			family: "uicon-iconfont",
-			source: 'url("https://at.alicdn.com/t/font_2225171_8kdcwk4po24.ttf")',
-			global: true,
-			success: (success) => {
-				console.log("Font loaded successfully", success);
-			},
-			fail: (fail) => {
-				console.log("Font loading failed", fail);
-			},
-		});
+	
 	},
-	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>

+ 7 - 6
config.js

@@ -1,10 +1,11 @@
 const base_url = {
-  // develop: 'http://192.168.100.128:9527', //开发版
-  develop: 'https://yongc.top/prod-api',
+  // 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://yongc.top/prod-api', //体验版
-  release: 'https://goldshulin.com/prod-api', //正式版
+  trial: 'https://yongc.top/prod-api',//体验版
+  release: 'https://goldshulin.com/prod-api',//正式版
 }
 
 const env = uni.getAccountInfoSync().miniProgram.envVersion
@@ -13,7 +14,7 @@ const config = {
   // baseUrl: 'https://vue.ruoyi.vip/prod-api',
   //cloud后台网关地址
   // baseUrl: 'http://192.168.100.139:9527', //嵘哥
-  baseUrl: base_url[env],
+  baseUrl: base_url[env],//龙哥
   // baseUrl: 'http://192.168.100.122:9527',
   // baseUrl: 'https://goldshulin.com/prod-api',
   mapKey: 'KFEBZ-P2GKZ-A5PX4-7Q6Y7-KXOBF-XCB4C',
@@ -23,7 +24,7 @@ const config = {
     // 应用名称
     name: 'ruoyi-app-vue3',
     // 应用版本
-    version: '1.1.0',
+    version: '1.2.0',
     // 应用logo
     logo: '/static/logo.png',
     // 官方网站

+ 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

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

+ 11 - 15
pages/index.vue

@@ -1,18 +1,10 @@
 <template>
   <view>
     <!-- 首页顶部定位区域 -->
-    <view class="home-banner" :class="{ 'home-banner-with-bg': showAddressBg }">
-      <view class="home-banner-left">
-        <view class="location-group" @click="cityClick">
-          <img src="@/static/uview/common/map-pin-fill@1x.png" alt="" class="map-pin-fill">
-          <text class="address-text">{{ data.address.name }}</text>
-          <image src="/static/img/Subscript.png" mode="widthFix" class="map-pin-Subscript"></image>
-        </view>
-        <view class="address-text-bg"></view>
-        <view class="search-group" @click="searchClick">
-          <img src="/static/img/map-pin-fill@1x.png" alt="" class="arrow-right">
-          <view class="address-text-bg-text">搜索服务</view>
-        </view>
+    <view class="home-banner"  :class="{ 'home-banner-with-bg': showAddressBg }">
+      <view class="home-banner-left" @click="cityClick">
+        <img src="@/static/uview/common/map-pin-fill@1x.png" alt="" class="map-pin-fill">
+        <text class="address-text">{{ data.address.name }}</text>
       </view>
     </view>
 
@@ -298,9 +290,10 @@ onPageScroll(e => {
 
 onMounted(async () => {
 
-  console.log("TCL:  uni.$u", )
-  getNotice()
-  const token = getToken();
+  try {
+    console.log("TCL:  uni.$u",)
+    getNotice()
+    const token = getToken();
 
     const res_dara = await regionAddresstree()
     addresstree.value = res_dara.data
@@ -319,6 +312,9 @@ onMounted(async () => {
     } else {
       getList();
     }
+  } catch (error) {
+    getList();
+  }
 })
 
 </script>

+ 4 - 0
pages/mine/index.vue

@@ -297,10 +297,12 @@ const userList = [
 const switchUserType = (userType) => {
   uni.setStorageSync('userType', userType)
   store.dispatch('GetInfo').then((res) => {
+    uni.$u.closeSoket();
     userInfo.value = store.state.user
     userOrWorker({ userType: userType })
       .then(res => {
         console.log("TCL: loginSuccess -> res", res)
+        uni.$u.connectSoket(userInfo.value.userId)
         uni.reLaunch({
           url: '/pages/index',
         })
@@ -385,6 +387,8 @@ const getDetails = async () => {
 }
 
 const handLsetTing = () => {
+  console.log('uni.$u.closeSoket',uni.$u);
+
   uni.navigateTo({
     url: '/pages_mine/pages/setupUser/index',
   })

+ 33 - 0
pages_home/pages/Volunteerside/goodsDetails.vue

@@ -1,6 +1,39 @@
 <template>
   <view>
 
+      <!-- 顶部轮播图 -->
+      <view>
+        <Detiles></Detiles>
+      </view>
+
+      <!-- 页面背景整体定位 -->
+      <view class="service-description-position">
+
+        <!-- 价格服务介绍 -->
+        <view class="service-description-container">
+          <view class="service-text">{{ listData.businessDescribe }}</view>
+          <view class="service-price-tag">¥{{ listData.businessPrice }}</view>
+        </view>
+
+      </view>
+
+
+
+
+
+    <view class="service-description-box">
+      <up-card title="志愿者介绍" :head-style="{ height: '80rpx', padding: '20rpx', fontWeight: 'bold' }">
+        <template #body>
+          <view class="volunteer-card">
+            <!-- 左侧图片 -->
+            <image class="volunteer-image" :src="listData.volunteerPicture" mode="aspectFill"></image>
+
+            <!-- 中间信息(姓名/类别等) -->
+            <view class="volunteer-info">
+              <view class="info-row">
+                <text class="info-label">姓名:</text>
+                <text class="info-value">{{ listData.name }}</text>
+
     <!-- 顶部轮播图 -->
     <view>
       <Detiles></Detiles>

+ 2 - 2
pages_orderuser/pages/talk/pages/index/index.vue

@@ -77,7 +77,7 @@ export default {
 			orderId: '',
 			orderInfo: {},//订单信息
 			userType: uni.getStorageSync('userType'), //读取本地存储
-			system: '2',
+			system: 2,
 			userId: uni.getStorageSync('userId'), //读取本地存储
 			conversationRecordId: null,//会话id
 			storeUser: store.state.user,
@@ -110,7 +110,7 @@ export default {
 		}
 	
 		//1用户2志愿者3后台
-		this.system = this.userType === 1 ? '1' : '2';
+		this.system = this.userType === 1 ? 1 : 2;
 		//客服
 		if(options.customerService){
 			// this.system = 3;

+ 9 - 20
store/modules/user.ts

@@ -5,7 +5,6 @@ import { login, logout, getInfo } from '@/api/login'
 import { getToken, setToken, removeToken } from '@/utils/auth'
 import { UserState, UserForm } from '@/types/store'
 import { Module } from 'vuex'
-import WebSocketManager from '@/utils/WebSocketManager.js';
 const baseUrl = config.baseUrl
 
 const user: Module<UserState, UserState> = {
@@ -99,6 +98,7 @@ const user: Module<UserState, UserState> = {
         login(username, password, code, uuid, referrerType, referrerId, latitude, longitude).then((res: any) => {
           setToken(res.token)
           commit('SET_TOKEN', res.token)
+          
           resolve(res)
         }).catch(error => {
           reject(error)
@@ -131,26 +131,9 @@ const user: Module<UserState, UserState> = {
           commit('SET_NICKNAME', res.user.nickName)
           commit('SET_USERID', res.user.userId)
 
+          uni.setStorageSync('userType', res.user.userId)
 
-
-          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)
-
-          }
+          uni.$u.connectSoket(res.user.userId);
 
 
           resolve(res)
@@ -169,6 +152,8 @@ const user: Module<UserState, UserState> = {
           commit('SET_PERMISSIONS', [])
           removeToken()
 
+          //清除soket
+          uni.$u.closeSoket();
           uni.setStorageSync('userType', 1)
           // uni.setStorageSync('userId', null)
           uni.removeStorageSync('userId')
@@ -182,6 +167,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);
     },
@@ -194,6 +182,7 @@ const user: Module<UserState, UserState> = {
         commit('SET_ROLES', [])
         commit('SET_PERMISSIONS', [])
         removeToken()
+        uni.$u.closeSoket();
         uni.removeStorageSync('userId')
         storage.clean()
       })

+ 21 - 12
utils/WebSocketManager.js

@@ -1,6 +1,7 @@
 import config from '@/config'
 const baseUrl = config.baseUrl
 import store from '@/store'
+import { getToken } from '@/utils/auth'
 class WebSocketManager {
     constructor(userId) {
         // 1用户 2志愿者
@@ -16,7 +17,8 @@ class WebSocketManager {
         this.reconnectTimer = null;
         this.isConnecting = false;
         this.onMessageCallback = null;
-
+        this.connectCount = 0;//重连次数
+        
     }
 
     /**
@@ -32,11 +34,15 @@ class WebSocketManager {
             console.log('已存在连接,正在关闭旧连接...');
             this.socketTask.close();
         }
+
         this.isConnecting = true;
         console.log('建立 WebSocket 连接:', this.url);
         this.socketTask = uni.connectSocket({
             url: this.url,
-            success: () => console.log('WebSocket 连接创建成功'),
+            success: (res) => console.log('WebSocket 连接创建成功',res),
+            header: { 
+                'Authorization': `Bearer ${getToken()}` 
+            }, 
         });
 
         this._setupEventListeners();
@@ -71,12 +77,14 @@ class WebSocketManager {
 
         this.socketTask.onError(err => {
             console.error('WebSocket 发生错误:', err);
+            this.connectCount <= 3 && this.reconnect();
         });
 
         this.socketTask.onClose(() => {
-            console.log('WebSocket 已关闭');
+            console.log('WebSocket 已关闭',this.connectCount);
             this.stopHeartbeat();
-            this.reconnect(); // 自动重连
+        
+            // this.connectCount <= 3 && this.reconnect();
         });
     }
 
@@ -111,11 +119,9 @@ class WebSocketManager {
      * 重新连接
      */
     reconnect() {
-        clearTimeout(this.reconnectTimer);
-        this.reconnectTimer = setTimeout(() => {
-            console.log('尝试重新连接...');
-            this.connect();
-        }, 3000);
+        console.log('尝试重新连接...');
+        this.connectCount = this.connectCount +1;
+        this.connect();
     }
 
     /**
@@ -137,11 +143,12 @@ class WebSocketManager {
      * 主动关闭连接
      */
     closeConnection() {
-        console.log('主动关闭连接',this.socketTask);
-        
+        console.log('主动关闭连接',this.socketTask,this.isConnected);
+        uni.closeSocket(this.socketTask);
         this.socketTask.close();
         this.socketTask = null;
-        // this.stopHeartbeat();
+        this.stopHeartbeat();
+        store.dispatch('handleSoket', null)
     }
 
     /**
@@ -153,4 +160,6 @@ class WebSocketManager {
     }
 }
 
+
+
 export default WebSocketManager;

+ 0 - 3
utils/adress.js

@@ -209,7 +209,6 @@ function normalizeAddress(str) {
  * @returns {Object|null} 包含 data/name、code、index 的对象
  */
 const getCityCode = (address,addressData) => {
-	console.log("TCL: getCityCode -> address", address)
   if(!addressData) return null;
    //address:重庆市永川区人民大道191号
   const names = address.split(/\s+/)
@@ -221,7 +220,6 @@ const getCityCode = (address,addressData) => {
 
   // 查找省份
   const provinceIndex = addressData.findIndex(p => p.name.includes(names[0]))
-	console.log("TCL: getCityCode -> provinceIndex", provinceIndex)
   if (provinceIndex === -1) return null
 
   const province = addressData[provinceIndex]
@@ -250,7 +248,6 @@ const getCityCode = (address,addressData) => {
   result.data.push(district.name)
   result.code.push(district.regionCode)
   result.index.push(districtIndex)
-	console.log("TCL: getCityCode -> result", result)
 
   return result
 

+ 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
+    }
+  }
+}

+ 61 - 0
utils/soketMixin.js

@@ -0,0 +1,61 @@
+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 () {
+    uni.loadFontFace({
+			family: "uicon-iconfont",
+			source: 'url("https://at.alicdn.com/t/font_2225171_8kdcwk4po24.ttf")',
+			global: true,
+			success: (success) => {
+				console.log("Font loaded successfully", success);
+			},
+			fail: (fail) => {
+				console.log("Font loading failed", fail);
+			},
+		});
+    uni.$u.connectSoket = this.connectSoket;
+    uni.$u.closeSoket = this.closeSoket;
+
+    uni.$u.debounce(this.connectSoket(), 500)
+  },
+  onHide: function () {
+    this.closeSoket();
+  },
+  methods: {
+    connectSoket(user_id){
+        const ws = store.state.user.wsManager;
+        const userId = user_id || uni.getStorageSync('userId');
+        const token = getToken();
+
+          if (!ws && userId && token) {
+            // 获取账户时,连接soket 
+            const ms = new WebSocketManager(userId);
+            // 设置消息回调
+            ms.onMessage(data => {
+              // 处理消息逻辑
+              if (data.type === 'msgUnreadCount') {
+                store.dispatch('handleMessageCount',data.data);
+              }
+            });
+            // 建立连接
+            ms.connect();
+            store.dispatch('handleSoket',ms);
+          }
+    },
+    closeSoket(){
+    
+        const ws = store.state.user.wsManager;
+        if(ws){
+          ws.closeConnection();
+        }
+        
+    }
+  }
+}