lineChartModel.vue 10 KB

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