Browse Source

优化 WeChat 环境判断

cc12458 1 month ago
parent
commit
7916e44a9e
2 changed files with 9 additions and 6 deletions
  1. 2 3
      src/modules/chat/HospitalGuide.vue
  2. 7 3
      src/tools/url.ts

+ 2 - 3
src/modules/chat/HospitalGuide.vue

@@ -32,8 +32,7 @@ tryOnBeforeMount(() => {
     navProps.leftArrow = true;
     navProps.leftText = '返回';
     searchParams.delete('back');
-  }
-  if (isWechat()) navProps.show = false;
+  } else if (isWechat()) navProps.show = false;
   register(searchParams);
 });
 
@@ -133,7 +132,7 @@ const { send: register } = useRequest(guideRegisterSessionMethod, { immediate: f
 
 <template>
   <chart-messages class="hospital-guide-wrapper" ref="chat-messages">
-    <template #chat-header>
+    <template #chat-header v-if="navProps.show">
       <van-nav-bar v-bind="navProps" @click-left="back()" />
     </template>
   </chart-messages>

+ 7 - 3
src/tools/url.ts

@@ -10,12 +10,16 @@ export function getClientURL(value: string, origin?: string) {
 }
 
 export function isFrameOpen() {
-  return window.parent !== window
+  return window.parent !== window;
 }
 
 export function isWechat() {
-  const userAgent = navigator.userAgent;
-  return userAgent.indexOf('miniprogram') > -1 && ( userAgent.indexOf('wx') || userAgent.indexOf('wechat') );
+  const userAgent = navigator.userAgent.toLowerCase();
+  return userAgent.includes('wx') || userAgent.includes('wechat') || userAgent.includes('micromessenger');
+}
+
+export function isWechatMiniprogram() {
+  return isWechat() && navigator.userAgent.toLowerCase().includes('miniprogram');
 }
 
 export function getBackReferrerUrl() {