|
| 1 | +import { SVGCharts, Tooltip, TreeSeries } from 'echarts-jsx'; |
| 2 | +import { Loading } from 'idea-react'; |
| 3 | +import { observer } from 'mobx-react'; |
| 4 | +import { ObservedComponent } from 'mobx-react-helper'; |
| 5 | +import { Form } from 'react-bootstrap'; |
| 6 | +import { renderToStaticMarkup } from 'react-dom/server'; |
| 7 | + |
| 8 | +import { DepartmentModel, DepartmentNode } from '../../models/Personnel/Department'; |
| 9 | +import { i18n, I18nContext } from '../../models/Translation'; |
| 10 | +import { GroupCard } from './Card'; |
| 11 | + |
| 12 | +@observer |
| 13 | +export default class DepartmentTree extends ObservedComponent<{}, typeof i18n> { |
| 14 | + static contextType = I18nContext; |
| 15 | + |
| 16 | + store = new DepartmentModel(); |
| 17 | + |
| 18 | + componentDidMount() { |
| 19 | + this.store.getAll(); |
| 20 | + } |
| 21 | + |
| 22 | + renderGroup(name: string) { |
| 23 | + const group = this.store.allItems.find(({ name: n }) => n === name); |
| 24 | + |
| 25 | + return renderToStaticMarkup(group?.summary ? <GroupCard {...group} /> : <></>); |
| 26 | + } |
| 27 | + |
| 28 | + jumpLink({ name }: DepartmentNode) { |
| 29 | + if (name === '理事会') { |
| 30 | + location.href = '/department/board-of-directors'; |
| 31 | + } else { |
| 32 | + location.href = `/department/${name}`; |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + render() { |
| 37 | + const { t } = this.observedContext, |
| 38 | + { downloading, activeShown, tree } = this.store; |
| 39 | + |
| 40 | + return ( |
| 41 | + <> |
| 42 | + {downloading > 0 && <Loading />} |
| 43 | + |
| 44 | + <label className="d-flex justify-content-center gap-3"> |
| 45 | + {t('show_active_departments')} |
| 46 | + <Form.Switch checked={activeShown} onChange={this.store.toggleActive} /> |
| 47 | + </label> |
| 48 | + |
| 49 | + <SVGCharts style={{ height: '80vh' }}> |
| 50 | + <Tooltip trigger="item" triggerOn="mousemove" /> |
| 51 | + |
| 52 | + <TreeSeries |
| 53 | + label={{ |
| 54 | + position: 'left', |
| 55 | + verticalAlign: 'middle', |
| 56 | + fontSize: 16, |
| 57 | + }} |
| 58 | + tooltip={{ |
| 59 | + formatter: ({ name }) => this.renderGroup(name), |
| 60 | + }} |
| 61 | + data={[tree]} |
| 62 | + onClick={({ data }) => this.jumpLink(data as DepartmentNode)} |
| 63 | + /> |
| 64 | + </SVGCharts> |
| 65 | + </> |
| 66 | + ); |
| 67 | + } |
| 68 | +} |
0 commit comments