liveRoomList.vue 7.71 KB
<!-- 直播间列表 -->
<template>
  <div class="live-room">
    <div class="container live-room">
      <div class="flex">
        <el-form>
          <el-form-item>
            <el-button :size="size" type="primary" class="el-icon-plus" @click="handleEdit(1)">新增直播</el-button>
          </el-form-item>
        </el-form>
        <el-form :inline="true" :model="searchForm">
          <el-form-item label="直播间搜索:">
            <el-input :size="size" v-model="searchForm.name" placeholder="请输入直播间名" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button :size="size" type="primary" @click="handleSearch">查询</el-button>
            <el-button :size="size" @click="handleReset">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <GLTable ref="liveRoomRef" :searchForm="searchForm" :tableParams="tableParams" :getListApi="getListApi" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn">
        <span slot="shareImgUrl" slot-scope="scope">
          <img class="img-60" :src="scope.scope.shareImgUrl" />
        </span>
        <span class="table-btns" slot="auth-button" slot-scope="scope" :data="scope.scope">
          <el-button type="text" @click="handleDetail(scope.scope)">控制台</el-button>
          <el-button type="text" @click="handleShare(scope.scope)">分享</el-button>
          <el-button v-if="scope.scope.liveStatus == '102'" type="text" @click="handleEdit(2, scope.scope)">编辑</el-button>
          <el-button v-if="scope.scope.liveStatus != '101'" type="text" @click="handleDelete(scope.scope)">删除</el-button>
        </span>
      </GLTable>
      <glsx-dialog title="分享" width="730px" :isVisible="isShareVisible" :noCancel="noCancel" @closeDialog="handleShareClose" @confirmDialog="handleShareClose">
        <div class="share-dialog">
          <div class="flex">
            <div class="flex box poster">
              <div>
                <p class="share-txt">海报</p>
                <!-- <p>小程序码不带参数</p> -->
                <el-button :size="size" type="primary">保存图片</el-button>
              </div>
              <img :src="shareForm.posterUrl" />
            </div>
            <div class="flex box poster">
              <div>
                <p class="share-txt">小程序码</p>
                <!-- <p>小程序码不带参数</p> -->
                <el-button :size="size" type="primary">保存图片</el-button>
              </div>
              <img :src="shareForm.cdnUrl" />
            </div>
          </div>
          <div class="box page-route">
            <div>
              <p class="route-txt">短链</p>
              <div class="flex">
                <p style="width: 426px;">{{shareForm.pagePath}}</p>
                <el-button :size="size" type="primary" @click="handleSaveTxt(shareForm.pagePath)">复制链接</el-button>
                <!-- <p>链接是直播间原始页面路径,如需加入参数,详见使用方法</p> -->
              </div>
            </div>
          </div>
        </div>
      </glsx-dialog>
    </div>
  </div>
</template>

<script>
import glsxDialog from '@/components/glsx-dialog'
// import glsxTable from '@/components/glsx-table'
import { getLiveRoomListApi, getLiveShareApi, deleteLiveRoomApi } from '@/api/modules/liveRoom'
import { liveStatusList } from '@/common/constant'
export default {
  name: 'liveRoom',
  data() {
    return {
      size: 'small',
      searchForm: {
        name: ''
      },
      // 分享 - 弹窗
      shareForm: {},
      isShareVisible: false,
      noCancel: true,
      // 表格组件
      getListApi: getLiveRoomListApi,
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      // 表格参数
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '最近开播',
            prop: 'time',
            width: '180',
            formatter: cellValue => {
              return cellValue.startTime + '-' + cellValue.endTime
            }
          },
          {
            label: '直播间名称',
            prop: 'name',
            line: 1
          },
          {
            label: '房间号',
            prop: 'roomId'
          },
          {
            label: '主播',
            prop: 'anchorName',
            line: 1
          },
          {
            label: '直播间图片',
            prop: 'shareImgUrl',
            line: 1,
            addHtml: 'shareImgUrl'
          },
          {
            label: '直播状态',
            prop: 'liveStatus',
            width: '80',
            formatter: cellValue => {
              return this.baseDataList.liveStatusList.find(item => item.confId == cellValue.liveStatus).confName
            }
          }
        ]
      },
      baseDataList: {
        liveStatusList: liveStatusList
      }
    }
  },

  components: {
    glsxDialog
    // glsxTable
  },

  mounted() {
    console.log(this.$common.utils)
  },

  methods: {
    beforeSearchFn() {
      return new Promise(resolve => {
        resolve()
      })
    },
    handleShare(row) {
      getLiveShareApi({ id: row.id }).then(res => {
        console.log(res)
        this.isShareVisible = !this.isShareVisible
        this.shareForm = res
      })
    },
    handleShareClose() {
      // this.handleShare()
      this.isShareVisible = !this.isShareVisible
    },
    handleSaveTxt(txt) {
      const input = document.createElement('input')
      document.body.appendChild(input)
      input.setAttribute('value', txt)
      input.select()
      document.execCommand('Copy')
      document.body.removeChild(input)
      this.$message({
        message: '复制成功',
        type: 'success'
      })
    },
    handleDetail(row) {
      this.$router.push({
        // name: 'liveControl',
        // path: '/liveRoom/liveControl',
        name: 'ServicesLiveRoomLiveControl',
        params: {
          id: row.id
        }
      })
    },
    handleDelete(row) {
      this.$messageBox.confirm('是否删除该直播间?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'error',
        callback: action => {
          if (action == 'confirm') {
            deleteLiveRoomApi({ id: row.id }).then(res => {
              this.$message({
                message: res.code == '0' ? '操作成功' : res.message,
                type: res.code == '0' ? 'success' : 'error'
              })
              if (res.code == '0') {
                this.handleSearch()
              }
            })
          }
        }
      })
    },
    // 1-新增;2-编辑
    handleEdit(addOrEdit, row) {
      // console.log(row)
      // this.$history.push('services/liveRoom/editLiveRoom', { addOrEdit: addOrEdit, row: row || {} })
      // this.eventBus.$emit('editRoom', {
      //   addOrEdit: addOrEdit,
      //   id: row ? row.id : ''
      // })
      this.$router.push({
        name: 'ServicesLiveRoomEditLiveRoom',
        params: {
          addOrEdit: addOrEdit,
          id: row ? row.id : '-1'
        }
        // name: 'editLiveRoom',
        // path: '/liveRoom/editLiveRoom'
      })
    },
    handleSearch() {
      this.$refs.liveRoomRef.refreshTable()
    }
  }
}
</script>
<style>
.live-room .flex {
  display: flex;
  justify-content: space-between;
}
.live-room .share-dialog .box {
  background: #f7f7f7;
  border-radius: 6px;
  padding: 30px;
}
.live-room .share-dialog .poster img {
  width: 150px;
  height: 240px;
  margin-left: 45px;
}
.live-room .share-dialog .page-route {
  margin-top: 16px;
}
.live-room .share-dialog .page-route .route-txt {
  font-weight: bold;
  padding-bottom: 10px;
}
.live-room .share-dialog .share-txt {
  font-weight: bold;
  margin-bottom: 50px;
}
</style>