周立森 5 年 前
コミット
cd67d73cc0
共有5 個のファイルを変更した251 個の追加166 個の削除を含む
  1. 5
    0
      config/config.js
  2. 16
    10
      src/components/EchartsTest/EChart.jsx
  3. 147
    127
      src/pages/indexEcharts/components/UserSource.jsx
  4. 6
    29
      src/pages/indexEcharts/index.jsx
  5. 77
    0
      src/pages/indexEcharts/userSource.jsx

+ 5
- 0
config/config.js ファイルの表示

@@ -329,6 +329,11 @@ export default {
329 329
                   name: '报表',
330 330
                   component: './indexEcharts/index',
331 331
                 },
332
+                {
333
+                  path: '/indexEcharts/userSource',
334
+                  name: '用户来源',
335
+                  component: './indexEcharts/userSource',
336
+                },
332 337
                 {
333 338
                   path: '/system/intention',
334 339
                   name: '意向值',

+ 16
- 10
src/components/EchartsTest/EChart.jsx ファイルの表示

@@ -3,17 +3,20 @@ import React, { Component } from 'react';
3 3
 // 引入 ECharts 主模块
4 4
 import echarts from 'echarts/lib/echarts';
5 5
 // 引入柱状图
6
-import  'echarts/lib/chart/bar';
6
+import 'echarts/lib/chart/bar';
7
+import 'echarts/lib/chart/pie';
7 8
 // 引入提示框和标题组件
8 9
 import 'echarts/lib/component/tooltip';
10
+import 'echarts/lib/component/legend';
9 11
 import 'echarts/lib/component/title';
10 12
 
13
+
11 14
 class EchartsTest extends Component {
12
-    chartRef = undefined
15
+    chartRef = React.createRef();
13 16
     chart = undefined
14 17
     defaultChartOption = {}
15 18
 
16
-    componentDidMount() {
19
+    componentDidMount () {
17 20
         this.chart = echarts.init(this.chartRef.current)
18 21
 
19 22
         // 绘制图表
@@ -23,25 +26,28 @@ class EchartsTest extends Component {
23 26
         });
24 27
     }
25 28
 
26
-    componentDidUpdate(preProps) {
29
+    componentDidUpdate (preProps) {
27 30
         if (preProps.options != this.props.options) {
28
-            this.chart.setOption({
31
+            const options = {
29 32
                 ...this.defaultChartOption,
30 33
                 ...this.props.options || {},
31
-            });
34
+            }
35
+
36
+            console.log(options)
37
+
38
+            this.chart.setOption(options);
32 39
         }
33 40
     }
34 41
 
35
-    handleDom = ref => this.chartRef = ref
36
-
37
-    render() {
42
+    render () {
38 43
         const style = {
39 44
             width: '600px',
45
+            height: '400px',
40 46
             ...this.props.style || {}
41 47
         }
42 48
 
43 49
         return (
44
-            <div ref={this.handleDom} style={style}></div>
50
+            <div ref={this.chartRef} style={style}></div>
45 51
         );
46 52
     }
47 53
 }

+ 147
- 127
src/pages/indexEcharts/components/UserSource.jsx ファイルの表示

@@ -1,160 +1,180 @@
1 1
 import React, { Component, useState, useEffect } from 'react';
2 2
 
3
-// 引入 ECharts 主模块
4
-import echarts from 'echarts/lib/echarts';
5
-// 引入环形图
6
-import 'echarts/lib/chart/pie';
7
-import 'echarts/lib/chart/bar'
8
-
9
-// 引入提示框和标题组件
10
-import 'echarts/lib/component/tooltip';
11
-import 'echarts/lib/component/title';
12
-import 'echarts/lib/component/visualMap';
3
+import EChart from '../../../components/EchartsTest/EChart';
13 4
 import request from '../../../utils/request';
14 5
 import apis from '../../../services/apis';
15 6
 import dayjs from 'dayjs';
7
+import router from 'umi/router';
8
+import {Table, Select, Row, Col, Menu, Dropdown, Button, Icon, message } from 'antd';
9
+// import UserSource from './mmm';
16 10
 
17 11
 
18
-// 
19
-class UserSource extends React.Component {
20
-
21
-  state = {
22
-    piedata: {},
23
-    loading: false,
24
-    dataset: {},
25
-    reportOpts: {
26
-      legend: {},
27
-      color: ['#286DD0', '#8565CE', '#6A96F8', '#F5749E', '#8B7FE2'],
28
-      tooltip: {},
29
-      yAxis: {},
30
-      grid: [
31
-        { right: '50%' },
32
-        { right: '5%' }
33
-      ],
34
-    },
35
-    userType: 'all',
36
-    tableTitle: ['日期'],
37
-  }
38
-
39
-
12
+const UserSource = (props) => {
40 13
 
41
-  initCharts = () => {
14
+  const [data, setData] = useState({ records: [] })
15
+  //柱图
42 16
 
17
+  useEffect(() => {
18
+    userResource()
19
+  }, [])
43 20
 
21
+  function userResource () {
22
+    request({
23
+      ...apis.indexEcharts.userResource,
24
+      params: { pageNum: 1, pageSize: 9999 }
25
+    }).then((data) => {
26
+      // console.log(data , '3333')
27
+      setData(data)
28
+    })
29
+  }
44 30
 
45
-    console.log(this.dataset, '5555')
46
-    // 基于准备好的dom,初始化echarts实例
47
-    var myChart = echarts.init(document.getElementById('usersourcebar'));
48
-    const source = this.dataset.columnar || [];
49
-
50
-    // 柱图
51
-    const barOptions = {
52
-
53
-
54
-      xAxis: { type: 'category' },
55
-      legend: {
56
-        left: '20%',
57
-        data: ['所有用户', '注册用户'],
58
-      },
59
-      series: [
60
-        { type: 'bar', name: '所有用户', datasetIndex: 0 },
61
-        { type: 'bar', name: '注册用户' },
62
-      ],
63
-      dataset: {
64
-        id: 'bar',
65
-        dimensions: ['fromName', 'userCount', 'registered'],
66
-        source: source,
67
-      },
31
+  function toEdit () {
32
+    router.push({
33
+      pathname: '/indexEcharts/userSource',
34
+      // query: {
35
+      //   a: 'b',
36
+      // },
37
+    });
38
+  }
68 39
 
69
-    };
70
-    const { person_estate_agent = 0, person_null = 0, person_realty_consultant = 0 } = this.dataset.pie || {};
71
-    const pieOptions = {
40
+  const dataset = data || {};
41
+  const source = dataset.columnar || [];
42
+
43
+  // const source = this.dataset.columnar || [];
44
+  const subtitle = '最近7天';
45
+  const baroptions = {
46
+    color: ['#286DD0', '#8565CE', '#6A96F8', '#F5749E', '#8B7FE2'],
47
+    xAxis: { type: 'category' },
48
+    legend: {
49
+      left: '20%',
50
+      data: ['所有用户', '注册用户'],
51
+    },
72 52
 
53
+    tooltip: {},
54
+
55
+    yAxis: {},
56
+    series: [
57
+      { type: 'bar', name: '所有用户', datasetIndex: 0 },
58
+      { type: 'bar', name: '注册用户' },
59
+    ],
60
+    dataset: {
61
+      id: 'bar',
62
+      dimensions: ['fromName', 'userCount', 'registered'],
63
+      source: source,
64
+    },
73 65
 
74
-      xAxis: {},
75
-      legend: {
76
-        left: '70%',
77
-        data: ['来源置业顾问', '来源全民经纪人', '自主进入'],
78
-      },
79
-      series: [
80
-        {
81
-          type: 'pie',
82
-          datasetIndex: 1,
83
-          center: ['75%', '50%'],
84
-          radius: [0, '50%'],
85
-        },
86
-      ],
87
-      dataset: {
88
-        id: 'pie',
89
-        source: [
90
-          { form: '来源置业顾问', value: person_realty_consultant },
91
-          { form: '来源全民经纪人', value: person_estate_agent },
92
-          { form: '自主进入', value: person_null },
93
-        ]
66
+  }
67
+  const { person_estate_agent = 0, person_null = 0, person_realty_consultant = 0 } = dataset.pie || {};
68
+  const pieoptions = {
69
+    // xAxis: {},
70
+    color: ['#286DD0', '#8565CE', '#6A96F8', '#F5749E', '#8B7FE2'],
71
+    legend: {
72
+      // left: '70%',
73
+      data: ['来源置业顾问', '来源全民经纪人', '自主进入'],
74
+    },
75
+    tooltip: {},
76
+    // yAxis: {},
77
+
78
+    series: [
79
+      {
80
+        type: 'pie',
81
+        // datasetIndex: 1,
82
+        center: ['50%', '50%'],
83
+        radius: [0, '50%'],
94 84
       },
85
+    ],
86
+    dataset: {
87
+      id: 'pie',
88
+      source: [
89
+        { form: '来源置业顾问', value: person_realty_consultant },
90
+        { form: '来源全民经纪人', value: person_estate_agent },
91
+        { form: '自主进入', value: person_null },
92
+      ]
93
+    },
95 94
 
96
-    };
97
-    // 绘制图表
98
-    myChart.setOption({
99
-      // ...this.reportOpts,
100
-      xAxis: { type: 'category' },
101
-        legend: {
102
-          left: '20%',
103
-          data: ['所有用户', '注册用户'],
104
-        },
105
-        series: [
106
-          { type: 'bar', name: '所有用户', datasetIndex: 0 },
107
-          { type: 'bar', name: '注册用户' },
108
-        ],
109
-        dataset: {
110
-          id: 'bar',
111
-          dimensions: [ 'fromName', 'userCount', 'registered' ],
112
-          source: source,
113
-        },
114
-    });
115 95
 
116 96
 
117
-  }
118 97
 
119 98
 
120
-  componentDidMount () {
121
-    this.initCharts();
122 99
   }
123
-  componentDidUpdate () {  //当图表切换的时候,重新执行
124
-    this.initCharts();
100
+  function handleSelectChange (e) {
101
+    // eslint-disable-next-line no-console
102
+    console.log(e)
125 103
   }
126 104
 
105
+  //表格
106
+  const dataSource = [
107
+    {
108
+      name: '置业顾问',
109
+      status: '1',//显示停用
110
+    },
111
+    {
112
+      name: '置业经理',
113
+      status: '1',//停用
114
+    },
115
+  ];
116
+
117
+  const columns = [
118
+    // {
119
+    //   title: '商品图片',
120
+    //   dataIndex: 'img',
121
+    //   key: 'img',
122
+    //   align: 'center',
123
+  
124
+    //   render: (text, record) => <img src={record.img} className={channels.touxiang} />,
125
+    // },
126
+    {
127
+      title: '角色名称',
128
+      dataIndex: 'name',
129
+      key: 'name',
130
+      align: 'center',
131
+      render: text => <a>{text}</a>,
132
+    },
133
+  
134
+    {
135
+      title: '操作  ',
136
+      dataIndex: 'status',
137
+      key: 'status',
138
+      align: 'center',
139
+  
140
+      render: () => <>11</>
141
+       
142
+    },
143
+  ];
127 144
 
145
+  const style = {
146
+    width: '100%',
147
+    height: '400px',
128 148
 
129
-  render () {
130
-    this.piedata = this.props.data;
131
-    this.dataset = this.piedata || {};
149
+  }
150
+  const styles = {
151
+    width: '100%',
152
+    height: '400px',
132 153
 
133
-    return (
154
+  }
134 155
 
135 156
 
157
+  return (
158
+    <>
136 159
       <div>
137
-        {/* 饼图 */}
138
-
139
-        {/* <div class="chart-box" v-if="mode == 'all' || mode == 'report'">
140
-      <h3>用户来源 <small>{{subtitle}}</small></h3>
141
-      <v-chart v-loading="loading" class="chart" options="options" />
142
-    </div>
143
-    <div class="chart-box" v-if="mode == 'all' || mode == 'table'">
144
-      <el-select v-model="userType">
145
-        <el-option label="所有用户" value="all"></el-option>
146
-        <el-option label="注册用户" value="registered"></el-option>
147
-      </el-select>
148
-      <el-table v-loading="loading" data="tableData"  border  center  style="width: 100%; margin-top: 16px" height="400">
149
-        <el-table-column v-for="(item, index) in tableTitle" key="index" label="item" prop="index == 0 ? 'label' : item"></el-table-column>
150
-      </el-table>
151
-    </div> */}
152
-
153
-        <div id="usersourcebar" style={{ width: '1060px', height: '560px' }}></div>
154
-
160
+        <h3>用户来源 <small>{subtitle}</small></h3>
161
+        <Row>
162
+          <Col span={16}>
163
+            <EChart options={baroptions} style={style} /></Col>
164
+          <Col span={8}>
165
+            <EChart options={pieoptions} style={styles} /></Col>
166
+        </Row>
155 167
       </div>
156
-    );
157
-  }
168
+      <Select style={{ width: '180px' }} placeholder="所有用户" onChange={handleSelectChange}>
169
+        <Option value={0}>所有用户</Option>
170
+        <Option value={1}>注册用户</Option>
171
+      </Select>
172
+
173
+
174
+      <Table dataSource={dataSource} columns={columns} />
175
+
176
+    </>
177
+  )
158 178
 }
159 179
 
160 180
 export default UserSource;

+ 6
- 29
src/pages/indexEcharts/index.jsx ファイルの表示

@@ -1,7 +1,7 @@
1 1
 
2 2
 import React, { useState, useEffect }  from 'react';
3 3
 import { Form, Input, Button, Icon, Select, message, Table, Divider, Row, Col, Tag, Pagination, Modal, DatePicker } from 'antd';
4
-import { FormattedMessage } from 'umi-plugin-react/locale';
4
+
5 5
 // import styles from '../../style/GoodsList.less';
6 6
 import router from 'umi/router';
7 7
 
@@ -11,40 +11,17 @@ import apis from '../../services/apis';
11 11
 import UserSource from './components/UserSource.jsx';
12 12
 
13 13
 
14
+const header = (props) => {
14 15
 
15 16
 
16
-const header = (props) => {
17
-  const [ data, setData ] = useState({records: []})
18
-  //柱图
19
-  
20
-  useEffect(() => {
21
-    userResource()
22
-  }, [])
23
-  
24
-  function userResource() {
25
-        request({
26
-          ...apis.indexEcharts.userResource,
27
-           params: { pageNum: 1, pageSize:9999}
28
-        }).then((data) => {
29
-            // console.log(data , '3333')
30
-            setData(data)
31
-        })
32
-      }
33
-
34
-  
35
-
36
-  
37
-
38
-
39
-
40
-  const { getFieldDecorator } = props.form
41 17
   return (
42 18
 
43 19
     <>
44
-     <UserSource data={data} ></UserSource>
20
+    {/* <div>2222</div> */}
21
+     <UserSource  ></UserSource>
45 22
     </>
46 23
   )
47 24
 }
48
-const WrappedHeader = Form.create({ name: 'header' })(header);
49 25
 
50
-export default WrappedHeader
26
+
27
+export default  header

+ 77
- 0
src/pages/indexEcharts/userSource.jsx ファイルの表示

@@ -0,0 +1,77 @@
1
+import dayjs from 'dayjs';
2
+import React from 'react';
3
+import {Radio, DatePicker,  Form, Input, Button, Icon, Select, message, Table, Divider, Tag, Pagination, Modal, Breadcrumb } from 'antd';
4
+
5
+import UserSource from './components/UserSource.jsx';
6
+// import XForm, { FieldTypes } from '../../components/XForm';
7
+import moment from 'moment';
8
+
9
+
10
+const header = props => {
11
+  const { RangePicker } = DatePicker;
12
+  function onChange(dates, dateStrings) {
13
+    console.log('From: ', dates[0], ', to: ', dates[1]);
14
+    console.log('From: ', dateStrings[0], ', to: ', dateStrings[1]);
15
+  }
16
+
17
+
18
+  const handleSubmit = (e, props) => {
19
+    e.preventDefault();
20
+    // props.form.validateFields((err, values) => {
21
+    //   if (!err) {
22
+    //     getList({ pageNum: 1, pageSize: 10, ...values })
23
+    //   }
24
+    // });
25
+  }
26
+
27
+
28
+  function getDataOf(days){      
29
+    // const endDate = new Date()
30
+    // const startDate = dayjs().subtract(days, 'day').toDate()
31
+
32
+    // this.$refs.chart.getData({ startDate, endDate })
33
+  }
34
+
35
+  function onChange(e) {
36
+    console.log(`radio checked:${e.target.value}`);
37
+  }
38
+
39
+  return (<>
40
+  {/* <el-button type="text" @click="() => getDataOf(7)">最近7天</el-button>
41
+      <el-button type="text" @click="() => getDataOf(30)">最近1月</el-button>
42
+      <el-date-picker
43
+        v-model="dateRange"
44
+        type="daterange"
45
+        start-placeholder="开始日期"
46
+        end-placeholder="结束日期"
47
+        style="margin-left: 16px">
48
+      </el-date-picker>
49
+      <el-button type="primary" icon="el-icon-search" style="margin-left: 32px" @click="search">查询</el-button>
50
+    </div>
51
+    <user-source ref="chart" mode="all"></user-source> */}
52
+  <Radio.Group onChange={onChange} defaultValue="a">
53
+        <Radio.Button value="a" onClick={getDataOf(7)}>最近7天</Radio.Button>
54
+        <Radio.Button value="b" onClick={getDataOf(30)}>最近1月</Radio.Button>
55
+      </Radio.Group>
56
+      <RangePicker
57
+      ranges={{
58
+        Today: [moment(), moment()],
59
+        'This Month': [moment().startOf('month'), moment().endOf('month')],
60
+      }}
61
+      showTime
62
+      format="YYYY/MM/DD HH:mm:ss"
63
+      // onChange={onChange}
64
+    />
65
+     <Button type="primary" htmlType="submit" >
66
+            查询
67
+          </Button>
68
+  <div>
69
+    
70
+
71
+    <UserSource ></UserSource>
72
+  </div>
73
+  </>
74
+  )
75
+}
76
+
77
+export default header