|
@@ -23,16 +23,21 @@ defineOptions({
|
|
|
interface Props {
|
|
|
fetchCard: Function,
|
|
|
fetchLine: Function,
|
|
|
- query?: {[key: string]: any}
|
|
|
+ query?: {[key: string]: any},
|
|
|
+ initMetric?: ShowMetric[],
|
|
|
+ metricEnum?: {[key: string]: string}[]
|
|
|
}
|
|
|
|
|
|
-const props = defineProps<Props>()
|
|
|
+const props = withDefaults(defineProps<Props>(), {
|
|
|
+ initMetric: () => [
|
|
|
+ {metric: 'Impression', color: '#0085ff', 'label': '曝光量'},
|
|
|
+ {metric: 'Click', color: '#3fd4cf', 'label': '点击量'},
|
|
|
+ {metric: 'Spend', color: '#ff9500', 'label': '花费'},
|
|
|
+ ],
|
|
|
+ metricEnum: () => spCampaignMetricsEnum
|
|
|
+})
|
|
|
const publicData = usePublicData()
|
|
|
-const metrics = ref([
|
|
|
- {metric: 'Impression', color: '#0085ff', 'label': '曝光量'},
|
|
|
- {metric: 'Click', color: '#3fd4cf', 'label': '点击量'},
|
|
|
- {metric: 'Spend', color: '#ff9500', 'label': '花费'},
|
|
|
-])
|
|
|
+const metrics = ref(props.initMetric)
|
|
|
const shopInfo = useShopInfo()
|
|
|
const metricsItems: Ref<MetricData[]> = ref([])
|
|
|
let chartObj:any
|
|
@@ -63,22 +68,20 @@ const option: any = {
|
|
|
{
|
|
|
id: 0,
|
|
|
type: 'value',
|
|
|
- name: '曝光量',
|
|
|
+ name: '',
|
|
|
splitLine: {
|
|
|
show: true // 设置显示分割线
|
|
|
},
|
|
|
axisLine: {
|
|
|
show: true,
|
|
|
- lineStyle: {
|
|
|
- color: '#0085ff'
|
|
|
- }
|
|
|
+ lineStyle: { color: '' }
|
|
|
},
|
|
|
show: true
|
|
|
},
|
|
|
{
|
|
|
id: 1,
|
|
|
type: 'value',
|
|
|
- name: '点击量',
|
|
|
+ name: '',
|
|
|
position: 'right',
|
|
|
splitLine: {
|
|
|
show: false
|
|
@@ -86,7 +89,7 @@ const option: any = {
|
|
|
axisLine: {
|
|
|
show: true,
|
|
|
lineStyle: {
|
|
|
- color: '#3fd4cf'
|
|
|
+ color: ''
|
|
|
}
|
|
|
},
|
|
|
show: true
|
|
@@ -96,14 +99,14 @@ const option: any = {
|
|
|
type: 'value',
|
|
|
position: 'right',
|
|
|
offset: 90,
|
|
|
- name: '花费',
|
|
|
+ name: '',
|
|
|
splitLine: {
|
|
|
show: false
|
|
|
},
|
|
|
axisLine: {
|
|
|
show: true,
|
|
|
lineStyle: {
|
|
|
- color: '#ff9500'
|
|
|
+ color: ''
|
|
|
}
|
|
|
},
|
|
|
show: true
|
|
@@ -112,37 +115,40 @@ const option: any = {
|
|
|
series: [
|
|
|
{
|
|
|
id: 0,
|
|
|
- name: '曝光量',
|
|
|
+ name: '',
|
|
|
type: 'bar',
|
|
|
encode: {
|
|
|
x: 'date',
|
|
|
- y: 'Impression'
|
|
|
+ y: ''
|
|
|
},
|
|
|
barWidth: '20px',
|
|
|
yAxisIndex: 0,
|
|
|
itemStyle: {
|
|
|
- color: '#0085ff',
|
|
|
+ color: '',
|
|
|
borderRadius: [6, 6, 6, 6],
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
id: 1,
|
|
|
- name: '点击量',
|
|
|
+ name: '',
|
|
|
type: 'line',
|
|
|
encode: {
|
|
|
x: 'date',
|
|
|
- y: 'Click'
|
|
|
+ y: ''
|
|
|
},
|
|
|
symbolSize: 6,
|
|
|
symbol: 'circle',
|
|
|
smooth: true,
|
|
|
yAxisIndex: 1,
|
|
|
- itemStyle: { color: '#3fd4cf', borderColor: '#3fd4cf' },
|
|
|
+ itemStyle: {
|
|
|
+ // color: '#ff9500',
|
|
|
+ // borderColor: '#ff9500'
|
|
|
+ },
|
|
|
areaStyle: {
|
|
|
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
- { offset: 0, color: '#3fd4cf53' },
|
|
|
- { offset: 1, color: '#3fd4cf03' },
|
|
|
- ]),
|
|
|
+ // color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
+ // { offset: 0, color: '#3fd4cf53' },
|
|
|
+ // { offset: 1, color: '#3fd4cf03' },
|
|
|
+ // ]),
|
|
|
},
|
|
|
emphasis: {
|
|
|
focus:'series'
|
|
@@ -150,23 +156,18 @@ const option: any = {
|
|
|
},
|
|
|
{
|
|
|
id: 2,
|
|
|
- name: '花费',
|
|
|
+ name: '',
|
|
|
type: 'line',
|
|
|
encode: {
|
|
|
x: 'date',
|
|
|
- y: 'Spend'
|
|
|
+ y: ''
|
|
|
},
|
|
|
symbolSize: 6,
|
|
|
symbol: 'circle',
|
|
|
smooth: true,
|
|
|
yAxisIndex: 2,
|
|
|
- itemStyle: { color: '#ff9500', borderColor: '#ff9500' },
|
|
|
- areaStyle: {
|
|
|
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
- { offset: 0, color: '#ff950053' },
|
|
|
- { offset: 1, color: '#ff950003' },
|
|
|
- ]),
|
|
|
- },
|
|
|
+ itemStyle: {},
|
|
|
+ areaStyle: {},
|
|
|
emphasis: {
|
|
|
focus:'series'
|
|
|
}
|
|
@@ -202,12 +203,35 @@ const initLine = async () => {
|
|
|
chartObj = echarts.init(chartRef.value)
|
|
|
const items = await getDataset()
|
|
|
option.dataset.source = items
|
|
|
+
|
|
|
+ XEUtils.arrayEach(option.series, (info:any, index) => {
|
|
|
+ const color = metrics.value[index].color
|
|
|
+ info.name = metrics.value[index].label
|
|
|
+ info.encode.y = metrics.value[index].metric
|
|
|
+ if (info.type === 'bar') {
|
|
|
+ info.itemStyle.color = color
|
|
|
+ } else {
|
|
|
+ info.itemStyle = { color: color, borderColor: color }
|
|
|
+ info.areaStyle = {
|
|
|
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
+ { offset: 0, color: color + '53' },
|
|
|
+ { offset: 1, color: color + '03' },
|
|
|
+ ])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ XEUtils.arrayEach(option.yAxis, (info:any, index) => {
|
|
|
+ info.name = metrics.value[index].label
|
|
|
+ info.axisLine.lineStyle.color = metrics.value[index].color
|
|
|
+ })
|
|
|
+
|
|
|
XEUtils.arrayEach(metricsItems.value, info => {
|
|
|
option.legend.selected[info.label] = false
|
|
|
})
|
|
|
for(const info of metrics.value) {
|
|
|
option.legend.selected[info.label] = true
|
|
|
}
|
|
|
+ console.log(option)
|
|
|
chartObj.setOption(option)
|
|
|
loading.value = false
|
|
|
}
|
|
@@ -219,7 +243,7 @@ const getMetricsItems = async () => {
|
|
|
const resp = await props.fetchCard(queryParams.value)
|
|
|
const data = resp.data
|
|
|
metricsItems.value.length = 0
|
|
|
- XEUtils.arrayEach(spCampaignMetricsEnum, info => {
|
|
|
+ XEUtils.arrayEach(props.metricEnum, info => {
|
|
|
const tmp:MetricData = {
|
|
|
label: info.label,
|
|
|
value: info.value,
|