From 89c15198a06cbcd3318d270a3e2df76eea2b4e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E6=88=90=E5=BC=BA?= Date: Mon, 16 Nov 2020 17:15:01 +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/store/modules/user.js | 9 +------- src/utils/permission.js | 46 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 54f90d8..8a868a4 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -27,18 +27,11 @@ const user = { let res = await apiUserInfo() if (res.code === 200) { commit('SET_USER_INFO', res.user) + commit('SET_USER_INFO', res.data) } else { this.$message.error(res.msg0) } }, - GET_PERMISSIONS: ({ commit }) => { - getDepList({type: 1}).then(response => { - const data = response.code === 200 ? response.data : [] - commit('SET_USER_AUTH', data) - }).catch(error => { - console.log(error) - }) - }, GET_DEPLIST: ({ commit }) => { getDepList({type: 1}).then(response => { const data = response.code === 200 ? response.data : [] diff --git a/src/utils/permission.js b/src/utils/permission.js index 19639ea..f2e2b42 100644 --- a/src/utils/permission.js +++ b/src/utils/permission.js @@ -1,6 +1,48 @@ import router from '@/router' -router.beforeEach((to, from, next) => { - next() +import store from '@/store' + +import * as dd from 'dingtalk-jsapi' +import { apiDingtalkLogin } from '@/api/login' +console.log('store: ', store) + +// 钉钉免登录 +async function handleDingtalkLogin (val) { + const res = await apiDingtalkLogin(val) + console.log('钉钉免登录res: ', res) + if (res && res.code === 200) { + this.$cookies.set('token', res.token) + return 1 + // window.open(window.location.protocol + '//' + window.location.host + '/digitization/kpi/workbench/home?code=' + this.dingCode.code) + } else { + this.$message.error('登录失败') + return 0 + } +} + +// 获取钉钉鉴权码 +function handleGetDingtalkCode () { + return new Promise((resolve, reject) => { + dd.runtime.permission.requestAuthCode({ + corpId: 'ding267474e759bbca1c35c2f4657eb6378f', + async onSuccess (res) { + console.log('result===', res) + let result = await handleDingtalkLogin(res) + resolve(result) + }, + onFail (err) { + console.log('err: ', err) + reject(err) + } + }) + }) +} +router.beforeEach(async (to, from, next) => { + if (!store.getters.userInfo.userNo && !dd.other) { + let res = await handleGetDingtalkCode() + if (res === 1) next() + } else { + next() + } }) router.afterEach(() => {