|
@@ -23,25 +23,6 @@ const props = defineProps<TemporalTrendProps>()
|
|
|
const activeTab = ref<string>('') // 激活的Tab
|
|
|
const iconSize = ref(20) // 图标的尺寸
|
|
|
|
|
|
-// 图表上放统计数据字段信息
|
|
|
-const compareFieldInfo = reactive<Array<StaticField>>([
|
|
|
- {
|
|
|
- name: 'yesterdayCount',
|
|
|
- cnName: '昨日总数',
|
|
|
- value: ''
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'todayCount',
|
|
|
- cnName: '今日总数',
|
|
|
- value: ''
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'yesterdayThisTimeCount',
|
|
|
- cnName: '昨日此时',
|
|
|
- value: ''
|
|
|
- }
|
|
|
-])
|
|
|
-
|
|
|
// 表格数据
|
|
|
const tableDataList = reactive<Array<any>>([])
|
|
|
|
|
@@ -55,11 +36,11 @@ const paginationConfig = reactive<TablePaginationSetting>({
|
|
|
hasLodingData: 0 // 已经加载的数据
|
|
|
})
|
|
|
|
|
|
-// 表格字段信息
|
|
|
+// 数据统计字段信息
|
|
|
const filedsInfo = reactive<Array<TableFieldInfo>>([])
|
|
|
|
|
|
// 图表的展示形式,曲线图或者是表格
|
|
|
-const selectShape = ref('trend')
|
|
|
+const selectShape = ref(1)
|
|
|
|
|
|
// 图表的信息,包括图例,数据,以及x轴的刻度label
|
|
|
const chartInfo = reactive<OptionsProps>({
|
|
@@ -73,12 +54,12 @@ const chartInfo = reactive<OptionsProps>({
|
|
|
* @param {*} name 图表的展现形式,可以使table或者trend
|
|
|
* @return {*}
|
|
|
*/
|
|
|
-const changeSelectShape = (name: string) => {
|
|
|
+const changeSelectShape = (name: number) => {
|
|
|
selectShape.value = name
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @description: 获取数据
|
|
|
+ * @description: 获取数据,填充表格和趋势图,对于分小时统计和按日期统计的数据,给出不同的处理方式
|
|
|
* @param {*} url 请求地址
|
|
|
* @param {*} props 传入的配置参数
|
|
|
* @return {*}
|
|
@@ -89,89 +70,100 @@ const getData = async (type: number) => {
|
|
|
.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) {
|
|
|
+ if (props.staticFields && props.tabInfo) {
|
|
|
+ props.staticFields.forEach((item, index, array) => {
|
|
|
+ array[index].value = data[item.name]
|
|
|
+ })
|
|
|
filedsInfo.splice(0, filedsInfo.length)
|
|
|
+ }
|
|
|
|
|
|
- let timesList = Object.keys(data.today)
|
|
|
- let todayList = data.today
|
|
|
- let yesterdayList = data.yesterday
|
|
|
+ // 总览数据赋值
|
|
|
+ // 根据返回数据的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 matchItem = props.tabInfo.find((item) => item.name === activeTab.value)
|
|
|
+ let timesList = Object.keys(data.today)
|
|
|
+ let todayList = data.today
|
|
|
+ let yesterdayList = data.yesterday
|
|
|
|
|
|
- let todayName = `today${matchItem?.name as string}`
|
|
|
- let yesterDayName = `yesterday${matchItem?.name as string}`
|
|
|
+ let matchItem = props.tabInfo.find((item) => item.name === activeTab.value)
|
|
|
|
|
|
- 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
|
|
|
- })
|
|
|
+ let todayName = `today${matchItem?.name as string}`
|
|
|
+ let yesterDayName = `yesterday${matchItem?.name as string}`
|
|
|
|
|
|
- timesList.map((item, index) => {
|
|
|
- newList.push({
|
|
|
- date: item,
|
|
|
- [todayName]: todayList[item],
|
|
|
- [yesterDayName]: yesterdayList[item]
|
|
|
+ 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
|
|
|
})
|
|
|
- })
|
|
|
-
|
|
|
- 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
|
|
|
- })
|
|
|
+ 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
|
|
|
+ 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)
|
|
|
}
|
|
|
- tableDataList.splice(0, tableDataList.length, ...newList)
|
|
|
- paginationConfig.total = Object.entries(timeDistribution).length
|
|
|
+ } else {
|
|
|
+ //
|
|
|
}
|
|
|
-
|
|
|
- console.log(newList)
|
|
|
})
|
|
|
})
|
|
|
}
|
|
@@ -182,14 +174,21 @@ const getData = async (type: number) => {
|
|
|
* @return {*}
|
|
|
*/
|
|
|
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')
|
|
|
+ if (props.tabInfo) {
|
|
|
+ let type = props.tabInfo.find((item) => item.name === tabName)?.type
|
|
|
+ if (type) getData(type)
|
|
|
+ else throw new Error('No match type')
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+watchEffect(() => getData(1))
|
|
|
+
|
|
|
onMounted(() => {
|
|
|
getData(1)
|
|
|
- activeTab.value = props.defaultActive
|
|
|
+ changeSelectShape(props.selectExpressForm)
|
|
|
+ if (props.defaultActive) {
|
|
|
+ activeTab.value = props.defaultActive
|
|
|
+ }
|
|
|
})
|
|
|
</script>
|
|
|
|
|
@@ -207,18 +206,22 @@ onMounted(() => {
|
|
|
-->
|
|
|
<div class="chartsBox">
|
|
|
<el-tabs class="tabsBox" v-model="activeTab" @tab-change="tabChange">
|
|
|
- <el-tab-pane
|
|
|
- :lazy="true"
|
|
|
- v-for="item in tabInfo"
|
|
|
- :label="item.tabTitle"
|
|
|
- :name="item.name"
|
|
|
- :key="item.name"
|
|
|
- >
|
|
|
- </el-tab-pane>
|
|
|
- <div class="chartContent" v-if="selectShape === 'trend'">
|
|
|
+ <span v-if="needTab">
|
|
|
+ <el-tab-pane
|
|
|
+ :lazy="true"
|
|
|
+ v-for="item in tabInfo"
|
|
|
+ :label="item.tabTitle"
|
|
|
+ :name="item.name"
|
|
|
+ :key="item.name"
|
|
|
+ >
|
|
|
+ </el-tab-pane>
|
|
|
+ </span>
|
|
|
+
|
|
|
+ <div class="chartContent" v-if="selectShape === 1">
|
|
|
<div class="yesterDayDataBox">
|
|
|
<StatisticText
|
|
|
- :fields-info="compareFieldInfo"
|
|
|
+ v-if="staticFields"
|
|
|
+ :fields-info="staticFields"
|
|
|
:value-class="'chartStaticValue'"
|
|
|
></StatisticText>
|
|
|
</div>
|
|
@@ -244,15 +247,17 @@ onMounted(() => {
|
|
|
</div>
|
|
|
</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 class="expressiveForm" v-if="needChangeExpress">
|
|
|
+ <span class="toolItem" @click="changeSelectShape(1)">
|
|
|
+ <el-icon :size="iconSize" :color="selectShape === 1 ? 'blue' : 'gray'"
|
|
|
+ ><TrendCharts
|
|
|
+ /></el-icon>
|
|
|
+ </span>
|
|
|
+ <span class="toolItem" @click="changeSelectShape(2)" style="margin-right: 10px">
|
|
|
+ <el-icon :size="iconSize" :color="selectShape === 2 ? 'blue' : 'gray'"
|
|
|
+ ><Grid
|
|
|
+ /></el-icon>
|
|
|
+ </span>
|
|
|
</span>
|
|
|
<span class="toolItem">
|
|
|
<el-icon :size="iconSize"><Download /></el-icon>
|