CRM项目前端将解析到的用户权限对应加载出可用的权限按钮和页面路由------CRM项目

249 篇文章 0 订阅
142 篇文章 0 订阅
<template>
    <el-container>
        <!-- 左侧 -->
      <el-aside :width="isShowed ? '3.4%' : '17%'">
        <div class="menuTitle">{{ isShowed ? "" : title }}</div>
        <!-- 菜单 -->
        <el-menu
        active-text-color="#ffd04b"
        background-color="#334157"
        class="el-menu-vertical-demo"
        :default-active="currentRouterPath"
        style="border-right: solid 0px;"
        :unique-opened="true"
        text-color="#fff"
        :collapse="isShowed"
        :collapse-transition="false"
        :router="true"
      >
      <el-sub-menu :index="index" v-for="(menuPermission, index) in user.menuPermissionList" :key="menuPermission.id">
          <template #title>
            <el-icon><component :is="menuPermission.icon"></component></el-icon>
            <span> {{menuPermission.name}} </span>
          </template>
          <el-menu-item v-for="(subPermission) in menuPermission.subPermissionList" :key="subPermission.id" :index="subPermission.url">
            <el-icon><component :is="subPermission.icon"></component></el-icon>
            {{subPermission.name}}
          </el-menu-item>
        </el-sub-menu>
      </el-menu>
      </el-aside>
      <el-container class="rightContent">
        <!-- 右侧上 -->
        <el-header>
          <!-- 折叠 -->
          <el-icon class="show" @click="showMenu()" v-show="isShowed===false"><Fold /></el-icon>
          <!-- 打开 -->
          <el-icon class="show" @click="showMenu()" v-show="isShowed"><Expand /></el-icon>
          <!-- 用户信息的下拉菜单 -->
          <el-dropdown :hide-on-click="false">
            <span class="el-dropdown-link">
              {{ user.name }}<el-icon class="el-icon--right"><arrow-down /></el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>我的资料</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item divided @click="logOut()">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </el-header>
        <!-- 右侧中 -->
        <el-main v-if="isRouterAlive">
          <router-view></router-view>
        </el-main>
        <!-- 右侧下 -->
        <el-footer>@版权所有 2000-2099 旧约Alatus 广东省广州市九龙大道206号第XX栋XX总部xx号</el-footer>
      </el-container>
    </el-container>
</template>

<script>
import { doGet } from "../http/httpRequest.js";
import { messageTip, removeToken, messageConfirm, later } from "../util/util.js";
export default {
    name : "dashboard",
    mounted(){
      // 挂载时获取用户名
      this.loadLoginName();
      this.loadCurrentRouter();
    },
    // 提供者生产者
    provide(){
      return {
        // 提供了一个函数,要求必须是箭头函数
        reload: () => {
          this.isRouterAlive = false;
          //提供一个函数 (页面局部刷新函数)
          this.$nextTick(function(){
            this.isRouterAlive = true;
          })
        }
      }
    },
    methods : {
      loadLoginName(){
        // 获取用户名
        doGet("/api/login/info",{}).then((resp) => {
          this.user = resp.data.data;
        });
      },
      // 左侧菜单左右展开与折叠
      showMenu(){
        // 取反即可
        this.isShowed = !this.isShowed;
      },
      loadCurrentRouter(){
        let arr = this.$route.path.split("/");
        this.currentRouterPath = "/"+arr[1]+"/"+arr[2];
      },
      // 退出登录
      logOut(){
        // 一样没有参数值,直接给个空的大括号就好
        doGet("/api/logOut",{}).then(resp => {
          if(resp.data.code === 200){
            messageTip('退出成功,即将返回首页',"success");
            // 退出成功
            removeToken();
            later("/");
          }
          else{
            messageConfirm(resp.data.msg+",是否强制退出?","账号退出异常").then(() => {
              messageTip('退出成功,即将返回首页',"success");
              // 后端不起作用,我们就把前端这里存的删了先
              removeToken();
              later("/");
            }).catch(() => {
              messageTip("已取消强制退出","warning");
            });
          }
        });
      }
    },
    data(){
      return {
        isShowed : false,
        // 登录的用户对象
        user : {},
        title : "@CRM管理系统",
        // 控制右侧子路由内容是否显示
        isRouterAlive : true,
        // 激活页面
        currentRouterPath : ''
      }
    }
}
</script>

<style scoped>
.el-dropdown{
  float: right;
  line-height: 225%;
}
.el-aside{
    background-color: black;
}
.menuTitle{
    color: white;
    text-align: center;
    height: 5%;
    line-height: 225%;
}
.el-header{
    background-color: azure;
    height: 5%;
    line-height: 225%;
}
.el-footer{
    background-color: aliceblue;
    height: 5%;
    line-height: 225%;
    text-align: center;
}
.rightContent{
    /* 高度设置为计算高度,屏幕高度的100% */
    height: calc(100vh);
}
.show{
  /* 聚焦事件 */
  cursor: pointer;
}
.el-icon {
  font-size: 1em;
}
</style>

<template>

    <el-container>

        <!-- 左侧 -->

      <el-aside :width="isShowed ? '3.4%' : '17%'">

        <div class="menuTitle">{{ isShowed ? "" : title }}</div>

        <!-- 菜单 -->

        <el-menu

        active-text-color="#ffd04b"

        background-color="#334157"

        class="el-menu-vertical-demo"

        :default-active="currentRouterPath"

        style="border-right: solid 0px;"

        :unique-opened="true"

        text-color="#fff"

        :collapse="isShowed"

        :collapse-transition="false"

        :router="true"

      >

      <el-sub-menu :index="index" v-for="(menuPermission, index) in user.menuPermissionList" :key="menuPermission.id">

          <template #title>

            <el-icon><component :is="menuPermission.icon"></component></el-icon>

            <span> {{menuPermission.name}} </span>

          </template>

          <el-menu-item v-for="(subPermission) in menuPermission.subPermissionList" :key="subPermission.id" :index="subPermission.url">

            <el-icon><component :is="subPermission.icon"></component></el-icon>

            {{subPermission.name}}

          </el-menu-item>

        </el-sub-menu>

      </el-menu>

      </el-aside>

      <el-container class="rightContent">

        <!-- 右侧上 -->

        <el-header>

          <!-- 折叠 -->

          <el-icon class="show" @click="showMenu()" v-show="isShowed===false"><Fold /></el-icon>

          <!-- 打开 -->

          <el-icon class="show" @click="showMenu()" v-show="isShowed"><Expand /></el-icon>

          <!-- 用户信息的下拉菜单 -->

          <el-dropdown :hide-on-click="false">

            <span class="el-dropdown-link">

              {{ user.name }}<el-icon class="el-icon--right"><arrow-down /></el-icon>

            </span>

            <template #dropdown>

              <el-dropdown-menu>

                <el-dropdown-item>我的资料</el-dropdown-item>

                <el-dropdown-item>修改密码</el-dropdown-item>

                <el-dropdown-item divided @click="logOut()">退出登录</el-dropdown-item>

              </el-dropdown-menu>

            </template>

          </el-dropdown>

        </el-header>

        <!-- 右侧中 -->

        <el-main v-if="isRouterAlive">

          <router-view></router-view>

        </el-main>

        <!-- 右侧下 -->

        <el-footer>@版权所有 2000-2099 旧约Alatus 广东省广州市九龙大道206号第XX栋XX总部xx号</el-footer>

      </el-container>

    </el-container>

</template>

<script>

import { doGet } from "../http/httpRequest.js";

import { messageTip, removeToken, messageConfirm, later } from "../util/util.js";

export default {

    name : "dashboard",

    mounted(){

      // 挂载时获取用户名

      this.loadLoginName();

      this.loadCurrentRouter();

    },

    // 提供者生产者

    provide(){

      return {

        // 提供了一个函数,要求必须是箭头函数

        reload: () => {

          this.isRouterAlive = false;

          //提供一个函数 (页面局部刷新函数)

          this.$nextTick(function(){

            this.isRouterAlive = true;

          })

        }

      }

    },

    methods : {

      loadLoginName(){

        // 获取用户名

        doGet("/api/login/info",{}).then((resp) => {

          this.user = resp.data.data;

        });

      },

      // 左侧菜单左右展开与折叠

      showMenu(){

        // 取反即可

        this.isShowed = !this.isShowed;

      },

      loadCurrentRouter(){

        let arr = this.$route.path.split("/");

        this.currentRouterPath = "/"+arr[1]+"/"+arr[2];

      },

      // 退出登录

      logOut(){

        // 一样没有参数值,直接给个空的大括号就好

        doGet("/api/logOut",{}).then(resp => {

          if(resp.data.code === 200){

            messageTip('退出成功,即将返回首页',"success");

            // 退出成功

            removeToken();

            later("/");

          }

          else{

            messageConfirm(resp.data.msg+",是否强制退出?","账号退出异常").then(() => {

              messageTip('退出成功,即将返回首页',"success");

              // 后端不起作用,我们就把前端这里存的删了先

              removeToken();

              later("/");

            }).catch(() => {

              messageTip("已取消强制退出","warning");

            });

          }

        });

      }

    },

    data(){

      return {

        isShowed : false,

        // 登录的用户对象

        user : {},

        title : "@CRM管理系统",

        // 控制右侧子路由内容是否显示

        isRouterAlive : true,

        // 激活页面

        currentRouterPath : ''

      }

    }

}

</script>

<style scoped>

.el-dropdown{

  float: right;

  line-height: 225%;

}

.el-aside{

    background-color: black;

}

.menuTitle{

    color: white;

    text-align: center;

    height: 5%;

    line-height: 225%;

}

.el-header{

    background-color: azure;

    height: 5%;

    line-height: 225%;

}

.el-footer{

    background-color: aliceblue;

    height: 5%;

    line-height: 225%;

    text-align: center;

}

.rightContent{

    /* 高度设置为计算高度,屏幕高度的100% */

    height: calc(100vh);

}

.show{

  /* 聚焦事件 */

  cursor: pointer;

}

.el-icon {

  font-size: 1em;

}

</style>

  • 21
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旧约Alatus

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值