Browse Source

调整移动端企业微信登录的问题

Lijy 2 years ago
parent
commit
541ebdffca

+ 106 - 85
fhKeeper/formulahousekeeper/timesheet_h5/src/views/index/index.vue

@@ -50,84 +50,88 @@
             //     document.head.appendChild(consoleScript);
             // }
             // console.log('userNameNeedTranslate',window.location.href);
-            if(this.user.userNameNeedTranslate == '1'){
-                this.agentConfig()
-            }
-            var ua = navigator.userAgent.toLowerCase();
-            if (ua.indexOf("wxwork") > 0) {
-                this.isCorpWX = true;
-            } else if (ua.indexOf("micromessenger") > 0) {
-                this.isWX = true;
-            }
-
-            if (this.user.company.packageEngineering == 1) {
-                this.routers.push(
-                {
-                    name: '专业审核',
-                    url: '/profession_review',
-                    icon: 'todo-list-o'
-                });
+            let that = this
+            if (localStorage.userInfo != null) {
+                that.getAccountInfo();
             }
-            var list = this.user.moduleList
-            for (var i in list) {
-                if(list[i].name == '工时报告') {
-                    this.routers.push({name: '查看日报',url: '/calendar',icon: 'description'})
-                    this.routers.push({name: '填写日报',url: '/edit',icon: 'edit'})
-                    // if (this.user.companyId == 817 || this.user.companyId == 7 || this.user.companyId == 10) {
-                        this.routers.push({name: '按周填报',url: '/weekEdit',icon: 'records'})
-                    // }
-                }
-                if(list[i].name == '待办任务') {
-                    this.routers.push({
-                        name: '待办任务',
-                        url: '/task',
-                        icon: 'coupon-o'
-                    });
+            that.getModule()
+            that.getMessage();
+            that.bindIfNessary();
+        },
+        components: {
+            Footer
+        },
+        methods: {
+            // 模块
+            getModule() {
+                if(this.user.userNameNeedTranslate == '1'){
+                    this.agentConfig()
                 }
-                if(list[i].name == '项目报告审核') {
-                    this.routers.push({name: '项目报告审核',url: '/review',icon: 'todo-list-o'})
+                var ua = navigator.userAgent.toLowerCase();
+                if (ua.indexOf("wxwork") > 0) {
+                    this.isCorpWX = true;
+                } else if (ua.indexOf("micromessenger") > 0) {
+                    this.isWX = true;
                 }
-                if(list[i].name == '项目管理') {
-                    this.routers.push({name: '项目管理',url: '/project',icon: 'label-o'})
+
+                if (this.user.company.packageEngineering == 1) {
+                    this.routers.push(
+                    {
+                        name: '专业审核',
+                        url: '/profession_review',
+                        icon: 'todo-list-o'
+                    });
                 }
-                if(list[i].name == '导入日报审核') {
-                    this.routers.push({name: '导入日报审核',url: '/audit',icon: 'label-o'})
+                var list = this.user.moduleList
+                for (var i in list) {
+                    if(list[i].name == '工时报告') {
+                        this.routers.push({name: '查看日报',url: '/calendar',icon: 'description'})
+                        this.routers.push({name: '填写日报',url: '/edit',icon: 'edit'})
+                        // if (this.user.companyId == 817 || this.user.companyId == 7 || this.user.companyId == 10) {
+                            this.routers.push({name: '按周填报',url: '/weekEdit',icon: 'records'})
+                        // }
+                    }
+                    if(list[i].name == '待办任务') {
+                        this.routers.push({
+                            name: '待办任务',
+                            url: '/task',
+                            icon: 'coupon-o'
+                        });
+                    }
+                    if(list[i].name == '项目报告审核') {
+                        this.routers.push({name: '项目报告审核',url: '/review',icon: 'todo-list-o'})
+                    }
+                    if(list[i].name == '项目管理') {
+                        this.routers.push({name: '项目管理',url: '/project',icon: 'label-o'})
+                    }
+                    if(list[i].name == '导入日报审核') {
+                        this.routers.push({name: '导入日报审核',url: '/audit',icon: 'label-o'})
+                    }
+                    if(list[i].name == '费用报销') {
+                        this.routers.push({
+                            name: '费用报销',
+                            url: '/expense',
+                            icon: 'balance-list-o'
+                        });
+                    }
                 }
-                if(list[i].name == '费用报销') {
-                    this.routers.push({
-                        name: '费用报销',
-                        url: '/expense',
-                        icon: 'balance-list-o'
+                if (this.user.manageDeptId != 0 && this.user.company.packageEngineering == 1) {
+                    this.routers.push(
+                    {
+                        name: '部门审核',
+                        url: '/department_review',
+                        icon: 'todo-list-o'
                     });
                 }
-            }
-            if (this.user.manageDeptId != 0 && this.user.company.packageEngineering == 1) {
-                this.routers.push(
-                {
-                    name: '部门审核',
-                    url: '/department_review',
-                    icon: 'todo-list-o'
-                });
-            }
-            
-            this.routers.push({
-                                name: '消息记录',
-                                url: '/msg',
-                                icon: 'todo-list-o',
-                                info: this.unreadNum
-                            });
+                
+                this.routers.push({
+                                    name: '消息记录',
+                                    url: '/msg',
+                                    icon: 'todo-list-o',
+                                    info: this.unreadNum
+                                });
+            },
 
-            
-            this.getMessage();
-            this.bindIfNessary();
-            if (localStorage.userInfo != null) {
-                this.getAccountInfo();
-            }
-        },
-        components: {
-            Footer
-        },
-        methods: {
             // 获取企业微信参数
             agentConfig(){
                 let curUrl = window.location.href.split('#')[0]
@@ -188,22 +192,37 @@
 
             //获取账户信息
             getAccountInfo() {
-                this.$axios.get('/user/loginByUserId', {params:{userId: this.user.id}})
-                            .then(res => {
-                                // console.log(res);
-                                if (res.code == 'error') {
-                                    localStorage.errorMsg = res.msg;
-                                    //账号信息有问题,不能使用。
-                                    this.$router.push("/error");
-                                } else {
-                                    
-                                    localStorage.userInfo = JSON.stringify(res.data);
-                                    this.user = res.data;
-                                } 
-                            }).catch(err=> {
-                                alert('err=' + err);
-                            });
+                let userId = this.user.id
+                if(window.location.href.indexOf('userId') != '-1') {
+                    let href = window.location.href;
+                    var loginUserId = href.substring(href.indexOf("userId=")+"userId=".length);
+                    if (loginUserId.includes('#/')) {
+                        loginUserId = loginUserId.substring(0, loginUserId.indexOf('#/'));
+                    }
+                    userId = loginUserId
+                }
+                if(window.location.href.indexOf('errorMsg') != '-1') {
+                    let err = window.location.href.split('errorMsg=')[1]
+                    let str = err.split('#/')[0]
+                    this.$router.push("/error");
+                }
+                this.$axios.get('/user/loginByUserId', {params:{userId: userId}})
+                .then(res => {
+                    // console.log(res);
+                    if (res.code == 'error') {
+                        localStorage.errorMsg = res.msg;
+                        //账号信息有问题,不能使用。
+                        this.$router.push("/error");
+                    } else {
+                        
+                        localStorage.userInfo = JSON.stringify(res.data);
+                        this.user = res.data;
+                    } 
+                }).catch(err=> {
+                    alert('err=' + err);
+                });
             },
+
             bindIfNessary() {
                 let href = window.location.href;
                 var requestUrl = "";
@@ -259,6 +278,7 @@
                     }
                 }
             },
+
             //获取消息
             getMessage() {
                 this.$axios.post("/information/list", {
@@ -272,6 +292,7 @@
                     } 
                 }).catch(err=> {this.$toast.clear();});
             },
+
         },
         activated(){
             this.getMessage()

+ 10 - 4
fhKeeper/formulahousekeeper/timesheet_h5/src/views/login/index.vue

@@ -144,7 +144,8 @@
                                     //获取openId
                                     if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
                                                 || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
-                                        localStorage.userInfo = JSON.stringify(res.data);
+                                        // localStorage.userInfo = JSON.stringify(res.data);
+                                        localStorage.setItem('userInfo', JSON.stringify(res.data))
                                         console.log('绑定成功');
                                         this.user = res.data;
                                         window.location.href = '/#/my/center';
@@ -160,6 +161,7 @@
                 }
             },
             tryAutoLogin() {
+                console.log('第三方回调')
                 var appId = "ww4e237fd6abb635af";//企业微信第三方的SUIT ID
                 var url = "http://worktime.ttkuaiban.com/api/corpWXAuth";//授权回调页面
                 var weixinUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+encodeURI(url)+"&response_type=code&scope=snsapi_base&state=0#wechat_redirect";
@@ -172,14 +174,17 @@
                         if (res == null) {
 
                         } else if(res.errcode != null) {
-                            
+
                         } else {
                             //获取openId
                             if (res.data != null) {
+                                // alert('赋值成功' + JSON.stringify(res.data))
+                                localStorage.setItem('userInfo', JSON.stringify(res.data))
                                 this.$store.commit("updateLogin", true);
-                                localStorage.userInfo = JSON.stringify(res.data);
                                 this.user = res.data;
-                                window.location.href = '/#/index';
+                                // alert('本地存储的值' + localStorage.getItem('userInfo'))
+                                // window.location.href = '/#/index';
+                                this.$router.push("/index");
                             }
                         }
                     }).catch(err=> {
@@ -212,6 +217,7 @@
                 if (localStorage.userInfo != null && !this.isCorpWX) {
                     this.$router.push("/index").catch(err => { console.log(err, '错误5')});
                 } else {
+                    console.log('判断企业微信是否授权',this.isCorpWX || this.isWX)
                     if (this.isCorpWX || this.isWX) {
                         //判断企业微信,是否存在授权
                         if (href.includes("com/?code")) {