Jugouout.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <template>
  2. <div class="Jugouout">
  3. <el-loading></el-loading>
  4. <div style="padding: 0 100px">
  5. <div style="position: relative">
  6. <video
  7. controls
  8. autoplay
  9. ref="video"
  10. @timeupdate="timeupdate"
  11. @error="videoerror"
  12. @canplay="videoload"
  13. :src="videoUrl"
  14. />
  15. <img
  16. v-show="videoerrorStart"
  17. class="videoerror"
  18. src="../../assets/img/videoerror.png"
  19. />
  20. </div>
  21. <div style="position: relative">
  22. <div
  23. class="chart"
  24. ref="chart"
  25. style="width: 100%; min-height: 300px"
  26. ></div>
  27. <div class="lineinfobackground" :style="'left:' + leftNum + 'px'">
  28. <div style="position: relative; width: 100%; height: 100%">
  29. <div class="line"></div>
  30. <el-row style="padding: 10px 0 0 20px">
  31. <el-col :span="6">
  32. <span class="icon" style="background-color: #e05c5c"></span>
  33. 流入
  34. </el-col>
  35. <el-col :span="6">
  36. <span class="icon" style="background-color: #6ab581"></span>
  37. 流出
  38. </el-col>
  39. <el-col :span="12">
  40. <span class="iconLine"></span>
  41. 收视率%
  42. <div style="float: right; padding: 0 5px 0 0">
  43. {{ tof(nowItem.audienceRating, 4) }}%
  44. </div>
  45. </el-col>
  46. </el-row>
  47. <div style="padding: 5px 20px">
  48. 当前时间:{{
  49. nowItem.date ? nowItem.date.split(' ')[1] || '' : ''
  50. }}
  51. <div style="float: right">人数: {{ formateNum(nowItem.uv) }}</div>
  52. </div>
  53. <el-row>
  54. <el-col :span="12">
  55. <div style="padding: 0 20px">
  56. 流入排行
  57. <div>
  58. <div
  59. style="font-size: 12px; line-height: 22px"
  60. v-for="(item, i) in left"
  61. :key="i"
  62. v-text="item"
  63. ></div>
  64. </div>
  65. </div>
  66. </el-col>
  67. <el-col :span="12">
  68. <div style="padding: 0 20px">
  69. 流出排行
  70. <div>
  71. <div
  72. style="font-size: 12px; line-height: 22px"
  73. v-for="(item, i) in right"
  74. :key="i"
  75. v-text="item"
  76. ></div>
  77. </div>
  78. </div>
  79. </el-col>
  80. </el-row>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. </template>
  87. <script>
  88. // @ is an alias to /src
  89. import { defaultAjax } from '@/api/index';
  90. import { markRaw } from 'vue';
  91. const ElLoading = require('element-plus/lib/el-loading/index');
  92. import 'element-plus/lib/theme-chalk/el-loading.css';
  93. import * as echarts from 'echarts';
  94. let sec = 0,
  95. timeout = undefined,
  96. isplay = false,
  97. isClick = false,
  98. stepNum = 6.8,
  99. page = 0;
  100. export default {
  101. name: 'Channel',
  102. data() {
  103. return {
  104. videoerrorStart: false,
  105. leftNum: 50,
  106. videoUrl: '',
  107. myChart: undefined,
  108. orgLi: [],
  109. nowItem: {},
  110. left: [],
  111. right: [],
  112. load: undefined,
  113. };
  114. },
  115. mounted() {
  116. this.getData();
  117. },
  118. computed: {},
  119. methods: {
  120. getData() {
  121. if (!this.load) this.load = ElLoading.default.service();
  122. let item = {
  123. channelId: 1,
  124. channelName: '陕西卫视',
  125. videoUrl:
  126. 'https://cxzx.smcic.net/live-flow/video/20230814/1.mp4',
  127. dataUrl:
  128. 'https://cxzx.smcic.net/live-flow/channel/20230814/channel-1.json',
  129. dt: '2023-08-14',
  130. channelStatus: 0,
  131. isDefault: 1,
  132. };
  133. this.videoUrl = item.videoUrl;
  134. defaultAjax({
  135. url: item.dataUrl,
  136. })
  137. .then(res => {
  138. this.load.close();
  139. let org = res || {},
  140. li = [];
  141. Object.keys(org).map(v => {
  142. org[v].date = v;
  143. li.push(org[v]);
  144. });
  145. if (!li.length) return;
  146. this.orgLi = li;
  147. this.nowItem = li[0];
  148. this.left = li[0].lrTop || [];
  149. this.right = li[0].lcTop || [];
  150. return this.chart();
  151. })
  152. .catch(() => {
  153. this.load.close();
  154. });
  155. },
  156. tof(num, t) {
  157. return Number(num * 100).toFixed(t || 2);
  158. },
  159. chart() {
  160. if (!this.myChart) {
  161. this.myChart = markRaw(echarts.init(this.$refs.chart));
  162. this.myChart.resize({
  163. height: 300,
  164. });
  165. this.myChart.on('datazoom', () => {
  166. if (isClick) return;
  167. isClick = true;
  168. let funisplay = !this.$refs.video.paused;
  169. if (timeout) clearTimeout(timeout), (timeout = undefined);
  170. this.$refs.video.pause();
  171. this.leftNum = 50;
  172. timeout = setTimeout(() => {
  173. clearTimeout(timeout);
  174. timeout = undefined;
  175. isClick = false;
  176. // 拖拽后的事件
  177. isplay = funisplay;
  178. this.leftNum = 50;
  179. this.$refs.video.currentTime =
  180. this.myChart.getOption().dataZoom[0].startValue;
  181. if (isplay) this.$refs.video.play();
  182. else this.$refs.video.pause();
  183. }, 200);
  184. });
  185. }
  186. let timeAll = [],
  187. Irdata = [],
  188. Icdata = [],
  189. audienceRating = [];
  190. this.orgLi.map(v => {
  191. v.date && timeAll.push(v.date.split(' ')[1] || '');
  192. Icdata.push(-1 * v.lc);
  193. Irdata.push(v.lr);
  194. audienceRating.push(v.audienceRating * 100);
  195. });
  196. this.myChart.setOption({
  197. dataZoom: [
  198. {
  199. maxSpan: 10,
  200. minSpan: 5,
  201. type: 'slider',
  202. brushSelect: false,
  203. // zoomLock: false,
  204. show: true,
  205. realtime: true,
  206. start: stepNum * page,
  207. end: stepNum * (page + 1),
  208. zoomOnMouseWheel: false,
  209. height: '30',
  210. top: '85%',
  211. handleIcon:
  212. 'path://M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
  213. handleSize: 15,
  214. textStyle: {
  215. color: '#c5c6cc',
  216. },
  217. dataBackground: {
  218. lineStyle: {
  219. color: '#fff',
  220. },
  221. areaStyle: {
  222. color: '#8b51a8',
  223. },
  224. },
  225. },
  226. ],
  227. xAxis: {
  228. data: timeAll,
  229. position: 'top',
  230. silent: false,
  231. axisLabel: {
  232. interval: 'auto',
  233. color: '#000',
  234. rotate: '-90',
  235. },
  236. },
  237. yAxis: [
  238. {
  239. scale: false,
  240. nameGap: 6,
  241. inverse: false,
  242. name: '流入流出',
  243. nameLocation: 'start',
  244. splitArea: {
  245. show: false,
  246. },
  247. splitLine: {
  248. show: false,
  249. },
  250. axisLabel: {
  251. color: '#000',
  252. formatter: function (value) {
  253. let v = value;
  254. if (v < 0) v *= -1;
  255. return v;
  256. },
  257. },
  258. axisTick: {
  259. show: false,
  260. },
  261. axisLine: {
  262. show: false,
  263. },
  264. nameTextStyle: {
  265. color: '#000',
  266. },
  267. },
  268. {
  269. scale: true,
  270. nameGap: 6,
  271. type: 'value',
  272. name: '收视率%',
  273. nameLocation: 'start',
  274. splitLine: {
  275. show: false,
  276. },
  277. axisTick: {
  278. show: false,
  279. },
  280. axisLine: {
  281. show: false,
  282. },
  283. axisLabel: {
  284. color: '#000',
  285. },
  286. nameTextStyle: {
  287. color: '#000',
  288. },
  289. },
  290. ],
  291. grid: {
  292. left: 50,
  293. right: 50,
  294. },
  295. series: [
  296. {
  297. name: '流入',
  298. type: 'bar',
  299. yAxisIndex: 0,
  300. stack: 'one',
  301. data: Irdata,
  302. sampling: 'lttb',
  303. emphasis: {
  304. focus: 'series',
  305. },
  306. itemStyle: {
  307. color: '#df5a5a',
  308. },
  309. },
  310. {
  311. name: '流出',
  312. type: 'bar',
  313. yAxisIndex: 0,
  314. sampling: 'lttb',
  315. stack: 'one',
  316. data: Icdata,
  317. emphasis: {
  318. focus: 'series',
  319. },
  320. itemStyle: {
  321. color: '#6ab581',
  322. },
  323. },
  324. {
  325. name: '收视率%',
  326. type: 'line',
  327. yAxisIndex: 1,
  328. smooth: true,
  329. showSymbol: false,
  330. data: audienceRating,
  331. lineStyle: {
  332. width: 1,
  333. color: '#50abfd',
  334. },
  335. },
  336. ],
  337. });
  338. },
  339. timeupdate(v) {
  340. if (sec === Math.floor(v.srcElement.currentTime)) return;
  341. sec = Math.floor(v.srcElement.currentTime);
  342. let width = this.$refs.chart.offsetWidth - 100;
  343. let item = this.orgLi[sec] || {};
  344. let s = this.myChart.getOption().dataZoom[0].startValue,
  345. e = this.myChart.getOption().dataZoom[0].endValue;
  346. let iW = width / (e - s),
  347. cheng = sec - s < 0 ? 0 : sec - s;
  348. let step = iW * cheng > width ? 0 : iW * cheng;
  349. if (!item.lrTop) return;
  350. this.nowItem = item;
  351. this.left = item.lrTop || [];
  352. this.right = item.lcTop || [];
  353. this.leftNum = 50 + step;
  354. if (iW * cheng <= width) return;
  355. page++;
  356. this.myChart.setOption({
  357. dataZoom: {
  358. start: stepNum * page,
  359. end: stepNum * (page + 1),
  360. },
  361. });
  362. },
  363. videoerror() {
  364. this.videoerrorStart = true;
  365. },
  366. videoload() {
  367. this.videoerrorStart = false;
  368. const video = document.querySelector('video');
  369. let w = Math.ceil((500 * video.videoWidth) / video.videoHeight);
  370. video.style.width = w + 'px';
  371. },
  372. formateNum(n) {
  373. let num = n;
  374. if (isNaN(n)) num = '0';
  375. else if (n >= 100000000)
  376. num =
  377. ((n / 100000000).toFixed(2) - 0 + '').replace(
  378. /\B(?=(?:\d{3})+\b)/g,
  379. ','
  380. ) + '亿';
  381. else if (n >= 10000)
  382. num =
  383. ((n / 10000).toFixed(2) - 0 + '').replace(
  384. /\B(?=(?:\d{3})+\b)/g,
  385. ','
  386. ) + '万';
  387. else num = (num + '').replace(/\B(?=(?:\d{3})+\b)/g, ',');
  388. return num;
  389. },
  390. },
  391. components: {},
  392. };
  393. </script>
  394. <style>
  395. body {
  396. overflow: hidden;
  397. }
  398. .Jugouout {
  399. min-width: 1149px;
  400. padding: 10px 12px;
  401. }
  402. .Jugouout video {
  403. width: 100%;
  404. height: 500px;
  405. background-color: #000;
  406. margin: 0 auto;
  407. display: block;
  408. }
  409. .Jugouout .lineinfobackground {
  410. font-size: 12px;
  411. border-radius: 9px;
  412. position: absolute;
  413. width: 345px;
  414. height: 200px;
  415. top: 30px;
  416. left: 50px;
  417. background: rgba(0, 0, 0, 0.5);
  418. transform: translateX(-50%);
  419. color: #fff;
  420. /* opacity: 0.5; */
  421. }
  422. .Jugouout .lineinfobackground .line {
  423. position: absolute;
  424. width: 2px;
  425. height: 120%;
  426. margin-top: -5%;
  427. margin-left: 50%;
  428. background-color: #888;
  429. }
  430. .Jugouout .lineinfobackground .icon {
  431. display: inline-block;
  432. width: 30px;
  433. height: 10px;
  434. border-radius: 10px;
  435. }
  436. .Jugouout .lineinfobackground .iconLine {
  437. background-color: #50abfd;
  438. display: inline-block;
  439. width: 30px;
  440. height: 2px;
  441. vertical-align: middle;
  442. border-radius: 10px;
  443. }
  444. .Jugouout .videoerror {
  445. position: absolute;
  446. top: 50%;
  447. left: 50%;
  448. transform: translate(-50%, -50%);
  449. }
  450. video::-webkit-media-controls-timeline {
  451. display: none;
  452. }
  453. .Jugouout .subtitle {
  454. width: 417px;
  455. line-height: 56px;
  456. height: 56px;
  457. background: url(https://dp.sxtvs.com.cn/screenss/images/subtitle.png);
  458. background-size: 417px 56px;
  459. text-align: left;
  460. font-size: 36px;
  461. color: #ffffff;
  462. font-weight: bold;
  463. letter-spacing: 1px;
  464. padding-left: 50px;
  465. }
  466. </style>