|
@@ -1,4 +1,4 @@
|
|
-import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
|
|
|
|
+import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
import styles from "./index.module.scss";
|
|
import styles from "./index.module.scss";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
import { A4_APIgetInfo } from "@/store/action/A4hot";
|
|
import { A4_APIgetInfo } from "@/store/action/A4hot";
|
|
@@ -51,6 +51,27 @@ function A4hot() {
|
|
|
|
|
|
// 从仓库获取数据
|
|
// 从仓库获取数据
|
|
const dataAll = useSelector((state: RootState) => state.A4hot.list);
|
|
const dataAll = useSelector((state: RootState) => state.A4hot.list);
|
|
|
|
+ const filterData = useMemo(() => {
|
|
|
|
+ const temp = [...dataAll];
|
|
|
|
+ const find18D1fIndex = temp.findIndex(i => i.name === '十八洞村陈列馆一楼');
|
|
|
|
+ const find18D2fIndex = temp.findIndex(i => i.name === '十八洞村陈列馆二楼');
|
|
|
|
+ if (find18D1fIndex > -1 && find18D2fIndex > -1) {
|
|
|
|
+ const temp18D1 = temp[find18D1fIndex];
|
|
|
|
+ const temp18D2 = temp[find18D2fIndex];
|
|
|
|
+ temp18D1.name = '十八洞村陈列馆';
|
|
|
|
+ temp18D1.pcsCheck += temp18D2.pcsCheck;
|
|
|
|
+ temp18D1.pcsShare += temp18D2.pcsShare;
|
|
|
|
+ temp18D1.pcsVisit += temp18D2.pcsVisit;
|
|
|
|
+ temp.splice(find18D2fIndex, 1)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const find18DV1Index = temp.findIndex(i => i.name === '十八洞村村部一楼');
|
|
|
|
+ if (find18DV1Index > -1) {
|
|
|
|
+ temp[find18DV1Index].name = '十八洞村村部';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return temp;
|
|
|
|
+ }, [dataAll])
|
|
|
|
|
|
// 生成饼图的函数
|
|
// 生成饼图的函数
|
|
const echBingFu = useCallback(
|
|
const echBingFu = useCallback(
|
|
@@ -157,7 +178,7 @@ function A4hot() {
|
|
|
|
|
|
// 单个饼图
|
|
// 单个饼图
|
|
|
|
|
|
- dataAll.forEach((v) => {
|
|
|
|
|
|
+ filterData.forEach((v) => {
|
|
maxFileArr[0].value += v.pcsVisit;
|
|
maxFileArr[0].value += v.pcsVisit;
|
|
maxFileArr[1].value += v.pcsStar;
|
|
maxFileArr[1].value += v.pcsStar;
|
|
maxFileArr[2].value += v.pcsCheck;
|
|
maxFileArr[2].value += v.pcsCheck;
|
|
@@ -169,8 +190,32 @@ function A4hot() {
|
|
maxFileArr[3].bing.push({ name: v.name, value: v.pcsShare });
|
|
maxFileArr[3].bing.push({ name: v.name, value: v.pcsShare });
|
|
});
|
|
});
|
|
maxFileArr = maxFileArr.sort((a, b) => b.value - a.value);
|
|
maxFileArr = maxFileArr.sort((a, b) => b.value - a.value);
|
|
|
|
+
|
|
|
|
+ maxFileArr[0].bing = getTop4Arr(maxFileArr[0].bing)
|
|
|
|
+ maxFileArr[1].bing = getTop4Arr(maxFileArr[1].bing)
|
|
|
|
+ maxFileArr[2].bing = getTop4Arr(maxFileArr[2].bing)
|
|
|
|
+ maxFileArr[3].bing = getTop4Arr(maxFileArr[3].bing)
|
|
|
|
+
|
|
setMaxData(maxFileArr);
|
|
setMaxData(maxFileArr);
|
|
- }, [dataAll]);
|
|
|
|
|
|
+ }, [filterData]);
|
|
|
|
+
|
|
|
|
+ const getTop4Arr = (arr: any[]) => {
|
|
|
|
+ const clone = arr.sort((a, b) => b.value - a.value)
|
|
|
|
+ const temp: any[] = []
|
|
|
|
+ clone.forEach((item, idx) => {
|
|
|
|
+ if (idx < 4) {
|
|
|
|
+ temp.push(item)
|
|
|
|
+ } else if (idx === 4) {
|
|
|
|
+ temp.push({
|
|
|
|
+ name: '其他',
|
|
|
|
+ value: item.value
|
|
|
|
+ })
|
|
|
|
+ } else if (temp[4]) {
|
|
|
|
+ temp[4].value += item.value
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ return temp
|
|
|
|
+ }
|
|
|
|
|
|
const maxDataObjRef = useRef({
|
|
const maxDataObjRef = useRef({
|
|
pcsVisit: echRef2,
|
|
pcsVisit: echRef2,
|