Просмотр исходного кода

feat(mallApp): 优化首页客服入口跳转

- 首页轮播客服入口按客服微信二维码配置决定进入客服页或直达在线聊天

- 透传门店、客户与二维码信息,保持聊天页参数与现有客服入口一致
shizhongqi 3 дней назад
Родитель
Сommit
890c6354f7
2 измененных файлов с 81 добавлено и 4 удалено
  1. 74 4
      mallApp/src/components/home/bannerSwiper.vue
  2. 7 0
      mallApp/src/pages/home/index.vue

+ 74 - 4
mallApp/src/components/home/bannerSwiper.vue

@@ -1,6 +1,7 @@
 <!--
   店铺首页-轮播图
   按 hdApp 后台配置的轮播间隔自动播放;右下角客服悬浮图标根据顶部导航客服开关显隐;
+  点击客服:有微信二维码进客服页,未设置则直达在线聊天;
   点击轮播图按关联类型(图文/商品/分类/场景)跳转对应浏览页
 -->
 <template>
@@ -21,7 +22,9 @@
         <image class="home-banner-img" :src="item.imgUrl" mode="aspectFill" @click="onBannerTap(index)" />
       </swiper-item>
     </swiper>
-    <view v-if="showService" class="service-float" @click="goChat"><zui-svg-icon icon="general-customerService" :width="24" :height="24" style="margin-top: 2upx"></zui-svg-icon></view>
+    <view v-if="showService" class="service-float" @click="goChat">
+      <zui-svg-icon icon="general-customerService" :width="24" :height="24" style="margin-top: 2upx"></zui-svg-icon>
+    </view>
   </view>
 </template>
 
@@ -44,6 +47,21 @@ export default {
     hdId: {
       type: [String, Number],
       default: ''
+    },
+    /** 客服微信二维码地址;*/
+    serviceWx: {
+      type: String,
+      default: ''
+    },
+    /** 当前用户在该店的客户 ID,直达聊天页时作为 customId */
+    customId: {
+      type: [String, Number],
+      default: 0
+    },
+    /** 门店信息,直达聊天页时取 shopId / 展示名 */
+    shopInfo: {
+      type: Object,
+      default: null
     }
   },
   methods: {
@@ -81,14 +99,66 @@ export default {
       }
     },
     /**
-     * 首页客服悬浮入口:先进入客服展示页(二维码/电话/在线咨询)
-     * 携带 account、hdId,便于客服页拉取当前门店信息
+     * 解析客服微信二维码:优先 props,其次本地缓存门店信息
+     * 未配置时返回空串,用于判断是否直达在线聊天
+     */
+    resolveServiceWx() {
+      const fromProp = (this.serviceWx || '').trim()
+      if (fromProp) return fromProp
+      const cached = uni.getStorageSync('currentShop') || {}
+      return ((cached && cached.serviceWx) || '').trim()
+    },
+    /**
+     * 首页客服悬浮入口
+     * 已设置微信二维码 → 客服展示页(二维码/电话/在线咨询)
+     * 未设置微信二维码 → 直接进入在线聊天页
      */
     goChat() {
       const account = this.account || uni.getStorageSync('account') || ''
       const hdId = this.hdId || uni.getStorageSync('hdId') || ''
+      // 有二维码走客服页;无二维码跳过中间页,直达聊天
+      if (this.resolveServiceWx()) {
+        uni.navigateTo({
+          url: `/pages/home/service?account=${account}&hdId=${hdId}`
+        })
+        return
+      }
+      this.goChatPage()
+    },
+    /**
+     * 跳转在线咨询聊天页
+     * 参数与客服页 / 商品详情 goChat 保持一致(不含商品信息)
+     */
+    goChatPage() {
+      if (isNaN(parseInt(this.loginInfo && this.loginInfo.id))) {
+        this.$msg('登录用户数据异常,请稍后再试')
+        return
+      }
+      const shop = this.shopInfo || uni.getStorageSync('currentShop') || {}
+      const customId = Number(this.customId) || Number((shop.custom && shop.custom.id) || 0)
+      const shopId = shop.id || shop.shopId || shop.account || uni.getStorageSync('account') || 0
+      if (isNaN(parseInt(customId)) || customId <= 0) {
+        this.$msg('客户数据异常,请稍后再试')
+        return
+      }
+      if (isNaN(parseInt(shopId)) || Number(shopId) <= 0) {
+        this.$msg('门店数据异常,请稍后再试')
+        return
+      }
+      const chatPerson = shop.merchantName || shop.shopName || shop.name || '客服'
+      const params = {
+        userId: this.loginInfo.id,
+        customId,
+        shopId,
+        name: this.loginInfo.name,
+        avatar: this.loginInfo.avatar,
+        chatPerson
+      }
       uni.navigateTo({
-        url: `/pages/home/service?account=${account}&hdId=${hdId}`
+        url: '/pages/chat/chatPage',
+        success(res) {
+          res.eventChannel.emit('acceptDataFromOpenerPage', params)
+        }
       })
     }
   }

+ 7 - 0
mallApp/src/pages/home/index.vue

@@ -29,6 +29,9 @@
               :show-service="showService"
               :account="account"
               :hd-id="hdId"
+              :service-wx="bannerServiceWx"
+              :custom-id="myCustomId"
+              :shop-info="shopInfo"
             />
             <home-notice-bar :account="account" />
           </view>
@@ -174,6 +177,10 @@ export default {
     showService() {
       const topNav = this.pageData && this.pageData.topNav
       return !!(topNav && topNav.enabled == 1 && topNav.customerServiceEnabled == 1)
+    },
+    /** 客服微信二维码,供轮播悬浮入口判断是否直达聊天页 */
+    bannerServiceWx() {
+      return (this.shopInfo && this.shopInfo.serviceWx) || ''
     }
   },
   methods: {