lineChartModel.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <div class="layout-container-main" id="jcsb">
  3. <div class="item" id="box1">
  4. <div class="layout-container-main-top">
  5. <div class="top-left">
  6. <div class="line"></div>
  7. <span>{{ title }}</span>
  8. </div>
  9. <div class="main" v-if="totalProfit">
  10. <el-row v-if="type === 'earn'">
  11. <el-col :span="8">
  12. <el-statistic title="今日收益" :value="totalProfit.today" :precision="2" />
  13. </el-col>
  14. <el-col :span="8">
  15. <el-statistic title="昨日收益" :value="totalProfit.yesterday" :precision="2" />
  16. </el-col>
  17. <el-col :span="8">
  18. <el-statistic title="本月收益" :value="totalProfit.month" :precision="2" />
  19. </el-col>
  20. </el-row>
  21. <el-row v-else>
  22. <el-col :span="8">
  23. <el-statistic title="今日ECPM" :value="totalProfit.ecpmToday" :precision="2" />
  24. </el-col>
  25. <el-col :span="8">
  26. <el-statistic title="昨日ECPM" :value="totalProfit.ecpmYesterday" :precision="2" />
  27. </el-col>
  28. <el-col :span="8">
  29. <el-statistic title="本月ECPM" :value="totalProfit.ecpmMonth" :precision="2" />
  30. </el-col>
  31. </el-row>
  32. </div>
  33. </div>
  34. <div class="main-echart" ref="chartRef">
  35. <el-table class="table" :data="tableData" border height="100%" :fit="true" :scroll-x="false"
  36. :style="{ width: '100%' }">
  37. <el-table-column prop="platform" label="统计" align="center" />
  38. <el-table-column :prop="type === 'earn' ? 'today' : 'ecpmToday'" label="今日" align="center" />
  39. <el-table-column :prop="type === 'earn' ? 'yesterday' : 'ecpmYesterday'" label="昨日"
  40. align="center" />
  41. <el-table-column :prop="type === 'earn' ? 'month' : 'ecpmMonth'" label="本月" align="center" />
  42. </el-table>
  43. <Chart class="chart" :option="options" />
  44. </div>
  45. </div>
  46. </div>
  47. </template>
  48. <script setup>
  49. import { ref, watch } from 'vue'
  50. import Chart from '@/components/charts/index.vue'
  51. const props = defineProps({
  52. // 表格数据
  53. tableData: {
  54. type: Array,
  55. default: []
  56. },
  57. // 折线图数据
  58. lineListData: {
  59. type: Object,
  60. default: {}
  61. },
  62. // 汇总数据
  63. totalProfit: {
  64. type: Object,
  65. default: {}
  66. },
  67. // 类型 'earn'- 收益 | 'ecpm'
  68. type: {
  69. type: String,
  70. default: 'earn'
  71. },
  72. title: {
  73. type: String,
  74. default: ''
  75. }
  76. });
  77. const xAxisList = [
  78. '00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00',
  79. '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00',
  80. '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00'
  81. ];
  82. const options = ref({
  83. /* title: {
  84. text: "单位:个",
  85. textStyle: {
  86. color: "#808080",
  87. fontSize: 12
  88. },
  89. left: "20",
  90. top: "0"
  91. }, */
  92. grid: {
  93. top: 20,
  94. right: 20,
  95. bottom: 0, // 可根据需要设为 0~40
  96. left: 40,
  97. containLabel: true
  98. },
  99. tooltip: {
  100. trigger: 'axis', // 触发类型为坐标轴
  101. axisPointer: {
  102. type: 'cross' // 指示器类型为十字准星
  103. },
  104. formatter: function (params) {
  105. // 自定义提示框内容
  106. let result = params[0].axisValue + '<br>'; // 显示时间点
  107. params.forEach(function (item) {
  108. // 为每个系列添加数据行
  109. result += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:'
  110. + item.color + '"></span>'
  111. + item.seriesName + ': ' + item.value + '<br>';
  112. });
  113. return result;
  114. }
  115. },
  116. legend: {
  117. data: ['穿山甲', '优量汇', '快手', 'Sigmob', '百度'],
  118. top: 'top',
  119. textStyle: {
  120. color: '#808080'
  121. }
  122. },
  123. xAxis: {
  124. type: 'category',
  125. data: xAxisList,
  126. axisLabel: {
  127. color: "#808080",
  128. fontSize: 12
  129. },
  130. axisLine: {
  131. show: false,
  132. },
  133. axisTick: {
  134. show: false
  135. },
  136. splitLine: {
  137. show: false
  138. },
  139. },
  140. yAxis: {
  141. min: 0,
  142. nameTextStyle: {
  143. color: '#808080',
  144. fontSize: 12,
  145. },
  146. axisLabel: {
  147. color: "#808080",
  148. fontSize: 12
  149. },
  150. axisLine: {
  151. show: false
  152. },
  153. axisTick: {
  154. show: false
  155. },
  156. splitLine: {
  157. show: true,
  158. lineStyle: {
  159. color: 'rgba(0,0,0,0.15)',
  160. }
  161. }
  162. },
  163. series: []
  164. });
  165. // 监听 props.lineListData 变化,动态更新 series
  166. watch(() => props.lineListData, (newVal) => {
  167. if (Object.keys(newVal).length === 0) return; // 空数据不更新
  168. options.value.series = [
  169. {
  170. type: 'line',
  171. name: '穿山甲',
  172. symbolSize: 6,
  173. z: 1,
  174. label: { show: false },
  175. itemStyle: { color: '#add7f6' },
  176. lineStyle: { color: '#add7f6', width: 2 },
  177. data: props.type === 'earn' ?
  178. newVal['穿山甲']?.estimatedRevenueList ?? [] :
  179. newVal['穿山甲']?.estimatedRevenueEcpmList ?? []
  180. },
  181. {
  182. type: 'line',
  183. name: '优量汇',
  184. symbolSize: 6,
  185. z: 1,
  186. label: { show: false },
  187. itemStyle: { color: '#f7a8b8' },
  188. lineStyle: { color: '#f7a8b8', width: 2 },
  189. data: props.type === 'earn' ?
  190. newVal['优量汇']?.estimatedRevenueList ?? [] :
  191. newVal['优量汇']?.estimatedRevenueEcpmList ?? []
  192. },
  193. {
  194. type: 'line',
  195. name: '快手',
  196. symbolSize: 6,
  197. z: 1,
  198. label: { show: false },
  199. itemStyle: { color: '#ffcc5c' },
  200. lineStyle: { color: '#ffcc5c', width: 2 },
  201. data: props.type === 'earn' ?
  202. newVal['快手']?.estimatedRevenueList ?? [] :
  203. newVal['快手']?.estimatedRevenueEcpmList ?? []
  204. },
  205. {
  206. type: 'line',
  207. name: 'Sigmob',
  208. symbolSize: 6,
  209. z: 1,
  210. label: { show: false },
  211. itemStyle: { color: '#88d8b0' },
  212. lineStyle: { color: '#88d8b0', width: 2 },
  213. data: props.type === 'earn' ?
  214. newVal['Sigmob']?.estimatedRevenueList ?? [] :
  215. newVal['Sigmob']?.estimatedRevenueEcpmList ?? []
  216. },
  217. {
  218. type: 'line',
  219. name: '百度',
  220. symbolSize: 6,
  221. z: 1,
  222. label: { show: false },
  223. itemStyle: { color: '#9966cc' },
  224. lineStyle: { color: '#9966cc', width: 2 },
  225. data: props.type === 'earn' ?
  226. newVal['百度']?.estimatedRevenueList ?? [] :
  227. newVal['百度']?.estimatedRevenueEcpmList ?? []
  228. }
  229. ]
  230. }, { immediate: true })
  231. </script>
  232. <style lang="scss" scoped>
  233. .layout-container-main {
  234. margin-top: 10px;
  235. display: flex;
  236. /* margin: 0 1.25rem; */
  237. flex-wrap: wrap;
  238. justify-content: space-between;
  239. .item {
  240. width: calc(100vw - 1.13rem - 1.31rem);
  241. display: flex;
  242. flex-direction: column;
  243. padding: 1.13rem 1.31rem;
  244. margin-bottom: 1.25rem;
  245. /* height: 26.94rem; */
  246. border-radius: 0.5rem;
  247. background: #fff;
  248. box-shadow: 0 0 0.13rem #00000029;
  249. .layout-container-main-top {
  250. height: 6vh;
  251. display: flex;
  252. // justify-content: space-between;
  253. .top-left {
  254. display: flex;
  255. .line {
  256. width: 0.25rem;
  257. height: 1.56rem;
  258. border-radius: 0.13rem;
  259. background: #409eff;
  260. }
  261. span {
  262. margin: 0 1rem;
  263. font-family: "PingFang SC SNaNremibold";
  264. font-weight: 600;
  265. font-size: 1.13rem;
  266. color: #333;
  267. }
  268. .text {
  269. display: inline-block;
  270. /* // margin: 0 0.63rem; */
  271. width: 3.63rem;
  272. font-weight: 400;
  273. height: 1.88rem;
  274. line-height: 1.88rem;
  275. border-radius: 0.25rem;
  276. background: transparent;
  277. border: 0.03rem solid #999;
  278. font-size: 0.88rem;
  279. text-align: center;
  280. color: #999;
  281. cursor: pointer;
  282. }
  283. .active {
  284. border-radius: 0.25rem;
  285. background: #fdb818;
  286. color: #fff;
  287. border: 0.03rem solid #fff;
  288. }
  289. }
  290. .main {
  291. // flex: 1;
  292. min-width: 300px;
  293. }
  294. }
  295. .main-echart {
  296. width: 100%;
  297. display: flex;
  298. height: 55vh;
  299. .table {
  300. flex: 1;
  301. min-width: 250px;
  302. /* 防止过窄导致表格挤压 */
  303. overflow-x: auto;
  304. }
  305. .table :deep(.el-table__body-wrapper tbody tr) {
  306. // height: calc(100% / 7);
  307. height: calc(61vh / 6);
  308. }
  309. .chart {
  310. flex: 3;
  311. min-width: 300px;
  312. }
  313. @media screen and (max-width: 1024px) {
  314. flex-direction: column;
  315. .table,
  316. .chart {
  317. width: 100%;
  318. min-width: unset;
  319. }
  320. .table {
  321. flex: 2;
  322. overflow-x: auto;
  323. margin-bottom: 10px;
  324. }
  325. .table :deep(.el-table__body-wrapper tbody tr) {
  326. height: calc(100% / 6);
  327. }
  328. .chart {
  329. flex: 3;
  330. }
  331. }
  332. }
  333. }
  334. }
  335. .stats-table {
  336. margin: 20px;
  337. width: 100vw;
  338. }
  339. :deep(.el-table__header th) {
  340. background-color: #f5f7fa;
  341. font-weight: bold;
  342. }
  343. </style>