Przeglądaj źródła

Merge branch 'master' of http://git.ycjcjy.com/medical-plat/pc-admin into master

zlisen 4 lat temu
rodzic
commit
9903962524

+ 1
- 0
package.json Wyświetl plik

@@ -55,6 +55,7 @@
55 55
     "antd": "^4.12.0",
56 56
     "array-move": "^3.0.1",
57 57
     "classnames": "^2.2.6",
58
+    "echarts": "^5.1.0",
58 59
     "lodash": "^4.17.11",
59 60
     "md5": "^2.3.0",
60 61
     "moment": "^2.25.3",

+ 39
- 0
src/components/ECharts/index.jsx Wyświetl plik

@@ -0,0 +1,39 @@
1
+// echarts 包太大, 因此需要按需引入
2
+import React, { useEffect, useRef, useImperativeHandle } from 'react';
3
+// 引入 echarts 核心模块,核心模块提供了 echarts 使用必须要的接口。
4
+import * as echarts from 'echarts/core';
5
+// 引入柱状图图表,图表后缀都为 Chart
6
+import {
7
+    BarChart
8
+} from 'echarts/charts';
9
+// 引入提示框,标题,直角坐标系组件,组件后缀都为 Component
10
+import {
11
+    TitleComponent,
12
+    TooltipComponent,
13
+    GridComponent
14
+} from 'echarts/components';
15
+
16
+// 注册必须的组件
17
+echarts.use(
18
+  [TitleComponent, TooltipComponent, GridComponent, BarChart]
19
+);
20
+
21
+export default React.forwardRef((props, ref) => {
22
+  const el = useRef()
23
+  const chartRef = useRef()
24
+
25
+  // 向父组件公开 echarts 实例
26
+  useImperativeHandle(ref, () => ({
27
+    chart: chartRef.current,
28
+  }))
29
+
30
+  useEffect(() => {
31
+    const chart = echarts.init(el.current)
32
+    chart.setOption(props.option)
33
+    chartRef.current = chart
34
+
35
+    return () => chart.dispose()
36
+  }, [props.option])
37
+
38
+  return <div ref={el}></div>
39
+})

+ 2
- 4
src/components/GlobalHeader/AvatarDropdown.jsx Wyświetl plik

@@ -2,6 +2,7 @@ import { LogoutOutlined } from '@ant-design/icons';
2 2
 import { Avatar, Menu, Spin } from 'antd';
3 3
 import React from 'react';
4 4
 import { history, connect } from 'umi';
5
+import { defaultAvatar } from '@/utils/utils';
5 6
 import HeaderDropdown from '../HeaderDropdown';
6 7
 import styles from './index.less';
7 8
 
@@ -45,10 +46,7 @@ class AvatarDropdown extends React.Component {
45 46
           <Avatar
46 47
             size="small"
47 48
             className={styles.avatar}
48
-            src={
49
-              currentUser.avatar ||
50
-              'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
51
-            }
49
+            src={ currentUser.avatar || defaultAvatar }
52 50
             alt="avatar"
53 51
           />
54 52
           <span className={`${styles.name} anticon`}>{currentUser.userName}</span>

+ 0
- 8
src/pages/Welcome.less Wyświetl plik

@@ -1,8 +0,0 @@
1
-@import '~antd/lib/style/themes/default.less';
2
-
3
-.pre {
4
-  margin: 12px 0;
5
-  padding: 12px 20px;
6
-  background: @input-bg;
7
-  box-shadow: @card-shadow;
8
-}

+ 47
- 0
src/pages/Welcome/components/HeaderContent.jsx Wyświetl plik

@@ -0,0 +1,47 @@
1
+import React, { useState, useEffect } from 'react'
2
+import { Image, Statistic, Spin, Badge } from 'antd'
3
+import { connect } from 'umi'
4
+import request from '@/utils/request'
5
+import { defaultAvatar } from '@/utils/utils';
6
+import Styles from '../style.less'
7
+
8
+const HeaderContent = (props) => {
9
+  const [loading, setLoading] = useState(false)
10
+  const [statis, setStatis] = useState({})
11
+
12
+  useEffect(() => {
13
+    setLoading(true)
14
+    request('/index/post-data').then((res) => {
15
+      setStatis(res)
16
+      setLoading(false)
17
+    }).catch((e) => {
18
+      setLoading(false)
19
+    })
20
+  }, [])
21
+
22
+  return (
23
+    <div className={Styles['header-content']}>
24
+      <div className={Styles['ctt-header']}>
25
+        <Image width="100%" src={props.user.avatar || defaultAvatar} />
26
+      </div>
27
+      <div className={Styles['ctt-body']}>
28
+        <h3>{`你好, ${props.user.userName}, 祝你开心每一天!`}</h3>
29
+        <p>
30
+          <span className={Styles['sub-title']}>{`登录名: ${props.user.loginName}`}</span>
31
+          <span className={Styles['sub-title']}>状态: 正常 <Badge status="success" /></span>
32
+        </p>
33
+      </div>
34
+      <div className={Styles['ctt-footer']}>
35
+        <Spin spinning={loading}>
36
+          <div className={Styles['st-wrapper']}>
37
+            <div className={Styles['st-item']}><Statistic title="科普数量" value={statis.total} /></div>
38
+            <div className={Styles['st-item']}><Statistic title="浏览总数" value={statis.pv} /></div>
39
+            <div className={Styles['st-item']}><Statistic title="学生总数" value={statis.student} /></div>
40
+          </div>
41
+        </Spin>
42
+      </div>
43
+    </div>
44
+  )
45
+}
46
+
47
+export default connect((s) => ({ user: s.user.currentUser }))(HeaderContent)

src/pages/Welcome.jsx → src/pages/Welcome/index.jsx Wyświetl plik

@@ -2,20 +2,18 @@ import React from 'react';
2 2
 import { PageContainer } from '@ant-design/pro-layout';
3 3
 import { Card, Alert, Typography } from 'antd';
4 4
 // import { useIntl, FormattedMessage } from 'umi';
5
-import styles from './Welcome.less';
6
-
7
-const CodePreview = ({ children }) => (
8
-  <pre className={styles.pre}>
9
-    <code>
10
-      <Typography.Text copyable>{children}</Typography.Text>
11
-    </code>
12
-  </pre>
13
-);
5
+import HeaderContent from './components/HeaderContent';
6
+import styles from './style.less';
14 7
 
15 8
 export default () => {
16 9
   // const intl = useIntl();
17 10
   return (
18
-    <PageContainer>
11
+    <PageContainer
12
+      header={{
13
+        title: '工作台'
14
+      }}
15
+      content={<HeaderContent />}
16
+    >
19 17
       <Card>
20 18
         <Alert
21 19
           // message={intl.formatMessage({
@@ -43,7 +41,7 @@ export default () => {
43 41
             欢迎使用
44 42
           </a>
45 43
         </Typography.Text>
46
-        <CodePreview>yarn add @ant-design/pro-table</CodePreview>
44
+    
47 45
         <Typography.Text
48 46
           strong
49 47
           style={{
@@ -61,7 +59,7 @@ export default () => {
61 59
             欢迎使用
62 60
           </a>
63 61
         </Typography.Text>
64
-        <CodePreview>yarn add @ant-design/pro-layout</CodePreview>
62
+
65 63
       </Card>
66 64
     </PageContainer>
67 65
   );

+ 55
- 0
src/pages/Welcome/style.less Wyświetl plik

@@ -0,0 +1,55 @@
1
+@import '~antd/lib/style/themes/default.less';
2
+
3
+.header-content {
4
+  display: flex;
5
+  
6
+  .ctt-header {
7
+    flex: none;
8
+    width: 72px;
9
+    height: 72px;
10
+    
11
+    img {
12
+      border-radius: 50%;
13
+      overflow: hidden;
14
+    }
15
+  }
16
+
17
+  .ctt-body {
18
+    flex: auto;
19
+    margin: 0 2em;
20
+
21
+    .sub-title {
22
+      display: inline-block;
23
+      size: 1em;
24
+      color: #666;
25
+      margin-right: 2em;
26
+    }
27
+  }
28
+
29
+  .ctt-footer {
30
+    flex: none;
31
+  }
32
+
33
+  .st-wrapper {
34
+    display: flex;
35
+
36
+    .st-item {
37
+      flex: none;
38
+      position: relative;
39
+
40
+      & + .st-item {
41
+        margin-left: 1em;
42
+        padding-left: 1em;
43
+
44
+        &::before {
45
+          position: absolute;
46
+          content: '';
47
+          border-left: 1px solid rgba(0, 0, 0, .2);
48
+          height: 60%;
49
+          top: 20%;
50
+          left: 0;
51
+        }
52
+      }
53
+    }
54
+  }
55
+}

+ 2
- 0
src/utils/utils.js Wyświetl plik

@@ -43,3 +43,5 @@ export function getCurrentRoute(pathname) {
43 43
 
44 44
   return routeArr.filter((x) => x.path === pathname)[0];
45 45
 }
46
+
47
+export const defaultAvatar = 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'