许静 5 年之前
父節點
當前提交
63f6f618ce
共有 3 個文件被更改,包括 138 次插入135 次删除
  1. 2
    2
      src/pages/customer/recommendCustomer/index.jsx
  2. 135
    132
      src/pages/indexEcharts/userSource.jsx
  3. 1
    1
      src/utils/request.js

+ 2
- 2
src/pages/customer/recommendCustomer/index.jsx 查看文件

@@ -86,7 +86,7 @@ function body(props) {
86 86
       ...apis.customer.customerRecommendRecommenderExport, 
87 87
       responseType: 'blob',
88 88
     }).then(response => {
89
-      // console.log('response: ', response)
89
+      console.log('exportRecommendCustomer: ', response.body())
90 90
       download(response)
91 91
     }).catch(error => {
92 92
 
@@ -213,7 +213,7 @@ function body(props) {
213 213
             </Button>
214 214
         </Form.Item>
215 215
       </Form>
216
-      <Button type="primary" onClick={() => exportRecommendCustomer()} className={Styles.SubmitButton} style={{ marginTop: '5px', marginBottom: '5px', display: 'none' }}>
216
+      <Button type="primary" onClick={() => exportRecommendCustomer()} className={Styles.SubmitButton} style={{ marginTop: '5px', marginBottom: '5px' }}>
217 217
         导出数据
218 218
       </Button>
219 219
       <Table dataSource={dataSource.records} columns={columns} pagination={{ total: dataSource.total, onChange }} />

+ 135
- 132
src/pages/indexEcharts/userSource.jsx 查看文件

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

+ 1
- 1
src/utils/request.js 查看文件

@@ -58,7 +58,7 @@ request.interceptors.request.use((url, options) => {
58 58
         requestType: data instanceof FormData ? 'form' : 'json',
59 59
         credentials: 'include', // 带 cookie
60 60
         interceptors: true,
61
-        getResponse: true
61
+        getResponse: true,
62 62
       },
63 63
     }
64 64
   );