|
@@ -1,37 +1,33 @@
|
|
<template>
|
|
<template>
|
|
- <MetricsCards v-model="metrics" :metric-items="metricsItems" @change="changeMetric"></MetricsCards>
|
|
|
|
- <div style="height: 350px;" ref="chartRef"></div>
|
|
|
|
|
|
+ <div v-loading="loading">
|
|
|
|
+ <MetricsCards v-model="metrics" :metric-items="metricsItems" @change="changeMetric"></MetricsCards>
|
|
|
|
+ <div style="height: 350px;" ref="chartRef"></div>
|
|
|
|
+</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
import { ref,onMounted, onBeforeUnmount, Ref, onBeforeMount, watch, computed } from 'vue'
|
|
import { ref,onMounted, onBeforeUnmount, Ref, onBeforeMount, watch, computed } from 'vue'
|
|
import * as echarts from 'echarts'
|
|
import * as echarts from 'echarts'
|
|
import { useShopInfo } from '/@/stores/shopInfo'
|
|
import { useShopInfo } from '/@/stores/shopInfo'
|
|
-import { getLineData, getCardData } from '../api'
|
|
|
|
import { spCampaignMetricsEnum } from '/@/views/adManage/utils/enum.js'
|
|
import { spCampaignMetricsEnum } from '/@/views/adManage/utils/enum.js'
|
|
import MetricsCards from '/@/components/MetricsCards/index.vue'
|
|
import MetricsCards from '/@/components/MetricsCards/index.vue'
|
|
import XEUtils from 'xe-utils'
|
|
import XEUtils from 'xe-utils'
|
|
import { buildChartOpt } from '/@/views/adManage/utils/tools.js'
|
|
import { buildChartOpt } from '/@/views/adManage/utils/tools.js'
|
|
|
|
+import { usePublicData } from '/@/stores/publicData'
|
|
|
|
+import { storeToRefs } from 'pinia'
|
|
|
|
|
|
defineOptions({
|
|
defineOptions({
|
|
name: "DataTendencyChart"
|
|
name: "DataTendencyChart"
|
|
})
|
|
})
|
|
|
|
|
|
-onBeforeMount(async () => {
|
|
|
|
- await getMetricsItems()
|
|
|
|
-})
|
|
|
|
-onMounted(() => {
|
|
|
|
- setTimeout(() => { initLine() }, 0)
|
|
|
|
- addResize()
|
|
|
|
-});
|
|
|
|
-onBeforeUnmount(() => {
|
|
|
|
- if(chartObj) {
|
|
|
|
- chartObj.dispose()
|
|
|
|
- chartObj = null
|
|
|
|
- }
|
|
|
|
- removeResize()
|
|
|
|
-})
|
|
|
|
|
|
+interface Props {
|
|
|
|
+ fetchCard: Function,
|
|
|
|
+ fetchLine: Function,
|
|
|
|
+ query?: {[key: string]: any}
|
|
|
|
+}
|
|
|
|
|
|
|
|
+const props = defineProps<Props>()
|
|
|
|
+const publicData = usePublicData()
|
|
const metrics = ref([
|
|
const metrics = ref([
|
|
{metric: 'Impression', color: '#0085ff', 'label': '曝光量'},
|
|
{metric: 'Impression', color: '#0085ff', 'label': '曝光量'},
|
|
{metric: 'Click', color: '#3fd4cf', 'label': '点击量'},
|
|
{metric: 'Click', color: '#3fd4cf', 'label': '点击量'},
|
|
@@ -177,33 +173,61 @@ const option: any = {
|
|
}
|
|
}
|
|
]
|
|
]
|
|
}
|
|
}
|
|
-const getDataset = async () => {
|
|
|
|
- const resp = await getLineData({profile: shopInfo.profile.profile_id, start: '2023-11-01', end: '2023-11-04'})
|
|
|
|
- return resp.data
|
|
|
|
-}
|
|
|
|
|
|
+const { dateRange } = storeToRefs(publicData)
|
|
|
|
+const loading = ref(true)
|
|
|
|
+const queryParams = computed(() => {
|
|
|
|
+ return {
|
|
|
|
+ profile: shopInfo.profile.profile_id,
|
|
|
|
+ start: dateRange.value[0],
|
|
|
|
+ end: dateRange.value[1],
|
|
|
|
+ ...props.query
|
|
|
|
+ }
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+onMounted(() => {
|
|
|
|
+ getMetricsItems()
|
|
|
|
+ addResize()
|
|
|
|
+ // initLine()
|
|
|
|
+ setTimeout(() => { initLine() }, 0)
|
|
|
|
+})
|
|
|
|
+onBeforeUnmount(() => {
|
|
|
|
+ if(chartObj) {
|
|
|
|
+ chartObj.dispose()
|
|
|
|
+ chartObj = null
|
|
|
|
+ }
|
|
|
|
+ removeResize()
|
|
|
|
+})
|
|
|
|
+
|
|
const initLine = async () => {
|
|
const initLine = async () => {
|
|
chartObj = echarts.init(chartRef.value)
|
|
chartObj = echarts.init(chartRef.value)
|
|
const items = await getDataset()
|
|
const items = await getDataset()
|
|
option.dataset.source = items
|
|
option.dataset.source = items
|
|
|
|
+ XEUtils.arrayEach(metricsItems.value, info => {
|
|
|
|
+ option.legend.selected[info.label] = false
|
|
|
|
+ })
|
|
for(const info of metrics.value) {
|
|
for(const info of metrics.value) {
|
|
option.legend.selected[info.label] = true
|
|
option.legend.selected[info.label] = true
|
|
}
|
|
}
|
|
chartObj.setOption(option)
|
|
chartObj.setOption(option)
|
|
|
|
+ loading.value = false
|
|
|
|
+}
|
|
|
|
+const getDataset = async () => {
|
|
|
|
+ const resp = await props.fetchLine(queryParams.value)
|
|
|
|
+ return resp.data
|
|
}
|
|
}
|
|
-
|
|
|
|
const getMetricsItems = async () => {
|
|
const getMetricsItems = async () => {
|
|
- const resp = await getCardData({start: '2023-11-01', end: '2023-11-04', profile: shopInfo.profile.profile_id})
|
|
|
|
|
|
+ const resp = await props.fetchCard(queryParams.value)
|
|
const data = resp.data
|
|
const data = resp.data
|
|
|
|
+ metricsItems.value.length = 0
|
|
XEUtils.arrayEach(spCampaignMetricsEnum, info => {
|
|
XEUtils.arrayEach(spCampaignMetricsEnum, info => {
|
|
const tmp:MetricData = {
|
|
const tmp:MetricData = {
|
|
label: info.label,
|
|
label: info.label,
|
|
value: info.value,
|
|
value: info.value,
|
|
metricVal: data[info.value],
|
|
metricVal: data[info.value],
|
|
gapVal: data[`gap${info.value}`],
|
|
gapVal: data[`gap${info.value}`],
|
|
- preVal: data[`prev${info.value}`]
|
|
|
|
|
|
+ preVal: data[`prev${info.value}`],
|
|
}
|
|
}
|
|
metricsItems.value.push(tmp)
|
|
metricsItems.value.push(tmp)
|
|
- option.legend.selected[info.label] = false
|
|
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
@@ -212,6 +236,18 @@ const changeMetric = () => {
|
|
chartObj.setOption(opt)
|
|
chartObj.setOption(opt)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+watch(
|
|
|
|
+ queryParams,
|
|
|
|
+ async () => {
|
|
|
|
+ loading.value = true
|
|
|
|
+ await getMetricsItems()
|
|
|
|
+ const items = await getDataset()
|
|
|
|
+ const opt = { dataset: { source: items } }
|
|
|
|
+ chartObj.setOption(opt)
|
|
|
|
+ loading.value = false
|
|
|
|
+ }
|
|
|
|
+)
|
|
|
|
+
|
|
const resizeChart = () => { chartObj.resize() }
|
|
const resizeChart = () => { chartObj.resize() }
|
|
const addResize = () => { window.addEventListener('resize', resizeChart) }
|
|
const addResize = () => { window.addEventListener('resize', resizeChart) }
|
|
const removeResize = () => { window.removeEventListener('resize', resizeChart) }
|
|
const removeResize = () => { window.removeEventListener('resize', resizeChart) }
|