|
@@ -1,18 +1,14 @@
|
|
|
-import { useState, useEffect, useRef, useMemo } from 'react'
|
|
|
|
|
|
|
+import { useState, useRef, useMemo } from 'react'
|
|
|
import BasicTable from '@/components/Table'
|
|
import BasicTable from '@/components/Table'
|
|
|
-import { DatePicker, Select, TreeSelect, Table, Typography } from 'antd'
|
|
|
|
|
-import { querySoftwareUsageList, queryUsageSelectOptions } from '@/services/statistic'
|
|
|
|
|
|
|
+import { DatePicker, Table, Typography } from 'antd'
|
|
|
|
|
+import { querySoftwareUsageList } from '@/services/statistic'
|
|
|
import consts from '@/consts'
|
|
import consts from '@/consts'
|
|
|
-import { useDebounceFn } from 'ahooks'
|
|
|
|
|
import dayjs from 'dayjs'
|
|
import dayjs from 'dayjs'
|
|
|
import { Pie } from '@ant-design/charts'
|
|
import { Pie } from '@ant-design/charts'
|
|
|
import { isMobile } from '@/utils/is'
|
|
import { isMobile } from '@/utils/is'
|
|
|
|
|
+import OptionSelect from '../../components/OptionSelect'
|
|
|
|
|
|
|
|
const { Text } = Typography
|
|
const { Text } = Typography
|
|
|
-const opMap = {
|
|
|
|
|
- STAFF: 'staff',
|
|
|
|
|
- DEPARTMENT: 'department'
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
const colLabelValToZH = {
|
|
const colLabelValToZH = {
|
|
|
giftsCount: '赠送',
|
|
giftsCount: '赠送',
|
|
@@ -23,42 +19,12 @@ const colLabelValToZH = {
|
|
|
const Usage = () => {
|
|
const Usage = () => {
|
|
|
const tRef = useRef(null)
|
|
const tRef = useRef(null)
|
|
|
const [state, setState] = useState({
|
|
const [state, setState] = useState({
|
|
|
- optionType: opMap.STAFF,
|
|
|
|
|
- opIds: [],
|
|
|
|
|
- department: null,
|
|
|
|
|
- staff: null,
|
|
|
|
|
- startMonth: [dayjs(new Date()), dayjs(new Date())]
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- const queryStaffAndDepartment = async () => {
|
|
|
|
|
- const { code = -1, data: { department = [], staff = [] } = {} } =
|
|
|
|
|
- await queryUsageSelectOptions()
|
|
|
|
|
- if (code === consts.RET_CODE.SUCCESS) {
|
|
|
|
|
- setState({
|
|
|
|
|
- ...state,
|
|
|
|
|
- department,
|
|
|
|
|
- staff
|
|
|
|
|
- })
|
|
|
|
|
- tRef.current?.reload()
|
|
|
|
|
|
|
+ params: {
|
|
|
|
|
+ optionType: 'staff',
|
|
|
|
|
+ dataIds: [],
|
|
|
|
|
+ startMonth: [dayjs(new Date()), dayjs(new Date())]
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const mainParams = useMemo(() => {
|
|
|
|
|
- const p = { optionType: state.optionType, startMonth: state.startMonth[0].format('YYYY-MM') }
|
|
|
|
|
- if (state.optionType === opMap.STAFF) {
|
|
|
|
|
- p.staffIds = state.opIds
|
|
|
|
|
- } else {
|
|
|
|
|
- p.departmentIds = state.opIds
|
|
|
|
|
- }
|
|
|
|
|
- return p
|
|
|
|
|
- }, [state.optionType, state.opIds, state.startMonth])
|
|
|
|
|
-
|
|
|
|
|
- const options = useMemo(() => {
|
|
|
|
|
- if (state.optionType === opMap.STAFF) {
|
|
|
|
|
- return state.staff?.map(item => ({ label: item.username, value: item.id })) || []
|
|
|
|
|
- }
|
|
|
|
|
- return state.department || []
|
|
|
|
|
- }, [state.optionType, state.staff, state.department])
|
|
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
const pieData = useMemo(() => {
|
|
const pieData = useMemo(() => {
|
|
|
if (!state.chart || !state.sum) return {}
|
|
if (!state.chart || !state.sum) return {}
|
|
@@ -79,21 +45,6 @@ const Usage = () => {
|
|
|
return { pieLeft, pieRight }
|
|
return { pieLeft, pieRight }
|
|
|
}, [state.chart])
|
|
}, [state.chart])
|
|
|
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- queryStaffAndDepartment()
|
|
|
|
|
- }, [])
|
|
|
|
|
- const { run: trySetOpIds } = useDebounceFn(
|
|
|
|
|
- ids => {
|
|
|
|
|
- setState({ ...state, opIds: ids })
|
|
|
|
|
- },
|
|
|
|
|
- { wait: 500 }
|
|
|
|
|
- )
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- // 发起请求
|
|
|
|
|
- if (state.opIds?.length) {
|
|
|
|
|
- tRef.current?.reload()
|
|
|
|
|
- }
|
|
|
|
|
- }, [state.opIds])
|
|
|
|
|
const columns = [
|
|
const columns = [
|
|
|
{
|
|
{
|
|
|
title: '名称',
|
|
title: '名称',
|
|
@@ -164,6 +115,9 @@ const Usage = () => {
|
|
|
interactions: [{ type: 'element-active' }]
|
|
interactions: [{ type: 'element-active' }]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const optionChange = (type, ids) =>
|
|
|
|
|
+ setState({ ...state, params: { ...state.params, optionType: type, dataIds: ids } })
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className="flex flex-col">
|
|
<div className="flex flex-col">
|
|
|
{!isMobile() && (
|
|
{!isMobile() && (
|
|
@@ -184,49 +138,18 @@ const Usage = () => {
|
|
|
actionRef={tRef}
|
|
actionRef={tRef}
|
|
|
rowkey="id"
|
|
rowkey="id"
|
|
|
toolbar={{
|
|
toolbar={{
|
|
|
- title: [
|
|
|
|
|
- <Select
|
|
|
|
|
- key="Select"
|
|
|
|
|
- defaultValue="staff"
|
|
|
|
|
- options={[
|
|
|
|
|
- { label: '部门', value: 'department' },
|
|
|
|
|
- { label: '员工', value: 'staff' }
|
|
|
|
|
- ]}
|
|
|
|
|
- onChange={val => setState({ ...state, optionType: val })}
|
|
|
|
|
- />,
|
|
|
|
|
- state.optionType === opMap.STAFF ? (
|
|
|
|
|
- <Select
|
|
|
|
|
- key="StaffSelect"
|
|
|
|
|
- className="min-w-120px"
|
|
|
|
|
- defaultOpen
|
|
|
|
|
- dropdownMatchSelectWidth
|
|
|
|
|
- options={options}
|
|
|
|
|
- mode="multiple"
|
|
|
|
|
- onChange={value => trySetOpIds(value)}
|
|
|
|
|
- />
|
|
|
|
|
- ) : (
|
|
|
|
|
- <TreeSelect
|
|
|
|
|
- key="DepartmentSelect"
|
|
|
|
|
- defaultOpen
|
|
|
|
|
- treeData={options}
|
|
|
|
|
- className="min-w-180px"
|
|
|
|
|
- dropdownMatchSelectWidth
|
|
|
|
|
- multiple
|
|
|
|
|
- onChange={value => trySetOpIds(value)}
|
|
|
|
|
- />
|
|
|
|
|
- )
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ title: <OptionSelect onChange={optionChange} />,
|
|
|
actions: [
|
|
actions: [
|
|
|
<DatePicker.RangePicker
|
|
<DatePicker.RangePicker
|
|
|
picker="month"
|
|
picker="month"
|
|
|
key="DatePicker"
|
|
key="DatePicker"
|
|
|
disabled={[false, true]}
|
|
disabled={[false, true]}
|
|
|
value={state.startMonth}
|
|
value={state.startMonth}
|
|
|
- onChange={val => setState({ ...state, startMonth: val })}
|
|
|
|
|
|
|
+ onChange={val => setState({ ...state, params: { ...state.params, startMonth: val } })}
|
|
|
/>
|
|
/>
|
|
|
]
|
|
]
|
|
|
}}
|
|
}}
|
|
|
- params={mainParams}
|
|
|
|
|
|
|
+ params={state.params}
|
|
|
pagination={false}
|
|
pagination={false}
|
|
|
bordered
|
|
bordered
|
|
|
request={async (params, sort, filter) => {
|
|
request={async (params, sort, filter) => {
|