1、在main.js中引入
import * as dd from 'dingtalk-jsapi';Vue.prototype.$dd = dd;
2、在login.vue页面中获取用户信息
<template><div></div></template><script>// 方案一 在.vue中引入// import * as dd from 'dingtalk-jsapi'; // 使用dd.### dd.env.platform// 方案二 在main.js中引入// 方案二:使用this.$dd.### this.$dd.env.platformexport default {data() {return {code: "",};},mounted() {this.autoLogin();},methods: {autoLogin() {this.$dd.device.notification.showPreloader({text: "使劲加载中..",showIcon: true,});var _this = this;this.$dd.ready(() => {this.$dd.runtime.permission.requestAuthCode({corpId: " ", // 企业的钉钉id 唯一值,写死onSuccess: function (info) {_this.code = info.code; // 经过该免登受权码能够获取用户身份_this.getUserInfo(info.code)//拿到用户钉钉的code信息传给后端获取用户信息},onFail: function (err) {this.$dd.device.notification.toast({icon: false,text: "用户信息获取失败",duration: 2,delay: 0,});}});});},getUserInfo(code) {this.$store.dispatch("user/getUser", code).then((res) => {if (res == 'ok') {this.$dd.device.notification.hidePreloader({onSuccess: function (res) {// 调用成功时回调console.log(res)},onFail: function (err) {// 调用失败时回调console.log(err)}});// 用户信息获取成功后跳转页面this.$router.replace({ path: "/contract-list" });}}).catch(err => {});},}};</script><style lang="scss" scoped></style>