yanghao 1 týždeň pred
rodič
commit
4a3e0aee81
5 zmenil súbory, kde vykonal 32 pridanie a 30 odobranie
  1. 2 2
      .env
  2. 3 3
      src/api/user.ts
  3. 1 0
      src/config/axios/service.ts
  4. 14 13
      src/router/index.ts
  5. 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='http://1.94.244.160:5172/login?loginType=dingding&type=20'
+VITE_DINGTALK_REDIRECT_URI='https://iot.deepoil.cc/login?loginType=dingding&type=20'
 
-VITE_BASE_URL='http://1.94.244.160:6080'
+VITE_BASE_URL='http://iot.deepoil.cc:5172'

+ 3 - 3
src/api/user.ts

@@ -1,9 +1,9 @@
 import request from "@/config/axios";
 
 // 钉钉扫码登录
-export function socialLogin(type: string, code: string, state: string) {
-  return request.post({
-    url: "/system/auth/social-login",
+export async function socialLogin(type: string, code: string, state: string) {
+  return await request.post({
+    url: "/admin-api/system/auth/social-login",
     data: {
       type,
       code,

+ 1 - 0
src/config/axios/service.ts

@@ -48,6 +48,7 @@ const service: AxiosInstance = axios.create({
 // request拦截器
 service.interceptors.request.use(
   (config: InternalAxiosRequestConfig) => {
+    config.headers["tenant-id"] = 1;
     // 是否需要设置 token
     let isToken = (config!.headers || {}).isToken === false;
     whiteList.some((v) => {

+ 14 - 13
src/router/index.ts

@@ -71,19 +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(); // 正常导航
-      }
+      // 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("10", loginTmpCode as string, state!);
 
-      // console.log("登录结果:", res);
+      console.log("登录结果:", res);
 
-      // authUtil.setToken(res);
+      authUtil.setToken(res);
     }
   };
 };