|
@@ -1,21 +1,27 @@
|
|
|
import consts from '@/consts'
|
|
import consts from '@/consts'
|
|
|
import { queryUsageSelectOptions } from '@/services/statistic'
|
|
import { queryUsageSelectOptions } from '@/services/statistic'
|
|
|
|
|
+import { getAuthCache, setAuthCache } from '@/utils/auth'
|
|
|
|
|
+import { STATISTIC_OPTION_KEY } from '@/utils/cache/cacheEnum'
|
|
|
import { useDebounceFn } from 'ahooks'
|
|
import { useDebounceFn } from 'ahooks'
|
|
|
import { Select, TreeSelect } from 'antd'
|
|
import { Select, TreeSelect } from 'antd'
|
|
|
import React, { useState, useEffect } from 'react'
|
|
import React, { useState, useEffect } from 'react'
|
|
|
|
|
|
|
|
-enum opMap {
|
|
|
|
|
|
|
+export enum statisticOptionMap {
|
|
|
STAFF = 'staff',
|
|
STAFF = 'staff',
|
|
|
DEPARTMENT = 'department'
|
|
DEPARTMENT = 'department'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type OptionSelectProps = {
|
|
type OptionSelectProps = {
|
|
|
|
|
+ type: string
|
|
|
onChange: (type: 'staff' | 'department', value) => void
|
|
onChange: (type: 'staff' | 'department', value) => void
|
|
|
}
|
|
}
|
|
|
-const OptionSelect: React.FC<OptionSelectProps> = ({ onChange }) => {
|
|
|
|
|
|
|
+const OptionSelect: React.FC<OptionSelectProps> = ({ type, onChange }) => {
|
|
|
|
|
+ const authOptions = getAuthCache(STATISTIC_OPTION_KEY)
|
|
|
|
|
+ const { optionType, dataIds } = authOptions?.[type] || {}
|
|
|
|
|
+
|
|
|
const [state, setState] = useState({
|
|
const [state, setState] = useState({
|
|
|
- optionType: opMap.STAFF,
|
|
|
|
|
- opIds: [],
|
|
|
|
|
|
|
+ optionType: optionType || statisticOptionMap.STAFF,
|
|
|
|
|
+ dataIds: dataIds || [],
|
|
|
department: [],
|
|
department: [],
|
|
|
staff: []
|
|
staff: []
|
|
|
})
|
|
})
|
|
@@ -33,12 +39,19 @@ const OptionSelect: React.FC<OptionSelectProps> = ({ onChange }) => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
queryStaffAndDepartment()
|
|
queryStaffAndDepartment()
|
|
|
|
|
+ if (optionType && dataIds?.length) {
|
|
|
|
|
+ onChange(optionType, dataIds)
|
|
|
|
|
+ }
|
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
|
const { run: trySetOpIds } = useDebounceFn(
|
|
const { run: trySetOpIds } = useDebounceFn(
|
|
|
ids => {
|
|
ids => {
|
|
|
- setState({ ...state, opIds: ids })
|
|
|
|
|
|
|
+ setState({ ...state, dataIds: ids })
|
|
|
onChange(state.optionType, ids)
|
|
onChange(state.optionType, ids)
|
|
|
|
|
+ setAuthCache(STATISTIC_OPTION_KEY, {
|
|
|
|
|
+ ...authOptions,
|
|
|
|
|
+ [type]: { optionType: state.optionType, dataIds: ids }
|
|
|
|
|
+ })
|
|
|
},
|
|
},
|
|
|
{ wait: 500 }
|
|
{ wait: 500 }
|
|
|
)
|
|
)
|
|
@@ -46,19 +59,19 @@ const OptionSelect: React.FC<OptionSelectProps> = ({ onChange }) => {
|
|
|
<div>
|
|
<div>
|
|
|
<span className="mr-2">
|
|
<span className="mr-2">
|
|
|
<Select
|
|
<Select
|
|
|
- defaultValue="staff"
|
|
|
|
|
|
|
+ defaultValue={state.optionType}
|
|
|
options={[
|
|
options={[
|
|
|
{ label: '按部门', value: 'department' },
|
|
{ label: '按部门', value: 'department' },
|
|
|
{ label: '按员工', value: 'staff' }
|
|
{ label: '按员工', value: 'staff' }
|
|
|
]}
|
|
]}
|
|
|
- onChange={val => setState({ ...state, optionType: val, opIds: [] })}
|
|
|
|
|
|
|
+ onChange={val => setState({ ...state, optionType: val, dataIds: [] })}
|
|
|
/>
|
|
/>
|
|
|
</span>
|
|
</span>
|
|
|
- {state.optionType === opMap.STAFF ? (
|
|
|
|
|
|
|
+ {state.optionType === statisticOptionMap.STAFF ? (
|
|
|
<TreeSelect
|
|
<TreeSelect
|
|
|
- value={state.opIds}
|
|
|
|
|
|
|
+ value={state.dataIds}
|
|
|
className="min-w-180px"
|
|
className="min-w-180px"
|
|
|
- defaultOpen
|
|
|
|
|
|
|
+ // defaultOpen
|
|
|
treeCheckable
|
|
treeCheckable
|
|
|
showCheckedStrategy="SHOW_PARENT"
|
|
showCheckedStrategy="SHOW_PARENT"
|
|
|
dropdownMatchSelectWidth
|
|
dropdownMatchSelectWidth
|
|
@@ -67,9 +80,9 @@ const OptionSelect: React.FC<OptionSelectProps> = ({ onChange }) => {
|
|
|
/>
|
|
/>
|
|
|
) : (
|
|
) : (
|
|
|
<TreeSelect
|
|
<TreeSelect
|
|
|
- value={state.opIds}
|
|
|
|
|
|
|
+ value={state.dataIds}
|
|
|
className="min-w-180px"
|
|
className="min-w-180px"
|
|
|
- defaultOpen
|
|
|
|
|
|
|
+ // defaultOpen
|
|
|
treeData={state.department}
|
|
treeData={state.department}
|
|
|
dropdownMatchSelectWidth
|
|
dropdownMatchSelectWidth
|
|
|
multiple
|
|
multiple
|