修改第三方登录方式

This commit is contained in:
龙运模 2024-09-01 14:15:55 +08:00
parent 98fbfdf9f8
commit 4638a5c862
7 changed files with 233 additions and 87 deletions

View File

@ -16,6 +16,20 @@ const routes = [
title: "登录" title: "登录"
} }
}, },
{
path:"/bind_wechat",
component:()=>import(/* webpackChunkName: "bindWechat" */ '@/views/login/bindWechat'),
meta:{
title:'绑定微信'
}
},
{
path:"/bind_dingtalk",
component:()=>import(/* webpackChunkName: "bindDingTalk" */ '@/views/login/bindDingTalk'),
meta:{
title:'绑定钉钉'
}
},
{ {
path: "/user_register", path: "/user_register",
component: () => import(/* webpackChunkName: "userRegister" */ '@/views/login/userRegister'), component: () => import(/* webpackChunkName: "userRegister" */ '@/views/login/userRegister'),

View File

@ -0,0 +1,32 @@
<template>
<div>
</div>
</template>
<script>
export default {
name: "bindDingTalk",
data(){
return{
}
},
created(){
let code = this.$TOOL.getParameterByName('code',window.location.href);
let state = this.$TOOL.getParameterByName('state',window.location.href);
this.$TOOL.addStorageEvent(1,"DINGTALK_LOGIN_MESSAGE",JSON.stringify({code:code,state:state}));
window.close();
},
mounted() {
},
methods:{
}
}
</script>
<style lang="scss" scoped>
</style>

View File

@ -0,0 +1,32 @@
<template>
<div>
</div>
</template>
<script>
export default {
name: "bindWechat",
data(){
return{
}
},
created(){
let code = this.$TOOL.getParameterByName('code',window.location.href);
let state = this.$TOOL.getParameterByName('state',window.location.href);
this.$TOOL.addStorageEvent(1,"WECHAT_LOGIN_MESSAGE",JSON.stringify({code:code,state:state}));
window.close();
},
mounted() {
},
methods:{
}
}
</script>
<style lang="scss" scoped>
</style>

View File

@ -26,11 +26,11 @@
<div class="thirdParty"> <div class="thirdParty">
<el-divider class="dividerBox">{{ $t('login.signInOther') }}</el-divider> <el-divider class="dividerBox">{{ $t('login.signInOther') }}</el-divider>
<div class="login-oauth"> <div class="login-oauth">
<div class="btnBox wechat" @click="wechatLogin"> <div class="btnBox wechat" @click="bindWechat">
<el-icon><sc-icon-wechat /></el-icon> <el-icon><sc-icon-wechat /></el-icon>
<span class="text">微信登录</span> <span class="text">微信登录</span>
</div> </div>
<div class="btnBox dingTalk"> <div class="btnBox dingTalk" @click="bindDingTalk">
<el-icon><sc-icon-DingTalk /></el-icon> <el-icon><sc-icon-DingTalk /></el-icon>
<span class="text">钉钉登录</span> <span class="text">钉钉登录</span>
</div> </div>
@ -103,31 +103,157 @@
} }
}, },
created: function () { created: function () {
// addEventListener
window.addEventListener('storage',this.storageChange);
this.$TOOL.cookie.remove("TOKEN") this.$TOOL.cookie.remove("TOKEN")
this.$TOOL.data.remove("USER_INFO") this.$TOOL.data.remove("USER_INFO")
this.$TOOL.data.remove("MENU") this.$TOOL.data.remove("MENU")
this.$TOOL.data.remove("USER_INFO")
this.$TOOL.data.remove("PERMISSIONS") this.$TOOL.data.remove("PERMISSIONS")
this.$TOOL.data.remove("DASHBOARDGRID") this.$TOOL.data.remove("DASHBOARDGRID")
this.$TOOL.data.remove("grid") this.$TOOL.data.remove("grid")
this.$store.commit("clearViewTags") this.$store.commit("clearViewTags")
this.$store.commit("clearKeepLive") this.$store.commit("clearKeepLive")
this.$store.commit("clearIframeList") this.$store.commit("clearIframeList")
localStorage.removeItem('bindDingTalk');
localStorage.removeItem('bindWechat');
},
unmounted() {
window.removeEventListener('storage', this.storageChange);
}, },
methods: { methods: {
configDark() {
this.config.dark = this.config.dark ? false : true
},
configLang(command) { configLang(command) {
this.config.lang = command.value this.config.lang = command.value
}, },
wechatLogin() {
this.showWechatLogin = true storageChange(e){
this.WechatLoginCode = "SCUI-823677237287236-" + new Date().getTime() let dingTalk = localStorage.getItem('bindDingTalk');
this.isWechatLoginResult = false let wechat = localStorage.getItem('bindWechat');
setTimeout(() => { if(e.key == 'DINGTALK_LOGIN_MESSAGE'){
this.isWechatLoginResult = true if(dingTalk == 1 && typeof e.newValue =="string" && e.newValue!=''){
}, 3000) this.dingTalkLogin(e.newValue)
} }
localStorage.removeItem("DINGTALK_LOGIN_MESSAGE");
}
if(e.key == 'WECHAT_LOGIN_MESSAGE'){
if(wechat == 1 && typeof e.newValue =="string" && e.newValue!=''){
this.wechatLogin(e.newValue);
}
localStorage.removeItem("WECHAT_LOGIN_MESSAGE");
}
},
//
async bindWechat(){
const res = await this.$API.auth.wechatCode.post();
if(res.code == 200){
const url = JSON.parse(JSON.stringify(res.data.redirect));
localStorage.setItem('bindWechat','1');
window.open(url);
}
},
//
async bindDingTalk(){
const res = await this.$API.auth.dingTalkCode.post();
if(res.code == 200){
const url = JSON.parse(JSON.stringify(res.data.redirect));
localStorage.setItem('bindDingTalk','1');
window.open(url);
}
},
//
async dingTalkLogin(e){
let em = JSON.parse(e);
let params = {code:em.code};
const user = await this.$API.auth.dingTalkLogin.post(params);
if(user.code == 200){
await this.setLoginData(user);
}else{
return false;
}
},
async setLoginData(user) {
this.$TOOL.cookie.set("TOKEN", user.data.token, {
expires: this.form.autologin ? 24 * 60 * 60 : 0
})
this.$TOOL.data.set("USER_INFO", user.data.user)
if(user.data.user.avatar!=''){
this.$store.commit("SET_LOGIN_AVATAR", user.data.user.avatar);
}
this.$store.commit("SET_LOGIN_NAME", user.data.user.name);
// WebSocket
// let global_callback = function () {};
// this.$socketApi.createWebSocket(global_callback, user.data.token);
//
let menu = null;
menu = await this.$API.system.menu.myMenus.get()
if (menu.code === 200) {
if (menu.data.menu.length === 0) {
this.islogin = false
await this.$alert("当前用户无任何菜单权限,请联系系统管理员", "无权限访问", {
type: 'error',
center: true
})
return false
}
this.$TOOL.data.set("MENU", menu.data.menu)
const data_auth = this.$TOOL.objCopy(menu.data.permissions);
data_auth.auth = this.$TOOL.authPermissions(data_auth.data_permissions);
this.$TOOL.data.set("PERMISSIONS", data_auth)
this.$TOOL.data.set("DASHBOARDGRID", menu.data.dashboardGrid)
} else {
this.$message.warning(menu.msg)
return false
}
this.$router.replace({
path: '/'
})
},
// passKey
async passKeyLogin(){
const res = await this.$API.system.user.generateAuthentication.post();
if(res.code == 200){
const publicKeyConfigForLogin = {
challenge: Uint8Array.from(res.data.challenge),
timeout: res.data.timeout,
rpId:res.data.rpId,
userVerification: res.data.userVerification
};
try {
const assertion = await navigator.credentials.get({ publicKey:publicKeyConfigForLogin });
await this.passKeyVerify(assertion);
}catch(err){
console.log(err,'您已取消');
}
}
},
async passKeyVerify(assertion) {
let params = {
id: assertion.id,
rawId: this.bufferToBase64URL(assertion.rawId),
type: assertion.type,
response: {
authenticatorData: this.bufferToBase64URL(assertion.response.authenticatorData),
clientDataJSON: this.bufferToBase64URL(assertion.response.clientDataJSON),
signature: this.bufferToBase64URL(assertion.response.signature),
userHandle:this.bufferToBase64URL(assertion.response.userHandle),
}
}
const res = await this.$API.system.user.verifyAuthentication.post(params);
if(res.code == 200){
await this.setLoginData(res);
}
},
bufferToBase64URL(buffer) {
return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)))
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=/g, "");
},
} }
} }
</script> </script>

View File

@ -18,9 +18,9 @@
</div> </div>
<div class="td module"> <div class="td module">
<div class="textName">操作权限</div> <div class="textName">操作权限</div>
<div class="viewBox"> <div class="viewBox viewBtn">
<el-checkbox v-model="em.action.view" :size="size">查看</el-checkbox> <el-checkbox v-model="em.action.view" :size="size"><span class="checkName">查看</span></el-checkbox>
<el-checkbox v-model="em.action.edit" :size="size">编辑</el-checkbox> <el-checkbox v-model="em.action.edit" :size="size"><span class="checkName">编辑</span></el-checkbox>
</div> </div>
</div> </div>
</div> </div>
@ -54,74 +54,7 @@ export default {
}, },
methods:{ methods:{
menuCheckChange(e){
this.list.forEach(item=>{
if(e.id == item.id){
if(item.children){
item.children.forEach(em=>{
em.checked = e.checked;
if(em.meta.data_permission && em.meta.data_permission.length>0){
em.meta.data_permission.forEach((li)=>{
li.checked = e.checked;
})
}
if(em.checked){
em.isCheck = false;
}
})
}
if(item.checked){
item.isCheck = false;
}
}
})
},
moduleCheckChange(pre,e){
this.list.forEach(item=>{
if(pre.id == item.id){
if(item.children){
item.children.forEach(em=>{
if(em.id == e.id){
if(em.meta.data_permission && em.meta.data_permission.length>0){
em.meta.data_permission.forEach((li)=>{
li.checked = e.checked;
})
}
if(e.checked){
e.isCheck = false;
}
}
})
let check = item.children.filter((em)=>em.checked).length;
let isCheck = item.children.filter((em)=>em.isCheck).length;
let ed = item.children.length;
item.checked = check>0 && check == ed?true:false;
item.isCheck = (check>0 || isCheck>0) && ed!=check?true:false;
}
}
})
},
checkChange(max,pre){
this.list.forEach(item=>{
if(item.id == max.id){
if(item.children){
item.children.forEach((em)=>{
if(pre.id == em.id){
let check = em.meta.data_permission.filter((em)=>em.checked).length;
let ed = em.meta.data_permission.length;
em.checked = check>0 && check == ed?true:false;
em.isCheck = check>0 && check != ed?true:false;
}
})
}
let check = item.children.filter((em)=>em.checked).length;
let isCheck = item.children.filter((em)=>em.isCheck).length;
let ed = item.children.length;
item.checked = check>0 && check == ed?true:false;
item.isCheck = (check>0 || isCheck>0) && ed!=check?true:false;
}
})
},
} }
}; };
</script> </script>
@ -210,6 +143,12 @@ export default {
.viewBox{ .viewBox{
padding: 0 0 0 10px; padding: 0 0 0 10px;
} }
.viewBtn{
.checkName{
width: 60px;
display: inline-block;
}
}
.nextTd { .nextTd {
border-bottom: 1px solid var(--el-border-color-light); border-bottom: 1px solid var(--el-border-color-light);
flex: 1; flex: 1;

View File

@ -179,12 +179,14 @@
this.showGroupLoading = false; this.showGroupLoading = false;
if(res.code == 200){ if(res.code == 200){
this.group = res.data.rows; this.group = res.data.rows;
this.role_id = res.data.rows && res.data.rows.length>0?res.data.rows[0].id:"";
if(flag){ if(flag){
await this.getMenu(); await this.getMenu();
await this.getRoleList(); await this.getRoleList();
await this.getDataList(); await this.getDataList();
} }
if(res.data.rows && res.data.rows.length>0){
this.role_id = res.data.rows[0].id;
}
} }
}, },
// //

View File

@ -339,8 +339,9 @@ export default {
authenticatorAttachment: credential.authenticatorAttachment, authenticatorAttachment: credential.authenticatorAttachment,
} }
const res = await this.$API.system.user.verifyResponse.post(params); const res = await this.$API.system.user.verifyResponse.post(params);
console.log(res,55) if(res.code == 200){
// this.$message.success(''); await this.getPassKeyList();
}
}, },
bufferToBase64URL(buffer) { bufferToBase64URL(buffer) {
return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer))) return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)))