console.vue 10.3 KB
<template>
  <div class="live-main">
    <div class="container">
      <div class="look-container">
        <div class="look-left">
          <div class="look-left-b">
            <img :src="room.liveVideoCover" v-show="room.liveVideoCover" />
          </div>
          <div class="look-left-content">
            <div class="look-title">{{ room.name }}</div>
            <div class="look-desc">开播时间:{{ getBetween }}</div>
            <div class="look-desc">房间号:{{ room.id }}</div>
            <div class="look-status" v-if="endStatus == 'end'">直播已结束</div>
            <div class="look-status" v-if="endStatus == 'start'">正在直播</div>
            <div class="look-status" v-if="endStatus == 'wait'">直播倒计时{{ endTime }}</div>
          </div>
        </div>
        <div class="look-right">
          <div class="look-item">
            <div class="look-item-icon"><img src="@/assets/look.png" alt="" /></div>
            <div class="look-item-text">观看</div>
            <div class="look-item-num">{{ room.totalVisitCnt }}</div>
          </div>
          <div class="look-item">
            <div class="look-item-icon"><img src="@/assets/online.png" alt="" /></div>
            <div class="look-item-text">在线</div>
            <div class="look-item-num">{{ room.totalOnlineCnt }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="container-header">基本信息</div>
      <div class="data-container">
        <div class="data-container-left">
          <div class="data-title">
            <img src="@/assets/eyes.png" alt="" />
            <span>观看数据</span>
          </div>
          <div class="data-desc">
            <span>峰值在线人数</span>
            <span>{{ baseInfo.visitPeakOnlineValue }}</span>
          </div>
          <div class="data-desc">
            <span>观看人数</span>
            <span>{{ baseInfo.visitNumberOfPeople }}</span>
          </div>
          <div class="data-desc data-desc-jump">
            <span>观看次数</span>
            <span>
              {{ baseInfo.visitNumberOfTimes }}
              <a @click="handleLook">查看</a>
            </span>
          </div>
          <div class="data-desc">
            <span>平均观看时长</span>
            <span>{{ baseInfo.visitAverageTime }}</span>
          </div>
        </div>
        <div class="data-container-right">
          <div class="data-title">
            <img src="@/assets/message.png" alt="" />
            <span>互动数据</span>
          </div>
          <div class="data-desc">
            <span>评论人数</span>
            <span>{{ baseInfo.interactNumberOfPeople }}</span>
          </div>
          <div class="data-desc">
            <span>评论次数</span>
            <span>{{ baseInfo.interactNumberOfTimes }}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="container">
      <div class="container-header">流量数据</div>
      <!-- 表格区域 开始 -->
      <div class="container-tabel">
        <div class="live-table-header">
          <h2>数据列表</h2>
          <el-button :size="size" type="primary" plain @click="detailexport">导出</el-button>
        </div>
        <GLTable ref="classifyRef" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn">
          <!-- <div class="table-btns" slot="auth-button" slot-scope="scope">
            <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="1"></GLTableButton>
          </div> -->
        </GLTable>
      </div>
    </div>
    <GLDialog width="1158px" :bigTitle="room.name" :hasFooter="false" :visible.sync="dialogVisible" mode="big">
      <record ref="recordForm" v-if="dialogVisible" :roomNum="roomNum" :peopleNum="peopleNum"></record>
    </GLDialog>
  </div>
</template>

<script>
import url from '@/assets/empty.png'
import record from './components/record.vue'
import { downloadUrl, GetDateDiff } from '@/utils'
export default {
  name: 'LiveIndex',
  components: {
    record
  },
  data() {
    return {
      endStatus: '',
      roomNum: 0,
      peopleNum: 0,
      roomId: '',
      endTime: '',
      dialogVisible: false,
      visitSource: '',
      dialogObj: {
        show: false
      },
      size: 'small',
      url: url,
      baseInfo: {},
      room: {},
      tableSearchForm: { id: '' },
      // 表格
      getListApi: this.$apis.console.consolePage,
      tableParams: {
        listName: 'list',
        tableOption: false,
        tableColumns: [
          {
            label: '访问来源',
            prop: 'visitSource'
          },
          {
            label: '观看总人数',
            prop: 'totalVisitPeople'
          },
          {
            label: '平均停留时长',
            prop: 'averageStayTime'
          }
        ]
      },
      tableButtonList: [
        {
          type: 'el-button',
          name: '详情',
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => {
              this.handleLook(row)
            }
          }
        }
      ],
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' }
    }
  },

  created() {
    this.roomId = this.$route.query.id
    this.consoleBasic(this.roomId)
    this.consoleInfo(this.roomId)
  },
  beforeDestroy() {
    clearInterval(this.timer)
  },
  computed: {
    getBetween() {
      const startTimeStr = this.room.startTimeStr
      const endTimeStr = this.room.endTimeStr
      if (!startTimeStr) return
      const [y1, d1] = startTimeStr.split(' ')
      const [y2, d2] = endTimeStr.split(' ')
      if (y1 == y2) {
        return y1 + ' ' + d1.substring(0, 5) + '-' + d2.substring(0, 5)
      } else {
        return y1 + ' ' + d1.substring(0, 5) + '-' + y2 + ' ' + d2.substring(0, 5)
      }
    }
  },
  methods: {
    //时间差
    getTime() {
      if (this.room.actualEndTime) {
        this.endTime = GetDateDiff(this.room.startTimeStr,this.room.actualEndTime)
        this.endStatus = 'end'
        clearInterval(this.timer)
      }
      if (new Date(this.room.startTimeStr).getTime() < new Date().getTime() && !this.room.actualEndTime) {
        this.endTime = GetDateDiff(this.room.startTimeStr, new Date())
        this.endStatus = 'start'
      }
      if (new Date(this.room.startTimeStr).getTime() > new Date().getTime()) {
        this.endTime = GetDateDiff(new Date(), this.room.startTimeStr)
        this.endStatus = 'wait'
      }
    },
    handleLook() {
      this.roomNum = this.baseInfo.visitNumberOfTimes
      this.peopleNum = this.baseInfo.visitNumberOfPeople
      this.dialogVisible = true
    },
    consoleBasic(id) {
      this.$apis.console.consoleBasic({ id }).then(res => {
        this.baseInfo = res || {}
      })
    },
    consoleInfo(id) {
      this.$apis.console.consoleInfo({ id }).then(res => {
        this.room = res || {}
        this.timer = setInterval(this.getTime, 1000)
        this.getTime()
      })
    },
    detailexport() {
      this.$apis.console.consoleExport({ id: this.roomId, currentPage: 1, pageSize: 100000 }).then(res => {
        downloadUrl(res)
      })
    },
    pageClick() {
      this.$router.push('/shortVideo/uploadVideo')
    },
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm.id = this.roomId
        resolve()
      })
    },
    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.classifyRef.data.length ? (this.$refs.classifyRef.tableHeightValues = '') : this.$refs.classifyRef.setTableHeightFun()
    }
  }
}
</script>

<style lang="scss" scoped>
@mixin title() {
  font-weight: 600;
  font-size: 16px;
  color: rgba(0, 0, 0, 0.85);
}
@mixin text() {
  font-size: 14px;
  color: #666666;
}
.live-main {
  .container {
    margin-bottom: 16px;
    background: #fff;
  }
  .container-tabel {
    padding: 20px;
  }
  .container-header {
    height: 58px;
    line-height: 58px;
    border-bottom: 1px solid #e5e5e5;
    padding-left: 20px;
  }
  .look-container {
    display: flex;
    justify-content: space-between;
    padding: 20px 120px 20px 20px;
    align-items: center;
    .look-left {
      display: flex;
      .look-left-b {
        width: 260px;
        height: 170px;
        img {
          width: 260px;
          height: 170px;
        }
      }
      .look-left-content {
        margin-left: 20px;
        .look-title {
          @include title();
          margin-bottom: 10px;
        }
        .look-desc {
          @include text();
          line-height: 24px;
        }
        .look-status {
          margin-top: 20px;
          display: inline-block;
          background: #eeedff;
          border-radius: 4px;
          font-size: 14px;
          color: #5850ff;
          padding: 4px 10px;
        }
      }
    }
    .look-right {
      display: flex;
      .look-item {
        text-align: center;
        margin-left: 68px;
        &-icon {
          width: 40px;
          height: 40px;
        }
        &-text {
          @include text();
          line-height: 24px;
        }
        &-num {
          line-height: 24px;
          font-weight: 600;
          font-size: 16px;
          color: rgba(0, 0, 0, 0.85);
        }
      }
    }
  }
  .data-container {
    padding: 20px 40px;
    display: flex;
    &-left {
      margin-right: 100px;
    }
    .data-title {
      @include title();
      font-size: 14px;
      line-height: 24px;
      transform: translateX(-20px);
      display: flex;
      align-items: center;
      img {
        width: 16px;
        height: 16px;
        margin-right: 5px;
      }
    }
    .data-desc {
      display: flex;
      justify-content: space-between;
      width: 200px;
      line-height: 24px;
      @include text();
      &.data-desc-jump {
        width: 238px;
        a {
          color: #5850ff;
          font-size: 14px;
          margin-left: 4px;
          cursor: pointer;
        }
      }
      span {
        &:last-child {
          @include title();
        }
      }
    }
  }
}

.live-table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  h2 {
    font-weight: 600;
    font-size: 16px;
    color: #333333;
  }
}
</style>