index.tsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. 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(
  42. (state: RootState) => state.loginStore.authPageArr
  43. );
  44. useEffect(() => {
  45. powerInfo.forEach((v: any) => {
  46. if (v.id === 100) tabListTemp[0].done = tempDone[0].done = true;
  47. if (v.id === 200) tabListTemp[1].done = true;
  48. if (v.id === 300) tabListTemp[2].done = tempDone[1].done = true;
  49. if (v.id === 400) tabListTemp[3].done = tempDone[2].done = true;
  50. if (v.id === 500) tempDone[3].done = true;
  51. if (v.id === 600) tabListTemp[4].done = tempDone[4].done = true;
  52. if (v.id === 800) tempDone[5].done = true;
  53. });
  54. window.setTimeout(() => {
  55. setTabList(tabListTemp);
  56. }, 100);
  57. }, [powerInfo, tabListTemp, tempDone]);
  58. // 实时时间
  59. const [nowTime, setNowTime] = useState(
  60. dayjs(Date.now()).format("YYYY年MM月DD HH:mm")
  61. );
  62. // 点击头部右侧和下面右侧
  63. const toPageFu = useCallback((path: string, flag: boolean) => {
  64. if (flag) return MessageFu.warning("没有该模块权限!");
  65. history.push(path);
  66. }, []);
  67. const timeRef = useRef(-1);
  68. useEffect(() => {
  69. timeRef.current = window.setInterval(() => {
  70. setNowTime(() => {
  71. return dayjs(Date.now()).format("YYYY年MM月DD HH:mm");
  72. });
  73. }, 1000);
  74. return () => {
  75. clearInterval(timeRef.current);
  76. };
  77. }, []);
  78. const userInfo = useMemo(() => {
  79. return getTokenInfo().user;
  80. }, []);
  81. // -----------图表
  82. const echartsFu = useCallback(async () => {
  83. const res = await getStores2API1();
  84. let list = res.data;
  85. if (list && list.length && list.length > 7) {
  86. list = list.slice(0, 7);
  87. } else {
  88. const num = 7 - list.length;
  89. for (let i = 0; i < num; i++) {
  90. if (i % 2 !== 0) list.unshift({ groupKey: "", count: null });
  91. else list.push({ groupKey: "", count: null });
  92. }
  93. }
  94. const chartDom: any = document.querySelector(".chart");
  95. const myChart = echarts.init(chartDom);
  96. const option = {
  97. color: ["#9F1927"],
  98. tooltip: {
  99. trigger: "axis",
  100. axisPointer: {
  101. type: "shadow",
  102. },
  103. },
  104. grid: {
  105. left: "3%",
  106. right: "4%",
  107. bottom: "3%",
  108. containLabel: true,
  109. },
  110. xAxis: [
  111. {
  112. type: "category",
  113. data: list.map((v: any) => v.groupKey),
  114. axisTick: {
  115. show: false,
  116. alignWithLabel: false,
  117. },
  118. axisLabel: {
  119. interval: 0, //强制文字产生间隔
  120. textStyle: {
  121. color: "#000", //坐标值得具体的颜色
  122. fontSize: 12,
  123. },
  124. },
  125. axisLine: {
  126. //Y轴坐标轴
  127. show: true,
  128. // 坐标的颜色和宽度
  129. lineStyle: {
  130. width: 2,
  131. color: "#9F1927",
  132. },
  133. },
  134. },
  135. ],
  136. yAxis: [
  137. {
  138. type: "value",
  139. axisLabel: {
  140. textStyle: {
  141. color: "#000", //坐标值得具体的颜色
  142. },
  143. },
  144. axisLine: {
  145. //Y轴坐标轴
  146. show: true,
  147. lineStyle: {
  148. width: 2,
  149. color: "#9F1927",
  150. },
  151. },
  152. // 隐藏背景坐标线段
  153. splitLine: {
  154. show: false,
  155. },
  156. },
  157. ],
  158. series: [
  159. {
  160. name: "",
  161. type: "bar",
  162. barMaxwidth: "50%",
  163. data: list.map((v: any) => v.count),
  164. itemStyle: {
  165. normal: {
  166. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  167. { offset: 0, color: "rgba(159, 25, 39, .5)" }, //渐变头部色
  168. { offset: 1, color: "rgba(159, 25, 39, 1)" },
  169. ]),
  170. barBorderRadius: 2,
  171. label: {
  172. show: true, //开启显示
  173. position: "top", //在上方显示
  174. textStyle: {
  175. //数值样式
  176. color: "#9F1927",
  177. fontSize: 16,
  178. },
  179. },
  180. },
  181. },
  182. },
  183. ],
  184. };
  185. option && myChart.setOption(option);
  186. }, []);
  187. // 代办提醒
  188. const [doneList, setDoneList] = useState(tempDone);
  189. const doneNumsAPIFu = useCallback(async () => {
  190. const res = await getHomeNumsAPI();
  191. const data = [...tempDone];
  192. res.data.forEach((v: any) => {
  193. if (v.groupKey === "register") data[0].num = v.count;
  194. else if (v.groupKey === "in") data[1].num = v.count;
  195. else if (v.groupKey === "out") data[2].num = v.count;
  196. else if (v.groupKey === "edit") data[3].num = v.count;
  197. else if (v.groupKey === "cancel") data[4].num = v.count;
  198. else if (v.groupKey === "move") data[5].num = v.count;
  199. });
  200. setDoneList(data);
  201. }, [tempDone]);
  202. useEffect(() => {
  203. echartsFu();
  204. doneNumsAPIFu();
  205. }, [doneNumsAPIFu, 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>藏馆统计</div>
  238. <Button onClick={() => history.push("/stores/2")}>
  239. 查看更多
  240. </Button>
  241. </div>
  242. {/* 图表 */}
  243. <div className="chartBox">
  244. <div className="chartTit">(件)</div>
  245. <div className="chart"></div>
  246. </div>
  247. </div>
  248. <div className="flooBoxR">
  249. <div className="flooTit">
  250. <div>审核提醒</div>
  251. </div>
  252. <div className="doneBox">
  253. {doneList.map((v, i) => (
  254. <div
  255. onClick={() => toPageFu(v.path, !v.done)}
  256. className={classNames(
  257. "doneRow",
  258. i >= 4 ? "noneRow" : "",
  259. !v.done ? "noAuth" : ""
  260. )}
  261. key={v.id}
  262. >
  263. <div className="doneRow_tit">{v.name}</div>
  264. <div className="doneRow_txt">
  265. 共有&emsp;<span>{v.num}</span>&emsp;待审核事项
  266. </div>
  267. </div>
  268. ))}
  269. </div>
  270. </div>
  271. </div>
  272. </div>
  273. </div>
  274. );
  275. }