diff --git a/src/pages/dashboard/analysis/components/Charts/Bar/index.tsx b/src/pages/dashboard/analysis/components/Charts/Bar/index.tsx index c419fdc9..8f1157ad 100644 --- a/src/pages/dashboard/analysis/components/Charts/Bar/index.tsx +++ b/src/pages/dashboard/analysis/components/Charts/Bar/index.tsx @@ -1,8 +1,8 @@ import { Axis, Chart, Geom, Tooltip } from 'bizcharts'; -import React, { Component } from 'react'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; import Debounce from 'lodash.debounce'; -import autoHeight from '../autoHeight'; import useStyles from '../index.style'; + export type BarProps = { title: React.ReactNode; color?: string; @@ -16,123 +16,107 @@ export type BarProps = { autoLabel?: boolean; style?: React.CSSProperties; }; -class Bar extends Component< - BarProps, - { - autoHideXLabels: boolean; - } -> { - state = { - autoHideXLabels: false, - }; - root: HTMLDivElement | undefined = undefined; - node: HTMLDivElement | undefined = undefined; - resize = Debounce(() => { - if (!this.node || !this.node.parentNode) { - return; - } - const canvasWidth = (this.node.parentNode as HTMLDivElement).clientWidth; - const { data = [], autoLabel = true } = this.props; - if (!autoLabel) { - return; - } - const minWidth = data.length * 30; - const { autoHideXLabels } = this.state; - if (canvasWidth <= minWidth) { - if (!autoHideXLabels) { - this.setState({ - autoHideXLabels: true, - }); +const Bar: React.FC = ({ + height = 1, + title, + forceFit = true, + data, + color = 'rgba(24, 144, 255, 0.85)', + padding, + autoLabel = true, +}) => { + const { styles } = useStyles(); + const [autoHideXLabels, setAutoHideXLabels] = useState(false); + const rootRef = useRef(null); + const nodeRef = useRef(null); + + const resize = useCallback( + Debounce(() => { + if (!nodeRef.current || !nodeRef.current.parentNode) { + return; + } + const canvasWidth = nodeRef.current.parentNode?.clientWidth || 0; + if (!autoLabel) { + return; } - } else if (autoHideXLabels) { - this.setState({ - autoHideXLabels: false, - }); - } - }, 500); - componentDidMount() { - window.addEventListener('resize', this.resize, { + const minWidth = data?.length * 30; + if (canvasWidth <= minWidth) { + if (!autoHideXLabels) { + setAutoHideXLabels(true); + } + } else if (autoHideXLabels) { + setAutoHideXLabels(false); + } + }, 500), + [autoHideXLabels, autoLabel, data?.length], + ); + + useEffect(() => { + window.addEventListener('resize', resize, { passive: true, }); - } - componentWillUnmount() { - window.removeEventListener('resize', this.resize); - } - handleRoot = (n: HTMLDivElement) => { - this.root = n; - }; - handleRef = (n: HTMLDivElement) => { - this.node = n; - }; - render() { - const { - height = 1, - title, - forceFit = true, - data, - color = 'rgba(24, 144, 255, 0.85)', - padding, - } = this.props; - const { autoHideXLabels } = this.state; - const scale = { - x: { - type: 'cat', - }, - y: { - min: 0, - }, + return () => { + window.removeEventListener('resize', resize); }; - const tooltip: [ - string, - (...args: any[]) => { - name?: string; - value: string; - }, - ] = [ - 'x*y', - (x: string, y: string) => ({ - name: x, - value: y, - }), - ]; - return ( -
-
- {title && ( -

- {title} -

- )} - { + rootRef.current = n; + }, []); + + const handleRef = useCallback((n: HTMLDivElement) => { + nodeRef.current = n; + }, []); + + const scale = { + x: { + type: 'cat', + }, + y: { + min: 0, + }, + }; + + const tooltip = [ + 'x*y', + (x: string, y: string) => ({ + name: x, + value: y, + }), + ]; + + return ( +
+
+ {title && ( +

- - - - - -

+ {title} + + )} + + + + + +
- ); - } -} -export default autoHeight()(Bar); +
+ ); +}; + +export default Bar; diff --git a/src/pages/dashboard/analysis/components/Charts/autoHeight.tsx b/src/pages/dashboard/analysis/components/Charts/autoHeight.tsx deleted file mode 100644 index cd9bcf24..00000000 --- a/src/pages/dashboard/analysis/components/Charts/autoHeight.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import React from 'react'; - -export type IReactComponent

= React.ComponentClass

| React.ClassicComponentClass

; - -function computeHeight(node: HTMLDivElement) { - const { style } = node; - style.height = '100%'; - const totalHeight = parseInt(`${getComputedStyle(node).height}`, 10); - const padding = - parseInt(`${getComputedStyle(node).paddingTop}`, 10) + - parseInt(`${getComputedStyle(node).paddingBottom}`, 10); - return totalHeight - padding; -} - -function getAutoHeight(n: HTMLDivElement | undefined) { - if (!n) { - return 0; - } - - const node = n; - - let height = computeHeight(node); - const parentNode = node.parentNode as HTMLDivElement; - if (parentNode) { - height = computeHeight(parentNode); - } - - return height; -} - -type AutoHeightProps = { - height?: number; -}; - -function autoHeight() { - return

( - WrappedComponent: React.ComponentClass

| React.FC

, - ): React.ComponentClass

=> { - class AutoHeightComponent extends React.Component

{ - state = { - computedHeight: 0, - }; - - root: HTMLDivElement | undefined = undefined; - - componentDidMount() { - const { height } = this.props; - if (!height) { - let h = getAutoHeight(this.root); - this.setState({ computedHeight: h }); - if (h < 1) { - h = getAutoHeight(this.root); - this.setState({ computedHeight: h }); - } - } - } - - handleRoot = (node: HTMLDivElement) => { - this.root = node; - }; - - render() { - const { height } = this.props; - const { computedHeight } = this.state; - const h = height || computedHeight; - return ( -

- {h > 0 && } -
- ); - } - } - return AutoHeightComponent; - }; -} -export default autoHeight; diff --git a/src/pages/dashboard/analysis/utils/utils.less b/src/pages/dashboard/analysis/utils/utils.less deleted file mode 100644 index de1aa642..00000000 --- a/src/pages/dashboard/analysis/utils/utils.less +++ /dev/null @@ -1,50 +0,0 @@ -.textOverflow() { - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; - word-break: break-all; -} - -.textOverflowMulti(@line: 3, @bg: #fff) { - position: relative; - max-height: @line * 1.5em; - margin-right: -1em; - padding-right: 1em; - overflow: hidden; - line-height: 1.5em; - text-align: justify; - &::before { - position: absolute; - right: 14px; - bottom: 0; - padding: 0 1px; - background: @bg; - content: '...'; - } - &::after { - position: absolute; - right: 14px; - width: 1em; - height: 1em; - margin-top: 0.2em; - background: white; - content: ''; - } -} - -// mixins for clearfix -// ------------------------ -.clearfix() { - zoom: 1; - &::before, - &::after { - display: table; - content: ' '; - } - &::after { - clear: both; - height: 0; - font-size: 0; - visibility: hidden; - } -} diff --git a/src/pages/dashboard/analysis/utils/utils.style.ts b/src/pages/dashboard/analysis/utils/utils.style.ts deleted file mode 100644 index 0ad5e64a..00000000 --- a/src/pages/dashboard/analysis/utils/utils.style.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { createStyles } from 'antd-style'; - -const useStyles = createStyles(() => { - return {}; -}); -export default useStyles; diff --git a/src/pages/dashboard/monitor/index.tsx b/src/pages/dashboard/monitor/index.tsx index 75561f11..62e646a2 100644 --- a/src/pages/dashboard/monitor/index.tsx +++ b/src/pages/dashboard/monitor/index.tsx @@ -114,14 +114,6 @@ const Monitor: FC = () => { > - {/* */} diff --git a/src/pages/dashboard/workplace/components/Radar/autoHeight.tsx b/src/pages/dashboard/workplace/components/Radar/autoHeight.tsx deleted file mode 100644 index cd9bcf24..00000000 --- a/src/pages/dashboard/workplace/components/Radar/autoHeight.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import React from 'react'; - -export type IReactComponent

= React.ComponentClass

| React.ClassicComponentClass

; - -function computeHeight(node: HTMLDivElement) { - const { style } = node; - style.height = '100%'; - const totalHeight = parseInt(`${getComputedStyle(node).height}`, 10); - const padding = - parseInt(`${getComputedStyle(node).paddingTop}`, 10) + - parseInt(`${getComputedStyle(node).paddingBottom}`, 10); - return totalHeight - padding; -} - -function getAutoHeight(n: HTMLDivElement | undefined) { - if (!n) { - return 0; - } - - const node = n; - - let height = computeHeight(node); - const parentNode = node.parentNode as HTMLDivElement; - if (parentNode) { - height = computeHeight(parentNode); - } - - return height; -} - -type AutoHeightProps = { - height?: number; -}; - -function autoHeight() { - return

( - WrappedComponent: React.ComponentClass

| React.FC

, - ): React.ComponentClass

=> { - class AutoHeightComponent extends React.Component

{ - state = { - computedHeight: 0, - }; - - root: HTMLDivElement | undefined = undefined; - - componentDidMount() { - const { height } = this.props; - if (!height) { - let h = getAutoHeight(this.root); - this.setState({ computedHeight: h }); - if (h < 1) { - h = getAutoHeight(this.root); - this.setState({ computedHeight: h }); - } - } - } - - handleRoot = (node: HTMLDivElement) => { - this.root = node; - }; - - render() { - const { height } = this.props; - const { computedHeight } = this.state; - const h = height || computedHeight; - return ( -

- {h > 0 && } -
- ); - } - } - return AutoHeightComponent; - }; -} -export default autoHeight; diff --git a/src/pages/dashboard/workplace/components/Radar/index.tsx b/src/pages/dashboard/workplace/components/Radar/index.tsx index 81819a92..f5d81d0a 100644 --- a/src/pages/dashboard/workplace/components/Radar/index.tsx +++ b/src/pages/dashboard/workplace/components/Radar/index.tsx @@ -1,7 +1,6 @@ import { Axis, Chart, Coord, Geom, Tooltip } from 'bizcharts'; import { Col, Row } from 'antd'; import React, { useEffect, useRef, useState } from 'react'; -import autoHeight from './autoHeight'; export type RadarProps = { title?: React.ReactNode; @@ -172,4 +171,4 @@ const Radar: React.FC = (props) => { ); }; -export default autoHeight()(Radar); +export default Radar; diff --git a/src/pages/dashboard/workplace/index.tsx b/src/pages/dashboard/workplace/index.tsx index 23aa9714..155cb5cb 100644 --- a/src/pages/dashboard/workplace/index.tsx +++ b/src/pages/dashboard/workplace/index.tsx @@ -10,6 +10,7 @@ import type { ActivitiesType, CurrentUser } from './data.d'; import { queryProjectNotice, queryActivities, fakeChartData } from './service'; import relativeTime from 'dayjs/plugin/relativeTime'; dayjs.extend(relativeTime); + const links = [ { title: '操作一', @@ -223,7 +224,7 @@ const Workplace: FC = () => { title="XX 指数" loading={data?.radarData?.length === 0} > -
+
{ flex: '1 1 0', color: token.colorTextSecondary, position: 'relative', - maxHeight: token.line * 1.5, + maxHeight: '4.5em', marginRight: '-1em', paddingRight: '1em', overflow: 'hidden', @@ -80,7 +80,7 @@ const useStyles = createStyles(({ token }) => { right: '14px', bottom: '0', padding: '0 1px', - background: token.bg, + background: token.colorBgContainer, content: "'...'", }, '&::after': { @@ -123,7 +123,7 @@ const useStyles = createStyles(({ token }) => { fontSize: '12px', lineHeight: '1.5em', position: 'relative', - maxHeight: token.line * 1.5, + maxHeight: '4.5em', marginRight: '-1em', paddingRight: '1em', textAlign: 'justify', @@ -132,7 +132,7 @@ const useStyles = createStyles(({ token }) => { right: '14px', bottom: '0', padding: '0 1px', - background: token.bg, + background: token.colorBgContainer, content: "'...'", }, '&::after': {