Sfoglia il codice sorgente

统计-用户来源

魏熙美 5 anni fa
parent
commit
6b13bc842b
1 ha cambiato i file con 136 aggiunte e 122 eliminazioni
  1. 136
    122
      src/pages/indexEcharts/userSource.jsx

+ 136
- 122
src/pages/indexEcharts/userSource.jsx Vedi File

@@ -9,64 +9,108 @@ import request from '../../utils/request';
9 9
 import apis from '../../services/apis';
10 10
 
11 11
 
12
+
13
+const { RangePicker } = DatePicker;
14
+const { Option } = Select
15
+
16
+
12 17
 // const formatDate = (start, end) => {
13 18
 //   const startDate = moment(start).format('YYYY-MM-DDT00:00:00.000') + 'Z'
14 19
 //   const endDate = moment(end).format('YYYY-MM-DDT23:59:59.999') + 'Z'
15 20
 //   return { startDate, endDate }
16 21
 // }
17 22
 
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
+  },
43
+  {
44
+    title: '小程序搜索',
45
+    dataIndex: '小程序搜索',
46
+    key: '小程序搜索',
47
+  },
48
+  {
49
+    title: '好友分享',
50
+    dataIndex: '好友分享',
51
+    key: '好友分享',
52
+
53
+  },
54
+
55
+
56
+]
57
+
58
+class Header extends React.Component {
59
+
60
+  constructor(props) {
61
+    super(props)
62
+    this.state = {
63
+      dataSoures: [],
64
+      tableData: [],
65
+      userType: 'all',
66
+      endDate: {},
67
+      startDate: {}
68
+    }
69
+  }
18 70
 
19
-const header = props => {
20
-
21
-  const [tableData, setTableData] = useState([])
22
-  const [userType, setuserType] = useState([])
23
-  const [endDate, setEndDate] = useState({})
24
-  const [startDate, setStartDate] = useState({})
25
-  let daterange = []
71
+  componentDidMount() {
72
+    this.setState({ endDate: new Date(), startDate: moment().subtract(7, 'day').toDate() })
73
+  }
26 74
 
27
-  useEffect(() => {
28
-    setEndDate(new Date())
29
-    setStartDate(moment().subtract(7, 'day').toDate())
30
-    setuserType('all')
31
-  }, [])
32 75
 
33
-  const { RangePicker } = DatePicker;
34 76
 
35
-  function onChangetime(dates, dateStrings) {
77
+  formatDate = (start, end) => {
78
+    const tempStartDate = `${moment(start).format('YYYY-MM-DDT00:00:00.000')}Z`
79
+    const tempEndDate = `${moment(end).format('YYYY-MM-DDT23:59:59.999')}Z`
80
+    return { startDate: tempStartDate, endDate: tempEndDate }
81
+  }
36 82
 
83
+  onChangetime = (_dates, dateStrings) => {
37 84
     daterange[1] = dateStrings[1]
38 85
     daterange[0] = dateStrings[0]
39
-
40 86
   }
41 87
 
42
-  const handleSubmit = (e, props) => {
88
+  handleSubmit = (e, props) => {
43 89
 
44 90
     e.preventDefault();
45 91
 
46 92
   }
47 93
 
48
-  const getDataOf = (days) => () => {
49
-
50
-    setEndDate(new Date())
51
-    setStartDate(moment().subtract(days, 'day').toDate())
52
-
94
+  getDataOf = (days) => () => {
95
+    this.setState({ endDate: new Date(), startDate: moment().subtract(days, 'day').toDate() })
53 96
   }
54 97
 
55
-  function datalist() {
56
-
57
-    setEndDate(daterange[1])
58
-    setStartDate(daterange[0])
98
+  datalist = () => {
59 99
 
100
+    this.setState({ endDate: daterange[1], startDate: daterange[0] })
60 101
   }
61 102
 
103
+  onSuccess = e => {
104
+    this.setState({ dataSoures: e }, () => {
105
+      this.onTabledatas(e)
106
+    })
107
+  }
62 108
 
63
-  let tableTitle = ['日期']
64
-
65
-
66
-  function onTabledatas(e) {
67
-    const data = (e.data || []).reduce((acc, item, index) => {
109
+  onTabledatas = (e) => {
110
+    console.log('this.state.userType: ', this.state.userType)
111
+    const data = (e.data || []).reduce((acc, item) => {
68 112
       const { date, fromName, count, registered } = item
69
-      const num = userType === 'registered' ? registered : count
113
+      const num = this.state.userType === 'registered' ? registered : count
70 114
 
71 115
       tableTitle = tableTitle.indexOf(fromName) > -1 ? tableTitle : tableTitle.concat(fromName) // eslint-disable-line
72 116
       acc[date] = { ...acc[date], [`${fromName}`]: !num ? 0 : num }
@@ -74,105 +118,75 @@ const header = props => {
74 118
       return acc
75 119
     }, {})
76 120
 
77
-    setTableData(Object.keys(data).map(x => ({ label: x, ...data[x] })))
121
+    this.setState({ tableData: Object.keys(data).map(x => ({ label: x, ...data[x] })) })
78 122
 
79 123
   }
80 124
 
81
-  const columns = [
82
-    {
83
-      title: '日期',
84
-      dataIndex: 'label',
85
-      key: 'label',
86
-      width:'20%'
87
-    },
88
-    {
89
-      title: '名片分享',
90
-      dataIndex: '名片分享',
91
-      key: '名片分享',
92
-    },
93
-    {
94
-      title: '生成海报',
95
-      dataIndex: '生成海报',
96
-      key: '生成海报',
97
-    },
98
-    {
99
-      title: '小程序搜索',
100
-      dataIndex: '小程序搜索',
101
-      key: '小程序搜索',
102
-    },
103
-    {
104
-      title: '好友分享',
105
-      dataIndex: '好友分享',
106
-      key: '好友分享',
107
-
108
-    },
109
-
110
-
111
-  ]
112
-
113
-  function handleSelectChange(e) {
114
-
115
-    console.log(e)
116
-    setuserType(e)
125
+  handleSelectChange = (e) => {
126
+    this.setState({ userType: e }, () => {
127
+      this.onTabledatas(this.state.dataSoures)
128
+    })
117 129
   }
118 130
 
119 131
 
120
-
121
-  return (<>
122
-    <div style={{
123
-      backgroundColor: '#fff',
124
-      padding: '32PX 28px',
125
-      boxShadow: '0px 0px 16px 2px rgba(0,0,0,0.12)',
126
-      borderRadius: '12px',
127
-      minHeight: '60vh'
128
-    }}>
129
-      <Radio.Group buttonStyle="solid" defaultValue="a">
130
-        <Radio.Button value="a" onClick={getDataOf(7)}>最近7天</Radio.Button>
131
-        <Radio.Button value="b" onClick={getDataOf(30)}>最近1月</Radio.Button>
132
-      </Radio.Group>
133
-      <RangePicker
134
-        style={{ paddingLeft: '30px' }}
135
-        ranges={{
136
-          Today: [moment(), moment()],
137
-          'This Month': [moment().startOf('month'), moment().endOf('month')],
138
-        }}
139
-        showTime
140
-        // format="YYYY/MM/DD HH:mm:ss"
141
-        onChange={onChangetime}
142
-      />
143
-      <Button type="primary" htmlType="submit" style={{ marginLeft: '30px' }} onClick={datalist}>
144
-        查询
145
-          </Button>
146
-      <div>
147
-
148
-        <div style={{ display: 'flex' }}>
149
-          <div style={{
150
-            width: '1060px',
151
-            height: '560px',
152
-            paddingTop: '40px',
153
-            marginRight: ' 40px',
154
-          }}>
155
-            <UserSource BuildSelectHide={true} endDate={endDate} startDate={startDate} onSuccess={(e) => onTabledatas(e)}></UserSource>
156
-          </div>
157
-          <div style={{
158
-            width: '509px',
159
-            height: '600px',
160
-            paddingTop: '40px',
161
-
162
-          }}>
163
-            <UserSourcepie endDate={endDate} startDate={startDate}></UserSourcepie>
132
+  render() {
133
+    return (
134
+    <>
135
+      <div style={{
136
+        backgroundColor: '#fff',
137
+        padding: '32PX 28px',
138
+        boxShadow: '0px 0px 16px 2px rgba(0,0,0,0.12)',
139
+        borderRadius: '12px',
140
+        minHeight: '60vh'
141
+      }}>
142
+        <Radio.Group buttonStyle="solid" defaultValue="a">
143
+          <Radio.Button value="a" onClick={() => this.getDataOf(7)}>最近7天</Radio.Button>
144
+          <Radio.Button value="b" onClick={() => this.getDataOf(30)}>最近1月</Radio.Button>
145
+        </Radio.Group>
146
+        <RangePicker
147
+          style={{ paddingLeft: '30px' }}
148
+          ranges={{
149
+            Today: [moment(), moment()],
150
+            'This Month': [moment().startOf('month'), moment().endOf('month')],
151
+          }}
152
+          showTime
153
+          // format="YYYY/MM/DD HH:mm:ss"
154
+          onChange={(_dates, dateStrings) => this.onChangetime(_dates, dateStrings)}
155
+        />
156
+        <Button type="primary" htmlType="submit" style={{ marginLeft: '30px' }} onClick={() => this.datalist()}>
157
+          查询
158
+        </Button>
159
+        <div>
160
+  
161
+          <div style={{ display: 'flex' }}>
162
+            <div style={{
163
+              width: '1060px',
164
+              height: '560px',
165
+              paddingTop: '40px',
166
+              marginRight: ' 40px',
167
+            }}>
168
+              <UserSource BuildSelectHide={true} endDate={this.state.endDate} startDate={this.state.startDate} onSuccess={(e) => this.onSuccess(e)}></UserSource>
169
+            </div>
170
+            <div style={{
171
+              width: '509px',
172
+              height: '600px',
173
+              paddingTop: '40px',
174
+  
175
+            }}>
176
+              <UserSourcepie endDate={this.state.endDate} startDate={this.state.startDate}></UserSourcepie>
177
+            </div>
164 178
           </div>
179
+          <Select style={{ width: '180px' }} placeholder="所有用户" onChange={(e) => this.handleSelectChange(e)}>
180
+            <Option value='all'>所有用户</Option>
181
+            <Option value='registered'>注册用户</Option>
182
+          </Select>
183
+  
184
+          <Table style={{marginTop:'20px'}} dataSource={this.state.tableData} columns={columns} pagination={false} scroll={{ y: 500 }}></Table>
165 185
         </div>
166
-        <Select style={{ width: '180px' }} placeholder="所有用户" onChange={handleSelectChange}>
167
-          <Option value='all'>所有用户</Option>
168
-          <Option value='registered'>注册用户</Option>
169
-        </Select>
170
-
171
-        <Table style={{marginTop:'20px'}} dataSource={tableData} columns={columns} pagination={false} scroll={{ y: 500 }}></Table>
172 186
       </div>
173
-    </div>
174
-  </>
175
-  )
187
+    </>
188
+    )
189
+  }
176 190
 }
177 191
 
178
-export default header
192
+export default Header