diff --git a/src/pages/login.vue b/src/pages/login.vue index cb39a8b9..2a3bd8ef 100644 --- a/src/pages/login.vue +++ b/src/pages/login.vue @@ -51,54 +51,46 @@ export default { handleLogin() { this.$refs.loginForm.validate(v => { if (v) { - let {name: module, libPath} = this.currentApp, - corpId = 'ww596787bb70f08288' - if (/\/project\/police\//.test(libPath)) { - module = 'hnjc' - } else if (/\/project\/saas\//.test(libPath)) { - module = 'online' - } else if (/\/project\/xincheng\//.test(libPath)) { - module = 'xaxc' - } else if (/\/project\/beta\//.test(libPath)) { - corpId = 'ww2a667717a70164f1' - module = 'wangge' - } - this.setModule(module) - this.getToken({...this.form, module, corpId}).then(() => { - if (module != 'AppCountryAlbum') { - this.getAccount({module}) - } - this.target ? uni.reLaunch({url: this.target}) : uni.navigateBack({}) - }).catch(() => 0) + this.handleSignIn({...this.form, module, corpId}) } }) }, handleLogout() { this.$http.delete("/auth/token/logout").finally(() => this.logout()) + }, + handleSignIn(params) { + this.getSystem().then(({module, corpId}) => this.getToken({...params, module, corpId}).then(() => { + if (module != 'AppCountryAlbum') { + this.getAccount({module}) + } + this.target ? uni.reLaunch({url: this.target}) : uni.navigateBack({}) + }).catch(() => 0)) + }, + getSystem() { + let {name: module, libPath} = this.currentApp, + corpId = 'ww596787bb70f08288' + if (/\/project\/police\//.test(libPath)) { + module = 'hnjc' + } else if (/\/project\/saas\//.test(libPath)) { + module = 'online' + } else if (/\/project\/xincheng\//.test(libPath)) { + module = 'xaxc' + } else if (/\/project\/beta\//.test(libPath)) { + corpId = 'ww2a667717a70164f1' + module = 'wangge' + } + this.setModule(module) + return {corpId, module} } }, onShow() { if (/wxwork/.test(navigator.userAgent)) { //在企微端 if (this.$route.query.code) { - let {name: module, libPath} = this.currentApp, - corpId = 'ww596787bb70f08288' - if (/\/project\/police\//.test(libPath)) { - module = 'hnjc' - } else if (/\/project\/beta\//.test(libPath)) { - corpId = 'ww2a667717a70164f1' - module = 'wangge' - } - let {code} = this.$route.query - this.getToken({code}).then(() => { - if (module != 'AppCountryAlbum') { - this.getAccount({module}) - } - this.target ? uni.reLaunch({url: this.target}) : uni.navigateBack({}) - }).catch(err => { - this.err = err - }) + const {code} = this.$route.query + this.handleSignIn({code}) } else { + this.getSystem() this.getCode().catch(err => { this.err = err })