Browse Source

feat: 优化仪表盘-部门/全部下与员工的逻辑交互

lanjianrong 4 years ago
parent
commit
a688dfd2a7
1 changed files with 27 additions and 4 deletions
  1. 27 4
      src/pages/Workbench/Dashboard/index.jsx

+ 27 - 4
src/pages/Workbench/Dashboard/index.jsx

@@ -18,6 +18,7 @@ import { getAuthCache, getPermAuthCache, setAuthCache } from '@/utils/auth'
 import { WORKBENCH_CYCLICAL_KEY } from '@/utils/cache/cacheEnum'
 import styles from './index.less'
 import { isDevMode } from '@/utils/env'
+import { isMobile } from '@/utils/is'
 
 const Dashboard = ({ dispatch, departments = [] }) => {
   const { initialState: { currentUser } = { currentUser: {} } } = useModel('@@initialState')
@@ -33,7 +34,6 @@ const Dashboard = ({ dispatch, departments = [] }) => {
     selectId: '',
     disabled: true,
     loading: true,
-    staffIds: null,
     immediate: false,
     visible: false,
     reminderData: [],
@@ -90,12 +90,25 @@ const Dashboard = ({ dispatch, departments = [] }) => {
     })
     if (code === consts.RET_CODE.SUCCESS && canSetState) {
       // list存起来
-      setState({ ...state, staffList: list })
+      setState({
+        ...state,
+        staffList: list,
+        params: { ...state.params, staffIds: list.map(item => `s_${item.id}`) }
+      })
     }
     return list
   }
   const handleStaffClick = id => {
     const sId = `s_${id}`
+    if (state.params.staffIds?.includes(sId)) {
+      setState({
+        ...state,
+        selectId: null,
+        immediate: true,
+        params: { ...state.params, staffIds: null }
+      })
+      return
+    }
     setState({
       ...state,
       selectId: id,
@@ -315,7 +328,7 @@ const Dashboard = ({ dispatch, departments = [] }) => {
               dataType="workbench"
             />
           </span>
-          {state.params.dataPermission === 'all' ? (
+          {!isMobile() && state.params.dataPermission === 'all' ? (
             <TreeSelect
               size="middle"
               style={{ width: 150 }}
@@ -327,12 +340,22 @@ const Dashboard = ({ dispatch, departments = [] }) => {
               treeData={departments}
               allowClear
               onSelect={queryStaffList}
+              onChange={e => {
+                if (!e)
+                  setState({
+                    ...state,
+                    params: { ...state.params, staffIds: null },
+                    staffList: [],
+                    selectId: null
+                  })
+              }}
             />
           ) : null}
         </span>
 
         <div className="flex items-center flex-row ml-2">
-          {['all', 'department'].includes(state.params.dataPermission) &&
+          {!isMobile() &&
+            ['all', 'department'].includes(state.params.dataPermission) &&
             state.staffList.map(item => (
               <div key={item.id} onClick={() => handleStaffClick(item.id)}>
                 <div