Browse Source

Merge branch 'iteration-20250225-use-code' into jenkins-test

lex-xin 4 weeks ago
parent
commit
66b61f876f

+ 2 - 2
src/hooks/useAuthCode/index.ts

@@ -138,12 +138,12 @@ export default function useAuthCode() {
 
     if (!code && !weChatCode.value) {
       console.warn('没有获取到微信Code');
-      return;
+      return '';
     }
 
     await getAppId();
     if (!wxAppId.value) {
-      return;
+      return '';
     }
     const { data } = await request.post(
       '/edu-app/open/paramConfig/wechatOpenId',

+ 44 - 25
src/router/router-root.ts

@@ -1,20 +1,44 @@
 // 不需要登录的路由
 export default [
   {
-    path: '/student-register',
-    name: 'student-register',
-    component: () => import('@/views/student-register/index'),
-    meta: {
-      title: '报名通道'
-    }
-  },
-  {
-    path: '/student-register-apply',
-    name: 'student-register-apply',
-    component: () => import('@/views/student-register/index-apply'),
-    meta: {
-      title: ''
-    }
+    //需要微信授权页面 微信授权
+    path: '/wx-auth',
+    name: 'wx-auth',
+    component: () => import('@/views/layout/wx-auth'),
+    children: [
+      {
+        path: '/intention-questionnaire',
+        name: 'intention-questionnaire',
+        component: () => import('@/views/intention-questionnaire/index'),
+        meta: {
+          title: '音乐(器乐)课堂数字化转型调查问卷'
+        }
+      },
+      {
+        path: '/pre-register-active',
+        name: 'pre-register-active',
+        component: () => import('@/views/pre-register-active/index'),
+        meta: {
+          title: '音乐数字化转型家长说明会'
+        }
+      },
+      {
+        path: '/student-register',
+        name: 'student-register',
+        component: () => import('@/views/student-register/index'),
+        meta: {
+          title: '报名通道'
+        }
+      },
+      {
+        path: '/student-register-apply',
+        name: 'student-register-apply',
+        component: () => import('@/views/student-register/index-apply'),
+        meta: {
+          title: ''
+        }
+      }
+    ]
   },
   {
     path: '/student-register-form',
@@ -268,21 +292,24 @@ export default [
   },
   {
     path: '/activationRegistration',
-    component: () => import('@/views/activation-code/instrument-registration/new-index'),
+    component: () =>
+      import('@/views/activation-code/instrument-registration/new-index'),
     meta: {
       title: '数字化转型报名'
     }
   },
   {
     path: '/activationRegistrationDetail',
-    component: () => import('@/views/activation-code/instrument-registration/detail'),
+    component: () =>
+      import('@/views/activation-code/instrument-registration/detail'),
     meta: {
       title: '数字化转型报名'
     }
   },
   {
     path: '/activationRegister',
-    component: () => import('@/views/activation-code/activation-register/index'),
+    component: () =>
+      import('@/views/activation-code/activation-register/index'),
     meta: {
       title: '音乐数字课堂AI学练工具激活'
     }
@@ -295,14 +322,6 @@ export default [
     }
   },
   {
-    path: '/pre-register-active',
-    name: 'pre-register-active',
-    component: () => import('@/views/pre-register-active/index'),
-    meta: {
-      title: '音乐数字化转型家长说明会'
-    }
-  },
-  {
     path: '/pre-register-video',
     name: 'pre-register-video',
     component: () => import('@/views/pre-register-active/video'),

+ 0 - 15
src/router/routes-common.ts

@@ -245,20 +245,5 @@ export default [
       }
     ]
   },
-  {
-    path: '/wx-auth',
-    name: 'wx-auth',
-    component: () => import('@/views/layout/wx-auth'),
-    children: [
-      {
-        path: '/intention-questionnaire',
-        name: 'intention-questionnaire',
-        component: () => import('@/views/intention-questionnaire/index'),
-        meta: {
-          title: '音乐(器乐)课堂数字化转型调查问卷'
-        }
-      }
-    ]
-  },
   ...rootRouter
 ];

+ 5 - 3
src/views/layout/wx-auth.tsx

@@ -10,9 +10,10 @@ export default defineComponent({
     const authCode = useAuthCode();
     const route = useRoute();
     const loading = ref(false);
+    const error = ref(false); // 如果授权失败了也可以正常访问页面
     const openId = ref('');
     const isNeedView = computed(() => {
-      return openId.value || !browser().weixin ? true : false;
+      return openId.value || error.value || !browser().weixin ? true : false;
     });
 
     const setAuth = async () => {
@@ -32,9 +33,10 @@ export default defineComponent({
               ...route.query
             })
         );
-        console.log(openId.value, 'wx-auth-layout');
-      } catch {
+      } catch (e: any) {
         //
+        console.log(e, 'error');
+        error.value = true;
       }
       loading.value = false;
     };

+ 11 - 10
src/views/pre-register-active/index.tsx

@@ -193,16 +193,17 @@ export default defineComponent({
     };
 
     onMounted(async () => {
-      forms.openId = await authCode.getOpenId(
-        getHttpOrigin() +
-          window.location.pathname +
-          '#' +
-          route.path +
-          '?' +
-          qs.stringify({
-            ...route.query
-          })
-      );
+      // forms.openId = await authCode.getOpenId(
+      //   getHttpOrigin() +
+      //     window.location.pathname +
+      //     '#' +
+      //     route.path +
+      //     '?' +
+      //     qs.stringify({
+      //       ...route.query
+      //     })
+      // );
+      forms.openId = authCode.onWeChatCatchOpenId('GET');
       try {
         if (!forms.schoolId) {
           showToast('信息获取失败,请联系老师');

+ 11 - 55
src/views/student-register/index-apply.tsx

@@ -1299,50 +1299,6 @@ export default defineComponent({
       }
     };
 
-    // const getAppIdAndCode = async (url?: string) => {
-    //   try {
-    //     // const { data } = await request.get(
-    //     //   '/edu-app/open/paramConfig/wechatAppId'
-    //     // );
-    //     // // 判断是否有微信appId
-    //     // if (data) {
-    //     //   closeToast();
-    //     //   goWechatAuth(data, url);
-    //     // }
-    //     sessionStorage.setItem('isWxcode', '1');
-    //     closeToast();
-    //     goWechatAuthTemp('wxccc2efd2678adbe3', url)
-    //   } catch {
-    //     //
-    //   }
-    // };
-
-    // if (browser().weixin) {
-    //   //授权
-    //   const openId = sessionStorage.getItem('active-open-id');
-    //   forms.openId = openId;
-    //   const code = getUrlCode();
-    //   const isWxcode = sessionStorage.getItem('isWxcode');
-    //   if (!code || isWxcode !== '1') {
-    //     const newUrl =
-    //       getHttpOrigin() +
-    //       window.location.pathname +
-    //       '#' +
-    //       route.path +
-    //       '?' +
-    //       qs.stringify({
-    //         ...route.query
-    //       });
-    //     getAppIdAndCode(newUrl);
-    //     return '';
-    //   } else {
-    //     forms.code = code;
-    //     // 获取微信分享签名
-    //     weChatShare.getAppSignature()
-    //   }
-
-    // }
-
     const formatTimerTo = (num: number): string => {
       if (num > 9) {
         return num + '';
@@ -1438,17 +1394,17 @@ export default defineComponent({
     };
 
     onMounted(async () => {
-      const openId = await authCode.getOpenId(
-        getHttpOrigin() +
-          window.location.pathname +
-          '#' +
-          route.path +
-          '?' +
-          qs.stringify({
-            ...route.query
-          })
-      );
-      forms.openId = openId;
+      // const openId = await authCode.getOpenId(
+      //   getHttpOrigin() +
+      //     window.location.pathname +
+      //     '#' +
+      //     route.path +
+      //     '?' +
+      //     qs.stringify({
+      //       ...route.query
+      //     })
+      // );
+      forms.openId = authCode.onWeChatCatchOpenId("GET");
       try {
         // 获取支付类型
         let expireDay = null;

+ 11 - 11
src/views/student-register/index.tsx

@@ -1587,17 +1587,17 @@ export default defineComponent({
     };
 
     onMounted(async () => {
-      const openId = await authCode.getOpenId(
-        getHttpOrigin() +
-          window.location.pathname +
-          '#' +
-          route.path +
-          '?' +
-          qs.stringify({
-            ...route.query
-          })
-      );
-      forms.openId = openId;
+      // const openId = await authCode.getOpenId(
+      //   getHttpOrigin() +
+      //     window.location.pathname +
+      //     '#' +
+      //     route.path +
+      //     '?' +
+      //     qs.stringify({
+      //       ...route.query
+      //     })
+      // );
+      forms.openId = authCode.onWeChatCatchOpenId("GET");
       try {
         // 获取支付类型
         let expireDay = null;