index.vue 6.55 KB
<template>
  <div class="live-room">
    <div class="container">
      <div>
        <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
      </div>

      <!-- 表格区域 开始 -->
      <div class="live-table-header">
        <h2>短视频列表</h2>
        <el-button :size="size" type="primary" @click="pageClick">新建短视频</el-button>
      </div>
      <GLTable ref="classifyRef" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <div slot="status" slot-scope="scope">
          <span :class="['table-circle', scope.scope.status == 1 ? 'back-green' : 'back-grey']"></span>
          <span>{{ scope.scope.statusStr || '--' }}</span>
        </div>
        <div slot="coverUrl" slot-scope="scope">
          <div class="image-popover" @click="handleLook(scope.scope)">
            <img :src="scope.scope.coverUrl" />
          </div>
        </div>

        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
        </div>
      </GLTable>
      <el-dialog class="image-dialog" :visible.sync="dialogVisibleImg" width="30%">
        <big-view ref="viewForm" v-if="dialogVisibleImg" :dialogSrc="dialogSrc" :dialogType="dialogType"></big-view>
      </el-dialog>
      <GLDialog title="提示" @onOk="handleSure" @onCancel="dialogVisibleDel = false" type="error" content="是否确认删除短视频?" :visible.sync="dialogVisibleDel" mode="small"></GLDialog>
    </div>
  </div>
</template>

<script>
import url from '@/assets/empty.png'
import bigView from '@/components/big-view'
export default {
  name: 'LiveIndex',
  components: {
    bigView
  },
  data() {
    return {
      dialogVisibleDel: false,
      dialogVisibleImg: false,
      dialogType: '',
      selectItem: '',
      size: 'small',
      url: url,
      searchForm: {
        term: '',
        status: ''
      },
      tableSearchForm: {},
      // 搜索
      searchFormData: [
        {
          label: '短视频搜索',
          name: 'term',
          type: 'input',
          placeholder: '请输入关键字',
          maxlength: 20
        },
        {
          label: '状态',
          name: 'status',
          type: 'select',
          width: '215px',
          optionList: [
            { confId: '', confName: '全部' },
            { confId: '0', confName: '未上传' },
            { confId: '1', confName: '已上传' },
            { confId: '2', confName: '已删除' }
          ],
          optionId: 'confId',
          optionLabel: 'confName'
        }
      ],
      // 表格
      getListApi: this.$apis.shortVideo.tencentcloudmediaPage,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '编号',
            prop: 'fileId'
          },
          {
            label: '视频名称',
            prop: 'fileName'
          },
          {
            label: '宣传文案',
            prop: 'introduction'
          },
          {
            label: '封面图',
            prop: 'coverUrl',
            addHtml: 'coverUrl'
          },
          {
            label: '创建日期',
            prop: 'createdDate'
          },
          {
            label: '状态',
            prop: 'status',
            addHtml: 'status'
          }
        ]
      },
      tableButtonList: [
        {
          type: 'el-button',
          name: '预览',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.status == 1
          },
          listeners: {
            click: row => {
              this.handleView(row)
            }
          }
        },
        {
          type: 'el-button',
          name: '编辑',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.status == 2 || row.status == 0
          },
          listeners: {
            click: row => {
              this.$router.push(`/shortVideo/uploadVideo?id=${row.id}`)
            }
          }
        },
        {
          type: 'el-button',
          name: '删除',
          attrs: {
            type: 'text'
          },
          condition: row => {
            return row.status == 0 || row.status == 1
          },
          listeners: {
            click: row => {
              this.handleDelete(row)
            }
          }
        }
      ],
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' }
    }
  },

  mounted() {},

  methods: {
    handleDelete(row) {
      this.selectItem = row
      this.dialogVisibleDel = true
    },
    pageClick() {
      this.$router.push(`/shortVideo/uploadVideo`)
    },
    handleView(row) {
      this.dialogType = 'video'
      this.dialogVisibleImg = true
      this.dialogSrc = row.mediaUrl
    },
    handleLook(row) {
      this.dialogType = 'img'
      this.dialogVisibleImg = true
      this.dialogSrc = row.coverUrl
    },
    handleSure() {
      const { id } = this.selectItem
      this.$apis.shortVideo
        .tencentcloudmediaDelete({
          id
        })
        .then(res => {
          if (res) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
          }
          this.handleSearch()
        })
      this.dialogVisibleDel = false
    },
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        resolve()
      })
    },
    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.classifyRef.data.length ? (this.$refs.classifyRef.tableHeightValues = '') : this.$refs.classifyRef.setTableHeightFun()
    },

    handleSearch() {
      this.$refs.classifyRef.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        term: '',
        status: ''
      }
      this.handleSearch()
    }
  }
}
</script>

<style lang="scss" scoped>
.live-table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  h2 {
    font-weight: 600;
    font-size: 16px;
    color: #333333;
  }
}
.table-circle {
  margin-right: 5px;
}
.image-popover {
  cursor: pointer;
  img {
    width: 36px;
    height: 36px;
  }
}
</style>