|
@@ -7,18 +7,15 @@
|
|
|
-->
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { onMounted, reactive, ref, watch, watchEffect } from 'vue'
|
|
|
-import { type StaticField, type TemporalTrendProps, type OptionsProps } from '@/types/dataAnalysis'
|
|
|
+import { onMounted, reactive, ref, watch } from 'vue'
|
|
|
+import { type TemporalTrendProps, type OptionsProps } from '@/types/dataAnalysis'
|
|
|
import type { TablePaginationSetting, TableFieldInfo } from '@/types/table'
|
|
|
import Table from '../Table.vue'
|
|
|
import TimeLineChart from '../echarts/TimeLineChart.vue'
|
|
|
import StatisticText from './StatisticText.vue'
|
|
|
-import { useRequest } from '@/hooks/useRequest'
|
|
|
+
|
|
|
import axiosInstance from '@/utils/axios/axiosInstance'
|
|
|
-import { useAnalysis } from '@/hooks/useAnalysis'
|
|
|
|
|
|
-const { updateReqConfig } = useAnalysis()
|
|
|
-const { AllApi, analysisResCode } = useRequest()
|
|
|
const props = defineProps<TemporalTrendProps>()
|
|
|
const activeTab = ref<string>('') // 激活的Tab
|
|
|
const iconSize = ref(20) // 图标的尺寸
|
|
@@ -36,8 +33,8 @@ const paginationConfig = reactive<TablePaginationSetting>({
|
|
|
hasLodingData: 0 // 已经加载的数据
|
|
|
})
|
|
|
|
|
|
-// 数据统计字段信息
|
|
|
-const filedsInfo = reactive<Array<TableFieldInfo>>([])
|
|
|
+// 表格字段信息
|
|
|
+const tableFieldsInfo = reactive<Array<TableFieldInfo>>([])
|
|
|
|
|
|
// 图表的展示形式,曲线图或者是表格
|
|
|
const selectShape = ref(1)
|
|
@@ -59,112 +56,102 @@ const changeSelectShape = (name: number) => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @description: 获取数据,填充表格和趋势图,对于分小时统计和按日期统计的数据,给出不同的处理方式
|
|
|
- * @param {*} url 请求地址
|
|
|
- * @param {*} props 传入的配置参数
|
|
|
+ * @description: 生成表格字段信息,必须要调用,因为legend的字段也依赖这里
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+const createTableField = () => {
|
|
|
+ // 生成表格的字段信息
|
|
|
+ tableFieldsInfo.splice(0, tableFieldsInfo.length)
|
|
|
+
|
|
|
+ for (const [key, value] of Object.entries(props.tableFieldsInfo)) {
|
|
|
+ // 根据传入的信息,生成table需要的字段信息
|
|
|
+ tableFieldsInfo.push({
|
|
|
+ name: key,
|
|
|
+ cnName: value as string,
|
|
|
+ isShow: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 生成表格需要的信息,包括表格的字段信息及表格数据
|
|
|
+ * @param {*} data 返回的data数据
|
|
|
+ * @return {*} 返回生成x轴信息和所有的数据
|
|
|
+ */
|
|
|
+const createTableData = (data: any) => {
|
|
|
+ // 图表的x轴信息
|
|
|
+ const xInfo = Object.keys(data[props.resDataFieldsInfo['xAxis']])
|
|
|
+ const valInfo: any = {}
|
|
|
+ // 把所有的表格需要的数据假如valInfo,其中index字段需要单独拿出来用x轴的信息填充
|
|
|
+ props.resDataFieldsInfo['values'].map((key: string) => {
|
|
|
+ valInfo[key] = Object.values(data[key])
|
|
|
+ })
|
|
|
+ valInfo['index'] = xInfo
|
|
|
+ // 生成表格数据
|
|
|
+ let newList = reactive<Array<any>>([])
|
|
|
+
|
|
|
+ // 以x轴字段的数据作为循环条件
|
|
|
+ // 拿到所有的字段name
|
|
|
+ let fieldList = tableFieldsInfo.map((field) => field.name)
|
|
|
+
|
|
|
+ // 生成每一行的数据
|
|
|
+ xInfo.map(() => {
|
|
|
+ let newItem: any = {}
|
|
|
+ fieldList.map((item, index) => {
|
|
|
+ newItem[item] = valInfo[item][index]
|
|
|
+ })
|
|
|
+ newList.push(newItem)
|
|
|
+ })
|
|
|
+
|
|
|
+ tableDataList.splice(0, tableDataList.length, ...newList)
|
|
|
+ paginationConfig.total = xInfo.length
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 生成图表的信息
|
|
|
+ * @param {*} data 返回的数据
|
|
|
* @return {*}
|
|
|
*/
|
|
|
+const createOptions = (data: any) => {
|
|
|
+ const valInfo: any = {}
|
|
|
+ const xInfo = Object.keys(data[props.resDataFieldsInfo['xAxis']])
|
|
|
+ // 把所有的表格需要的数据假如valInfo,其中index字段需要单独拿出来用x轴的信息填充
|
|
|
+ props.resDataFieldsInfo['values'].map((key: string) => {
|
|
|
+ valInfo[key] = Object.values(data[key])
|
|
|
+ })
|
|
|
+
|
|
|
+ chartInfo.xAxisData = xInfo
|
|
|
+
|
|
|
+ chartInfo.legendData = tableFieldsInfo
|
|
|
+ .filter((item) => item.name !== 'index')
|
|
|
+ .map((val) => val.cnName)
|
|
|
+
|
|
|
+ chartInfo.seriesData = Object.values(valInfo)
|
|
|
+}
|
|
|
+
|
|
|
const getData = async (type: number) => {
|
|
|
axiosInstance
|
|
|
.post(props.requestConfig.url, { ...props.requestConfig.otherOptions, type })
|
|
|
- .then((data) => {
|
|
|
- analysisResCode(data).then((info) => {
|
|
|
- let data = info.data
|
|
|
- // 表格赋值
|
|
|
- let newList = reactive<Array<any>>([])
|
|
|
- if (props.staticFields && props.tabInfo) {
|
|
|
- props.staticFields.forEach((item, index, array) => {
|
|
|
- array[index].value = data[item.name]
|
|
|
- })
|
|
|
- filedsInfo.splice(0, filedsInfo.length)
|
|
|
- }
|
|
|
-
|
|
|
- // 总览数据赋值
|
|
|
- // 根据返回数据的key给对应的字段赋值
|
|
|
- if (props.staticFields && props.tabInfo) {
|
|
|
- props.staticFields.forEach((item, index, array) => {
|
|
|
- array[index].value = data[item.name]
|
|
|
- })
|
|
|
- if (props.type === 1) {
|
|
|
- filedsInfo.splice(0, filedsInfo.length)
|
|
|
-
|
|
|
- let timesList = Object.keys(data.today)
|
|
|
- let todayList = data.today
|
|
|
- let yesterdayList = data.yesterday
|
|
|
-
|
|
|
- let matchItem = props.tabInfo.find((item) => item.name === activeTab.value)
|
|
|
-
|
|
|
- let todayName = `today${matchItem?.name as string}`
|
|
|
- let yesterDayName = `yesterday${matchItem?.name as string}`
|
|
|
-
|
|
|
- filedsInfo.push({
|
|
|
- name: 'date',
|
|
|
- cnName: `时间段`,
|
|
|
- isShow: true
|
|
|
- })
|
|
|
- filedsInfo.push({
|
|
|
- name: todayName,
|
|
|
- cnName: `今日${(matchItem?.tabTitle as string).slice(0, 2)}`,
|
|
|
- isShow: true
|
|
|
- })
|
|
|
- filedsInfo.push({
|
|
|
- name: yesterDayName,
|
|
|
- cnName: `昨日${(matchItem?.tabTitle as string).slice(0, 2)}`,
|
|
|
- isShow: true
|
|
|
- })
|
|
|
-
|
|
|
- timesList.map((item, index) => {
|
|
|
- newList.push({
|
|
|
- date: item,
|
|
|
- [todayName]: todayList[item],
|
|
|
- [yesterDayName]: yesterdayList[item]
|
|
|
- })
|
|
|
- })
|
|
|
- tableDataList.splice(0, tableDataList.length, ...newList)
|
|
|
-
|
|
|
- paginationConfig.total = timesList.length
|
|
|
-
|
|
|
- chartInfo.legendData = [
|
|
|
- `今日${matchItem?.tabTitle.slice(0, 2) as string}`,
|
|
|
- `昨日${matchItem?.tabTitle.slice(0, 2) as string}`
|
|
|
- ]
|
|
|
- chartInfo.seriesData = [Object.values(todayList), Object.values(yesterdayList)]
|
|
|
- chartInfo.xAxisData = timesList
|
|
|
- } else {
|
|
|
- filedsInfo.splice(0, filedsInfo.length)
|
|
|
-
|
|
|
- let matchItem = props.tabInfo.find((item) => item.name === activeTab.value)
|
|
|
- let timeDistribution = data.timeDistribution
|
|
|
- let matchName = matchItem?.name as string
|
|
|
-
|
|
|
- filedsInfo.push({
|
|
|
- name: 'date',
|
|
|
- cnName: `日期`,
|
|
|
- isShow: true
|
|
|
- })
|
|
|
-
|
|
|
- filedsInfo.push({
|
|
|
- name: matchName,
|
|
|
- cnName: matchItem?.tabTitle as string,
|
|
|
- isShow: true
|
|
|
- })
|
|
|
- for (const [k, v] of Object.entries(timeDistribution)) {
|
|
|
- newList.push({
|
|
|
- date: k,
|
|
|
- [matchName]: v
|
|
|
- })
|
|
|
- }
|
|
|
- tableDataList.splice(0, tableDataList.length, ...newList)
|
|
|
- paginationConfig.total = Object.entries(timeDistribution).length
|
|
|
-
|
|
|
- chartInfo.legendData = [matchItem?.tabTitle]
|
|
|
- chartInfo.seriesData = [Object.values(timeDistribution)]
|
|
|
- chartInfo.xAxisData = Object.keys(timeDistribution)
|
|
|
- }
|
|
|
- } else {
|
|
|
- //
|
|
|
- }
|
|
|
- })
|
|
|
+ .then((info) => {
|
|
|
+ let data = info.data
|
|
|
+ // 生成表格字段
|
|
|
+ createTableField()
|
|
|
+ // 生成表格数据
|
|
|
+ if (props.needTable) {
|
|
|
+ createTableData(info.data)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果有统计数据的配置,则生成
|
|
|
+ if (props.staticFields) {
|
|
|
+ props.staticFields.forEach((item, index, array) => {
|
|
|
+ array[index].value = data[item.name]
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // options配置赋值
|
|
|
+ if (props.needCharts) {
|
|
|
+ createOptions(info.data)
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -181,14 +168,24 @@ const tabChange = (tabName: string) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-watchEffect(() => getData(1))
|
|
|
+/**
|
|
|
+ * @description: 监听请求参数的变化,有变化了之后重新请求数据,并且把tab置为第一个
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+watch(
|
|
|
+ () => [props.requestConfig.otherOptions],
|
|
|
+ () => {
|
|
|
+ if (props.tabInfo) activeTab.value = props.tabInfo[0].name
|
|
|
+ getData(1)
|
|
|
+ },
|
|
|
+ {
|
|
|
+ deep: true
|
|
|
+ }
|
|
|
+)
|
|
|
|
|
|
onMounted(() => {
|
|
|
getData(1)
|
|
|
- changeSelectShape(props.selectExpressForm)
|
|
|
- if (props.defaultActive) {
|
|
|
- activeTab.value = props.defaultActive
|
|
|
- }
|
|
|
+ if (props.tabInfo) activeTab.value = props.tabInfo[0].name
|
|
|
})
|
|
|
</script>
|
|
|
|
|
@@ -206,7 +203,7 @@ onMounted(() => {
|
|
|
-->
|
|
|
<div class="chartsBox">
|
|
|
<el-tabs class="tabsBox" v-model="activeTab" @tab-change="tabChange">
|
|
|
- <span v-if="needTab">
|
|
|
+ <span v-if="tabInfo">
|
|
|
<el-tab-pane
|
|
|
:lazy="true"
|
|
|
v-for="item in tabInfo"
|
|
@@ -226,6 +223,7 @@ onMounted(() => {
|
|
|
></StatisticText>
|
|
|
</div>
|
|
|
<TimeLineChart
|
|
|
+ v-if="props.needCharts"
|
|
|
:legend-data="chartInfo.legendData"
|
|
|
:series-data="chartInfo.seriesData"
|
|
|
:x-axis-data="chartInfo.xAxisData"
|
|
@@ -234,12 +232,13 @@ onMounted(() => {
|
|
|
</div>
|
|
|
<div class="tableContent" v-else>
|
|
|
<Table
|
|
|
+ v-if="props.needTable"
|
|
|
:data-list="tableDataList"
|
|
|
:need-rowindex="true"
|
|
|
:need-average="false"
|
|
|
:need-right-tools="false"
|
|
|
:pagination-config="paginationConfig"
|
|
|
- :table-fields-info="filedsInfo"
|
|
|
+ :table-fields-info="tableFieldsInfo"
|
|
|
:need-left-tools="false"
|
|
|
:open-filter-query="false"
|
|
|
:open-page-query="false"
|