ソースを参照

用户来源新需求

傅行帆 5 年 前
コミット
db034230f1
共有4 個のファイルを変更した240 個の追加58 個の削除を含む
  1. 19
    13
      src/pages/indexEcharts/components/UserSource.jsx
  2. 139
    0
      src/pages/indexEcharts/components/UserSourceDetail.jsx
  3. 72
    45
      src/pages/indexEcharts/userSource.jsx
  4. 10
    0
      src/services/apis.js

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

@@ -16,7 +16,9 @@ const formatDate = (start, end) => {
16 16
 }
17 17
 
18 18
 const UserSource = (props) => {
19
-  const [data, setData] = useState({ records: [] })
19
+  const [xData, setxData] = useState([])
20
+  const [fromData, setFromData] = useState([])
21
+  const [registerData, setRegisterData] = useState([])
20 22
   //柱图
21 23
   useEffect(() => {
22 24
     userResource(formatDate(props.startDate, props.endDate))
@@ -24,21 +26,23 @@ const UserSource = (props) => {
24 26
 
25 27
   function userResource(params) {
26 28
     request({
27
-      ...apis.indexEcharts.userResource,
29
+      ...apis.indexEcharts.selectPersonFrom,
28 30
       params,
29 31
     }).then((data) => {
30
-      setData(data)
31
-      console.log(data,"datadatadatadatavvvdatadatav")
32
+      setxData(data.map(x =>  x.sceneAlias))
33
+      setFromData(data.map(x => x.fromData))
34
+      setRegisterData(data.map(x => x.registerSum))
32 35
       props.onSuccess(data)
33 36
     })
34 37
   }
35 38
 
36
-  const dataset = data || {};
37
-  const source = dataset.columnar || [];
38 39
   const subtitle = '最近7天';
39 40
   const baroptions = {
40 41
     title: { },
41
-    xAxis: { type: 'category' },
42
+    xAxis: { 
43
+              type: 'category',
44
+              data: xData
45
+            },
42 46
     legend: {
43 47
       left: '20%',
44 48
       data: ['所有用户', '注册用户']
@@ -51,6 +55,7 @@ const UserSource = (props) => {
51 55
       {
52 56
         type: 'bar', name: '所有用户', datasetIndex: 0,
53 57
         barWidth: 20,
58
+        data: fromData,
54 59
         itemStyle: {
55 60
           normal: {
56 61
             barBorderRadius: [20, 20, 0, 0],
@@ -70,6 +75,7 @@ const UserSource = (props) => {
70 75
         type: 'bar',
71 76
         name: '注册用户',
72 77
         barWidth: 20,
78
+        data: registerData,
73 79
         itemStyle: {
74 80
           normal: {
75 81
             barBorderRadius: [20, 20, 0, 0],
@@ -87,11 +93,11 @@ const UserSource = (props) => {
87 93
 
88 94
       },
89 95
     ],
90
-    dataset: {
91
-      id: 'bar',
92
-      dimensions: ['fromName', 'userCount', 'registered'],
93
-      source: source,
94
-    },
96
+    // dataset: {
97
+    //   id: 'bar',
98
+    //   dimensions: ['fromName', 'userCount', 'registered'],
99
+    //   source: source,
100
+    // },
95 101
   }
96 102
 
97 103
 
@@ -104,7 +110,7 @@ const UserSource = (props) => {
104 110
   return (
105 111
     <>
106 112
       <div>
107
-      <p onClick={()=>router.push('/indexEcharts/userSource')}><span style={{borderBottom:'1px solid #f02d40',cursor: 'pointer',color:'#333',fontSize:'0.12rem',fontWeight:'600'}}>用户来源</span> {!props.BuildSelectHide && <span style={{ fontSize: '0.09rem', color: '#888', marginLeft: '0.06rem' }}>最近七天</span>}</p>
113
+      <p onClick={()=>router.push('/indexEcharts/userSource')}><span style={{borderBottom:'1px solid #f02d40',cursor: 'pointer',color:'#333',fontSize:'0.12rem',fontWeight:'600'}}>用户来源1</span> {!props.BuildSelectHide && <span style={{ fontSize: '0.09rem', color: '#888', marginLeft: '0.06rem' }}>最近七天</span>}</p>
108 114
 
109 115
         <EChart options={baroptions} style={barstyle} />
110 116
 

+ 139
- 0
src/pages/indexEcharts/components/UserSourceDetail.jsx ファイルの表示

@@ -0,0 +1,139 @@
1
+import React, { Component, useState, useEffect } from 'react';
2
+import echarts from 'echarts/lib/echarts';
3
+import EChart from '../../../components/EchartsTest/EChart';
4
+import request from '../../../utils/request';
5
+import apis from '../../../services/apis';
6
+import moment from 'moment';
7
+import router from 'umi/router';
8
+import { Table, Select, Row, Col, Menu, Dropdown, Button, Icon, message } from 'antd';
9
+
10
+import styles from '../styles.less'
11
+
12
+const formatDate = (start, end) => {
13
+  const startDate = moment(start).format('YYYY-MM-DDT00:00:00.000') + 'Z'
14
+  const endDate = moment(end).format('YYYY-MM-DDT23:59:59.999') + 'Z'
15
+  return { startDate, endDate }
16
+}
17
+
18
+const UserSourceDetail = (props) => {
19
+  const [xData, setxData] = useState([])
20
+  const [fromData, setFromData] = useState([])
21
+  const [registerData, setRegisterData] = useState([])
22
+  //柱图
23
+  useEffect(() => {
24
+    userResource(formatDate(props.startDate, props.endDate))
25
+  }, [props.startDate, props.endDate])
26
+
27
+  function userResource(params) {
28
+    request({
29
+      ...apis.indexEcharts.selectPersonFromGroupByDay,
30
+      params,
31
+    }).then((data) => {
32
+      setxData(data.map(x =>  x.createTime))
33
+      setFromData(data.map(x => x.fromNum))
34
+      setRegisterData(data.map(x => x.registeredNum))
35
+      props.onSuccess(data)
36
+    })
37
+  }
38
+
39
+  const subtitle = '最近7天';
40
+  const baroptions = {
41
+    title: {
42
+    },
43
+    tooltip: {
44
+        trigger: 'axis'
45
+    },
46
+    legend: {
47
+        data: ['新用户数', '授权注册']
48
+    },
49
+    toolbox: {
50
+        show: true,
51
+        feature: {
52
+            dataZoom: {
53
+                yAxisIndex: 'none'
54
+            },
55
+            dataView: {readOnly: false},
56
+            magicType: {type: ['line', 'bar']},
57
+            restore: {},
58
+            saveAsImage: {}
59
+        }
60
+    },
61
+    xAxis: {
62
+        type: 'category',
63
+        boundaryGap: false,
64
+        data: xData
65
+    },
66
+    yAxis: {
67
+        type: 'value',
68
+        axisLabel: {
69
+            formatter: '{value} °C'
70
+        }
71
+    },
72
+    series: [
73
+        {
74
+            name: '新用户数',
75
+            type: 'line',
76
+            data: fromData,
77
+            markPoint: {
78
+                data: [
79
+                    {type: 'max', name: '最大值'},
80
+                    {type: 'min', name: '最小值'}
81
+                ]
82
+            },
83
+            markLine: {
84
+                data: [
85
+                    {type: 'average', name: '平均值'}
86
+                ]
87
+            }
88
+        },
89
+        {
90
+            name: '授权注册',
91
+            type: 'line',
92
+            data: registerData,
93
+            markPoint: {
94
+                data: [
95
+                    {name: '周最低', value: -2, xAxis: 1, yAxis: -1.5}
96
+                ]
97
+            },
98
+            markLine: {
99
+                data: [
100
+                    {type: 'average', name: '平均值'},
101
+                    [{
102
+                        symbol: 'none',
103
+                        x: '90%',
104
+                        yAxis: 'max'
105
+                    }, {
106
+                        symbol: 'circle',
107
+                        label: {
108
+                            position: 'start',
109
+                            formatter: '最大值'
110
+                        },
111
+                        type: 'max',
112
+                        name: '最高点'
113
+                    }]
114
+                ]
115
+            }
116
+        }
117
+    ]
118
+}
119
+
120
+  const barstyle = {
121
+    width: '100%',
122
+    height: '480px',
123
+    minWidth: '400px'
124
+  }
125
+
126
+  return (
127
+    <>
128
+      <div>
129
+      <p onClick={()=>router.push('/indexEcharts/userSource')}><span style={{borderBottom:'1px solid #f02d40',cursor: 'pointer',color:'#333',fontSize:'0.12rem',fontWeight:'600'}}>用户来源1</span> {!props.BuildSelectHide && <span style={{ fontSize: '0.09rem', color: '#888', marginLeft: '0.06rem' }}>最近七天</span>}</p>
130
+
131
+        <EChart options={baroptions} style={barstyle} />
132
+
133
+      </div>
134
+
135
+    </>
136
+  )
137
+}
138
+
139
+export default UserSourceDetail;

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

@@ -1,6 +1,6 @@
1 1
 import React, { Component, useState, useEffect } from 'react';
2 2
 import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Table, Avatar, Radio, Modal, Descriptions } from 'antd';
3
-import UserSource from './components/UserSource.jsx';
3
+import UserSourceDetail from './components/UserSourceDetail.jsx';
4 4
 import UserSourcepie from './components/UserSourcepie.jsx';
5 5
 // import XForm, { FieldTypes } from '../../components/XForm';
6 6
 import moment from 'moment';
@@ -21,38 +21,43 @@ const { Option } = Select
21 21
 // }
22 22
 
23 23
 let daterange = []
24
-let tableTitle = ['日期']
25
-
26
-const columns = [
27
-  {
28
-    title: '日期',
29
-    dataIndex: 'label',
30
-    key: 'label',
31
-    width:'20%'
32
-  },
33
-  {
34
-    title: '名片分享',
35
-    dataIndex: '名片分享',
36
-    key: '名片分享',
37
-  },
38
-  {
39
-    title: '生成海报',
40
-    dataIndex: '生成海报',
41
-    key: '生成海报',
42
-  },
24
+// let tableTitle = ['类型']
25
+
26
+// const columns = [
27
+//   {
28
+//     title: '日期',
29
+//     dataIndex: 'label',
30
+//     key: 'label',
31
+//     width:'20%'
32
+//   },
33
+//   {
34
+//     title: '名片分享',
35
+//     dataIndex: '名片分享',
36
+//     key: '名片分享',
37
+//   },
38
+//   {
39
+//     title: '生成海报',
40
+//     dataIndex: '生成海报',
41
+//     key: '生成海报',
42
+//   },
43
+//   {
44
+//     title: '小程序搜索',
45
+//     dataIndex: '小程序搜索',
46
+//     key: '小程序搜索',
47
+//   },
48
+//   {
49
+//     title: '好友分享',
50
+//     dataIndex: '好友分享',
51
+//     key: '好友分享',
52
+//   },
53
+// ]
54
+
55
+let columns = [
43 56
   {
44
-    title: '小程序搜索',
45
-    dataIndex: '小程序搜索',
46
-    key: '小程序搜索',
47
-  },
48
-  {
49
-    title: '好友分享',
50
-    dataIndex: '好友分享',
51
-    key: '好友分享',
52
-
53
-  },
54
-
55
-
57
+    title: '类型',
58
+    dataIndex: 'value',
59
+    key: 'value',
60
+  }
56 61
 ]
57 62
 
58 63
 class Header extends React.Component {
@@ -72,8 +77,6 @@ class Header extends React.Component {
72 77
     this.setState({ endDate: new Date(), startDate: moment().subtract(7, 'day').toDate() })
73 78
   }
74 79
 
75
-
76
-
77 80
   formatDate = (start, end) => {
78 81
     const tempStartDate = `${moment(start).format('YYYY-MM-DDT00:00:00.000')}Z`
79 82
     const tempEndDate = `${moment(end).format('YYYY-MM-DDT23:59:59.999')}Z`
@@ -111,17 +114,41 @@ class Header extends React.Component {
111 114
 
112 115
   onTabledatas = (e) => {
113 116
     console.log('this.state.userType: ', this.state.userType)
114
-    const data = (e.data || []).reduce((acc, item) => {
115
-      const { date, fromName, count, registered } = item
116
-      const num = this.state.userType === 'registered' ? registered : count
117
-
118
-      tableTitle = tableTitle.indexOf(fromName) > -1 ? tableTitle : tableTitle.concat(fromName) // eslint-disable-line
119
-      acc[date] = { ...acc[date], [`${fromName}`]: !num ? 0 : num }
117
+    // const data = (e || []).reduce((acc, item) => {
118
+    //   const { date, fromName, count, registered } = item
119
+    //   const num = this.state.userType === 'registered' ? registered : count
120
+
121
+    //   tableTitle = tableTitle.indexOf(fromName) > -1 ? tableTitle : tableTitle.concat(fromName) // eslint-disable-line
122
+    //   acc[date] = { ...acc[date], [`${fromName}`]: !num ? 0 : num }
123
+
124
+    //   return acc
125
+    // }, {})
126
+
127
+    const data = (e || []).reduce((acc, item) => {
128
+      const { fromNum, registeredNum, createTime } = item || {}
129
+      const title = createTime.replace(/-/, '年').replace(/-/, '月')
130
+
131
+      columns = columns.filter(x => x.key != createTime).concat({
132
+        title,
133
+        dataIndex: createTime,
134
+        key: createTime,
135
+      })
136
+
137
+      acc[0] = {
138
+        ...acc[0],
139
+        [`${createTime}`]: fromNum,
140
+      }
141
+      acc[1] = {
142
+        ...acc[1],
143
+        [`${createTime}`]: registeredNum,
144
+      }
120 145
 
121 146
       return acc
122
-    }, {})
147
+    }, [{key: 'fromNum', value: '新增用户'}, {key: 'registeredNum', value: '授权注册'}])
148
+
149
+    console.log(columns, data)
123 150
 
124
-    this.setState({ tableData: Object.keys(data).map(x => ({ label: x, ...data[x] })) })
151
+    this.setState({ tableData: data })
125 152
 
126 153
   }
127 154
 
@@ -169,7 +196,7 @@ class Header extends React.Component {
169 196
               paddingTop: '40px',
170 197
               marginRight: ' 40px',
171 198
             }}>
172
-              <UserSource BuildSelectHide={true} endDate={this.state.endDate} startDate={this.state.startDate} onSuccess={(e) => this.onSuccess(e)}></UserSource>
199
+              <UserSourceDetail BuildSelectHide={true} endDate={this.state.endDate} startDate={this.state.startDate} onSuccess={(e) => this.onSuccess(e)}></UserSourceDetail>
173 200
             </div>
174 201
             <div style={{
175 202
               width: '509px',
@@ -180,10 +207,10 @@ class Header extends React.Component {
180 207
               <UserSourcepie endDate={this.state.endDate} startDate={this.state.startDate}></UserSourcepie>
181 208
             </div>
182 209
           </div>
183
-          <Select style={{ width: '180px' }} placeholder="所有用户" onChange={(e) => this.handleSelectChange(e)}>
210
+          {/* <Select style={{ width: '180px' }} placeholder="所有用户" onChange={(e) => this.handleSelectChange(e)}>
184 211
             <Option value='all'>所有用户</Option>
185 212
             <Option value='registered'>注册用户</Option>
186
-          </Select>
213
+          </Select> */}
187 214
   
188 215
           <Table style={{marginTop:'20px'}} dataSource={this.state.tableData} columns={columns} pagination={false} scroll={{ y: 500 }}></Table>
189 216
         </div>

+ 10
- 0
src/services/apis.js ファイルの表示

@@ -320,6 +320,16 @@ export default {
320 320
       url: `${prefix}/selectUserResource`,
321 321
       action: 'userStatistics',
322 322
     },
323
+    selectPersonFrom: {
324
+      method: 'GET',
325
+      url: `${prefix}/selectPersonFrom`,
326
+      action: 'userStatistics',
327
+    },
328
+    selectPersonFromGroupByDay: {
329
+      method: 'GET',
330
+      url: `${prefix}/selectPersonFromGroupByDay`,
331
+      action: 'userStatistics',
332
+    },
323 333
     list:{
324 334
       method:'Get',
325 335
       url: `${prefix}/indexStatistical`,