ソースを参照

APP端 新增切换用户功能

zhulu 1 年間 前
コミット
12d0307b9d

+ 24 - 1
src/api/public.js

@@ -1,4 +1,5 @@
 import request from '@/utils/request'
+import { FALSE } from 'sass'
 
 // 登录方法
 export function login(data) {
@@ -23,6 +24,27 @@ export function tokenLogin(token) {
   })
 }
 
+// 切换用户
+export function switchUser(subUserId) {
+  return request({
+    url: `/auth/switchUser?subUserId=${subUserId}`,
+    headers: {
+      isToken: false
+    },
+    method: 'get'
+  })
+}
+
+//获取用户
+export function userUnDoList(userIds) {
+  return request({
+    url: `/core/panel/userUndoList`,
+    method: 'post',
+    data:userIds
+  })
+}
+
+
 // 注册方法
 export function register(data) {
   return request({
@@ -61,11 +83,12 @@ export function refreshToken() {
 // 获取用户详细信息
 export function userInfo() {
   return request({
-    url: '/system/user/getInfo',
+    url: `/system/user/getInfo`,
     method: 'get'
   })
 }
 
+
 // 获取用户详细信息
 export function getDot() {
   return request({

+ 152 - 14
src/components/TopBar.vue

@@ -19,7 +19,7 @@
       </div>
     </div>
     <div class="top-card">
-      <div class="top-card-line">
+      <div class="top-card-line" style="display: inline-flex;">
         <van-image
           round
           width="1.3rem"
@@ -27,18 +27,42 @@
           style="float: left"
           :src="require('@/assets/img/my/header.png')"
         />
-        <p class="user-name">{{ userName }}</p>
+        <div class="user-name">
+         {{ getShowUserName() }}    
+        </div>
+        <!-- <div style="line-height: 11vw;" v-if="subUserActions && subUserActions.length>0">
+            <van-popover v-model="showPopover" placement="left-end" trigger="click" 
+              :actions="subUserActions"          
+              @select="onSelect">         
+              <template #reference>
+                <van-button size="mini" icon="exchange" round  type="info">切换机构</van-button>
+              </template>
+          </van-popover>
+        </div> -->
+        
+      
       </div>
-      <div class="top-card-line">
+      <div class="top-card-line" style="display: flex;">
+        <div style="-webkit-box-flex: 1;-webkit-flex: 1;flex: 1;">
         <van-image
           width="0.7rem"
           height="0.6rem"
           style="float: left"
           :src="require('@/assets/img/my/org.png')"
         />
-        <p style="line-height: 28px;">
+        <p style="line-height: 28px; padding-right:10px;">
           <span class="top_text_content">{{ orgName }}</span>
         </p>
+       </div>
+        <div  v-if="subUserActions && subUserActions.length>0">
+            <van-popover v-model="showPopover" placement="left-end" trigger="click" class="xxxx"
+              :actions="subUserActions"          
+              @select="onSelect">         
+              <template #reference>
+                <van-button size="mini" round icon="exchange"  type="default">切换机构</van-button>
+              </template>
+          </van-popover>
+        </div>
       </div>
       <div class="top-card-line">
         <van-image
@@ -54,31 +78,144 @@
       <div style="height: 2vw;"></div>
     </div>
     <div class="card-footer"></div>
+    
   </div>
 </template>
 <script>
   import { mapGetters } from 'vuex'
-  import { logout } from '@/api/public'
+  import { logout,switchUser,userUnDoList } from '@/api/public'
   export default {
     data() {
-      return {}
+      return {
+        showPopover:false,
+        subUserActions: [],
+      }
+    },
+    created(){
+    },
+    mounted(){
+      
+    },
+    watch:{
+      subUserList:{
+          handler(val,val2){
+            console.log("subUserList",val,val2);
+          if(val){
+            this.initSubUserActions();
+          }
+        },
+        immediate:true,
+      }
     },
     computed: {
-      ...mapGetters(['userName', 'orgName','roleList', 'orgId']),
+      ...mapGetters(['userName', 'orgName','roleList', 'orgId','subUserList','masterUserName','masterUserId']),
     },
     methods: {
+      getShowUserName()
+      {
+        // console.log("getShowUserName",this.masterUserName ,this.masterUserId)
+        if(this.masterUserName &&  this.masterUserId)
+        {
+          return this.masterUserName;
+        }
+        else
+        {
+          return this.userName;
+        }
+      },
+      initSubUserActions(){
+         console.log("initSubUserActions",this.subUserList)        
+        if(this.subUserList && this.subUserList.length>0)
+        {
+          this.getSubUserUnDoTaskList();
+        }
+      },
+      clickSwitchUser(subUserId)
+      {        
+        switchUser(subUserId).then(res => {
+          // console.log(res, 'res')
+          sessionStorage.clear();
+          sessionStorage.setItem('access_token', res.data.access_token)
+          this.$router.replace({
+              name:'home',
+              path:'/home',
+              params:{event:'SwitchUser'},
+              query:{event:'SwitchUser'},
+              })
+        })
+      },
+      onSelect(action)
+      {
+        // console.log("onSelect",action,action.text);
+        this.clickSwitchUser(action.subUserId);
+      },
+      getSubUserUnDoTaskList()
+      {
+        if(this.subUserList && this.subUserList.length>0)
+        {
+          let users= this.subUserList.map((i) =>{
+            return {userId:i.subUserId,orgId:i.subUserOrgId};
+          } );
+          userUnDoList(users).then(res => {
+            
+          // console.log("initSubUserActions2",this.subUserList)
+          this.subUserActions=[];
+          this.subUserList.forEach(sUser => {
+            let haveUnDoTask=false;
+            if(res.data){
+              let index= res.data.findIndex(x=>x.userId == sUser.subUserId && x.haveUnDoTask===true)
+              if(index>-1)
+              {
+                haveUnDoTask=true;
+              }
+            }            
+            // let tempText= `${sUser.subUserOrgName}`; 
+            let tempAction={ text: sUser.subUserOrgName,subUserId:sUser.subUserId};
+            if(haveUnDoTask)
+            {
+              tempAction={className:"haveUnDoTask",...tempAction};
+            }
+            this.subUserActions.push(tempAction)
+          
+          });
+          // console.log("xxx",this.subUserActions)
+          })
+        }
+      },
       clickOutLogin() {
         logout().then(res => {
           sessionStorage.clear();
           this.$router.replace('/login');
           this.$toast('退出登录');
         })
-      },
+      }      
     }
   }
 </script>
-
-<style scoped lang="scss">
+<style lang="scss">
+ .van-popover__action{
+    width: 60vw !important;
+    .van-popover__action-text{
+      flex:none !important;
+    }
+  }
+ 
+  .haveUnDoTask
+  {
+    .van-popover__action-text::before{
+      content: "";      
+      width:10px;
+      height:10px;
+      background-color: red;
+      position: absolute;
+      left: -15px;
+      border-radius: 50%;
+    }
+  }
+</style>
+<style scoped lang="scss"> 
+  
+  
   .card-footer{
     height: 3vw;
   }
@@ -92,15 +229,16 @@
     min-height: 37vw;
     background-color: #FFFFFF;
     margin-top: -23vw;
-    margin-left: 6%;
-    margin-right: 6%;
+    margin-left: 5%;
+    margin-right: 5%;
     border-radius: 10px;
     .top-card-line{
-      padding: 20px 40px 0 40px;
+      padding: 20px 10px 0 40px;
     }
   }
   .user-name{
-    padding-left: 15vw;
+    padding-left: 5vw;
+    padding-right: 20vw;
     font-size: 6.333333vw;
     line-height: 14vw;
   }

+ 9 - 0
src/components/layouts/index.vue

@@ -16,6 +16,7 @@
 import TabBar from '@/components/TabBar'
 import { userInfo } from '@/api/public'
 export default {
+  name:"home",
   data() {
     return {
       container: null,
@@ -30,6 +31,11 @@ export default {
   },
   watch: {
     $route(to, from) {
+      //console.log("home route",to,from);
+      if(to.query && to.query.event=='SwitchUser')
+      {
+        this.getUserInfo();
+      }
       //如果 要 to(进入) 的页面是需要 keepAlive 缓存的,把 name push 进 include数组
       if (to.meta.keepAlive) {
         !this.include.includes(to.name) && this.include.push(to.name)
@@ -58,6 +64,9 @@ export default {
         this.$store.commit('SET_USER_ORGID', info.user.orgId)
         this.$store.commit('SET_USER_ORGNAME', info.user.orgName)
         this.$store.commit('SET_USER_ORGTYPE', info.user.orgType)
+        this.$store.commit('SET_USER_SUBUSERLIST', info.subUserList)
+        this.$store.commit('SET_MASTER_USER_ID', info.masterUserId)
+        this.$store.commit('SET_MASTER_USER_NAME', info.masterUserName)
         //登陆之后手动触发一次水印数据刷新
           this.$parent.$refs.watercom.getWater(1)
       })

+ 2 - 1
src/router/index.js

@@ -47,7 +47,8 @@ router.beforeEach((to, from, next) => {
     }
   }
   sessionStorage.setItem('ROUTER',JSON.stringify(object));
-  console.log('从' + from.path + '跳向' + to.path)
+  console.log('beforeEach 从' , from , to)
+  console.log('beforeEach 从' + from.path + '跳向' + to.path)
   //如果当前是工作台页面返回的时候判断当前是否是A标签跳转是进行重定向到works
   if (to.path === '/login' || to.path === '/tokenlogin') return next()
   let token = sessionStorage.getItem('access_token')

+ 12 - 1
src/router/router.config.js

@@ -86,8 +86,13 @@ export let routers = [
   },
   {
     path: '/home',
+    name: 'home',
     component: () => import('@/components/layouts/index'),
-    redirect: '/works',
+    redirect: to => {
+      // 保留查询参数
+      const params = { ...to.params };
+      return { path: '/works', params };
+    },
     meta: {
       title: '主页',
       keepAlive: false
@@ -255,6 +260,12 @@ export let routers = [
         component: () => import('@/views/menu/rehearsalTask/optimal'),
         meta: { title: '优秀案例管理', keepAlive: false }
       },
+      // {
+      //   path: '/rehearsaloptimal2',
+      //   name: 'rehearsaloptimal2',
+      //   component: () => import('@/views/menu/rehearsalTask/optimal2'),
+      //   meta: { title: '优秀案例管理2', keepAlive: false }
+      // },
       {
         path: '/training',
         name: 'training',

+ 4 - 0
src/store/getters.js

@@ -5,6 +5,10 @@ const getters = {
   orgType: state => state.user.orgType,
   orgName: state => state.user.orgName,
   roleList: state => state.user.userRoleList,
+  masterUserId: state => state.user.masterUserId,
+  masterUserName: state => state.user.masterUserName,
+  // masterUserOrgName:state => state.user.masterUserOrgName,
+  subUserList: state => state.user.subUserList,
   orgTree: state => state.app.orgTree,
   orgTreeHangshe: state => state.app.orgTreeHangshe,
   depTree: state => state.app.depTree,

+ 29 - 0
src/store/modules/user.js

@@ -11,6 +11,17 @@ const state = {
   orgName:JSON.parse(sessionStorage.getItem("SET_USER_ORGNAME"))||null,
   //机构类型
   orgType:JSON.parse(sessionStorage.getItem("SET_USER_ORGTYPE"))||null,
+
+  subUserList:JSON.parse(sessionStorage.getItem("SET_USER_SUBUSERLIST"))||[],
+
+  //主用户用户名
+  masterUserName: JSON.parse(sessionStorage.getItem("SET_MASTER_USER_NAME"))||null,
+  //主用户id
+  masterUserId: JSON.parse(sessionStorage.getItem("SET_MASTER_USER_ID"))||null,
+  //主用户机构名称
+  // masterUserOrgName: JSON.parse(sessionStorage.getItem("SET_MASTER_USER_ORG_NAME"))||null,
+
+  
 }
 const mutations = {
   SET_USER_NAME(state, name) {
@@ -43,6 +54,24 @@ const mutations = {
     state.orgName = '';
     sessionStorage.setItem("SET_USER_ORGNAME", JSON.stringify(''))
   },
+  SET_USER_SUBUSERLIST(state, name) {
+    state.subUserList = name;
+    sessionStorage.setItem("SET_USER_SUBUSERLIST", JSON.stringify(name))
+  },
+
+  SET_MASTER_USER_ID(state, val) {
+    state.masterUserId = val;
+    sessionStorage.setItem("SET_MASTER_USER_ID", JSON.stringify(val))
+  },
+
+  SET_MASTER_USER_NAME(state, val) {
+    state.masterUserName = val;
+    sessionStorage.setItem("SET_MASTER_USER_NAME", JSON.stringify(val))
+  },
+  // SET_MASTER_USER_ORG_NAME(state, val) {
+  //   state.masterUserOrgName = val;
+  //   sessionStorage.setItem("SET_MASTER_USER_ORG_NAME", JSON.stringify(val))
+  // },
 }
 const actions = {
   // 设置name