2213980799@qq.com 1 ano atrás
pai
commit
6077ac6a11

+ 12 - 3
src/api/layout/index.js

@@ -3,8 +3,8 @@ import request from '@/utils/request';
 /**
  * 获取当前登录的菜单、按钮权限
  */
-export async function getResourcesTree () {
-  const res = await request.get('/system/resources/getResourcesTree');
+ export async function getResourcesTree ({groupId,roleId}) {
+  const res = await request.get('/system/resources/getResourcesTree?groupId='+groupId+'&roleId='+roleId);
   if (res.data.code == 0 && res.data.data) {
     return res.data.data;
   }
@@ -21,7 +21,16 @@ export async function updatePassword (data) {
   }
   return Promise.reject(new Error(res.data.message));
 }
-
+/**
+ * 角色切换 重新获取token
+ */
+ export async function changeRole(data) {
+  const res = await request.post('/main/user/changeRole',data);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}
 /**
  * 查询未读通知
  */

+ 115 - 57
src/layout/components/header-tools.vue

@@ -17,6 +17,28 @@
     <div class="ele-admin-header-tool-item">
       <header-notice />
     </div>
+    <div class="ele-admin-header-tool-item">
+      <el-select v-model="groupId" @change="groupIdChange">
+        <el-option
+          v-for="item in loginChangeGroupVOList"
+          :key="item.groupId"
+          :label="item.groupName"
+          :value="item.groupId"
+        >
+        </el-option>
+      </el-select>
+    </div>
+    <div class="ele-admin-header-tool-item">
+      <el-select v-model="roleId" @change="roleChange">
+        <el-option
+          v-for="item in loginChangeRoleVOList"
+          :key="item.roleId"
+          :label="item.roleName"
+          :value="item.roleId"
+        >
+        </el-option>
+      </el-select>
+    </div>
     <!-- 用户信息 -->
     <div class="ele-admin-header-tool-item">
       <el-dropdown @command="onUserDropClick">
@@ -67,67 +89,103 @@
 </template>
 
 <script>
-  import HeaderNotice from './header-notice.vue';
-  import PasswordModal from './password-modal.vue';
-  import SettingDrawer from './setting-drawer.vue';
-  import I18nIcon from './i18n-icon.vue';
-  import { logout } from '@/utils/page-tab-util';
-  import { userLogout } from '@/api/system/user';
-  import xyy from '@/assets/xyy.jpg';
-  export default {
-    components: { HeaderNotice, PasswordModal, SettingDrawer, I18nIcon },
-    props: {
-      // 是否是全屏
-      fullscreen: Boolean
+import HeaderNotice from './header-notice.vue';
+import PasswordModal from './password-modal.vue';
+import SettingDrawer from './setting-drawer.vue';
+import I18nIcon from './i18n-icon.vue';
+import { logout } from '@/utils/page-tab-util';
+import { userLogout } from '@/api/system/user';
+import xyy from '@/assets/xyy.jpg';
+import router from '@/router/index';
+export default {
+  components: { HeaderNotice, PasswordModal, SettingDrawer, I18nIcon },
+  props: {
+    // 是否是全屏
+    fullscreen: Boolean
+  },
+  data() {
+    return {
+      xyy,
+      // 是否显示修改密码弹窗
+      passwordVisible: false,
+      // 是否显示主题设置抽屉
+      settingVisible: false,
+      groupId: '',
+      roleId: '',
+      currentUser:{
+        currentGroupId:'',
+        currentRoleId:''
+      }
+    };
+  },
+  created() {
+    this.currentUser = JSON.parse(sessionStorage['currentUser']);
+    this.groupId =  this.currentUser.currentGroupId;
+    this.roleId =  this.currentUser.currentRoleId;
+  },
+  computed: {
+    // 当前用户信息
+    loginUser() {
+      return this.$store.state.user.info;
     },
-    data() {
-      return {
-        xyy,
-        // 是否显示修改密码弹窗
-        passwordVisible: false,
-        // 是否显示主题设置抽屉
-        settingVisible: false
-      };
+    // 部门下拉
+    loginChangeGroupVOList() {
+      return this.$store.state.user?.info?.loginChangeGroupVOList;
     },
-    computed: {
-      // 当前用户信息
-      loginUser() {
-        return this.$store.state.user.info;
-      }
+    // 角色下拉
+    loginChangeRoleVOList() {
+      return this.$store.state.user?.info?.loginChangeGroupVOList.find(
+        (item) => item.groupId == this.groupId
+      )?.loginChangeRoleVOList;
+    }
+  },
+  methods: {
+    groupIdChange(val) {
+      this.roleChange(this.loginChangeRoleVOList[0].roleId);
+    },
+    roleChange(val) {
+      this.roleId = val;
+      this.currentUser.currentGroupId = this.groupId;
+      this.currentUser.currentRoleId = val;
+      sessionStorage['currentUser']=JSON.stringify(this.currentUser)
+      this.$store
+        .dispatch('user/fetchUserInfo')
+        .then(({ menus, homePath, authoritiesRouter }) => {
+          router.roleChange({ menus, homePath, authoritiesRouter });
+        });
     },
-    methods: {
-      /* 用户信息下拉点击事件 */
-      onUserDropClick(command) {
-        if (command === 'password') {
-          this.passwordVisible = true;
-        } else if (command === 'profile') {
-          if (this.$route.fullPath !== '/user/profile') {
-            this.$router.push('/user/profile');
-          }
-        } else if (command === 'logout') {
-          // 退出登录
-          this.$confirm(
-            this.$t('layout.logout.message'),
-            this.$t('layout.logout.title'),
-            { type: 'warning' }
-          )
-            .then(() => {
-              userLogout().then((res) => {
-                localStorage.removeItem('userId');
-                logout();
-              });
-            })
-            .catch(() => {});
+    /* 用户信息下拉点击事件 */
+    onUserDropClick(command) {
+      if (command === 'password') {
+        this.passwordVisible = true;
+      } else if (command === 'profile') {
+        if (this.$route.fullPath !== '/user/profile') {
+          this.$router.push('/user/profile');
         }
-      },
-      /* 全屏切换 */
-      toggleFullscreen() {
-        this.$emit('fullscreen');
-      },
-      /* 打开设置抽屉 */
-      openSetting() {
-        this.settingVisible = true;
+      } else if (command === 'logout') {
+        // 退出登录
+        this.$confirm(
+          this.$t('layout.logout.message'),
+          this.$t('layout.logout.title'),
+          { type: 'warning' }
+        )
+          .then(() => {
+            userLogout().then((res) => {
+              localStorage.removeItem('userId');
+              logout();
+            });
+          })
+          .catch(() => {});
       }
+    },
+    /* 全屏切换 */
+    toggleFullscreen() {
+      this.$emit('fullscreen');
+    },
+    /* 打开设置抽屉 */
+    openSetting() {
+      this.settingVisible = true;
     }
-  };
+  }
+};
 </script>

+ 22 - 1
src/router/index.js

@@ -8,10 +8,11 @@ import { WHITE_LIST, REDIRECT_PATH, LAYOUT_PATH } from '@/config/setting';
 import store from '@/store';
 import { statistics } from '@/api/bpm/components/inspectionManage';
 import { getTodoTaskPage } from '@/api/bpm/task';
-import { getToken } from '@/utils/token-util';
+import { getToken, setToken } from '@/utils/token-util';
 import { routes, getMenuRoutes } from './routes';
 import { SYSTEM_NAME } from '@/config/setting';
 import { getLoginUser } from '@/api/login';
+import { changeRole } from '@/api/layout/index';
 
 Vue.use(VueRouter);
 
@@ -104,5 +105,25 @@ router.afterEach((to) => {
     }, 200);
   }
 });
+router.roleChange = async ({ menus, homePath, authoritiesRouter }) => {
+  const currentUser = JSON.parse(sessionStorage['currentUser']);
 
+  if (menus && menus.length > 0) {
+    router.addRoute(
+      getMenuRoutes([...menus, ...authoritiesRouter], homePath)
+    );
+    if (router.currentRoute.path != (menus[0].redirect || menus[0].path)) {
+      await router.replace({
+        path: menus[0].redirect || menus[0].path,
+      })
+    }
+    const newToken = await changeRole({ groupId: currentUser.currentGroupId, roleId: currentUser.currentRoleId })
+    setToken(newToken)
+    setTimeout(() => {
+      window.location.reload()
+    }, 100);
+  }
+
+  // next({ ...to, replace: true });
+};
 export default router;

+ 3 - 3
src/store/modules/user.js

@@ -106,9 +106,9 @@ export default {
     //   console.log('menus',menus, 'homePath',homePath)
     //   return { menus, homePath };
     // },
-    //动态路由
-    async fetchUserInfo({ commit }) {
-      const result = await getResourcesTree().catch(() => {});
+    async fetchUserInfo({ commit}) {
+      let currentUser=JSON.parse(sessionStorage['currentUser'])
+      const result = await getResourcesTree({groupId:currentUser.currentGroupId,roleId:currentUser.currentRoleId}).catch(() => {});
       const list = result?.filter((i) => i.path === '/page-wt');
       if (!list?.length) {
         return {};

+ 80 - 24
src/views/login/index.vue

@@ -1,16 +1,34 @@
 <template>
-  <div :class="[
-    'login-wrapper',
-    ['', 'login-form-right', 'login-form-left'][direction]
-  ]">
-    <el-form ref="form" size="large" :model="form" :rules="rules" class="login-form ele-bg-white"
-      @keyup.enter.native="submit">
+  <div
+    :class="[
+      'login-wrapper',
+      ['', 'login-form-right', 'login-form-left'][direction]
+    ]"
+  >
+    <el-form
+      ref="form"
+      size="large"
+      :model="form"
+      :rules="rules"
+      class="login-form ele-bg-white"
+      @keyup.enter.native="submit"
+    >
       <h4>{{ $t('login.title') }}</h4>
       <el-form-item prop="loginName">
-        <el-input clearable v-model="form.loginName" prefix-icon="el-icon-user" placeholder="请输入登录账号" />
+        <el-input
+          clearable
+          v-model="form.loginName"
+          prefix-icon="el-icon-user"
+          placeholder="请输入登录账号"
+        />
       </el-form-item>
       <el-form-item prop="loginPwd">
-        <el-input show-password v-model="form.loginPwd" prefix-icon="el-icon-lock" placeholder="请输入登录密码" />
+        <el-input
+          show-password
+          v-model="form.loginPwd"
+          prefix-icon="el-icon-lock"
+          placeholder="请输入登录密码"
+        />
       </el-form-item>
       <!-- <el-form-item prop="code">
         <div class="login-input-group">
@@ -33,19 +51,36 @@
         <el-checkbox v-model="form.remember">
           {{ $t('login.remember') }}
         </el-checkbox>
-        <el-link type="primary" :underline="false" class="ele-pull-right" @click="$router.push('/forget')">
+        <el-link
+          type="primary"
+          :underline="false"
+          class="ele-pull-right"
+          @click="$router.push('/forget')"
+        >
           忘记密码
         </el-link>
       </div>
       <div class="el-form-item">
-        <el-button size="large" type="primary" class="login-btn" :loading="loading" @click="submit">
+        <el-button
+          size="large"
+          type="primary"
+          class="login-btn"
+          :loading="loading"
+          @click="submit"
+        >
           {{ loading ? $t('login.loading') : $t('login.login') }}
         </el-button>
       </div>
       <div class="ele-text-center" style="margin-bottom: 10px">
         <i class="login-oauth-icon el-icon-_qq" style="background: #3492ed"></i>
-        <i class="login-oauth-icon el-icon-_wechat" style="background: #4daf29"></i>
-        <i class="login-oauth-icon el-icon-_weibo" style="background: #cf1900"></i>
+        <i
+          class="login-oauth-icon el-icon-_wechat"
+          style="background: #4daf29"
+        ></i>
+        <i
+          class="login-oauth-icon el-icon-_weibo"
+          style="background: #cf1900"
+        ></i>
       </div>
     </el-form>
     <div class="login-copyright">
@@ -53,10 +88,15 @@
     </div>
     <!-- 多语言切换 -->
     <div style="position: absolute; right: 30px; top: 20px">
-      <i18n-icon :icon-style="{ fontSize: '22px', color: '#fff', cursor: 'pointer' }" />
+      <i18n-icon
+        :icon-style="{ fontSize: '22px', color: '#fff', cursor: 'pointer' }"
+      />
     </div>
     <!-- 实际项目去掉这段 -->
-    <div class="hidden-xs-only" style="position: absolute; right: 30px; bottom: 20px; z-index: 9">
+    <div
+      class="hidden-xs-only"
+      style="position: absolute; right: 30px; bottom: 20px; z-index: 9"
+    >
       <el-radio-group v-model="direction" size="mini">
         <el-radio-button label="2">居左</el-radio-button>
         <el-radio-button label="0">居中</el-radio-button>
@@ -70,8 +110,8 @@
 import I18nIcon from '@/layout/components/i18n-icon.vue';
 import { getToken } from '@/utils/token-util';
 import { login, getCaptcha, sub } from '@/api/login';
-import {getPathAddress} from "@/api/system/file";
-import  xyy from '@/assets/xyy.jpg'
+import { getPathAddress } from '@/api/system/file';
+import xyy from '@/assets/xyy.jpg';
 export default {
   // eslint-disable-next-line vue/multi-word-component-names
   name: 'Login',
@@ -85,9 +125,15 @@ export default {
       loading: false,
       // 表单数据
       form: {
-        loginName: localStorage.getItem('accountInfo') ? JSON.parse(localStorage.getItem('accountInfo')).loginName : '',
-        loginPwd: localStorage.getItem('accountInfo') ? JSON.parse(localStorage.getItem('accountInfo')).loginPwd : '',
-        remember: localStorage.getItem('accountInfo') ? JSON.parse(localStorage.getItem('accountInfo')).remember : false,
+        loginName: localStorage.getItem('accountInfo')
+          ? JSON.parse(localStorage.getItem('accountInfo')).loginName
+          : '',
+        loginPwd: localStorage.getItem('accountInfo')
+          ? JSON.parse(localStorage.getItem('accountInfo')).loginPwd
+          : '',
+        remember: localStorage.getItem('accountInfo')
+          ? JSON.parse(localStorage.getItem('accountInfo')).remember
+          : false
       },
       // 验证码base64数据
       captcha: '',
@@ -138,8 +184,19 @@ export default {
           .then(async (res) => {
             localStorage.setItem('userId', res.data.userId);
             // 用户信息
-            const filePath = await getPathAddress()
-            res.data.avatarAddress = res.data.avatar && res.data.avatar.length ? filePath + res.data.avatar[0].storePath : xyy
+            if (res.data?.loginChangeGroupVOList.length > 0) {
+              sessionStorage['currentUser'] = JSON.stringify({
+                currentGroupId: res.data.loginChangeGroupVOList[0].groupId,
+                currentRoleId:
+                  res.data.loginChangeGroupVOList[0].loginChangeRoleVOList[0]
+                    .roleId
+              });
+            }
+            const filePath = await getPathAddress();
+            res.data.avatarAddress =
+              res.data.avatar && res.data.avatar.length
+                ? filePath + res.data.avatar[0].storePath
+                : xyy;
             this.$store.commit('user/setUserInfo', res.data);
             this.loading = false;
             this.$message.success(res.message);
@@ -160,7 +217,7 @@ export default {
     },
     /* 跳转到首页 */
     goHome() {
-      this.$router.push(this.$route?.query?.from ?? '/').catch(() => { });
+      this.$router.push(this.$route?.query?.from ?? '/').catch(() => {});
     },
     /* 更换图形验证码 */
     changeCaptcha() {
@@ -221,7 +278,7 @@ export default {
     margin: 0 0 25px 0;
   }
 
-  &>.el-form-item {
+  & > .el-form-item {
     margin-bottom: 25px;
   }
 }
@@ -314,7 +371,6 @@ export default {
 }
 
 @media screen and (max-width: 768px) {
-
   .login-form-right .login-form,
   .login-form-left .login-form {
     left: 50%;