index.tsx 8.0 KB

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