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