123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863 |
- <template>
- <div class="asj-container">
- <div class="container-main">
- <!-- 卡片内容 不要删除这个类 -->
- <div class="home-container" style="margin-top: 8px" v-loading="cardLoading">
- <el-row :gutter="15" class="home-card-one mb15">
- <el-col
- :xs="24"
- :sm="12"
- :md="12"
- :lg="6"
- :xl="6"
- v-for="(v, k) in state.homeOne"
- :key="k"
- :class="{ 'home-media home-media-lg': k > 1, 'home-media-sm': k === 1 }"
- >
- <div class="home-card-item flex">
- <div class="flex-margin flex w100" :class="` home-one-animation${k}`">
- <div class="flex-auto" style="margin-top: -10px">
- <div class="mt10">{{ v.cardTitle }}</div>
- <div class="font30">{{ v.num1 }}</div>
- <div style="display: inline-block; margin-right: 10px; margin-left: 3px;">
- {{ v.compareNum }}
- </div>
- <el-icon :style="{ color: String(v.num2).includes('-') ? '#59b939' : '#e36f53' }" style="display: inline-block; padding-top: 2px">
- <template v-if="String(v.num2).includes('-')">
- <Bottom/> <!-- num2 是负数时显示向下箭头 -->
- </template>
- <template v-else>
- <Top/> <!-- num2 不是负数时显示向上箭头 -->
- </template>
- </el-icon>
- <span class="ml5 font16" :style="{ color: String(v.num2).includes('-') ? '#59b939' : '#e36f53' }">{{ v.num2 }}%</span>
- </div>
- <div class="home-card-item-icon flex" :style="{ background: `var(${v.color2})` }">
- <i class="flex-margin font32" :class="v.num4" :style="{ color: `var(${v.color3})` }"></i>
- </div>
- </div>
- </div>
- </el-col>
- </el-row>
- </div>
- <!-- 折线图 -->
- <el-card v-loading="loading" style="margin-top: -5px;">
- <div style="height: 350px;" ref="chartRefOne"></div>
- </el-card>
- <el-row :gutter="5" style="margin-top: 10px">
- <el-col :span="12">
- <el-card v-loading="loading">
- <div style="height: 350px;" ref="chartRefAcos"></div>
- </el-card>
- </el-col>
- <el-col :span="12">
- <el-card v-loading="loading">
- <div style="height: 350px;" ref="chartRefCPCandCTR"></div>
- </el-card>
- </el-col>
- </el-row>
- <el-row :gutter="5" style="margin-top: 10px">
- <el-col :span="12">
- <el-card v-loading="loading">
- <div style="height: 350px;" ref="chartRefTotalPurchases"></div>
- </el-card>
- </el-col>
- <el-col :span="12">
- <el-card v-loading="loading">
- <div style="height: 350px;" ref="chartRefImpandCli"></div>
- </el-card>
- </el-col>
- </el-row>
- </div>
- <!--<el-button @click="changeCardData">按钮</el-button>-->
- </div>
- </template>
- <script lang="ts" setup>
- import {onMounted, reactive, ref, watch} from 'vue'
- import * as echarts from 'echarts'
- import {useShopInfo} from '/@/stores/shopInfo'
- import {usePublicData} from '/@/stores/publicData'
- import {storeToRefs} from 'pinia'
- import {createCrudOptions} from '/@/views/adManage/sp/targets/crud'
- import {useFs} from '@fast-crud/fast-crud'
- import {getCardTotalData, getChartTotalData} from '/src/views/adManage/ad-overview/total/api'
- const loading = ref(true)
- const cardLoading = ref(true)
- const publicData = usePublicData()
- const {dateRange} = storeToRefs(publicData)
- const shopInfo = useShopInfo()
- const { profile } = storeToRefs(shopInfo)
- const tabActiveName = ref('Campaigns')
- const queryParams = ref({
- profileId: profile.value.profile_id,
- dateRange
- })
- const {crudBinding, crudRef, crudExpose} = useFs({createCrudOptions, context: queryParams})
- // 发送请求获取数据
- async function setTotalData() {
- try {
- cardLoading.value = true
- const resp = await getCardTotalData({ startDate: dateRange.value[0], endDate: dateRange.value[1], profileId: queryParams.value.profileId })
- console.log('resp.data', resp.data)
- state.homeOne[0].num1 = resp.data.Spend
- state.homeOne[0].compareNum = resp.data.prevSpend
- state.homeOne[0].num2 = resp.data.gapSpend
- state.homeOne[1].num1 = resp.data.TotalSales
- state.homeOne[1].compareNum = resp.data.prevTotalSales
- state.homeOne[1].num2 = resp.data.gapTotalSales
- state.homeOne[2].num1 = resp.data.TotalPurchases
- state.homeOne[2].compareNum = resp.data.prevTotalPurchases
- state.homeOne[2].num2 = resp.data.gapTotalPurchases
- state.homeOne[3].num1 = resp.data.ACOS
- state.homeOne[3].compareNum = resp.data.prevACOS
- state.homeOne[3].num2 = resp.data.gapACOS
- } catch (error) {
- console.log('获取数据失败:', error)
- } finally {
- cardLoading.value = false
- }
- }
- let optionSource
- async function setChartTotalData() {
- try {
- loading.value = true
- const resp = await getChartTotalData({ startDate: dateRange.value[0], endDate: dateRange.value[1], profileId: queryParams.value.profileId })
- optionSource = resp.data
- await setChartOptions()
- return resp.data
- } catch (error) {
- console.log('获取数据失败:', error)
- } finally {
- loading.value = false
- }
- }
- onMounted(async () => {
- // crudExpose.doRefresh()
- await setTotalData()
- await setChartTotalData()
- })
- watch(queryParams, async() => {
- try {
- loading.value = true
- console.log('queryParams.value', queryParams.value)
- await setTotalData()
- await setChartTotalData()
- loading.value = false
- } catch (error) {
- console.log(error)
- }
- }, {deep: true})
- // 卡片相关功能
- const state = reactive({
- homeOne: [
- {
- num1: '',
- compareNum: '',
- num2: '',
- cardTitle: '花费',
- num4: 'fa fa-meetup',
- // color1: '#FF6462',
- color2: '--next-color-primary-lighter',
- color3: '--el-color-primary',
- },
- {
- num1: '',
- compareNum: '',
- num2: '',
- cardTitle: '销售额',
- num4: 'iconfont icon-ditu',
- color2: '--next-color-success-lighter',
- color3: '--el-color-success',
- },
- {
- num1: '',
- compareNum: '',
- num2: '',
- cardTitle: '订单数',
- num4: 'iconfont icon-zaosheng',
- color2: '--next-color-warning-lighter',
- color3: '--el-color-warning',
- },
- {
- num1: '',
- compareNum: '',
- num2: '',
- cardTitle: 'ACOS',
- num4: 'fa fa-github-alt',
- color2: '--next-color-danger-lighter',
- color3: '--el-color-danger',
- },
- ],
- myCharts: [],
- charts: {
- theme: '',
- bgColor: '',
- color: '#303133',
- },
- })
- // 折线图相关功能
- const chartRefOne = ref()
- let chartObjOne
- const option = {
- title: {text: '花费 & 销售额'},
- dataset: {
- source: []
- },
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- label: {
- backgroundColor: '#6a7985'
- }
- }
- },
- legend: {
- selected: {}, // 控制显隐
- data: ['花费', '销售额'],
- show: true
- },
- grid: {
- top: 50, right: 65, bottom: 30, left: 65,
- },
- xAxis: {
- type: 'category',
- // boundaryGap: false,
- },
- yAxis: [
- {
- type: 'value',
- axisLine: {
- show: true,
- lineStyle: {
- color: '#3a83f7' // 第一个 Y 轴的颜色
- }
- }
- },
- {
- type: 'value',
- splitLine: {
- show: false
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: '#f19a37' // 第二个 Y 轴的颜色
- }
- }
- }
- ],
- series: [
- {
- name: '花费',
- yAxisIndex: 0,
- encode: {
- x: 'Name',
- y: 'Spend',
- },
- type: 'line',
- smooth: true,
- itemStyle: {
- color: '#3a83f7',
- },
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: 'rgba(58, 131, 247, 0.5)' // 顶部不透明
- }, {
- offset: 0.2, color: 'rgba(58, 131, 247, 0.2)' // 中间更透明
- }, {
- offset: 1, color: 'rgba(58, 131, 247, 0)' // 底部完全透明
- }],
- global: false // 缺省为 false
- }
- }
- },
- {
- name: '销售额',
- yAxisIndex: 1,
- encode: {
- x: 'Name',
- y: 'TotalSales',
- },
- type: 'line',
- smooth: true,
- lineStyle: {
- type: 'dashed'
- },
- itemStyle: {
- color: '#f19a37',
- },
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: 'rgba(241, 154, 55, 0.5)' // 顶部半透明
- }, {
- offset: 0.2, color: 'rgba(241, 154, 55, 0.2)' // 中间更透明
- }, {
- offset: 1, color: 'rgba(241, 154, 55, 0)' // 底部完全透明
- }],
- global: false // 缺省为 false
- }
- }
- },
- ]
- }
- const chartRefAcos = ref()
- let chartObjAcos
- const option2 = {
- title: {text: 'Acos'},
- dataset: {
- source: []
- },
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- label: {
- backgroundColor: '#6a7985'
- }
- }
- },
- legend: {
- selected: {}, // 控制显隐
- data: ['Acos'],
- show: true
- },
- grid: {
- top: 50, right: 65, bottom: 30, left: 65,
- },
- xAxis: {
- type: 'category',
- // boundaryGap: false,
- },
- yAxis: [
- {
- type: 'value',
- axisLine: {
- show: true,
- lineStyle: {
- color: '#3a83f7'
- }
- }
- }
- ],
- series: [
- {
- name: 'Acos',
- yAxisIndex: 0,
- encode: {
- x: 'Name',
- y: 'Acos',
- },
- type: 'line',
- smooth: true,
- lineStyle: {
- type: 'dashed'
- },
- legendHoverLink: false,
- itemStyle: {
- color: '#3a83f7',
- },
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: 'rgba(58, 131, 247, 0.5)' // 顶部不透明
- }, {
- offset: 0.2, color: 'rgba(58, 131, 247, 0.2)' // 中间更透明
- }, {
- offset: 1, color: 'rgba(58, 131, 247, 0)' // 底部完全透明
- }],
- global: false // 缺省为 false
- }
- }
- },
- ]
- }
- const chartRefCPCandCTR = ref()
- let chartObjCPCandCTR
- const option3 = {
- title: {text: '点击成本 & 点击率'},
- dataset: {
- source: []
- },
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- label: {
- backgroundColor: '#6a7985'
- }
- }
- },
- legend: {
- selected: {}, // 控制显隐
- data: ['点击成本', '点击率'],
- show: true
- },
- grid: {
- top: 50, right: 65, bottom: 30, left: 65,
- },
- xAxis: {
- type: 'category',
- // boundaryGap: false,
- },
- yAxis: [
- {
- type: 'value',
- axisLine: {
- show: true,
- lineStyle: {
- color: '#3a83f7' // 第一个 Y 轴的颜色
- }
- }
- },
- {
- type: 'value',
- splitLine: {
- show: false
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: '#f19a37' // 第二个 Y 轴的颜色
- }
- }
- }
- ],
- series: [
- {
- name: '点击成本',
- yAxisIndex: 0,
- encode: {
- x: 'Name',
- y: 'CPC',
- },
- type: 'line',
- smooth: true,
- itemStyle: {
- color: '#3a83f7',
- },
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: 'rgba(58, 131, 247, 0.5)' // 顶部不透明
- }, {
- offset: 0.2, color: 'rgba(58, 131, 247, 0.2)' // 中间更透明
- }, {
- offset: 1, color: 'rgba(58, 131, 247, 0)' // 底部完全透明
- }],
- global: false // 缺省为 false
- }
- }
- },
- {
- name: '点击率',
- yAxisIndex: 1,
- encode: {
- x: 'Name',
- y: 'CTR',
- },
- type: 'line',
- smooth: true,
- itemStyle: {
- color: '#f19a37',
- },
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: 'rgba(241, 154, 55, 0.5)' // 顶部半透明
- }, {
- offset: 0.2, color: 'rgba(241, 154, 55, 0.2)' // 中间更透明
- }, {
- offset: 1, color: 'rgba(241, 154, 55, 0)' // 底部完全透明
- }],
- global: false // 缺省为 false
- }
- }
- },
- ]
- }
- const chartRefTotalPurchases = ref()
- let chartObjTotalPurchases
- const option4 = {
- title: {text: '订单数'},
- dataset: {
- source: []
- },
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- label: {
- backgroundColor: '#6a7985'
- }
- }
- },
- legend: {
- selected: {}, // 控制显隐
- data: ['订单数'],
- show: true
- },
- grid: {
- top: 50, right: 65, bottom: 30, left: 65,
- },
- xAxis: {
- type: 'category',
- // boundaryGap: false,
- },
- yAxis: [
- {
- type: 'value',
- axisLine: {
- show: true,
- lineStyle: {
- color: '#3a83f7'
- }
- }
- }
- ],
- series: [
- {
- name: '订单数',
- yAxisIndex: 0,
- encode: {
- x: 'Name',
- y: 'TotalPurchases',
- },
- type: 'line',
- smooth: true,
- lineStyle: {
- type: 'dashed'
- },
- legendHoverLink: false,
- itemStyle: {
- color: '#3a83f7',
- },
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: 'rgba(58, 131, 247, 0.5)' // 顶部不透明
- }, {
- offset: 0.2, color: 'rgba(58, 131, 247, 0.2)' // 中间更透明
- }, {
- offset: 1, color: 'rgba(58, 131, 247, 0)' // 底部完全透明
- }],
- global: false // 缺省为 false
- }
- }
- },
- ]
- }
- const chartRefImpandCli = ref()
- let chartObjImpandCli
- const option5 = {
- title: {text: '曝光量 & 点击量'},
- dataset: {
- source: []
- },
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- label: {
- backgroundColor: '#6a7985'
- }
- }
- },
- legend: {
- selected: {}, // 控制显隐
- data: ['曝光量', '点击量'],
- show: true
- },
- grid: {
- top: 50, right: 65, bottom: 30, left: 65,
- },
- xAxis: {
- type: 'category',
- // boundaryGap: false,
- },
- yAxis: [
- {
- type: 'value',
- axisLine: {
- show: true,
- lineStyle: {
- color: '#3a83f7' // 第一个 Y 轴的颜色
- }
- }
- },
- {
- type: 'value',
- splitLine: {
- show: false
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: '#f19a37' // 第二个 Y 轴的颜色
- }
- }
- }
- ],
- series: [
- {
- name: '曝光量',
- yAxisIndex: 0,
- encode: {
- x: 'Name',
- y: 'Impression',
- },
- type: 'line',
- smooth: true,
- itemStyle: {
- color: '#3a83f7',
- },
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: 'rgba(58, 131, 247, 0.5)' // 顶部不透明
- }, {
- offset: 0.2, color: 'rgba(58, 131, 247, 0.2)' // 中间更透明
- }, {
- offset: 1, color: 'rgba(58, 131, 247, 0)' // 底部完全透明
- }],
- global: false // 缺省为 false
- }
- }
- },
- {
- name: '点击量',
- yAxisIndex: 1,
- encode: {
- x: 'Name',
- y: 'Click',
- },
- type: 'line',
- smooth: true,
- itemStyle: {
- color: '#f19a37',
- },
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: 'rgba(241, 154, 55, 0.5)' // 顶部半透明
- }, {
- offset: 0.2, color: 'rgba(241, 154, 55, 0.2)' // 中间更透明
- }, {
- offset: 1, color: 'rgba(241, 154, 55, 0)' // 底部完全透明
- }],
- global: false // 缺省为 false
- }
- }
- },
- ]
- }
- function initLine() {
- chartObjOne = echarts.init(chartRefOne.value)
- chartObjAcos = echarts.init(chartRefAcos.value)
- chartObjCPCandCTR = echarts.init(chartRefCPCandCTR.value)
- chartObjTotalPurchases = echarts.init(chartRefTotalPurchases.value)
- chartObjImpandCli = echarts.init(chartRefImpandCli.value)
- }
- function setChartOptions() {
- const chartOptions = [
- { chart: chartObjOne, option: option },
- { chart: chartObjAcos, option: option2 },
- { chart: chartObjCPCandCTR, option: option3 },
- { chart: chartObjTotalPurchases, option: option4 },
- { chart: chartObjImpandCli, option: option5 }
- ];
- chartOptions.forEach(chartOption => {
- try {
- chartOption.option.dataset.source = optionSource
- chartOption.chart.setOption(chartOption.option)
- } catch (error) {
- console.error('设置图表选项失败:', error)
- }
- })
- }
- function resizeChart() {
- chartObjOne.resize()
- chartObjAcos.resize()
- chartObjCPCandCTR.resize()
- chartObjTotalPurchases.resize()
- chartObjImpandCli.resize()
- }
- onMounted(async () => {
- initLine()
- window.addEventListener('resize', resizeChart) // 监听窗口大小变化,调整图表大小
- setTimeout(() => {
- resizeChart()
- }, 10)
- })
- </script>
- <style scoped lang="scss">
- $homeNavLengh: 8;
- .home-container {
- overflow: hidden;
- margin-top: 10px;
- .home-card-one,
- .home-card-two,
- .home-card-three {
- .home-card-item {
- width: 100%;
- height: 130px;
- border-radius: 4px;
- transition: all ease 0.3s;
- padding: 20px;
- overflow: hidden;
- background: #ffffff;
- box-shadow: var(--el-box-shadow-light);
- color: var(--el-text-color-primary);
- border: 1px solid var(--next-border-color-light);
- &:hover {
- box-shadow: 0 2px 12px var(--next-color-dark-hover);
- transition: all ease 0.3s;
- }
- &-icon {
- width: 70px;
- height: 70px;
- border-radius: 100%;
- flex-shrink: 1;
- i {
- color: var(--el-text-color-placeholder);
- }
- }
- &-title {
- font-size: 15px;
- font-weight: bold;
- height: 30px;
- }
- }
- }
- .home-card-one {
- @for $i from 0 through 3 {
- .home-one-animation#{$i} {
- opacity: 0;
- animation-name: error-num;
- animation-duration: 0.5s;
- animation-fill-mode: forwards;
- animation-delay: calc($i/10) + s;
- }
- }
- }
- .home-card-two,
- .home-card-three {
- .home-card-item {
- height: 400px;
- width: 100%;
- overflow: hidden;
- .home-monitor {
- height: 100%;
- .flex-warp-item {
- width: 25%;
- height: 111px;
- display: flex;
- .flex-warp-item-box {
- margin: auto;
- text-align: center;
- color: var(--el-text-color-primary);
- display: flex;
- border-radius: 5px;
- background: var(--next-bg-color);
- cursor: pointer;
- transition: all 0.3s ease;
- &:hover {
- background: var(--el-color-primary-light-9);
- transition: all 0.3s ease;
- }
- }
- @for $i from 0 through $homeNavLengh {
- .home-animation#{$i} {
- opacity: 0;
- animation-name: error-num;
- animation-duration: 0.5s;
- animation-fill-mode: forwards;
- animation-delay: calc($i/10) + s;
- }
- }
- }
- }
- }
- }
- }
- .down {
- margin-top: 10px;
- }
- </style>
|