yanghao 1 週間 前
コミット
6432a0170e
3 ファイル変更28 行追加28 行削除
  1. 2 2
      .env
  2. 14 14
      src/router/index.ts
  3. 12 12
      src/views/login.vue

+ 2 - 2
.env

@@ -1,6 +1,6 @@
 VITE_APP_TITLE='科瑞石油技术门户网站'
 
 VITE_DINGTALK_APP_ID='dingmr9ez0ecgbmscfeb'
-VITE_DINGTALK_REDIRECT_URI='https://iot.deepoil.cc/login?loginType=dingding&type=20'
+VITE_DINGTALK_REDIRECT_URI='https://iot.deepoil.cc:5172/login?loginType=dingding&type=20'
 
-VITE_BASE_URL='http://iot.deepoil.cc:5172'
+VITE_BASE_URL='http://iot.deepoil.cc:5172'

+ 14 - 14
src/router/index.ts

@@ -71,20 +71,20 @@ router.beforeEach(async (to, from, next) => {
     }
   } else {
     if (whiteList.indexOf(to.path) !== -1) {
-      // const code = to.query.code;
-      // if (code) {
-      //   const res = await socialLogin(
-      //     "20",
-      //     typeof code === "string" ? code : "",
-      //     "22"
-      //   );
-      //   console.log(">>>>>>>>>>>>>>>>>>>>>>>>>", res);
-      //   authUtil.setToken(res);
-      //   next({ path: "/" });
-      // } else {
-      //   next(); // 正常导航
-      // }
-      next();
+      const code = to.query.code;
+      if (code) {
+        const res = await socialLogin(
+          "20",
+          typeof code === "string" ? code : "",
+          "22"
+        );
+        console.log(">>>>>>>>>>>>>>>>>>>>>>>>>", res);
+        authUtil.setToken(res);
+        next({ path: "/" });
+      } else {
+        next(); // 正常导航
+      }
+      // next();
     } else {
       next(`/login`);
     }

+ 12 - 12
src/views/login.vue

@@ -140,21 +140,21 @@ const handleMsg = (state?: string) => {
     if (event.origin === "https://login.dingtalk.com") {
       let loginTmpCode = event.data;
       console.log("收到钉钉扫码登录消息:", loginTmpCode);
-      // window.location.href =
-      //   "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=" +
-      //   import.meta.env.VITE_DINGTALK_APP_ID +
-      //   "&response_type=code&scope=snsapi_login&state=" +
-      //   state +
-      //   "&redirect_uri=" +
-      //   import.meta.env.VITE_DINGTALK_REDIRECT_URI +
-      //   "&loginTmpCode=" +
-      //   loginTmpCode;
+      window.location.href =
+        "https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=" +
+        import.meta.env.VITE_DINGTALK_APP_ID +
+        "&response_type=code&scope=snsapi_login&state=" +
+        state +
+        "&redirect_uri=" +
+        import.meta.env.VITE_DINGTALK_REDIRECT_URI +
+        "&loginTmpCode=" +
+        loginTmpCode;
 
-      const res = await socialLogin("10", loginTmpCode as string, state!);
+      // const res = await socialLogin("20", loginTmpCode as string, "22");
 
-      console.log("登录结果:", res);
+      // console.log("登录结果:", res);
 
-      authUtil.setToken(res);
+      // authUtil.setToken(res);
     }
   };
 };