Selaa lähdekoodia

fix: 兼容企微授权回调参数读取

补充从浏览器地址查询参数中兜底读取 code,兼容 H5 hash 路由下企业微信授权回跳后的参数解析。

Made-with: Cursor
haifeng.zhang 4 tuntia sitten
vanhempi
commit
e0a22d1b4a
1 muutettua tiedostoa jossa 16 lisäystä ja 0 poistoa
  1. 16 0
      src/pages/home/index.vue

+ 16 - 0
src/pages/home/index.vue

@@ -13,6 +13,14 @@ const authInfoText = ref('');
 const shouldShowAuthInfoPopup = ref(false);
 const externalContactPopupVisible = ref(false);
 const externalContactPopupText = ref('');
+
+const getCodeFromLocation = () => {
+  if (typeof window === 'undefined') return ''
+
+  const searchParams = new URLSearchParams(window.location.search)
+  return searchParams.get('code') || ''
+}
+
 onLoad(async (option) => {
   if (option && option.code) {
     const { code } = option;
@@ -21,6 +29,14 @@ onLoad(async (option) => {
   }
 
   if (!codeParams.value) {
+    const codeFromLocation = getCodeFromLocation()
+    if (codeFromLocation) {
+      codeParams.value = codeFromLocation
+      shouldShowAuthInfoPopup.value = true;
+    }
+  }
+
+  if (!codeParams.value) {
     showNotify({ type: 'warning', message: '缺少企业微信授权参数,请重新进入页面' });
     return;
   }