Pārlūkot izejas kodu

feat: 监控、统计表格数据调整

chenhao 2 gadi atpakaļ
vecāks
revīzija
2ef9d1ddd1

+ 47 - 23
src/modules/analysis/monitoring/index.vue

@@ -17,11 +17,11 @@
             <div class="p-base card-title">{{ card.title }}</div>
             <div class="p-l-extra-base p-r-mini p-b-extra-small flex-1 overflow-hidden">
               <base-table
-                v-bind="tableProps"
+                v-bind="getTableProps(card.hasAll)"
                 size="small"
                 height="100%"
                 :columns="getColumns(card.valueLabel)"
-                :data="getData(sortableResult[card.dataField])"
+                :data="getData(sortableResult[card.dataField], card.hasAll)"
               >
                 <template #empty>
                   <empty :image-size="100"></empty>
@@ -158,6 +158,7 @@ interface Card {
   dataField: string
   title: string
   valueLabel: string
+  hasAll: boolean
 }
 
 const cards: Card[] = [
@@ -165,41 +166,49 @@ const cards: Card[] = [
     dataField: 'totalPaperList',
     title: '评卷份数',
     valueLabel: '份数',
+    hasAll: true,
   },
   {
     dataField: 'xyRelateList',
     title: '相关系数',
     valueLabel: '相关系数',
+    hasAll: true,
   },
   {
     dataField: 'avgList',
     title: '平均分',
     valueLabel: '平均分',
+    hasAll: true,
   },
   {
     dataField: 'stdList',
     title: '标准差',
     valueLabel: '标准差',
+    hasAll: true,
   },
   {
     dataField: 'scoreTopLowList',
     title: '近5分钟最高最低分',
     valueLabel: '分数',
+    hasAll: false,
   },
   {
     dataField: 'objSubRateList',
     title: '近5分钟客主比',
     valueLabel: '最高',
+    hasAll: false,
   },
   {
     dataField: 'objSubAvgRateList',
     title: '平均客主比',
     valueLabel: '平均最高',
+    hasAll: false,
   },
   {
     dataField: 'integrationList',
     title: '综合',
-    valueLabel: '标准差',
+    valueLabel: '综合指数',
+    hasAll: false,
   },
 ]
 
@@ -216,16 +225,20 @@ const viewMarkDetail = (row: ExtractArrayValue<ExtractRecordValue<ExtractApiResp
   })
 }
 
-const tableProps: EpTableProps = {
-  highlightCurrentRow: false,
-  rowClassName({ rowIndex }) {
-    if (rowIndex > 0 && rowIndex <= 3) {
-      return 'top-three-row'
-    } else if (rowIndex >= 4 && rowIndex <= 6) {
-      return 'last-three-row'
-    }
-    return ''
-  },
+const getTableProps: (hasAll: boolean) => EpTableProps = (hasAll) => {
+  return {
+    highlightCurrentRow: false,
+    rowClassName({ rowIndex }) {
+      const startIndex = hasAll ? 1 : 0
+      const splitIndex = hasAll ? 3 : 2
+      if (rowIndex >= startIndex && rowIndex <= splitIndex) {
+        return 'top-three-row'
+      } else if (rowIndex >= splitIndex + 1 && rowIndex <= splitIndex + 3) {
+        return 'last-three-row'
+      }
+      return ''
+    },
+  }
 }
 
 const getColumns = (
@@ -264,21 +277,32 @@ const interval = computed(() => fetchModel.refresh * 60 * 1000)
 
 const { fetch, result } = useFetch('getStatistics')
 
-const getData = (data: ExtractRecordValue<ExtractApiResponse<'getStatistics'>>) => {
-  return data?.slice(0, 4).concat(data?.slice(4).slice(-3)) || []
+const getData = (data: ExtractRecordValue<ExtractApiResponse<'getStatistics'>>, hasAll: boolean) => {
+  return data?.slice(0, hasAll ? 4 : 3).concat(data?.slice(hasAll ? 4 : 3).slice(-3)) || []
 }
 
 const sortableResult = computed<typeof result.value>(() => {
   if (!result.value) return {}
-  const sortable: typeof result.value = {}
-  for (let k in result.value) {
-    const arr = [...result.value[k]]
+  return cards.reduce((final, { dataField, hasAll }) => {
+    let resultData = result.value[dataField]?.filter((v) => hasAll || v.markerId) || []
+
+    if (dataField === 'scoreTopLowList') {
+      const scoreTopList = result.value?.['scoreTopList']?.filter((v) => hasAll || v.markerId) || []
+      const scoreLowList = result.value?.['scoreLowList']?.filter((v) => hasAll || v.markerId) || []
+      resultData = scoreTopList
+        .concat(scoreLowList)
+        ?.filter((d, i, arr) => d && i === arr.findIndex((v) => v.markerId === d.markerId))
+    }
+
+    const arr = [...resultData]
     const totalIndex = arr.findIndex((v) => v.markerId === 0)
-    const [total] = arr.splice(totalIndex, 1)
-    total && arr.unshift(total)
-    sortable[k] = arr
-  }
-  return sortable
+    if (totalIndex >= 0) {
+      const [total] = arr.splice(totalIndex, 1)
+      total && arr.unshift(total)
+    }
+    final[dataField] = arr
+    return final
+  }, {} as typeof result.value)
 })
 
 const onRefresh = () => {

+ 27 - 16
src/modules/analysis/statistics/index.vue

@@ -143,6 +143,7 @@ interface Card {
   dataField: string
   title: string
   valueLabel: string
+  hasAll: boolean
 }
 
 const cards: Card[] = [
@@ -150,41 +151,49 @@ const cards: Card[] = [
     dataField: 'totalPaperList',
     title: '评卷份数',
     valueLabel: '份数',
+    hasAll: true,
   },
   {
     dataField: 'xyRelateList',
     title: '相关系数',
     valueLabel: '相关系数',
+    hasAll: true,
   },
   {
     dataField: 'avgList',
     title: '平均分',
     valueLabel: '平均分',
+    hasAll: true,
   },
   {
     dataField: 'stdList',
     title: '标准差',
     valueLabel: '标准差',
+    hasAll: true,
   },
   {
     dataField: 'scoreTopLowList',
     title: '近5分钟最高最低分',
     valueLabel: '分数',
+    hasAll: false,
   },
   {
     dataField: 'objSubRateList',
     title: '近5分钟客主比',
     valueLabel: '最高',
+    hasAll: false,
   },
   {
     dataField: 'objSubAvgRateList',
     title: '平均客主比',
     valueLabel: '平均最高',
+    hasAll: false,
   },
   {
     dataField: 'integrationList',
     title: '综合',
-    valueLabel: '标准差',
+    valueLabel: '综合指数',
+    hasAll: false,
   },
 ]
 
@@ -225,15 +234,24 @@ const { fetch, result, loading } = useFetch('getStatistics')
 
 const sortableResult = computed<typeof result.value>(() => {
   if (!result.value) return {}
-  const sortable: typeof result.value = {}
-  for (let k in result.value) {
-    const arr = [...result.value[k]]
+  return cards.reduce((final, { dataField, hasAll }) => {
+    let resultData = result.value[dataField]?.filter((v) => hasAll || v.markerId) || []
+    if (dataField === 'scoreTopLowList') {
+      const scoreTopList = result.value?.['scoreTopList']?.filter((v) => hasAll || v.markerId) || []
+      const scoreLowList = result.value?.['scoreLowList']?.filter((v) => hasAll || v.markerId) || []
+      resultData = scoreTopList
+        .concat(scoreLowList)
+        ?.filter((d, i, arr) => d && i === arr.findIndex((v) => v.markerId === d.markerId))
+    }
+    const arr = [...resultData]
     const totalIndex = arr.findIndex((v) => v.markerId === 0)
-    const [total] = arr.splice(totalIndex, 1)
-    total && arr.unshift(total)
-    sortable[k] = arr
-  }
-  return sortable
+    if (totalIndex >= 0) {
+      const [total] = arr.splice(totalIndex, 1)
+      total && arr.unshift(total)
+    }
+    final[dataField] = arr
+    return final
+  }, {} as typeof result.value)
 })
 
 const onRefresh = () => {
@@ -241,13 +259,6 @@ const onRefresh = () => {
 }
 
 onOptionInit(onRefresh)
-
-const getData = (data?: ExtractRecordValue<typeof result.value>) => {
-  if (!data) return []
-  return Array.from({ length: 50 }).map((_, i) => {
-    return data[i % data.length]
-  })
-}
 </script>
 
 <style scoped lang="scss">