gaoshp
2024-04-16 5ce658c5cf97b40cc0d84d8bfb37f96053ea8ef1
src/views/login/components/passwordForm.vue
@@ -61,40 +61,7 @@
               grant_type: "password",
               scope: "all"
            }
            //获取菜单
            // var menu = null
            // if(this.form.user == 'admin'){
            //    menu = await this.$API.system.menu.myMenus.get()
            // }else{
            //    menu = await this.$API.demo.menu.get()
            // }
            // if(menu.code == 200){
            //    if(menu.data.menu.length==0){
            //       this.islogin = false
            //       this.$alert("当前用户无任何菜单权限,请联系系统管理员", "无权限访问", {
            //          type: 'error',
            //          center: true
            //       })
            //       return false
            //    }
            //    this.$TOOL.data.set("MENU", menu.data.menu)
            //    this.$TOOL.data.set("PERMISSIONS", menu.data.permissions)
            //    this.$TOOL.data.set("DASHBOARDGRID", menu.data.dashboardGrid)
            // }else{
            //    this.islogin = false
            //    this.$message.warning(menu.message)
            //    return false
            // }
            // this.$router.replace({
            //    path: '/'
            // })
            // this.$message.success("Login Success 登录成功")
            // this.islogin = false
            await this.$HTTP.postJ("/api/blade-auth/oauth/token",data).then(res=> {
            await this.$HTTP.postJ("/api/blade-auth/oauth/token?" + this.$TOOL.qsStringify(data)).then(res=> {
               if(res.user_id) {
                  //获取token
                  this.$TOOL.cookie.set("TOKEN", res.access_token, {
@@ -105,11 +72,8 @@
                  res.dashboard = "0";
                  res.userId =  "1";
                  this.$TOOL.data.set("USER_INFO", res);
                  //获取菜单
               }else {
                  this.islogin = false;
               }else {
                  this.$message({
                      showClose: true,
                      message: res.error_description,
@@ -117,32 +81,81 @@
                    });
               }
            })
            await this.$API.system.menu.myMenus.get().then(resp=> {
                     console.log('>>>>>>')
                     if(resp.data.menu.length==0){
                        this.islogin = false
                        this.$alert("当前用户无任何菜单权限,请联系系统管理员", "无权限访问", {
                           type: 'error',
                           center: true
                        })
                        return false
                     }
                     this.$TOOL.data.set("MENU", resp.data.menu)
                     this.$TOOL.data.set("PERMISSIONS", resp.data.permissions)
                     this.$TOOL.data.set("DASHBOARDGRID", resp.data.dashboardGrid)
                  });
                  this.$router.replace({
                     path: '/'
                  })
                  this.$message.success("Login Success 登录成功")
            //获取菜单
            await this.$HTTP.get("/api/blade-system/menu/routes?" + this.$TOOL.qsStringify({"appCode": "CPS"})).then(res=> {
               if(res.data.length==0){
                  this.islogin = false
         },
                  this.$alert("当前用户无任何菜单权限,请联系系统管理员", "无权限访问", {
                     type: 'error',
                     center: true
                  })
                  return false
               }
               //开始
               function addComponentToLastLevel(items) {
                  return items.map((item) => {
                     // 复制当前项,避免直接修改原始对象
                     const clonedItem = { ...item };
                     // 检查当前项是否有 children 属性
                     if (clonedItem.children) {
                        // 递归处理 children
                        clonedItem.children = addComponentToLastLevel(clonedItem.children);
                     } else {
                        // 如果没有 children 属性,说明是最后一级,添加 component 对象
                        var len = clonedItem.path.length;
                        if(item.name == "任务调度") {
                           //clonedItem.component = clonedItem.path;   //有component不可以使用iframe
                        }else {
                           clonedItem.component = clonedItem.path.substring(1,len);
                        }
                     }
                     if(item.name == "任务调度") {
                        clonedItem.meta = {title: clonedItem.name,icon: "el-icon-takeaway-box", type: "iframe"}
                     }else {
                        clonedItem.meta = {title: clonedItem.name,icon: "el-icon-takeaway-box", type: "menu"}
                     }
                     return clonedItem;
                  });
               }
               var transformedArray = addComponentToLastLevel(res.data);
               //获取多个工作台
               this.$HTTP.get("/api/blade-system/workbench/list?status=1").then(resp=> {
                  if(resp.data.length) {
                     //console.log(resp.data,resp.data[0].name,333);
                     resp.data.forEach((item,index)=> {
                        item.component = "home";
                        item.meta = {title: item.name, icon: 'el-icon-menu', affix: true};
                        item.path = "/dashboard";
                        item.parentId = item.id;
                     })
                     transformedArray[0].path = "/home";
                     transformedArray[0].children = resp.data;
                     var obj = {
                        dashboardGrid: ["welcome", "ver", "time", "progress", "echarts", "about"],
                        menu: transformedArray,
                        permissions: ["list.add", "list.edit", "list.delete", "user.add", "user.edit", "user.delete"]
                     }
                     this.$TOOL.data.set("MENU", obj.menu)
                     this.$TOOL.data.set("PERMISSIONS", obj.permissions)
                     this.$TOOL.data.set("DASHBOARDGRID", obj.dashboardGrid)
                     console.log(transformedArray,222)
                     this.$router.replace({
                        path: '/'
                     })
                     this.$message.success("Login Success 登录成功")
                     this.islogin = false;
                  }
               })
            })
         }
      }
   }
</script>
<style>
.login-form {margin: 0 auto;margin-top: 46px;width: 354px;}
.inputHeight {height: 60px;line-height: 60px;}
.login-form {margin: 0 auto;margin-top: 46px;width: 294px;}
.inputHeight {height: 40px;line-height: 40px;}
</style>