Prechádzať zdrojové kódy

移动端飞书登录

Lijy 2 rokov pred
rodič
commit
0a1b157ebf

+ 3 - 0
fhKeeper/formulahousekeeper/timesheet_h5/public/index.html

@@ -18,6 +18,9 @@
     <!-- 引入企业微信js -->
     <script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js" referrerpolicy="origin"></script>
     <script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js" referrerpolicy="origin"></script>
+    <!-- 接入飞书 -->
+    <script type="text/javascript" src="https://lf1-cdn-tos.bytegoofy.com/goofy/lark/op/h5-js-sdk-1.5.16.js"></script>
+    <!-- <script src="https://s.url.cn/qqun/qun/qqweb/m/qun/confession/js/vconsole.min.js "></script> -->
 
     <meta name="wpk-bid" content="dta_2_71020">
         <script>

+ 63 - 23
fhKeeper/formulahousekeeper/timesheet_h5/src/views/login/index.vue

@@ -217,6 +217,23 @@
                         this.$toast.fail(res.msg);
                     }
                 }).catch(err=> {this.$toast.clear();});
+            },
+            // 飞书登录
+            flyingBook(appid, code) {
+                this.$axios.post('/feishu-info/loginByFeishu', {appId: appid,code: code})
+                .then(res => {
+                    if(res.code == "ok") {
+                        let user = res.data;
+                        this.$store.commit("updateLogin", true);
+                        localStorage.userInfo = JSON.stringify(user);
+                        
+                        this.$router.push("/index").catch(err => { console.log(err, '错误3')});
+                        //强制刷新,避免index页面中的mounted不执行
+                        // window.location.reload();
+                    } else {
+                        this.$toast.fail(res.msg);
+                    }
+                }).catch(err=> {this.$toast.clear();});
             }
         },
         created() {
@@ -274,33 +291,56 @@
                         
                     } else {
                         //检查环境,如果是钉钉有$CORPID$
-                        
-                        var key = '?corpid=';
-                        var jumpkey = '&jumpto=';
-                        var url = location.href;
-                        var that = this;
-                        if (url.indexOf(key) > 0) {
-                            var corpId = ''
-                            if(url.indexOf(jumpkey) > 0){
-                                corpId = url.substring(url.indexOf(key)+key.length,url.indexOf(jumpkey));
-                            }else{
-                                corpId = url.substring(url.indexOf(key)+key.length,url.indexOf('#'));
+                        if(href.indexOf("corpid") > 0) {
+                            var key = '?corpid=';
+                            var jumpkey = '&jumpto=';
+                            var url = location.href;
+                            var that = this;
+                            if (url.indexOf(key) > 0) {
+                                var corpId = ''
+                                if(url.indexOf(jumpkey) > 0){
+                                    corpId = url.substring(url.indexOf(key)+key.length,url.indexOf(jumpkey));
+                                }else{
+                                    corpId = url.substring(url.indexOf(key)+key.length,url.indexOf('#'));
+                                }
+                                alert('钉钉登录==='+corpId);
+                                this.isDingding = true
+                                dd.ready(function() {
+                                    dd.runtime.permission.requestAuthCode({
+                                        corpId: corpId, // 企业id
+                                        onSuccess: function (info) {
+                                            var code = info.code // 通过该免登授权码可以获取用户身份
+                                            that.loginByCode(code, corpId);
+                                        }});
+                                });
+                            } 
+                        } else {
+                            // 飞书登陆
+                            if(href.indexOf("appId") > 0) {
+                                console.log('执行到这里---飞书')
+                                let arr = href.split('appId=')[1]
+                                let str = arr.split('#')[0]
+                                console.log(str, window)
+                                window.h5sdk.ready(() => { // ready方法不需要每次都调用
+                                    tt.requestAuthCode({
+                                    appId: str,
+                                    success: (info) => {
+                                        console.info(info.code, '飞书 code')
+                                        this.flyingBook(str, info.code)
+                                    },
+                                    fail: (error) => {
+                                        console.error(error)
+                                    }
+                                    });
+                                });
                             }
-                            alert('钉钉登录==='+corpId);
-                            this.isDingding = true
-                            dd.ready(function() {
-                                dd.runtime.permission.requestAuthCode({
-                                    corpId: corpId, // 企业id
-                                    onSuccess: function (info) {
-                                        var code = info.code // 通过该免登授权码可以获取用户身份
-                                        that.loginByCode(code, corpId);
-                                    }});
-                            });
-                        } 
+
+                        }
+
                     }
                 }
             }
-        }
+        },
     };
 </script>