|
@@ -192,8 +192,12 @@ const { ZmTable, ZmTableColumn } = useTableComponents()
|
|
|
import { useUserStore } from '@/store/modules/user'
|
|
import { useUserStore } from '@/store/modules/user'
|
|
|
const userStore = useUserStore()
|
|
const userStore = useUserStore()
|
|
|
|
|
|
|
|
-type SummaryItem = Record<string, number>
|
|
|
|
|
-type ChildMap = Record<string, SummaryItem[]>
|
|
|
|
|
|
|
+type SummaryItem = Record<string, any>
|
|
|
|
|
+type ChartDataItem = {
|
|
|
|
|
+ id?: string | number
|
|
|
|
|
+ name: string
|
|
|
|
|
+ value: number
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
const DRILLDOWN_KEYS = ['个人防护', '规范操作', '规范指挥', '人员位置', '作业场所'] as const
|
|
const DRILLDOWN_KEYS = ['个人防护', '规范操作', '规范指挥', '人员位置', '作业场所'] as const
|
|
|
|
|
|
|
@@ -300,30 +304,49 @@ const downloadSOC = async (row) => {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const child = ref<ChildMap>({})
|
|
|
|
|
|
|
+const childData = ref<SummaryItem[]>([])
|
|
|
const totalData = ref<SummaryItem[]>([])
|
|
const totalData = ref<SummaryItem[]>([])
|
|
|
const currentDrilldownKey = ref('')
|
|
const currentDrilldownKey = ref('')
|
|
|
|
|
+const currentDrilldownId = ref<string | number | undefined>(undefined)
|
|
|
|
|
+
|
|
|
|
|
+const normalizeChartData = (source: SummaryItem[] = []): ChartDataItem[] => {
|
|
|
|
|
+ return source
|
|
|
|
|
+ .map((item) => {
|
|
|
|
|
+ if (!item) return null
|
|
|
|
|
+
|
|
|
|
|
+ if ('name' in item || 'className' in item || 'label' in item) {
|
|
|
|
|
+ return {
|
|
|
|
|
+ id: item.id ?? item.socClass ?? item.valueId,
|
|
|
|
|
+ name: item.name ?? item.className ?? item.label ?? '',
|
|
|
|
|
+ value: Number(item.value ?? item.count ?? item.total ?? 0) || 0
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const entries = Object.entries(item)
|
|
|
|
|
+ const nameEntry =
|
|
|
|
|
+ entries.find(
|
|
|
|
|
+ ([key, value]) =>
|
|
|
|
|
+ !['id', 'socClass', 'valueId', 'value', 'count', 'total'].includes(key) &&
|
|
|
|
|
+ typeof value === 'number'
|
|
|
|
|
+ ) || entries.find(([key]) => !['id', 'socClass', 'valueId'].includes(key))
|
|
|
|
|
+
|
|
|
|
|
+ const [name, value] = nameEntry || ['', 0]
|
|
|
|
|
+ return {
|
|
|
|
|
+ id: item.id ?? item.socClass ?? item.valueId,
|
|
|
|
|
+ name,
|
|
|
|
|
+ value: Number(value) || 0
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .filter((item): item is ChartDataItem => !!item && !!item.name)
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
const totalChartData = computed(() => {
|
|
const totalChartData = computed(() => {
|
|
|
- return (totalData.value as SummaryItem[]).map((item) => {
|
|
|
|
|
- const [name, value] = Object.entries(item || {})[0] || ['', 0]
|
|
|
|
|
- return {
|
|
|
|
|
- name,
|
|
|
|
|
- value: Number(value) || 0
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ return normalizeChartData(totalData.value as SummaryItem[])
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
const childChartData = computed(() => {
|
|
const childChartData = computed(() => {
|
|
|
if (!currentDrilldownKey.value) return []
|
|
if (!currentDrilldownKey.value) return []
|
|
|
- const source = (child.value as ChildMap)?.[currentDrilldownKey.value] || []
|
|
|
|
|
- return source.map((item) => {
|
|
|
|
|
- const [name, value] = Object.entries(item || {})[0] || ['', 0]
|
|
|
|
|
- return {
|
|
|
|
|
- name,
|
|
|
|
|
- value: Number(value) || 0
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ return normalizeChartData(childData.value as SummaryItem[])
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
const chartColorMap: Record<string, string> = {
|
|
const chartColorMap: Record<string, string> = {
|
|
@@ -465,6 +488,8 @@ const socChartOption = computed<EChartsOption>(() => {
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
data: sourceData.map((item) => ({
|
|
data: sourceData.map((item) => ({
|
|
|
|
|
+ id: item.id,
|
|
|
|
|
+ name: item.name,
|
|
|
value: item.value,
|
|
value: item.value,
|
|
|
itemStyle: getBarItemStyle(item.name, isDrilldown)
|
|
itemStyle: getBarItemStyle(item.name, isDrilldown)
|
|
|
})),
|
|
})),
|
|
@@ -490,8 +515,8 @@ async function getStatic() {
|
|
|
// 日期
|
|
// 日期
|
|
|
observationDate: queryParams.observationDate
|
|
observationDate: queryParams.observationDate
|
|
|
})
|
|
})
|
|
|
- child.value = res.child
|
|
|
|
|
- totalData.value = res.total
|
|
|
|
|
|
|
+ totalData.value = res.total || res || []
|
|
|
|
|
+ childData.value = []
|
|
|
staticLoading.value = false
|
|
staticLoading.value = false
|
|
|
} else {
|
|
} else {
|
|
|
staticLoading.value = true
|
|
staticLoading.value = true
|
|
@@ -501,22 +526,39 @@ async function getStatic() {
|
|
|
// 日期
|
|
// 日期
|
|
|
observationDate: queryParams.observationDate
|
|
observationDate: queryParams.observationDate
|
|
|
})
|
|
})
|
|
|
- child.value = res.child
|
|
|
|
|
- totalData.value = res.total
|
|
|
|
|
|
|
+ totalData.value = res.total || res || []
|
|
|
|
|
+ childData.value = []
|
|
|
staticLoading.value = false
|
|
staticLoading.value = false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const handleChartClick = (params: any) => {
|
|
|
|
|
|
|
+const handleChartClick = async (params: any) => {
|
|
|
const name = params?.name
|
|
const name = params?.name
|
|
|
if (!name || currentDrilldownKey.value) return
|
|
if (!name || currentDrilldownKey.value) return
|
|
|
- if (DRILLDOWN_KEYS.some((item) => item === name)) {
|
|
|
|
|
- currentDrilldownKey.value = name
|
|
|
|
|
|
|
+ const target = totalChartData.value.find((item) => item.name === name)
|
|
|
|
|
+ const socClass = params?.data?.id ?? target?.id
|
|
|
|
|
+ if (DRILLDOWN_KEYS.some((item) => item === name) && socClass !== undefined) {
|
|
|
|
|
+ staticLoading.value = true
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await IotSocSummaryApi.getSocSummaryStatisticsChild({
|
|
|
|
|
+ deptId: queryParams.deptId || userStore.user.deptId,
|
|
|
|
|
+ observationDate: queryParams.observationDate,
|
|
|
|
|
+ socClass
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ currentDrilldownKey.value = name
|
|
|
|
|
+ currentDrilldownId.value = socClass
|
|
|
|
|
+ childData.value = res?.total || res?.list || res || []
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ staticLoading.value = false
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const resetDrilldown = () => {
|
|
const resetDrilldown = () => {
|
|
|
currentDrilldownKey.value = ''
|
|
currentDrilldownKey.value = ''
|
|
|
|
|
+ currentDrilldownId.value = undefined
|
|
|
|
|
+ childData.value = []
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** 初始化 **/
|
|
/** 初始化 **/
|