提交 b34e883f 编写于 作者: KK's avatar KK

钉钉认证

上级 a69be6a9
<template>
<ion-page :className="{ 'app-login': true }">
<ion-content fullscreen>
<ion-content fullscreen v-if="!platform">
<div class="app-login-contant">
<img src="assets/images/logo.png" class="ibizLogo"/>
<form class="app-login-form">
......@@ -30,7 +30,8 @@
import { Vue, Component } from "vue-property-decorator";
import { Loading } from '@/ibiz-core/utils';
import { Environment } from '@/environments/environment';
import { ThirdPartyService } from '@ibiz-core'
import { DingTalkService } from '../../ibiz-core/third-party-service/DingTalkService';
@Component({
components: {},
i18n: {
......@@ -53,6 +54,18 @@ import { Environment } from '@/environments/environment';
}
})
export default class Login extends Vue {
/**
* 第三方服务
*
* @type {string}
* @memberof Login
*/
public thirdPartyService:ThirdPartyService = ThirdPartyService.getInstance();
public platform:any = "";
/**
* 用户名
*
......@@ -61,6 +74,36 @@ export default class Login extends Vue {
*/
public username: string = "";
/**
* 生命周期
*
* @memberof Login
*/
public created(){
this.platform = this.thirdPartyService.platform;
if(this.platform){
this.thirdLogin();
}
}
/**
* 第三方登录
*
* @type {string}
* @memberof Login
*/
public async thirdLogin(){
let loginStatus :any = await this.thirdPartyService.login();
if(!loginStatus.issuccess){
this.$notice.error(loginStatus.message?loginStatus.message:"钉钉认证失败,请联系管理员");
}else{
const url: any = this.$route.query.redirect? this.$route.query.redirect: "*";
this.$router.replace({ path: url });
this.$router.go(-1)
}
}
/**
* 密码
*
......
......@@ -31,7 +31,7 @@ export class DingTalkService {
* @type {string}
* @memberof WeChatService
*/
private readonly appId: string = "dingf89eefecd565b89cbc961a6cb783455b";
private readonly appId: string = "ding0466097cd833d9f9a1320dcb25e91351";
/**
* 钉钉sdk
*
......@@ -84,15 +84,28 @@ export class DingTalkService {
public async login(): Promise<any> {
const data = await this.getUserInfo();
if (!data || !data.value || Object.is(data.value, '')) {
// 获取临时登录授权码
const res: { code: string } = await dd.runtime.permission.requestAuthCode({ corpId: this.appId });
if (res && res.code) {
const userInfo = await this.get(`./dingtalk/login?code=${res.code}`);
dd.util.domainStorage.setItem({ name: this.infoName, value: userInfo });
data.value = userInfo;
const access_token :any= await this.get(`/uaa/open/dingtalk/access_token`);
if(access_token.status == 200 && access_token.data && access_token.data.regionid){
const res: any= await dd.runtime.permission.requestAuthCode({ corpId: access_token.data.regionid });
if (res && res.code) {
const userInfo:any = await this.get(`/uaa/open/dingtalk/auth/${res.code}`);
if(userInfo.status == 200 && userInfo.data.token && userInfo.data.user){
localStorage.setItem("token", userInfo.data.token);
localStorage.setItem("user", JSON.stringify(userInfo.data.user));
dd.util.domainStorage.setItem({ name: this.infoName, value: userInfo.data });
return {issuccess:true,message:""};
}else if(userInfo.status == 400){
return {issuccess:false,message:userInfo.data.message};
}else{
return {issuccess:false,message:userInfo.data.message};
}
}else{
return {issuccess:false,message:"钉钉用户信息获取失败"};
}
}else{
return {issuccess:false,message:"获取企业id失败"};
}
}
return data.value;
}
/**
......@@ -125,8 +138,9 @@ export class DingTalkService {
private async get(url: string): Promise<any> {
return new Promise((resolve) => {
axios.get(url).then((response: any) => {
resolve(response.data);
resolve(response);
}).catch((error: any) => {
resolve(error);
console.log('请求异常');
});
})
......
......@@ -24,7 +24,7 @@ export class ThirdPartyService {
* @type {('WeChat' | 'DingTalk' | null)}
* @memberof ThirdPartyService
*/
protected platform: 'WeChat' | 'DingTalk' | null = null;
public platform: 'WeChat' | 'DingTalk' | null = null;
/**
* 钉钉服务
*
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册