知与行后台管理端

UserConversion.jsx 3.9KB

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