index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. import { AccountBookOutlined, AppstoreOutlined, BuildOutlined, LeftOutlined, MoneyCollectOutlined, RightOutlined, TransactionOutlined, UsergroupAddOutlined } from "@ant-design/icons";
  2. import { useHover, useScroll, useSize } from "ahooks";
  3. import { Button, Card, Space, Spin, Statistic } from "antd"
  4. import React, { useEffect, useRef, useState } from "react"
  5. import style from './index.less'
  6. import LineC from "./lineC";
  7. import { AllSurveyTotalDataProps, getAllSurveyTotalDataApi } from "@/services/gameData/allSurvey";
  8. import { useAjax } from "@/Hook/useAjax";
  9. import QueryForm from "@/components/QueryForm";
  10. import moment from "moment";
  11. const AllSurvey: React.FC = () => {
  12. /* ==================== */
  13. const ref = useRef(null);
  14. const ref1 = useRef(null);
  15. const ref2 = useRef(null);
  16. const ref3 = useRef(null);
  17. const isHovering = useHover(ref); // 是否hover
  18. const isHovering1 = useHover(ref1); // 是否hover
  19. const isHovering2 = useHover(ref2); // 是否hover
  20. const size = useSize(ref); // div大小
  21. const size3 = useSize(ref3); // div大小
  22. const scroll = useScroll(ref);
  23. const [leftShow, setLeftShow] = useState<boolean>(false)
  24. const [rightShow, setRightShow] = useState<boolean>(false)
  25. const [isPass, setIsPass] = useState<boolean>(false) // 容器是否大于内容宽度
  26. const [queryForm, setQueryForm] = useState<AllSurveyTotalDataProps>({})
  27. const [totalData, setTotalData] = useState<any>({})
  28. /* ==================== */
  29. const getAllSurveyTotalData = useAjax((params) => getAllSurveyTotalDataApi(params))
  30. // 处理左右按钮隐藏 显示
  31. useEffect(() => {
  32. // console.log('isHovering---->', isHovering, 'size---->', size, 'scroll--->', scroll);
  33. if (isHovering || isHovering1 || isHovering2) {
  34. let width = size.width || 0
  35. let left = scroll.left || 0
  36. if (width >= 1960) { // 容器大于内容宽度 兼容
  37. setLeftShow(false)
  38. setRightShow(false)
  39. setIsPass(true)
  40. } else {
  41. setIsPass(false)
  42. if (left === 0) {
  43. setLeftShow(false)
  44. } else {
  45. setLeftShow(true)
  46. }
  47. if (width < 1960) {
  48. setRightShow(true)
  49. }
  50. if (width + left === 1960) {
  51. setRightShow(false)
  52. }
  53. }
  54. } else {
  55. setLeftShow(false)
  56. setRightShow(false)
  57. }
  58. }, [isHovering, isHovering1, isHovering2, size, scroll])
  59. // 左右移动
  60. const aboutHandle = (about: 'left' | 'right') => {
  61. let left = scroll.left || 0
  62. if (about === 'left') {
  63. (ref?.current as any)?.scrollTo(left - 100, 0)
  64. } else {
  65. (ref?.current as any)?.scrollTo(left + 100, 0)
  66. }
  67. }
  68. useEffect(() => {
  69. getAllSurveyTotalData.run(queryForm).then((res) => {
  70. setTotalData(res)
  71. })
  72. }, [queryForm])
  73. return <div className={style.allSurver}>
  74. <Space direction="vertical" style={{ width: '100%' }}>
  75. <div ref={ref3}>
  76. <Card bordered={false} bodyStyle={{ padding: '12px 24px' }} style={{ borderRadius: 8 }}>
  77. <QueryForm
  78. onChange={(data: any) => {
  79. console.log(data)
  80. const { beginDay, ...par } = data
  81. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  82. if (beginDay && beginDay?.length === 2) {
  83. newQueryForm['beginDate'] = moment(beginDay[0]).format('YYYY-MM-DD')
  84. newQueryForm['endDate'] = moment(beginDay[1]).format('YYYY-MM-DD')
  85. } else {
  86. delete newQueryForm['beginDate']
  87. delete newQueryForm['endDate']
  88. }
  89. setQueryForm({ ...newQueryForm, ...par })
  90. }}
  91. isAccountId
  92. isGameId
  93. isSysUserId
  94. isAgentId
  95. isBeginDay
  96. />
  97. </Card>
  98. </div>
  99. <Spin spinning={getAllSurveyTotalData.loading}>
  100. <div className={style.overviewC}>
  101. <div className={style.left}><Button type="primary" ref={ref1} style={{ opacity: leftShow ? 1 : 0 }} onClick={() => aboutHandle('left')} shape="circle" icon={<LeftOutlined />} /></div>
  102. <div className={style.right}><Button type="primary" ref={ref2} style={{ opacity: rightShow ? 1 : 0 }} onClick={() => aboutHandle('right')} shape="circle" icon={<RightOutlined />} /></div>
  103. <div className={style.overviews} ref={ref}>
  104. <div style={{ width: isPass ? '100%' : 1960 }}>
  105. <Card bordered={false} style={{ width: 320, borderRadius: 8 }}>
  106. <div className={style.overview}>
  107. <div className={style.left}>
  108. <UsergroupAddOutlined style={{ fontSize: 24 }} />
  109. <div>玩家</div>
  110. </div>
  111. <div className={style.right}>
  112. <div className={style.top}>
  113. 总计:<Statistic value={totalData?.totalPlayers || 0} valueStyle={{ fontSize: 20, fontWeight: 600 }} />
  114. </div>
  115. <div className={style.bottom}>
  116. <div>昨日:<Statistic value={totalData?.yesterdayPlayerCount || 0} /></div>
  117. <div>今日:<Statistic value={totalData?.todayPlayerCount || 0} /></div>
  118. </div>
  119. </div>
  120. </div>
  121. </Card>
  122. <Card bordered={false} style={{ width: 320, borderRadius: 8 }}>
  123. <div className={style.overview}>
  124. <div className={style.left} style={{ backgroundColor: '#36a3f7' }}>
  125. <TransactionOutlined style={{ fontSize: 24 }} />
  126. <div>消耗</div>
  127. </div>
  128. <div className={style.right}>
  129. <div className={style.top} style={{ borderColor: '#36a3f7' }}>
  130. 总计:<Statistic value={totalData?.totalCost || 0} valueStyle={{ fontSize: 20, fontWeight: 600 }} />
  131. </div>
  132. <div className={style.bottom}>
  133. <div>昨日:<Statistic value={totalData?.yesterdayTotalCost || 0} /></div>
  134. <div>今日:<Statistic value={totalData?.todayTotalCost || 0} /></div>
  135. </div>
  136. </div>
  137. </div>
  138. </Card>
  139. <Card bordered={false} style={{ width: 320, borderRadius: 8 }}>
  140. <div className={style.overview}>
  141. <div className={style.left} style={{ backgroundColor: '#f4516c' }}>
  142. <MoneyCollectOutlined style={{ fontSize: 24 }} />
  143. <div>充值</div>
  144. </div>
  145. <div className={style.right}>
  146. <div className={style.top} style={{ borderColor: '#f4516c' }}>
  147. 总计:<Statistic value={totalData?.totalAmount || 0} valueStyle={{ fontSize: 20, fontWeight: 600 }} />
  148. </div>
  149. <div className={style.bottom}>
  150. <div style={{ justifyContent: 'space-between' }}>
  151. <div>昨账:<Statistic value={totalData?.yesterdayAmount || 0} /></div>
  152. <div>昨新:<Statistic value={totalData?.yesterdayNewPlayerAmount || 0} /></div>
  153. </div>
  154. <div style={{ justifyContent: 'space-between', flex: 1 }}>
  155. <div>今账:<Statistic value={totalData?.todayAmount || 0} /></div>
  156. <div>今新:<Statistic value={totalData?.todayNewPlayerAmount || 0} /></div>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. </Card>
  162. <Card bordered={false} style={{ width: 320, borderRadius: 8 }}>
  163. <div className={style.overview}>
  164. <div className={style.left} style={{ backgroundColor: '#52c41a' }}>
  165. <AppstoreOutlined style={{ fontSize: 24 }} />
  166. <div>渠道</div>
  167. </div>
  168. <div className={style.right}>
  169. <div className={style.top} style={{ borderColor: '#52c41a' }}>
  170. 总计:<Statistic value={totalData?.totalAgentCount || 0} valueStyle={{ fontSize: 20, fontWeight: 600 }} />
  171. </div>
  172. <div className={style.bottom}>
  173. <div>昨日:<Statistic value={totalData?.yesterdayAgentCount || 0} /></div>
  174. <div>今日:<Statistic value={totalData?.todayAgentCount || 0} /></div>
  175. </div>
  176. </div>
  177. </div>
  178. </Card>
  179. <Card bordered={false} style={{ width: 320, borderRadius: 8 }}>
  180. <div className={style.overview}>
  181. <div className={style.left} style={{ backgroundColor: '#597ef7' }}>
  182. <BuildOutlined style={{ fontSize: 24 }} />
  183. <div>游戏</div>
  184. </div>
  185. <div className={style.right}>
  186. <div className={style.top} style={{ borderColor: '#597ef7' }}>
  187. 总计:<Statistic value={totalData?.totalGameCount || 0} valueStyle={{ fontSize: 20, fontWeight: 600 }} />
  188. </div>
  189. <div className={style.bottom}>
  190. <div>昨日:<Statistic value={totalData?.yesterdayGameCount || 0} /></div>
  191. <div>今日:<Statistic value={totalData?.todayGameCount || 0} /></div>
  192. </div>
  193. </div>
  194. </div>
  195. </Card>
  196. <Card bordered={false} style={{ width: 320, borderRadius: 8 }}>
  197. <div className={style.overview}>
  198. <div className={style.left} style={{ backgroundColor: '#9254de' }}>
  199. <AccountBookOutlined style={{ fontSize: 24 }} />
  200. <div>回本</div>
  201. </div>
  202. <div className={style.right}>
  203. <div className={style.top} style={{ borderColor: '#9254de' }}>
  204. 总回:<Statistic value={totalData?.totalRoi || 0} valueStyle={{ fontSize: 20, fontWeight: 600, color: 'red' }} precision={2} suffix="%" />
  205. </div>
  206. <div className={style.bottom}>
  207. <div style={{ justifyContent: 'space-between' }}>
  208. <div>首日:<Statistic value={totalData?.firstRoi || 0} suffix="%" precision={2} /></div>
  209. <div>7天:<Statistic value={totalData?.d7TotalRoi || 0} suffix="%" precision={2} /></div>
  210. </div>
  211. <div style={{ justifyContent: 'space-between', flex: 1 }}>
  212. <div>30天:<Statistic value={totalData?.d30TotalRoi || 0} suffix="%" precision={2} /></div>
  213. </div>
  214. </div>
  215. </div>
  216. </div>
  217. </Card>
  218. </div>
  219. </div>
  220. </div>
  221. </Spin>
  222. </Space>
  223. <LineC height={size3.height || 0} queryForm={queryForm} />
  224. </div>
  225. }
  226. export default AllSurvey