LiveChannel.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <div class="program">
  3. <el-page-header :content="row.tv_name" @back="goBack" />
  4. <br />
  5. <el-tabs type="card" v-model="tabs">
  6. <el-tab-pane name="0" label="实时信息">
  7. <el-button-group>
  8. <el-button
  9. v-if="tab !== '2h'"
  10. size="mini"
  11. @click="() => tabBtn('2h')"
  12. >
  13. 最近2h
  14. </el-button>
  15. <el-button
  16. v-if="tab === '2h'"
  17. color="#1989fa"
  18. type="primary"
  19. size="mini"
  20. >
  21. 最近2h
  22. </el-button>
  23. <el-button
  24. v-if="tab !== '1min'"
  25. size="mini"
  26. @click="() => tabBtn('1min')"
  27. >
  28. 最近1min
  29. </el-button>
  30. <el-button
  31. v-if="tab === '1min'"
  32. color="#1989fa"
  33. type="primary"
  34. size="mini"
  35. >
  36. 最近1min
  37. </el-button>
  38. </el-button-group>
  39. <el-button
  40. style="float: right;margin-left: 1em"
  41. type="primary"
  42. size="small"
  43. @click="getlist"
  44. >
  45. 查询
  46. </el-button>
  47. <el-select
  48. v-model="channel"
  49. placeholder="请选择频道"
  50. size="small"
  51. multiple
  52. style="float: right;"
  53. collapse-tags
  54. @change="channelSelect"
  55. >
  56. <el-option label="全部" value="all"> </el-option>
  57. <el-option
  58. v-for="item in channelNameList"
  59. :key="item.value"
  60. :label="item.label"
  61. :value="item.value"
  62. :disabled="item.disabled"
  63. >
  64. </el-option>
  65. </el-select>
  66. <real-line-chart
  67. v-if="lineChart.length"
  68. :list="lineChart"
  69. :tab="tab"
  70. :channelId="[row.id, ...channel]"
  71. ref="chart"
  72. ></real-line-chart>
  73. </el-tab-pane>
  74. <el-tab-pane name="1" label="流入流出">
  75. <in-out
  76. v-if="tabs === '1' && inOut.length"
  77. :list="inOut"
  78. :chatList="inOutList"
  79. >
  80. </in-out>
  81. </el-tab-pane>
  82. <el-tab-pane name="2" v-if="epg.length" label="EPG信息">
  83. <el-table align="center" :header-cell-style="{ backgroundColor: '#f4f5f7',color: '#606266' }" :data="epg" style="width: 100%">
  84. <el-table-column prop="epg_name" label="今日历史节目" />
  85. <el-table-column prop="pv" label="播出时间" :formatter="liveTime" />
  86. <el-table-column
  87. prop="tv_ratings"
  88. :formatter="matrerLive"
  89. label="收视率"
  90. width="180"
  91. />
  92. </el-table>
  93. </el-tab-pane>
  94. <el-tab-pane name="3" v-if="advertisement.length" label="广告表现">
  95. <el-table :header-cell-style="{ backgroundColor: '#f4f5f7',color: '#606266' }" :data="advertisement" style="width: 100%">
  96. <el-table-column align="center" prop="brand" label="品牌名称" />
  97. <el-table-column align="center" prop="pv" label="频次" />
  98. <el-table-column
  99. align="center"
  100. prop="grp"
  101. :formatter="matrer"
  102. label="GRP"
  103. width="180"
  104. />
  105. </el-table>
  106. </el-tab-pane>
  107. </el-tabs>
  108. </div>
  109. </template>
  110. <script>
  111. // @ is an alias to /src
  112. import realLineChart from "@/components/realLineChart.vue";
  113. import inOut from "@/components/inOut.vue";
  114. import config from "@/config/index";
  115. import {
  116. liveRealDataApi,
  117. liveRealDataMinApi,
  118. advertisementApi,
  119. epgApi,
  120. inOutApi,
  121. } from "@/api/index.js";
  122. let Interval = undefined;
  123. let params = {};
  124. export default {
  125. name: "LiveChannel",
  126. data() {
  127. return {
  128. tab: "2h",
  129. row: {},
  130. lineChart: [],
  131. channel: [],
  132. advertisement: [],
  133. epg: [],
  134. inOut: [],
  135. inOutList: [],
  136. tabs: "0",
  137. };
  138. },
  139. mounted() {
  140. this.row = JSON.parse(this.$route.query.row || "{}");
  141. const t = this.dateFormat();
  142. params = {
  143. tab: this.tab,
  144. channel: JSON.parse(JSON.stringify(this.channel)),
  145. };
  146. this.hourTime();
  147. advertisementApi({
  148. tv_id: this.row.id,
  149. day: [t.year, t.month, t.day].join("-"),
  150. })
  151. .then(r => {
  152. this.advertisement = r || [];
  153. })
  154. .catch(() => {
  155. this.advertisement = [];
  156. });
  157. epgApi({ tv_id: this.row.id })
  158. .then(r => {
  159. this.epg = r || [];
  160. })
  161. .catch(() => {
  162. this.epg = [];
  163. });
  164. inOutApi({
  165. tv_id: this.row.id,
  166. area_id: this.row.area_id,
  167. })
  168. .then(r => {
  169. this.inOut = r.high_low || [];
  170. this.inOutList = r.list || [];
  171. })
  172. .catch(() => {
  173. this.inOut = [];
  174. this.inOutList = [];
  175. });
  176. },
  177. computed: {
  178. channelNameList() {
  179. let li = [];
  180. for (let i = 0; i < config.channelNameList.length; i++) {
  181. const v = config.channelNameList[i];
  182. if (v.value === this.row.id) continue;
  183. li.push(v);
  184. }
  185. return li;
  186. },
  187. },
  188. methods: {
  189. liveTime(row) {
  190. let s = (row.end_time || "").split(" ")[1] || "",
  191. e = (row.end_time || "").split(" ")[1] || "";
  192. return s + "~" + e;
  193. },
  194. matrer(row, column, cellValue) {
  195. return cellValue.toFixed(4) + "%";
  196. },
  197. matrerLive(row, column, cellValue) {
  198. return (cellValue *100).toFixed(4) + "%";
  199. },
  200. dateFormat(date) {
  201. let D = date ? new Date(date) : new Date();
  202. let m = D.getMonth() + 1;
  203. let d = D.getDate();
  204. let h = D.getHours();
  205. let M = D.getMinutes();
  206. let s = D.getSeconds();
  207. m > 9 ? m : (m = "0" + m);
  208. d > 9 ? d : (d = "0" + d);
  209. h > 9 ? h : (h = "0" + h);
  210. M > 9 ? M : (M = "0" + M);
  211. s > 9 ? s : (s = "0" + s);
  212. return {
  213. year: D.getFullYear(),
  214. month: m,
  215. day: d,
  216. hour: h,
  217. minutes: M,
  218. seconds: s,
  219. };
  220. },
  221. getlist() {
  222. if (Interval) clearInterval(Interval);
  223. params = {
  224. tab: this.tab,
  225. channel: JSON.parse(JSON.stringify(this.channel)),
  226. };
  227. this.tab === "2h" ? this.hourTime() : this.realTime();
  228. },
  229. time() {
  230. if (!params.channel.length || params.tab === "2h") return "";
  231. const t = this.dateFormat();
  232. return t.year + t.month + t.day + t.hour + t.minutes + t.seconds;
  233. // return "20210928171007";
  234. },
  235. channelSelect(a) {
  236. let select = a[a.length - 1];
  237. if (a[0] === "all") a.shift();
  238. if (select === "all") this.channel = ["all"];
  239. else this.channel = a;
  240. },
  241. tabBtn(type) {
  242. this.tab = type;
  243. if (Interval) clearInterval(Interval);
  244. type === "2h" ? this.hourTime() : this.realTime();
  245. params = {
  246. tab: this.tab,
  247. channel: JSON.parse(JSON.stringify(this.channel)),
  248. };
  249. },
  250. hourTime() {
  251. if (Interval) clearInterval(Interval);
  252. liveRealDataApi({
  253. tv_id: this.row.id,
  254. area: this.row.area_id,
  255. sd: '20231016',
  256. t: 2,
  257. vs: (params.channel.join(",") + ",")
  258. .replace(this.row.id + ",", "")
  259. .replace(/,$/, "")
  260. .split(","),
  261. // t: this.time(),
  262. }).then(r => {
  263. if (r.vs && r.vs.length) this.lineChart = [r.list, ...r.vs] || [];
  264. else this.lineChart = [r.list] || [];
  265. this.$refs.chart && this.$refs.chart.updata(this.lineChart);
  266. });
  267. Interval = setInterval(() => {
  268. liveRealDataApi({
  269. tv_id: this.row.id,
  270. area_id: this.row.area_id,
  271. vs: (params.channel.join(",") + ",")
  272. .replace(this.row.id + ",", "")
  273. .replace(/,$/, "")
  274. .split(","),
  275. // t: this.time(),
  276. }).then(r => {
  277. if (r.vs && r.vs.length) this.lineChart = [r.list, ...r.vs] || [];
  278. else this.lineChart = [r.list] || [];
  279. this.$refs.chart && this.$refs.chart.updata(this.lineChart);
  280. });
  281. }, 60000);
  282. },
  283. realTime() {
  284. if (Interval) clearInterval(Interval);
  285. liveRealDataMinApi({
  286. tv_id: this.row.id,
  287. area_id: this.row.area_id,
  288. vs: (params.channel.join(",") + ",")
  289. .replace(this.row.id + ",", "")
  290. .replace(/,$/, "")
  291. .split(","),
  292. // t: this.time(),
  293. }).then(r => {
  294. if (r.vs && r.vs.length) this.lineChart = [r.list, ...r.vs] || [];
  295. else this.lineChart = [r.list] || [];
  296. this.$refs.chart.updata(this.lineChart);
  297. });
  298. Interval = setInterval(() => {
  299. liveRealDataMinApi({
  300. tv_id: this.row.id,
  301. area_id: this.row.area_id,
  302. vs: (params.channel.join(",") + ",")
  303. .replace(this.row.id + ",", "")
  304. .replace(/,$/, "")
  305. .split(","),
  306. // t: this.time(),
  307. }).then(r => {
  308. if (r.vs && r.vs.length) this.lineChart = [r.list, ...r.vs] || [];
  309. else this.lineChart = [r.list] || [];
  310. this.$refs.chart.updata(this.lineChart);
  311. });
  312. }, 1000);
  313. },
  314. goBack() {
  315. this.$router.go(-1);
  316. },
  317. },
  318. beforeUnmount: function() {
  319. if(Interval) clearInterval(Interval);
  320. },
  321. components: { realLineChart, inOut },
  322. };
  323. </script>
  324. <style></style>