|
@@ -7,34 +7,37 @@
|
|
|
-->
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { onMounted, reactive, ref } from 'vue'
|
|
|
+import { onMounted, reactive, ref, watchEffect } from 'vue'
|
|
|
import {
|
|
|
StaticDataType,
|
|
|
type StaticDataItemInfo,
|
|
|
- type TemporalTrendProps
|
|
|
+ type TemporalTrendProps,
|
|
|
+ type StaticReqConfig
|
|
|
} 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'
|
|
|
|
|
|
+const { AllApi, analysisResCode } = useRequest()
|
|
|
const props = defineProps<TemporalTrendProps>()
|
|
|
-const activeTab = ref()
|
|
|
+const activeTab = ref() // 激活的Tab
|
|
|
+const iconSize = ref(20) // 图标的尺寸
|
|
|
|
|
|
const yesterdayData = reactive<Array<StaticDataItemInfo>>([
|
|
|
{
|
|
|
dataTitle: '昨日',
|
|
|
value: 16,
|
|
|
dataType: StaticDataType.NUM,
|
|
|
- compareInfo: {
|
|
|
- compareVal: 30
|
|
|
- }
|
|
|
+ compareVal: 30
|
|
|
},
|
|
|
{
|
|
|
dataTitle: '昨日此时',
|
|
|
value: 16,
|
|
|
dataType: StaticDataType.NUM,
|
|
|
- compareInfo: {
|
|
|
- compareVal: 10
|
|
|
- }
|
|
|
+ compareVal: 10
|
|
|
},
|
|
|
{
|
|
|
dataTitle: '今日',
|
|
@@ -43,6 +46,80 @@ const yesterdayData = reactive<Array<StaticDataItemInfo>>([
|
|
|
}
|
|
|
])
|
|
|
|
|
|
+// 配置总览数据的请求参数
|
|
|
+const compareDataReqConfig = reactive<StaticReqConfig>({
|
|
|
+ url: '',
|
|
|
+ otherOptions: ''
|
|
|
+})
|
|
|
+
|
|
|
+// 配置请求参数
|
|
|
+const tableRequestConfig = reactive({
|
|
|
+ url: AllApi.mock,
|
|
|
+ other: {
|
|
|
+ appSecret: '6YJSuc50uJ18zj45'
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+// 配置分页数据
|
|
|
+const paginationConfig = reactive<TablePaginationSetting>({
|
|
|
+ limit: 6, // 每页展示个数
|
|
|
+ currentPage: 1, // 当前页码
|
|
|
+ total: 0, // 数据总数
|
|
|
+ pagesizeList: [6], // 页数大小列表
|
|
|
+ loading: true, // 加载图标
|
|
|
+ hasLodingData: 0 // 已经加载的数据
|
|
|
+})
|
|
|
+
|
|
|
+// 字段信息
|
|
|
+const filedsInfo = reactive<Array<TableFieldInfo>>([
|
|
|
+ {
|
|
|
+ name: 'date',
|
|
|
+ cnName: '日期',
|
|
|
+ isShow: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '新增设备',
|
|
|
+ cnName: 'newEquip',
|
|
|
+ isShow: true
|
|
|
+ }
|
|
|
+])
|
|
|
+
|
|
|
+// 选择的展示形式
|
|
|
+const selectShape = ref('trend')
|
|
|
+
|
|
|
+// 图表上方总览数据
|
|
|
+const overViewData = reactive<Array<StaticDataItemInfo>>([])
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 改变图表形式的时候
|
|
|
+ * @param {*} name 图表的展现形式,可以使table或者trend
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+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 {*} TabPaneName 对应的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')
|
|
|
+}
|
|
|
+
|
|
|
+// watchEffect(() => getData(props.requestConfig.url))
|
|
|
+
|
|
|
onMounted(() => {
|
|
|
activeTab.value = props.defaultActive
|
|
|
})
|
|
@@ -51,17 +128,17 @@ onMounted(() => {
|
|
|
<template>
|
|
|
<div class="trendBox">
|
|
|
<div class="boxHeader">
|
|
|
- <span class="title">数据趋势</span>
|
|
|
+ <span class="headerTitle">{{ title }}</span>
|
|
|
</div>
|
|
|
<el-divider />
|
|
|
- <div class="toolsBox">
|
|
|
- <el-tabs class="tabsBox" v-model="activeTab">
|
|
|
- <!-- 一定要加上lazy=true,因为在这时chart组件已经被渲染完成了,但是他此时是被隐藏的,无法获取宽高
|
|
|
+ <!-- 一定要加上lazy=true,因为在这时chart组件已经被渲染完成了,但是他此时是被隐藏的,无法获取宽高
|
|
|
所以让他延迟渲染,等到真正切换到这个标签时,再去渲染里面的内容
|
|
|
|
|
|
同时需要配合v-if去重新渲染这个组件,不然当窗口大小变化的时候,resize方法被调用,但是display为none,
|
|
|
导致切换过去尺寸又没了
|
|
|
-->
|
|
|
+ <div class="chartsBox">
|
|
|
+ <el-tabs class="tabsBox" v-model="activeTab" @tab-change="tabChange">
|
|
|
<el-tab-pane
|
|
|
class="tabItem"
|
|
|
:lazy="true"
|
|
@@ -70,17 +147,51 @@ onMounted(() => {
|
|
|
:name="item.tabTitle"
|
|
|
:key="item.tabTitle"
|
|
|
>
|
|
|
- <div class="yesterDayDataBox">
|
|
|
- <StatisticText
|
|
|
- :value-class="'chartStaticValue'"
|
|
|
- :data-list="yesterdayData"
|
|
|
- ></StatisticText>
|
|
|
+ <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>
|
|
|
- <TimeLineChart v-if="activeTab === item.tabTitle"></TimeLineChart>
|
|
|
</el-tab-pane>
|
|
|
</el-tabs>
|
|
|
+ <div class="toolsBox">
|
|
|
+ <span class="toolItem" @click="changeSelectShape('trend')">
|
|
|
+ <el-icon :size="iconSize" :color="selectShape === 'trend' ? 'blue' : 'gray'"
|
|
|
+ ><TrendCharts
|
|
|
+ /></el-icon>
|
|
|
+ </span>
|
|
|
+ <span class="toolItem" @click="changeSelectShape('table')" style="margin-right: 10px">
|
|
|
+ <el-icon :size="iconSize" :color="selectShape === 'table' ? 'blue' : 'gray'"
|
|
|
+ ><Grid
|
|
|
+ /></el-icon>
|
|
|
+ </span>
|
|
|
+ <span class="toolItem">
|
|
|
+ <el-icon :size="iconSize"><Download /></el-icon>
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- <div class="chartsBox"></div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -91,13 +202,17 @@ onMounted(() => {
|
|
|
/* background-color: lightblue; */
|
|
|
padding: 24px;
|
|
|
box-sizing: border-box;
|
|
|
- box-shadow:
|
|
|
- 0 4px 8px 0 rgba(0, 0, 0, 0.02),
|
|
|
- 0 1px 3px 0 rgba(0, 0, 0, 0.02);
|
|
|
+ background-color: white;
|
|
|
}
|
|
|
|
|
|
-.toolsBox {
|
|
|
+.headerTitle {
|
|
|
+ font-size: 14px;
|
|
|
+ color: #1c2438;
|
|
|
+ font-weight: 600;
|
|
|
+}
|
|
|
+.chartsBox {
|
|
|
width: 100%;
|
|
|
+ position: relative;
|
|
|
}
|
|
|
|
|
|
.tabItem {
|
|
@@ -111,4 +226,20 @@ onMounted(() => {
|
|
|
left: 24px;
|
|
|
top: 0;
|
|
|
}
|
|
|
+
|
|
|
+.chart {
|
|
|
+ top: 40px;
|
|
|
+}
|
|
|
+
|
|
|
+.toolsBox {
|
|
|
+ position: absolute;
|
|
|
+ right: 0;
|
|
|
+ top: 15px;
|
|
|
+ /* width: 100px; */
|
|
|
+}
|
|
|
+
|
|
|
+.toolItem {
|
|
|
+ padding-right: 10px;
|
|
|
+ cursor: pointer;
|
|
|
+}
|
|
|
</style>
|