Bladeren bron

飞书手动授权登录

huwei 2 weken geleden
bovenliggende
commit
d480cf7549
2 gewijzigde bestanden met toevoegingen van 28 en 8 verwijderingen
  1. 6 1
      server/internal/admin/api/admin_user.go
  2. 22 7
      web/src/components/FeiShu/FeishuLoginQR.vue

+ 6 - 1
server/internal/admin/api/admin_user.go

@@ -149,7 +149,9 @@ type AdminIamServer struct {
 }
 
 func (s *AdminIamServer) CheckToken(ctx context.Context, req *iam.CheckTokenReq) (*iam.CheckTokenResp, error) {
-	resp := &iam.CheckTokenResp{}
+	resp := &iam.CheckTokenResp{
+		Data: &iam.AdminUserInfo{},
+	}
 	tokenKey := config.GetTokenKey(req.GetToken())
 	if config.TokenRedis.Exists(tokenKey).Val() == 0 {
 		resp.Code = consts.CodeCheckLogin
@@ -223,6 +225,7 @@ func (s *AdminIamServer) BatchGetAdminUser(ctx context.Context, req *iam.BatchGe
 	if err != nil {
 		resp.Code = 1
 		resp.Msg = err.Error()
+		resp.Data = []*iam.AdminUserInfo{}
 	} else {
 		resp.Data = users
 	}
@@ -236,6 +239,7 @@ func (s *AdminIamServer) GetAdminUserByNickName(ctx context.Context, req *iam.Ge
 	if err != nil {
 		resp.Code = 1
 		resp.Msg = err.Error()
+		resp.Data = &iam.AdminUserInfo{}
 	} else {
 		resp.Data = user
 	}
@@ -249,6 +253,7 @@ func (s *AdminIamServer) GetRoleSystems(ctx context.Context, req *iam.GetRoleSys
 	if err != nil {
 		resp.Code = 1
 		resp.Msg = err.Error()
+		resp.Data = []*iam.SystemInfo{}
 	} else {
 		resp.Data = systems
 	}

+ 22 - 7
web/src/components/FeiShu/FeishuLoginQR.vue

@@ -1,6 +1,7 @@
 <template>
   <div id="login-text">飞书扫码登录</div>
   <div id="login-container"></div>
+  <div id="login-click-text"> 扫码不便,<a @click="handleClickLogin">点击登录</a> </div>
 </template>
 
 <script lang="ts">
@@ -9,20 +10,28 @@
   export default {
     name: 'FeishuLoginQR',
     data() {
-      return {};
+      const { VITE_GLOB_FEISHU_APPID, VITE_GLOB_FEISHU_REDIRECTURI } = getFeiShuConfig();
+      const redirectUri = encodeURIComponent(VITE_GLOB_FEISHU_REDIRECTURI);
+      const gotoUrl = `https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=${VITE_GLOB_FEISHU_APPID}&redirect_uri=${redirectUri}&response_type=code&state=STATE`;
+      return {
+        gotoUrl,
+      };
     },
     mounted() {
       this.initQRCodeLogin();
     },
     methods: {
+      handleClickLogin() {
+        window.open(this.gotoUrl, '_self');
+      },
+
       initQRCodeLogin() {
-        const { VITE_GLOB_FEISHU_APPID, VITE_GLOB_FEISHU_REDIRECTURI } = getFeiShuConfig();
-        const redirectUri = encodeURIComponent(VITE_GLOB_FEISHU_REDIRECTURI);
-        const gotoUrl = `https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=${VITE_GLOB_FEISHU_APPID}&redirect_uri=${redirectUri}&response_type=code&state=STATE`;
-        console.log('=======gotoUrl', gotoUrl);
+        // const { VITE_GLOB_FEISHU_APPID, VITE_GLOB_FEISHU_REDIRECTURI } = getFeiShuConfig();
+        // const redirectUri = encodeURIComponent(VITE_GLOB_FEISHU_REDIRECTURI);
+        // const gotoUrl = `https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=${VITE_GLOB_FEISHU_APPID}&redirect_uri=${redirectUri}&response_type=code&state=STATE`;
         const QRLoginObj = window.QRLogin({
           id: 'login-container',
-          goto: gotoUrl,
+          goto: this.gotoUrl,
           width: '300',
           height: '300',
         });
@@ -32,7 +41,7 @@
           if (QRLoginObj.matchOrigin(event.origin) && QRLoginObj.matchData(event.data)) {
             const loginTmpCode = event.data.tmp_code;
             // 在授权页面地址上拼接上参数 tmp_code,并跳转
-            window.location.href = `${gotoUrl}&tmp_code=${loginTmpCode}`;
+            window.location.href = `${this.gotoUrl}&tmp_code=${loginTmpCode}`;
           }
         };
         if (typeof window.addEventListener != 'undefined') {
@@ -58,4 +67,10 @@
     margin-top: 10px;
     font-size: 14px;
   }
+
+  #login-click-text {
+    text-align: center;
+    margin-top: 10px;
+    font-size: 14px;
+  }
 </style>