1.npm install dingtalk-jsapi --save
2. import * as dd from 'dingtalk-jsapi';
3.调用钉钉免登陆API
// 获取code getCode() { dd.getAuthCode({ corpId: 'ding************', success: (res) => { console.log('获取新的免登码成功', res); const code = res.code console.log('code', code); this.getToken(code) }, fail: (res) => { console.log('获取免登码失败', res); }, complete: () => { }, }); },
// 获取token getToken(code) { getCode(code).then(res => { console.log('res', res.token); if (res.token) { setToken(res.token) this.$store.commit('SET_TOKEN', res.token) // this.$router.push({ path: '/index' }); // 判断当前用户是否已拉取完user_info信息 this.$store.dispatch('GetInfo').then((res) => { this.$store.dispatch('GenerateRoutes').then(accessRoutes => { // 根据roles权限生成可访问的路由表 router.addRoutes(accessRoutes) // 动态添加可访问路由表 this.init() }) }) } else { this.$message.error(res.message) } }) },