|
@@ -7,60 +7,45 @@
|
|
|
-->
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { onMounted, reactive, ref, watchEffect } from 'vue'
|
|
|
-import {
|
|
|
- StaticDataType,
|
|
|
- type StaticDataItemInfo,
|
|
|
- type TemporalTrendProps,
|
|
|
- type StaticReqConfig
|
|
|
-} from '@/types/dataAnalysis'
|
|
|
+import { onMounted, reactive, ref, watch, watchEffect } from 'vue'
|
|
|
+import { type StaticField, 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() // 激活的Tab
|
|
|
+const activeTab = ref<string>('') // 激活的Tab
|
|
|
const iconSize = ref(20) // 图标的尺寸
|
|
|
|
|
|
-const yesterdayData = reactive<Array<StaticDataItemInfo>>([
|
|
|
+// 图表上放统计数据字段信息
|
|
|
+const compareFieldInfo = reactive<Array<StaticField>>([
|
|
|
{
|
|
|
- dataTitle: '昨日',
|
|
|
- value: 16,
|
|
|
- dataType: StaticDataType.NUM,
|
|
|
- compareVal: 30
|
|
|
+ name: 'yesterdayCount',
|
|
|
+ cnName: '昨日总数',
|
|
|
+ value: ''
|
|
|
},
|
|
|
{
|
|
|
- dataTitle: '昨日此时',
|
|
|
- value: 16,
|
|
|
- dataType: StaticDataType.NUM,
|
|
|
- compareVal: 10
|
|
|
+ name: 'todayCount',
|
|
|
+ cnName: '今日总数',
|
|
|
+ value: ''
|
|
|
},
|
|
|
{
|
|
|
- dataTitle: '今日',
|
|
|
- value: 16,
|
|
|
- dataType: StaticDataType.NUM
|
|
|
+ name: 'yesterdayThisTimeCount',
|
|
|
+ cnName: '昨日此时',
|
|
|
+ value: ''
|
|
|
}
|
|
|
])
|
|
|
|
|
|
-// 配置总览数据的请求参数
|
|
|
-const compareDataReqConfig = reactive<StaticReqConfig>({
|
|
|
- url: '',
|
|
|
- otherOptions: ''
|
|
|
-})
|
|
|
-
|
|
|
-// 配置请求参数
|
|
|
-const tableRequestConfig = reactive({
|
|
|
- url: AllApi.mock,
|
|
|
- other: {
|
|
|
- appSecret: '6YJSuc50uJ18zj45'
|
|
|
- }
|
|
|
-})
|
|
|
+// 表格数据
|
|
|
+const tableDataList = reactive<Array<any>>([])
|
|
|
|
|
|
-// 配置分页数据
|
|
|
+// 配置表格分页数据
|
|
|
const paginationConfig = reactive<TablePaginationSetting>({
|
|
|
limit: 6, // 每页展示个数
|
|
|
currentPage: 1, // 当前页码
|
|
@@ -70,25 +55,18 @@ const paginationConfig = reactive<TablePaginationSetting>({
|
|
|
hasLodingData: 0 // 已经加载的数据
|
|
|
})
|
|
|
|
|
|
-// 字段信息
|
|
|
-const filedsInfo = reactive<Array<TableFieldInfo>>([
|
|
|
- {
|
|
|
- name: 'date',
|
|
|
- cnName: '日期',
|
|
|
- isShow: true
|
|
|
- },
|
|
|
- {
|
|
|
- name: '新增设备',
|
|
|
- cnName: 'newEquip',
|
|
|
- isShow: true
|
|
|
- }
|
|
|
-])
|
|
|
+// 表格字段信息
|
|
|
+const filedsInfo = reactive<Array<TableFieldInfo>>([])
|
|
|
|
|
|
-// 选择的展示形式
|
|
|
+// 图表的展示形式,曲线图或者是表格
|
|
|
const selectShape = ref('trend')
|
|
|
|
|
|
-// 图表上方总览数据
|
|
|
-const overViewData = reactive<Array<StaticDataItemInfo>>([])
|
|
|
+// 图表的信息,包括图例,数据,以及x轴的刻度label
|
|
|
+const chartInfo = reactive<OptionsProps>({
|
|
|
+ legendData: [],
|
|
|
+ xAxisData: [],
|
|
|
+ seriesData: []
|
|
|
+})
|
|
|
|
|
|
/**
|
|
|
* @description: 改变图表形式的时候
|
|
@@ -99,28 +77,118 @@ const changeSelectShape = (name: string) => {
|
|
|
selectShape.value = name
|
|
|
}
|
|
|
|
|
|
-const getData = async (url: string) => {
|
|
|
- axiosInstance.post(url, props.requestConfig).then((data) => {
|
|
|
- analysisResCode(data).then((info) => {
|
|
|
- console.log(info)
|
|
|
+/**
|
|
|
+ * @description: 获取数据
|
|
|
+ * @param {*} url 请求地址
|
|
|
+ * @param {*} props 传入的配置参数
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+const getData = async (type: number) => {
|
|
|
+ axiosInstance
|
|
|
+ .post(props.requestConfig.url, { ...props.requestConfig.otherOptions, type })
|
|
|
+ .then((data) => {
|
|
|
+ analysisResCode(data).then((info) => {
|
|
|
+ let data = info.data
|
|
|
+
|
|
|
+ // 总览数据赋值
|
|
|
+ // 根据返回数据的key给对应的字段赋值
|
|
|
+ compareFieldInfo.map((item) => {
|
|
|
+ item.value = data[item.name]
|
|
|
+ })
|
|
|
+
|
|
|
+ // 表格赋值
|
|
|
+ let newList = reactive<Array<any>>([])
|
|
|
+ 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 = [todayList, yesterdayList]
|
|
|
+ chartInfo.xAxisData = timesList
|
|
|
+ console.log(chartInfo)
|
|
|
+ } 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
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(newList)
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @description: 当标签页切换的时候,重新获取数据
|
|
|
- * @param {*} TabPaneName 对应的tabName,去tabinfo中找到对应的url
|
|
|
+ * @description: 当标签页切换的时候,重新获取数据,这里可能会改为修改配置,而不是修改url
|
|
|
+ * @param {*} tabName 对应的tabName,去tabinfo中找到对应的url
|
|
|
* @return {*}
|
|
|
*/
|
|
|
-const tabChange = (TabPaneName: string) => {
|
|
|
- let url = props.tabInfo.find((item) => item.tabTitle === TabPaneName)?.url
|
|
|
- if (url) getData(url)
|
|
|
- else throw new Error('No match url')
|
|
|
+const tabChange = (tabName: string) => {
|
|
|
+ let type = props.tabInfo.find((item) => item.name === tabName)?.type
|
|
|
+ if (type) getData(type)
|
|
|
+ else throw new Error('No match type')
|
|
|
}
|
|
|
|
|
|
-// watchEffect(() => getData(props.requestConfig.url))
|
|
|
-
|
|
|
onMounted(() => {
|
|
|
+ getData(1)
|
|
|
activeTab.value = props.defaultActive
|
|
|
})
|
|
|
</script>
|
|
@@ -140,41 +208,40 @@ onMounted(() => {
|
|
|
<div class="chartsBox">
|
|
|
<el-tabs class="tabsBox" v-model="activeTab" @tab-change="tabChange">
|
|
|
<el-tab-pane
|
|
|
- class="tabItem"
|
|
|
:lazy="true"
|
|
|
v-for="item in tabInfo"
|
|
|
:label="item.tabTitle"
|
|
|
- :name="item.tabTitle"
|
|
|
- :key="item.tabTitle"
|
|
|
+ :name="item.name"
|
|
|
+ :key="item.name"
|
|
|
>
|
|
|
- <div class="chartContent" v-if="selectShape === 'trend'">
|
|
|
- <div class="yesterDayDataBox">
|
|
|
- <StatisticText
|
|
|
- :request-config="compareDataReqConfig"
|
|
|
- :value-class="'chartStaticValue'"
|
|
|
- :data-list="yesterdayData"
|
|
|
- ></StatisticText>
|
|
|
- </div>
|
|
|
- <TimeLineChart
|
|
|
- :legend-data="chartInfo.legendData"
|
|
|
- :series-data="chartInfo.seriesData"
|
|
|
- :x-axis-data="chartInfo.xAxisData"
|
|
|
- class="chart"
|
|
|
- v-if="activeTab === item.tabTitle"
|
|
|
- ></TimeLineChart>
|
|
|
- </div>
|
|
|
- <div class="tableContent" v-else>
|
|
|
- <Table
|
|
|
- :need-right-tools="false"
|
|
|
- :pagination-config="paginationConfig"
|
|
|
- :table-fields-info="filedsInfo"
|
|
|
- :request-config="tableRequestConfig"
|
|
|
- :need-left-tools="false"
|
|
|
- :open-filter-query="false"
|
|
|
- :open-page-query="false"
|
|
|
- ></Table>
|
|
|
- </div>
|
|
|
</el-tab-pane>
|
|
|
+ <div class="chartContent" v-if="selectShape === 'trend'">
|
|
|
+ <div class="yesterDayDataBox">
|
|
|
+ <StatisticText
|
|
|
+ :fields-info="compareFieldInfo"
|
|
|
+ :value-class="'chartStaticValue'"
|
|
|
+ ></StatisticText>
|
|
|
+ </div>
|
|
|
+ <TimeLineChart
|
|
|
+ :legend-data="chartInfo.legendData"
|
|
|
+ :series-data="chartInfo.seriesData"
|
|
|
+ :x-axis-data="chartInfo.xAxisData"
|
|
|
+ class="chart"
|
|
|
+ ></TimeLineChart>
|
|
|
+ </div>
|
|
|
+ <div class="tableContent" v-else>
|
|
|
+ <Table
|
|
|
+ :data-list="tableDataList"
|
|
|
+ :need-rowindex="true"
|
|
|
+ :need-average="false"
|
|
|
+ :need-right-tools="false"
|
|
|
+ :pagination-config="paginationConfig"
|
|
|
+ :table-fields-info="filedsInfo"
|
|
|
+ :need-left-tools="false"
|
|
|
+ :open-filter-query="false"
|
|
|
+ :open-page-query="false"
|
|
|
+ ></Table>
|
|
|
+ </div>
|
|
|
</el-tabs>
|
|
|
<div class="toolsBox">
|
|
|
<span class="toolItem" @click="changeSelectShape('trend')">
|