chenlei hace 1 día
padre
commit
d9f21e8cbd
Se han modificado 2 ficheros con 24 adiciones y 7 borrados
  1. 22 5
      src/pages/Abench/A1statistics/index.tsx
  2. 2 2
      src/store/action/Abench/A1.ts

+ 22 - 5
src/pages/Abench/A1statistics/index.tsx

@@ -23,7 +23,6 @@ const DEFAULT_COLORS = ['#c11b2d', '#243220', '#24664b', '#8acfb2', '#806e4c', '
 
 
 // 先写一些静态的
 // 先写一些静态的
 type DictItem = { name: string; id: number }
 type DictItem = { name: string; id: number }
-type TextureItem = { name: string; id: number; count: number }
 type TotalItem = { pcs: number | null; level: string | null }
 type TotalItem = { pcs: number | null; level: string | null }
 
 
 function A1statistics() {
 function A1statistics() {
@@ -156,9 +155,17 @@ function A1statistics() {
     const fetch = async () => {
     const fetch = async () => {
       try {
       try {
         const res = await A1_APIgetDataTextureByTagId(textureTagId)
         const res = await A1_APIgetDataTextureByTagId(textureTagId)
-        if (res?.code === 0 && Array.isArray(res.data)) {
+        if (
+          res?.code === 0 &&
+          res.data &&
+          typeof res.data === 'object' &&
+          !Array.isArray(res.data)
+        ) {
           setTextureData(
           setTextureData(
-            (res.data as TextureItem[]).map(({ name, count }) => ({ name, value: count }))
+            Object.entries(res.data as Record<string, number>).map(([name, value]) => ({
+              name,
+              value
+            }))
           )
           )
         } else {
         } else {
           setTextureData([])
           setTextureData([])
@@ -179,9 +186,17 @@ function A1statistics() {
     const fetch = async () => {
     const fetch = async () => {
       try {
       try {
         const res = await A1_APIgetDataTagByTagId(categoryTagId)
         const res = await A1_APIgetDataTagByTagId(categoryTagId)
-        if (res?.code === 0 && Array.isArray(res.data)) {
+        if (
+          res?.code === 0 &&
+          res.data &&
+          typeof res.data === 'object' &&
+          !Array.isArray(res.data)
+        ) {
           setCategoryData(
           setCategoryData(
-            (res.data as TextureItem[]).map(({ name, count }) => ({ name, value: count }))
+            Object.entries(res.data as Record<string, number>).map(([name, value]) => ({
+              name,
+              value
+            }))
           )
           )
         } else {
         } else {
           setCategoryData([])
           setCategoryData([])
@@ -379,6 +394,8 @@ function A1statistics() {
       return
       return
     }
     }
 
 
+    // 有数据时先清除,避免从「暂无数据」切换后 graphic 残留
+    myChart.clear()
     // 计算总数用于百分比
     // 计算总数用于百分比
     const total = data.reduce((sum, item) => sum + item.value, 0)
     const total = data.reduce((sum, item) => sum + item.value, 0)
 
 

+ 2 - 2
src/store/action/Abench/A1.ts

@@ -17,7 +17,7 @@ export const A1_APIgetDictById = () => {
 
 
 /**
 /**
  * 根据 tagId 获取材质统计数据
  * 根据 tagId 获取材质统计数据
- * 返回 {name:string; id:number; count:number}[]
+ * 返回 {[string]: number} 例如 {"无机质":1, "单一质地":1}
  */
  */
 export const A1_APIgetDataTextureByTagId = (tagId: number) => {
 export const A1_APIgetDataTextureByTagId = (tagId: number) => {
   return http.get(`cms/workCount/getDataTextureByTagId/${tagId}`)
   return http.get(`cms/workCount/getDataTextureByTagId/${tagId}`)
@@ -25,7 +25,7 @@ export const A1_APIgetDataTextureByTagId = (tagId: number) => {
 
 
 /**
 /**
  * 根据 tagId 获取品类统计数据
  * 根据 tagId 获取品类统计数据
- * 返回 {name:string; id:number; count:number}[]
+ * 返回 {[string]: number} 例如 {"无机质":1, "单一质地":1}
  */
  */
 export const A1_APIgetDataTagByTagId = (tagId: number) => {
 export const A1_APIgetDataTagByTagId = (tagId: number) => {
   return http.get(`cms/workCount/getDataTagByTagId/${tagId}`)
   return http.get(`cms/workCount/getDataTagByTagId/${tagId}`)