From 4363a682bd47be66e6fdd3bd33a68d96a8675814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E6=88=90=E5=BC=BA?= Date: Fri, 6 Nov 2020 15:42:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 61 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/src/App.vue b/src/App.vue index 0d2fb76..2b2422d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -13,7 +13,8 @@ export default { data () { return { active: true, - fullPage: true + fullPage: true, + dingCode: '' } }, components: { @@ -22,6 +23,12 @@ export default { ...mapState(['user']) }, async mounted () { + console.log('dd: ', dd) + if (!dd.other) { + await this.handleGetDingtalkCode() + await this.handleDingtalkLogin() + } + this.GET_DEPLIST() }, methods: { @@ -31,34 +38,36 @@ export default { ...mapActions(['GET_DEPLIST', 'SET_USER_INFO']), // 获取钉钉鉴权码 handleGetDingtalkCode () { - let _this = this - dd.runtime.permission.requestAuthCode({ - corpId: 'ding267474e759bbca1c35c2f4657eb6378f', - onSuccess (res) { - console.log('result===', res) - _this.handleDingtalkLogin(res) - _this.dingCode = res - }, - onFail (err) { - console.log('err===', err) - _this.dingCode = err - } + return new Promise((resolve, reject) => { + let _this = this + dd.runtime.permission.requestAuthCode({ + corpId: 'ding267474e759bbca1c35c2f4657eb6378f', + onSuccess (res) { + console.log('result===', res) + _this.dingCode = res + resolve() + }, + onFail (err) { + console.log('err===', err) + _this.dingCode = err + resolve() + } + }) }) }, // 钉钉免登录 - handleDingtalkLogin (val) { - apiDingtalkLogin(val).then(res => { - if (res && res.code === 0) { - this.$cookies.set('token', res.token) - this.handleInfo() - this.dataForm.verify = '登录成功,跳转中...' - window.open(window.location.protocol + '//' + window.location.host + '/digitization/kpi/workbench/home?code=' + this.dingCode.code) - } else { - this.dataForm.verify = '身份验证失败' + res.msg - this.$message.error(this.dataForm.verify) - this.$router.replace({ name: 'dingTalkLogin' }) - } - }) + async handleDingtalkLogin (val = this.dingCode) { + const res = await apiDingtalkLogin(val) + if (res && res.code === 0) { + this.$cookies.set('token', res.token) + await this.handleInfo() + this.dataForm.verify = '登录成功,跳转中...' + window.open(window.location.protocol + '//' + window.location.host + '/digitization/kpi/workbench/home?code=' + this.dingCode.code) + } else { + this.dataForm.verify = '身份验证失败' + res.msg + this.$message.error(this.dataForm.verify) + this.$router.replace({ name: 'dingTalkLogin' }) + } }, // 获取用户信息 async handleInfo () {