index.tsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. import { getTokenInfo } from '@/utils/storage'
  2. import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
  3. import styles from './index.module.scss'
  4. import dayjs from 'dayjs'
  5. import { Button } from 'antd'
  6. import classNames from 'classnames'
  7. import * as echarts from 'echarts/core'
  8. import { TooltipComponent, GridComponent } from 'echarts/components'
  9. import { BarChart } from 'echarts/charts'
  10. import { CanvasRenderer } from 'echarts/renderers'
  11. import history from '@/utils/history'
  12. import { getStores2API1, getStores2API2 } from '@/store/action/stores1'
  13. import { getHomeNumsAPI } from '@/store/action/login'
  14. import { useSelector } from 'react-redux'
  15. import { RootState } from '@/store'
  16. import { MessageFu } from '@/utils/message'
  17. echarts.use([TooltipComponent, GridComponent, BarChart, CanvasRenderer])
  18. export default function Home() {
  19. // 顶部右侧数据
  20. const tabListTemp = useMemo(() => {
  21. return [
  22. { id: 1, done: false, path: '/object', name: '藏品登记' },
  23. { id: 2, done: false, path: '/object/2', name: '藏品总账' },
  24. { id: 3, done: false, path: '/object/3', name: '入库管理' },
  25. { id: 4, done: false, path: '/object/4', name: '出库管理' },
  26. { id: 5, done: false, path: '/object/6', name: '藏品注销' }
  27. ]
  28. }, [])
  29. // 右下方的数据
  30. const tempDone = useMemo(() => {
  31. return [
  32. { id: 1, done: false, path: '/object', num: 0, name: '藏品登记' },
  33. { id: 2, done: false, path: '/object/3', num: 0, name: '入库管理' },
  34. { id: 3, done: false, path: '/object/4', num: 0, name: '出库管理' },
  35. { id: 4, done: false, path: '/object/5', num: 0, name: '藏品修改' },
  36. { id: 5, done: false, path: '/object/6', num: 0, name: '藏品注销' },
  37. { id: 6, done: false, path: '/stores/3', num: 0, name: '藏品移库' }
  38. ]
  39. }, [])
  40. const [tabList, setTabList] = useState(tabListTemp)
  41. const powerInfo = useSelector((state: RootState) => state.loginStore.authPageArr)
  42. useEffect(() => {
  43. powerInfo.forEach((v: any) => {
  44. if (v.id === 100) tabListTemp[0].done = tempDone[0].done = true
  45. if (v.id === 200) tabListTemp[1].done = true
  46. if (v.id === 300) tabListTemp[2].done = tempDone[1].done = true
  47. if (v.id === 400) tabListTemp[3].done = tempDone[2].done = true
  48. if (v.id === 500) tempDone[3].done = true
  49. if (v.id === 600) tabListTemp[4].done = tempDone[4].done = true
  50. if (v.id === 800) tempDone[5].done = true
  51. })
  52. window.setTimeout(() => {
  53. setTabList(tabListTemp)
  54. }, 100)
  55. }, [powerInfo, tabListTemp, tempDone])
  56. // 实时时间
  57. const [nowTime, setNowTime] = useState(dayjs(Date.now()).format('YYYY年MM月DD HH:mm'))
  58. // 点击头部右侧和下面右侧
  59. const toPageFu = useCallback((path: string, flag: boolean) => {
  60. if (flag) return MessageFu.warning('没有该模块权限!')
  61. history.push(path)
  62. }, [])
  63. const timeRef = useRef(-1)
  64. useEffect(() => {
  65. timeRef.current = window.setInterval(() => {
  66. setNowTime(() => {
  67. return dayjs(Date.now()).format('YYYY年MM月DD HH:mm')
  68. })
  69. }, 1000)
  70. return () => {
  71. clearInterval(timeRef.current)
  72. }
  73. }, [])
  74. const userInfo = useMemo(() => {
  75. return getTokenInfo().user
  76. }, [])
  77. // -----------图表
  78. const echartsFu = useCallback(async (val: string) => {
  79. const res = val === '文物类别' ? await getStores2API1() : await getStores2API2()
  80. let list = res.data
  81. if (list && list.length && list.length > 7) {
  82. list = list.slice(0, 7)
  83. } else {
  84. const num = 7 - list.length
  85. for (let i = 0; i < num; i++) {
  86. if (i % 2 !== 0) list.unshift({ groupKey: '', count: null })
  87. else list.push({ groupKey: '', count: null })
  88. }
  89. }
  90. // list = list.sort((a: any, b: any) => b.count - a.count)
  91. const chartDom: any = document.querySelector('.chart')
  92. const myChart = echarts.getInstanceByDom(chartDom) || echarts.init(chartDom)
  93. const option = {
  94. color: ['#9F1927'],
  95. tooltip: {
  96. trigger: 'axis',
  97. axisPointer: {
  98. type: 'shadow'
  99. }
  100. },
  101. grid: {
  102. left: '3%',
  103. right: '4%',
  104. bottom: '3%',
  105. containLabel: true
  106. },
  107. xAxis: [
  108. {
  109. type: 'category',
  110. data: list.map((v: any) => v.groupKey),
  111. axisTick: {
  112. show: false,
  113. alignWithLabel: false
  114. },
  115. axisLabel: {
  116. interval: 0, //强制文字产生间隔
  117. textStyle: {
  118. color: '#000', //坐标值得具体的颜色
  119. fontSize: 12
  120. }
  121. },
  122. axisLine: {
  123. //Y轴坐标轴
  124. show: true,
  125. // 坐标的颜色和宽度
  126. lineStyle: {
  127. width: 2,
  128. color: '#9F1927'
  129. }
  130. }
  131. }
  132. ],
  133. yAxis: [
  134. {
  135. type: 'value',
  136. axisLabel: {
  137. textStyle: {
  138. color: '#000' //坐标值得具体的颜色
  139. }
  140. },
  141. axisLine: {
  142. //Y轴坐标轴
  143. show: true,
  144. lineStyle: {
  145. width: 2,
  146. color: '#9F1927'
  147. }
  148. },
  149. // 隐藏背景坐标线段
  150. splitLine: {
  151. show: false
  152. }
  153. }
  154. ],
  155. series: [
  156. {
  157. name: '',
  158. type: 'bar',
  159. barMaxwidth: '50%',
  160. data: list.map((v: any) => v.count),
  161. itemStyle: {
  162. normal: {
  163. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  164. { offset: 0, color: 'rgba(159, 25, 39, .5)' }, //渐变头部色
  165. { offset: 1, color: 'rgba(159, 25, 39, 1)' }
  166. ]),
  167. barBorderRadius: 2,
  168. label: {
  169. show: true, //开启显示
  170. position: 'top', //在上方显示
  171. textStyle: {
  172. //数值样式
  173. color: '#9F1927',
  174. fontSize: 16
  175. }
  176. }
  177. }
  178. }
  179. }
  180. ]
  181. }
  182. option && myChart.setOption(option)
  183. }, [])
  184. // 代办提醒
  185. const [doneList, setDoneList] = useState(tempDone)
  186. const doneNumsAPIFu = useCallback(async () => {
  187. const res = await getHomeNumsAPI()
  188. const data = [...tempDone]
  189. res.data.forEach((v: any) => {
  190. if (v.groupKey === 'register') data[0].num = v.count
  191. else if (v.groupKey === 'in') data[1].num = v.count
  192. else if (v.groupKey === 'out') data[2].num = v.count
  193. else if (v.groupKey === 'edit') data[3].num = v.count
  194. else if (v.groupKey === 'cancel') data[4].num = v.count
  195. else if (v.groupKey === 'move') data[5].num = v.count
  196. })
  197. setDoneList(data)
  198. }, [tempDone])
  199. useEffect(() => {
  200. doneNumsAPIFu()
  201. }, [doneNumsAPIFu])
  202. const [echBtnAc, setEchBtnAc] = useState('文物类别')
  203. useEffect(() => {
  204. echartsFu(echBtnAc)
  205. }, [echBtnAc, echartsFu])
  206. return (
  207. <div className={styles.Home}>
  208. <div className='homeMain'>
  209. {/* 顶部页面 */}
  210. <div className='title'>
  211. <div className='titleL'>
  212. <h3>
  213. 欢迎 {userInfo.realName} 进入
  214. <br />
  215. <br />
  216. 乐山市博物馆馆藏管理系统!
  217. </h3>
  218. <p>{nowTime}</p>
  219. </div>
  220. <div className='titleR'>
  221. {tabList.map((v, i) => (
  222. <div
  223. onClick={() => toPageFu(v.path, !v.done)}
  224. className={classNames('row', !v.done ? 'noAuth' : '')}
  225. key={v.id}
  226. >
  227. <div className={`bac${v.id}`}></div>
  228. <p>{v.name}</p>
  229. </div>
  230. ))}
  231. </div>
  232. </div>
  233. {/* 下面数据 */}
  234. <div className='flooBox'>
  235. <div className='flooBoxL'>
  236. <div className='flooTit'>
  237. <div>
  238. 藏馆统计
  239. <div className='flooTitBtn'>
  240. {['文物类别', '藏品级别'].map(v => (
  241. <Button
  242. onClick={() => setEchBtnAc(v)}
  243. type={echBtnAc === v ? 'primary' : 'default'}
  244. size='small'
  245. key={v}
  246. >
  247. {v}
  248. </Button>
  249. ))}
  250. </div>
  251. </div>
  252. <Button onClick={() => history.push('/stores/2')}>查看更多</Button>
  253. </div>
  254. {/* 图表 */}
  255. <div className='chartBox'>
  256. <div className='chartTit'>(件)</div>
  257. <div className='chart'></div>
  258. </div>
  259. </div>
  260. <div className='flooBoxR'>
  261. <div className='flooTit'>
  262. <div>审核提醒</div>
  263. </div>
  264. <div className='doneBox'>
  265. {doneList.map((v, i) => (
  266. <div
  267. onClick={() => toPageFu(v.path, !v.done)}
  268. className={classNames(
  269. 'doneRow',
  270. i >= 4 ? 'noneRow' : '',
  271. !v.done ? 'noAuth' : ''
  272. )}
  273. key={v.id}
  274. >
  275. <div className='doneRow_tit'>{v.name}</div>
  276. <div className='doneRow_txt'>
  277. 共有&emsp;<span>{v.num}</span>&emsp;待审核事项
  278. </div>
  279. </div>
  280. ))}
  281. </div>
  282. </div>
  283. </div>
  284. </div>
  285. </div>
  286. )
  287. }