Sfoglia il codice sorgente

feat: 仪表盘 数据权限、月份选择器应用数据持久化存储,再打开时恢复历史选择项

lanjianrong 5 anni fa
parent
commit
e4b0f63537

+ 24 - 5
src/pages/workbench/Dashboard/index.jsx

@@ -12,9 +12,21 @@ import { cardTypeMap, cyclicalOp } from './consts'
 import BusinessChar from './components/BusinessChar'
 import RatioPanels from './components/RatioPanels'
 import PermSelect from '@/pages/Customer/Company/components/PermSelect'
+import { getAuthCache, setAuthCache } from '@/utils/auth'
+import { PERMISSION_SELECT_KEY, WORKBENCH_CYCLICAL_KEY } from '@/utils/cache/cacheEnum'
 
 const Dashboard = () => {
   const timer = useRef(null)
+  const permAuthCache = getAuthCache(PERMISSION_SELECT_KEY)
+  let defaultPermValue = 'onself'
+  if (permAuthCache && permAuthCache.workbench) {
+    defaultPermValue = permAuthCache.workbench
+  }
+  const cyclicalAuthCache = getAuthCache(WORKBENCH_CYCLICAL_KEY)
+  let defaultCyclicalValue = 'week'
+  if (cyclicalAuthCache) {
+    defaultCyclicalValue = cyclicalAuthCache
+  }
   const [state, setState] = useState({
     disabled: true,
     loading: true,
@@ -30,7 +42,11 @@ const Dashboard = () => {
     serviceLogChainRatio: {},
     aggregation: {},
     businessChar: {},
-    params: { businessGroupId: '', dataPermission: 'oneself', cyclical: 'week' }
+    params: {
+      businessGroupId: '',
+      dataPermission: defaultPermValue,
+      cyclical: defaultCyclicalValue
+    }
   })
   const { toggleModal, setModalProps } = useModal()
   // 展示服务弹窗详情
@@ -208,6 +224,11 @@ const Dashboard = () => {
       params: { ...state.params, staffIds: null, dataPermission }
     })
   }
+
+  const handleCyclicalChange = value => {
+    setAuthCache(WORKBENCH_CYCLICAL_KEY, value)
+    setState({ ...state, immediate: true, params: { ...state.params, cyclical: value } })
+  }
   return (
     <div>
       <div className="shadow-card">
@@ -240,10 +261,8 @@ const Dashboard = () => {
             loading={state.loading}
             options={cyclicalOp}
             dropdownMatchSelectWidth={false}
-            defaultValue="week"
-            onChange={e =>
-              setState({ ...state, immediate: true, params: { ...state.params, cyclical: e } })
-            }
+            defaultValue={defaultCyclicalValue}
+            onChange={handleCyclicalChange}
           />
         </span>
       </div>

+ 3 - 0
src/utils/cache/cacheEnum.ts

@@ -17,6 +17,9 @@ export const PERMISSION_SELECT_KEY = 'PERMISSION_SELECT_KEY'
 // table columns map
 export const TABLE_COLUMNS_MAP = 'TABLE_COLUMNS_MAP'
 
+// workbench cyclical key
+export const WORKBENCH_CYCLICAL_KEY = 'WORKBENCH_CYCLICAL_KEY'
+
 // permission select component defualtValue key
 export enum MainMenuKeyEnum {
   /** @name 客户 */

+ 3 - 1
src/utils/cache/persistent.ts

@@ -10,7 +10,8 @@ import {
   CASCADER_HISTORY_KEY,
   PERMISSION_SELECT_KEY,
   MAIN_MENU_KEY,
-  TABLE_COLUMNS_MAP
+  TABLE_COLUMNS_MAP,
+  WORKBENCH_CYCLICAL_KEY
 } from './cacheEnum'
 import { DEFAULT_CACHE_TIME } from '@/settings/encryptionSetting'
 import { pick, omit } from 'lodash-es'
@@ -20,6 +21,7 @@ interface BasicStore {
   [CASCADER_HISTORY_KEY]: { key: string; value: string[]; label: string }[] | null | underfined
   [PERMISSION_SELECT_KEY]: { [key in MAIN_MENU_KEY]: string } | null | underfined
   [TABLE_COLUMNS_MAP]: { [key in MAIN_MENU_KEY]: Record<string, ColumnsState> } | null | underfined
+  [WORKBENCH_CYCLICAL_KEY]: string
 }
 
 type LocalStore = BasicStore