dingxin пре 5 година
родитељ
комит
431d783894
1 измењених фајлова са 46 додато и 26 уклоњено
  1. 46
    26
      src/pages/indexEcharts/components/UserConversion.jsx

+ 46
- 26
src/pages/indexEcharts/components/UserConversion.jsx Прегледај датотеку

13
 const UserSource = props => {
13
 const UserSource = props => {
14
 
14
 
15
   const [theCurrent, setTheCurrent] = useState({ records: [] })
15
   const [theCurrent, setTheCurrent] = useState({ records: [] })
16
-
16
+  const [conversionRate, setConversionRate] = useState(0)
17
   useEffect(() => {
17
   useEffect(() => {
18
     UserConversionRate({ conversion: 'authorization_phone' })
18
     UserConversionRate({ conversion: 'authorization_phone' })
19
   }, [])
19
   }, [])
20
 
20
 
21
- function UserConversionRate(params) {
22
-   
23
-      request({
24
-        ...apis.indexEcharts.userConversion,
25
-        params,
26
-      }).then(data => {
27
-        setDataset(data, params.conversion)
28
-      })
21
+  function UserConversionRate (params) {
22
+
23
+    request({
24
+      ...apis.indexEcharts.userConversion,
25
+      params,
26
+    }).then(data => {  
27
+      console.log(data.data_count.registeredCount/data.data_count.pvNum,'1241234')
28
+      setDataset(data, params.conversion)
29
+    })
29
   }
30
   }
30
 
31
 
31
- function setDataset(data, theStatis) {
32
+  function setDataset (data, theStatis) {
32
     const { pvNum, ...other } = data.data_count
33
     const { pvNum, ...other } = data.data_count
33
 
34
 
34
     // 获取第一个值
35
     // 获取第一个值
41
     if (pvNum < num) {
42
     if (pvNum < num) {
42
       setTheCurrent([])
43
       setTheCurrent([])
43
     } else {
44
     } else {
45
+
46
+      setConversionRate(num/pvNum)
44
       setTheCurrent([
47
       setTheCurrent([
45
         { name: getStatisName(theStatis), value: num },
48
         { name: getStatisName(theStatis), value: num },
46
         { name: '其余', value: pvNum - num },
49
         { name: '其余', value: pvNum - num },
48
     }
51
     }
49
   }
52
   }
50
 
53
 
51
-  function getStatisName(theStatis) {
52
-     const statisTypes = [
53
-    { label: '授权手机', value: 'authorization_phone' },
54
-    { label: '项目收藏', value: 'building_save' },
55
-    { label: '项目转发', value: 'building_share' },
56
-    { label: '活动收藏', value: 'activity_save' },
57
-    { label: '活动转发', value: 'activity_share' },
58
-    { label: '资讯收藏', value: 'news_save' },
59
-    { label: '资讯转发', value: 'news_share' },
60
-    { label: '活动报名', value: 'activity_sign' },
61
-
62
-  ]
54
+  function getStatisName (theStatis) {
55
+    const statisTypes = [
56
+      { label: '授权手机', value: 'authorization_phone' },
57
+      { label: '项目收藏', value: 'building_save' },
58
+      { label: '项目转发', value: 'building_share' },
59
+      { label: '活动收藏', value: 'activity_save' },
60
+      { label: '活动转发', value: 'activity_share' },
61
+      { label: '资讯收藏', value: 'news_save' },
62
+      { label: '资讯转发', value: 'news_share' },
63
+      { label: '活动报名', value: 'activity_sign' },
64
+
65
+    ]
63
     return statisTypes.filter(x => x.value === theStatis)[0].label
66
     return statisTypes.filter(x => x.value === theStatis)[0].label
64
   }
67
   }
65
 
68
 
66
   const options = {
69
   const options = {
67
     legend: {},
70
     legend: {},
68
-    color: ['#8B7FE2', '#DDDDDD'],
71
+    color: ['#FF7E48', '#dcdcdc'],
69
     tooltip: {},
72
     tooltip: {},
70
     series: {
73
     series: {
71
       type: 'pie',
74
       type: 'pie',
72
       name: '转化率',
75
       name: '转化率',
73
       radius: ['34%', '52%'],
76
       radius: ['34%', '52%'],
77
+      avoidLabelOverlap: false,
78
+      label: { 
79
+        normal: { 
80
+          show: true,
81
+          position: 'center',
82
+          color: '#666666',
83
+          fontSize: 24,
84
+          fontWeight: 'bold',
85
+          formatter: `${(conversionRate*100).toFixed(2) === 'NaN' ? 0 : (conversionRate*100).toFixed(2) }%`, // {b}:数据名; {c}:数据值; {d}:百分比,可以自定义显示内容,
86
+        }
87
+      },
88
+      labelLine: {
89
+        normal: {
90
+          show: false
91
+        }
92
+      },
93
+
74
       data: theCurrent,
94
       data: theCurrent,
75
     },
95
     },
76
   }
96
   }
77
 
97
 
78
-  function onChange(e) {
98
+  function onChange (e) {
79
     UserConversionRate({ conversion: e })
99
     UserConversionRate({ conversion: e })
80
   }
100
   }
81
   const piestyles = {
101
   const piestyles = {
86
   return (
106
   return (
87
     <>
107
     <>
88
       <div>
108
       <div>
89
-      <p style={{ fontSize: '0.12rem', fontWeight: '600' }}>转化率</p>
109
+        <p style={{ fontSize: '0.12rem', fontWeight: '600' }}>转化率</p>
90
 
110
 
91
         <Select
111
         <Select
92
           style={{ width: 200 }}
112
           style={{ width: 200 }}
110
 
130
 
111
     </>
131
     </>
112
   )
132
   )
113
- }
133
+}
114
 
134
 
115
 export default UserSource
135
 export default UserSource