index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="8" class="list" v-for="(item, index) in list" :key="index">
  6. <el-col :span="24" class="title">
  7. <span>[{{ item.room_id }}]</span>{{ item.title }}
  8. </el-col>
  9. <el-col :span="24" class="video">
  10. <video :id="item.room_id" controls class="h5video"></video>
  11. </el-col>
  12. <el-col :span="24" class="btn">
  13. <el-button type="danger" size="mini">强制关闭直播</el-button>
  14. </el-col>
  15. </el-col>
  16. </el-col>
  17. </el-row>
  18. </div>
  19. </template>
  20. <script>
  21. import { mapState, createNamespacedHelpers } from 'vuex';
  22. const { mapActions: dock } = createNamespacedHelpers('dock');
  23. import flvjs from 'flv.js';
  24. export default {
  25. metaInfo() {
  26. return { title: this.$route.meta.title };
  27. },
  28. name: 'index',
  29. props: {},
  30. components: {},
  31. data: function() {
  32. return {
  33. list: [],
  34. datasss: [],
  35. };
  36. },
  37. async created() {
  38. await this.search();
  39. },
  40. methods: {
  41. ...dock(['query']),
  42. async search() {
  43. let res = await this.query({ status: '1' });
  44. if (this.$checkRes(res)) {
  45. this.$set(this, `list`, res.data);
  46. }
  47. },
  48. searchLive() {
  49. for (const val of this.list) {
  50. let player = document.getElementById(val.room_id);
  51. let rmtpUrl = `${process.env.VUE_APP_LIVE_URL + val.room_id}`;
  52. if (flvjs.isSupported()) {
  53. var flvPlayer = flvjs.createPlayer({
  54. isLive: true,
  55. type: 'flv',
  56. url: rmtpUrl,
  57. });
  58. flvPlayer.attachMediaElement(player);
  59. flvPlayer.load(); //加载
  60. this.datasss.push(flvPlayer);
  61. }
  62. }
  63. },
  64. get() {
  65. if (this.list.length > 0) {
  66. clearInterval(this.timer);
  67. this.searchLive();
  68. }
  69. },
  70. },
  71. mounted() {
  72. this.timer = setInterval(this.get, 1000);
  73. },
  74. computed: {
  75. ...mapState(['user']),
  76. },
  77. watch: {},
  78. };
  79. </script>
  80. <style lang="less" scoped>
  81. .main {
  82. .list {
  83. width: 32%;
  84. height: 295px;
  85. margin: 0 10px 10px 0;
  86. border-radius: 5px;
  87. padding: 10px;
  88. box-shadow: 0 0 5px #ccc;
  89. .title {
  90. text-align: center;
  91. font-size: 18px;
  92. overflow: hidden;
  93. text-overflow: ellipsis;
  94. -webkit-line-clamp: 2;
  95. word-break: break-all;
  96. display: -webkit-box;
  97. -webkit-box-orient: vertical;
  98. font-weight: bold;
  99. height: 54px;
  100. line-height: 25px;
  101. span {
  102. font-size: 16px;
  103. color: #ff0000;
  104. }
  105. }
  106. .video {
  107. height: 180px;
  108. overflow: hidden;
  109. margin: 0 0 10px 0;
  110. text-align: center;
  111. border: 1px solid #f1f1f1;
  112. .h5video {
  113. width: 100%;
  114. height: 180px;
  115. overflow: hidden;
  116. }
  117. }
  118. .btn {
  119. text-align: center;
  120. }
  121. }
  122. .list:nth-child(3n) {
  123. margin: 0 0 10px 0;
  124. }
  125. .list:hover {
  126. cursor: pointer;
  127. box-shadow: 0 0 5px #666;
  128. .title {
  129. color: #409eff;
  130. }
  131. }
  132. }
  133. </style>