index.vue 7.1 KB
<template>
  <div class="app-container">
    <el-header height>
      <el-input v-model="queryForm.title" style="width: 200px" placeholder="视频名称" clearable></el-input>
      <el-select v-model="queryForm.playbackTypeCode" placeholder="请选择" clearable @change="searchPlayback">
        <el-option
          v-for="item in playbackTypeList"
          :key="item.playbackTypeCode"
          :label="item.typeName"
          :value="item.playbackTypeCode">
        </el-option>
      </el-select>
      <el-button @click="searchPlayback" type="primary">搜索</el-button>
      <el-button type="primary" @click="playbackCreate">创建</el-button>
    </el-header>
    <el-main>
      <el-table
        :data="playbackList"
        style="width: 100%"
        stripe
        highlight-current-row
        v-loading="loading"
      >
        <el-table-column label="名称" prop="title"></el-table-column>
        <el-table-column label="视频链接" prop="videoUrl"></el-table-column>
        <el-table-column label="内容" prop="videoContent">
        </el-table-column>
        <el-table-column label="类型" prop="typeName"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-link type="primary" @click="playbackEdit(scope.row)">编辑 &nbsp;</el-link>
            <el-link type="primary" @click="playbackDelete(scope.row.playbackCode)">删除 &nbsp;</el-link>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
    <el-footer>
      <div style="text-align:right;">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryForm.page"
          :page-size="queryForm.size"
          layout="total, prev, pager, next"
          :total="total">
        </el-pagination>
      </div>
    </el-footer>

    <el-dialog
      width="60%"
      :title="title"
      :visible.sync="dialogVisible">
      <el-form :model="playbackForm" ref="playbackForm" :rules="playbackRules" label-width="180px">
        <el-form-item label="名称:" prop="title">
          <el-input v-model="playbackForm.title" maxlength="100" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="视频链接:" prop="videoUrl">
          <el-input v-model="playbackForm.videoUrl" maxlength="100" show-word-limit></el-input>
          <div>视频链接提取方法:
            <div>1.电脑打开qq视频链接
              2.鼠标移动至视频左下角分享按钮
              3.点击复制通用代码
              4.取复制内容中src的值
            </div>
          </div>
        </el-form-item>
        <el-form-item label="类型:" prop="playbackTypeCode">
          <el-select v-model="playbackForm.playbackTypeCode" placeholder="请选择">
            <el-option
              v-for="item in playbackTypeList"
              :key="item.playbackTypeCode"
              :label="item.typeName"
              :value="item.playbackTypeCode">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="内容描述:" prop="videoContent">
          <el-input type="textarea" maxlength="100" show-word-limit v-model="playbackForm.videoContent"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('playbackForm')">提交</el-button>
        <el-button @click="cancelCreate">取消</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
  import {request} from '@/api/fetch-api'
  import UploadItem from '@/components/UploadItem'

  let urls = {
    playbackTypeListUrl: '/tianbao_edu_api/admin/playbackType/list',
    playbackListUrl: '/tianbao_edu_api/admin/playback/list',
    playbackSaveUrl: '/tianbao_edu_api/admin/playback/save',
    playbackDelUrl: '/tianbao_edu_api/admin/playback/delete',
  }

  export default {
    components: {UploadItem},
    data() {
      return {
        playbackList: [],
        total: 0,
        loading: false,
        queryForm: {
          page: 1,
          size: 10,
          playbackTypeCode: '',
          title: ''
        },
        dialogVisible: false,
        title: '',
        playbackForm: {},
        playbackRules: {
          title: [{required: true, message: '请输入名称', trigger: 'blur'}],
          videoUrl: [{required: true, message: '请输入视频链接', trigger: 'blur'}],
          playbackTypeCode: [{required: true, message: '请选择', trigger: 'blur'}],
          videoContent: [{required: true, message: '请输入内容', trigger: 'blur'}]
        },
        playbackTypeList: []
      }
    },
    methods: {
      searchPlayback() {
        this.queryForm.page = 1
        this.initPlayBack()
      },
      initPlayBack() {
        this.loading = true
        request.get(urls.playbackListUrl, this.queryForm).then(data => {
          this.loading = false
          this.playbackList = data.content.list
          this.total = data.content.total
        }).catch(() => {

        })
      },
      initPlayBackType() {
        let form = {
          page: 1,
          size: 1000,
        }
        request.get(urls.playbackTypeListUrl, form).then(data => {
          this.playbackTypeList = data.content.list
        }).catch(() => {

        })
      },
      playbackEdit(row) {
        this.title = '编辑'
        this.dialogVisible = true
        this.playbackForm = JSON.parse(JSON.stringify(row))
      },
      playbackDelete(code) {
        this.$confirm('是否永远删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let form = {
            playbackCode: code
          }
          request.post(urls.playbackDelUrl, form).then(data => {
            this.initPlayBack()
            this.$message.success("删除成功")
          }).catch(() => {

          })
        }).catch(() => {

        })

      },
      cancelCreate() {
        this.dialogVisible = false
        this.playbackForm = {}
      },
      playbackCreate() {
        this.playbackForm = {}
        this.dialogVisible = true
        this.title = '创建'
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            request.post(urls.playbackSaveUrl, this.playbackForm).then(response => {
              this.dialogVisible = false
              this.$message.success("保存成功")
              this.initPlayBack()
            }).catch(() => {

            })
          } else {
            console.log('error submit!!')
            return false
          }
        })

      },
      /*分页*/
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`)
        this.queryForm.size = val
        this.queryForm.page = 1
        this.initPlayBack()
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`)
        this.queryForm.page = val
        this.initPlayBack()
      },

    },
    created() {
      this.initPlayBack()
      this.initPlayBackType()
    }
  }
</script>

<style scoped>

</style>