Statistic.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. 'use client'
  2. import { useState } from 'react'
  3. import cn from '@/utils/classnames'
  4. import ReactECharts from 'echarts-for-react'
  5. import * as echarts from 'echarts'
  6. const cardClass = 'bg-[#FCFCFC] border rounded-[10px] border-[#E6E7EB] p-6 flex'
  7. const Statistic = () => {
  8. const [knowledges, setKnowledges] = useState(0)
  9. const [depts, setDepts] = useState(0)
  10. const [tags, setTags] = useState(0)
  11. const [typeData, setTypeData] = useState([])
  12. const [updateData, setUpdateData] = useState([])
  13. const [tagData, setTagData] = useState([
  14. { name: '标签1', value: 10 },
  15. { name: '标签2', value: 10 },
  16. { name: '标签3', value: 10 },
  17. { name: '标签4', value: 10 },
  18. { name: '标签5', value: 10 },
  19. { name: '标签6', value: 10 },
  20. { name: '标签7', value: 10 },
  21. { name: '标签8', value: 10 },
  22. { name: '标签9', value: 10 },
  23. { name: '标签10', value: 10 },
  24. { name: '标签11', value: 10 },
  25. { name: '标签12', value: 10 },
  26. { name: '标签13', value: 10 },
  27. { name: '标签14', value: 10 },
  28. { name: '标签15', value: 10 },
  29. ])
  30. const typeOptions = {
  31. grid: {
  32. top: 0,
  33. bottom: 0,
  34. left: 0,
  35. right: 0,
  36. },
  37. tooltip: {
  38. trigger: 'item',
  39. },
  40. legend: {
  41. orient: 'horizontal',
  42. top: 0,
  43. itemWidth: 8,
  44. itemHeight: 8,
  45. },
  46. series: [
  47. {
  48. type: 'pie',
  49. radius: ['26%', '50%'],
  50. data: [
  51. { value: 1048, name: 'Search Engine' },
  52. { value: 735, name: 'Direct' },
  53. { value: 580, name: 'Email' },
  54. { value: 484, name: 'Union Ads' },
  55. { value: 300, name: 'Video Ads' },
  56. ],
  57. label: {
  58. formatter: '{b} {d}%',
  59. },
  60. emphasis: {
  61. disabled: true,
  62. },
  63. },
  64. ],
  65. }
  66. const updateOptions = {
  67. grid: {
  68. top: 40,
  69. bottom: 20,
  70. left: 40,
  71. right: 0,
  72. },
  73. tooltip: {
  74. trigger: 'axis',
  75. },
  76. xAxis: {
  77. type: 'category',
  78. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  79. axisLine: { show: false },
  80. axisTick: { show: false },
  81. splitLine: { show: false },
  82. axisLabel: {
  83. fontSize: 10,
  84. interval: 0,
  85. color: 'rgba(87, 98, 117, 1)',
  86. },
  87. },
  88. yAxis: {
  89. type: 'value',
  90. axisLine: { show: false },
  91. axisTick: { show: false },
  92. splitNumber: 3,
  93. splitLine: {
  94. lineStyle: {
  95. type: 'dashed',
  96. color: 'rgba(239, 241, 248, 1)',
  97. },
  98. },
  99. axisLabel: {
  100. fontSize: 10,
  101. },
  102. },
  103. series: [
  104. {
  105. type: 'bar',
  106. data: [120, 200, 150, 80, 70, 110, 130],
  107. itemStyle: {
  108. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  109. { offset: 0, color: '#2078FC' },
  110. { offset: 1, color: '#5DC9F9' },
  111. ]),
  112. },
  113. },
  114. ],
  115. }
  116. const tagColors = ['#7185fb', '#4bc97d', '#2079fe', '#dba53c', '#4ec5f9']
  117. const tagOptions = {
  118. tooltip: {
  119. trigger: 'item',
  120. },
  121. series: [
  122. {
  123. type: 'graph',
  124. layout: 'force',
  125. data: tagData.map((v, i) => {
  126. v.itemStyle = {
  127. color: tagColors[i % tagColors.length],
  128. }
  129. return v
  130. }),
  131. links: [],
  132. roam: true,
  133. force: {
  134. repulsion: 100,
  135. },
  136. symbolSize: 60,
  137. label: {
  138. show: true,
  139. },
  140. emphasis: {
  141. disabled: true,
  142. },
  143. },
  144. ],
  145. }
  146. return (
  147. <div className="w-full px-12">
  148. <div className={cn('w-full gap-6', cardClass)}>
  149. <div className="flex h-[120px] grow items-center bg-[url('/imgs/statistic-bg.png')] bg-[length:100%_100%] bg-no-repeat pl-6">
  150. <img src="/imgs/statistic-icon-1.png" className="mr-6 h-16 w-16"/>
  151. <div>
  152. <div className="text-[36px] text-[#111111]">{knowledges}</div>
  153. <div className="text-[#111111]">知识库总量</div>
  154. </div>
  155. </div>
  156. <div className="flex h-[120px] grow items-center bg-[url('/imgs/statistic-bg.png')] bg-[length:100%_100%] bg-no-repeat pl-6">
  157. <img src="/imgs/statistic-icon-2.png" className="mr-6 h-16 w-16"/>
  158. <div>
  159. <div className="text-[36px] text-[#111111]">{depts}</div>
  160. <div className="text-[#111111]">部门总量</div>
  161. </div>
  162. </div>
  163. <div className="flex h-[120px] grow items-center bg-[url('/imgs/statistic-bg.png')] bg-[length:100%_100%] bg-no-repeat pl-6">
  164. <img src="/imgs/statistic-icon-3.png" className="mr-6 h-16 w-16"/>
  165. <div>
  166. <div className="text-[36px] text-[#111111]">{tags}</div>
  167. <div className="text-[#111111]">标签总量</div>
  168. </div>
  169. </div>
  170. </div>
  171. <div className='mt-6 flex w-full gap-8'>
  172. <div className={cn(cardClass, 'h-[360px] flex-1 flex-col overflow-hidden')}>
  173. <div className="text-2xl font-bold text-[#333333]">知识库类别统计</div>
  174. <div className="relative mt-3 flex flex-1 items-center justify-center">
  175. <img src="/imgs/statistic-icon-4.png" className="absolute"/>
  176. <ReactECharts option={typeOptions} className="flex-1" />
  177. </div>
  178. </div>
  179. <div className={cn(cardClass, 'h-[360px] flex-1 flex-col overflow-hidden')}>
  180. <div className="text-2xl font-bold text-[#333333]">知识库更新情况统计</div>
  181. <ReactECharts option={updateOptions} className="flex-1" />
  182. </div>
  183. <div className={cn(cardClass, 'h-[360px] flex-1 flex-col overflow-hidden bg-[url("/imgs/statistic-icon-5.png")] bg-[length:100%_100%] bg-no-repeat')}>
  184. <div className="text-2xl font-bold text-[#333333]">标签云图</div>
  185. <ReactECharts option={tagOptions} className="flex-1" />
  186. </div>
  187. </div>
  188. </div>
  189. )
  190. }
  191. export default Statistic