修改第三方登录方式
This commit is contained in:
parent
98fbfdf9f8
commit
4638a5c862
@ -16,6 +16,20 @@ const routes = [
|
||||
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",
|
||||
component: () => import(/* webpackChunkName: "userRegister" */ '@/views/login/userRegister'),
|
||||
|
||||
32
src/views/login/bindDingTalk.vue
Normal file
32
src/views/login/bindDingTalk.vue
Normal 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>
|
||||
32
src/views/login/bindWechat.vue
Normal file
32
src/views/login/bindWechat.vue
Normal 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>
|
||||
@ -26,11 +26,11 @@
|
||||
<div class="thirdParty">
|
||||
<el-divider class="dividerBox">{{ $t('login.signInOther') }}</el-divider>
|
||||
<div class="login-oauth">
|
||||
<div class="btnBox wechat" @click="wechatLogin">
|
||||
<div class="btnBox wechat" @click="bindWechat">
|
||||
<el-icon><sc-icon-wechat /></el-icon>
|
||||
<span class="text">微信登录</span>
|
||||
</div>
|
||||
<div class="btnBox dingTalk">
|
||||
<div class="btnBox dingTalk" @click="bindDingTalk">
|
||||
<el-icon><sc-icon-DingTalk /></el-icon>
|
||||
<span class="text">钉钉登录</span>
|
||||
</div>
|
||||
@ -103,31 +103,157 @@
|
||||
}
|
||||
},
|
||||
created: function () {
|
||||
// 监听缓存变化 addEventListener
|
||||
window.addEventListener('storage',this.storageChange);
|
||||
|
||||
this.$TOOL.cookie.remove("TOKEN")
|
||||
this.$TOOL.data.remove("USER_INFO")
|
||||
this.$TOOL.data.remove("MENU")
|
||||
this.$TOOL.data.remove("USER_INFO")
|
||||
this.$TOOL.data.remove("PERMISSIONS")
|
||||
this.$TOOL.data.remove("DASHBOARDGRID")
|
||||
this.$TOOL.data.remove("grid")
|
||||
this.$store.commit("clearViewTags")
|
||||
this.$store.commit("clearKeepLive")
|
||||
this.$store.commit("clearIframeList")
|
||||
|
||||
localStorage.removeItem('bindDingTalk');
|
||||
localStorage.removeItem('bindWechat');
|
||||
},
|
||||
unmounted() {
|
||||
window.removeEventListener('storage', this.storageChange);
|
||||
},
|
||||
methods: {
|
||||
configDark() {
|
||||
this.config.dark = this.config.dark ? false : true
|
||||
},
|
||||
configLang(command) {
|
||||
this.config.lang = command.value
|
||||
},
|
||||
wechatLogin() {
|
||||
this.showWechatLogin = true
|
||||
this.WechatLoginCode = "SCUI-823677237287236-" + new Date().getTime()
|
||||
this.isWechatLoginResult = false
|
||||
setTimeout(() => {
|
||||
this.isWechatLoginResult = true
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
storageChange(e){
|
||||
let dingTalk = localStorage.getItem('bindDingTalk');
|
||||
let wechat = localStorage.getItem('bindWechat');
|
||||
if(e.key == 'DINGTALK_LOGIN_MESSAGE'){
|
||||
if(dingTalk == 1 && typeof e.newValue =="string" && e.newValue!=''){
|
||||
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>
|
||||
|
||||
@ -18,9 +18,9 @@
|
||||
</div>
|
||||
<div class="td module">
|
||||
<div class="textName">操作权限</div>
|
||||
<div class="viewBox">
|
||||
<el-checkbox v-model="em.action.view" :size="size">查看</el-checkbox>
|
||||
<el-checkbox v-model="em.action.edit" :size="size">编辑</el-checkbox>
|
||||
<div class="viewBox viewBtn">
|
||||
<el-checkbox v-model="em.action.view" :size="size"><span class="checkName">查看</span></el-checkbox>
|
||||
<el-checkbox v-model="em.action.edit" :size="size"><span class="checkName">编辑</span></el-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -54,74 +54,7 @@ export default {
|
||||
|
||||
},
|
||||
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>
|
||||
@ -210,6 +143,12 @@ export default {
|
||||
.viewBox{
|
||||
padding: 0 0 0 10px;
|
||||
}
|
||||
.viewBtn{
|
||||
.checkName{
|
||||
width: 60px;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
.nextTd {
|
||||
border-bottom: 1px solid var(--el-border-color-light);
|
||||
flex: 1;
|
||||
|
||||
@ -179,12 +179,14 @@
|
||||
this.showGroupLoading = false;
|
||||
if(res.code == 200){
|
||||
this.group = res.data.rows;
|
||||
this.role_id = res.data.rows && res.data.rows.length>0?res.data.rows[0].id:"";
|
||||
if(flag){
|
||||
await this.getMenu();
|
||||
await this.getRoleList();
|
||||
await this.getDataList();
|
||||
}
|
||||
if(res.data.rows && res.data.rows.length>0){
|
||||
this.role_id = res.data.rows[0].id;
|
||||
}
|
||||
}
|
||||
},
|
||||
//添加
|
||||
|
||||
@ -339,8 +339,9 @@ export default {
|
||||
authenticatorAttachment: credential.authenticatorAttachment,
|
||||
}
|
||||
const res = await this.$API.system.user.verifyResponse.post(params);
|
||||
console.log(res,55)
|
||||
// this.$message.success('通行秘钥创建成功');
|
||||
if(res.code == 200){
|
||||
await this.getPassKeyList();
|
||||
}
|
||||
},
|
||||
bufferToBase64URL(buffer) {
|
||||
return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user