diff --git a/src/router/systemRouter.js b/src/router/systemRouter.js index 8e67110..c81f531 100644 --- a/src/router/systemRouter.js +++ b/src/router/systemRouter.js @@ -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'), diff --git a/src/views/login/bindDingTalk.vue b/src/views/login/bindDingTalk.vue new file mode 100644 index 0000000..df17998 --- /dev/null +++ b/src/views/login/bindDingTalk.vue @@ -0,0 +1,32 @@ + + + + + diff --git a/src/views/login/bindWechat.vue b/src/views/login/bindWechat.vue new file mode 100644 index 0000000..8bb6bbb --- /dev/null +++ b/src/views/login/bindWechat.vue @@ -0,0 +1,32 @@ + + + + + diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 908afcf..b09e705 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -26,11 +26,11 @@
{{ $t('login.signInOther') }}
-
+
微信登录
-
+
钉钉登录
@@ -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, ""); + }, } } diff --git a/src/views/setting/role/dataPermissions.vue b/src/views/setting/role/dataPermissions.vue index a1c7945..b686ba1 100644 --- a/src/views/setting/role/dataPermissions.vue +++ b/src/views/setting/role/dataPermissions.vue @@ -18,9 +18,9 @@
操作权限
-
- 查看 - 编辑 +
+ 查看 + 编辑
@@ -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; - } - }) - }, + } }; @@ -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; diff --git a/src/views/setting/role/index.vue b/src/views/setting/role/index.vue index bcd523b..2afef79 100644 --- a/src/views/setting/role/index.vue +++ b/src/views/setting/role/index.vue @@ -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; + } } }, //添加 diff --git a/src/views/userCenter/user/bind.vue b/src/views/userCenter/user/bind.vue index 3de28d5..387b632 100644 --- a/src/views/userCenter/user/bind.vue +++ b/src/views/userCenter/user/bind.vue @@ -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)))