index.vue 7.66 KB
<template>
  <div class="app-container">
    <el-header height>
      <el-input type="primary" v-model="queryForm.videoName" placeholder="视频名" style="width: 200px" clearable></el-input>
      <el-select v-model="queryForm.videoTypeCode" placeholder="请选择" clearable @change="searchVideo">
        <el-option
          v-for="item in videoTypeList"
          :key="item.videoTypeCode"
          :label="item.typeName"
          :value="item.videoTypeCode">
          <span style="float: left">{{ item.typeName }}</span>
          <span style="float: right; color: #8492a6; font-size: 13px" v-if="item.machine===1">软件</span>
          <span style="float: right; color: #8492a6; font-size: 13px" v-if="item.machine===0">硬件</span>
        </el-option>
      </el-select>
      <el-button type="primary" @click="searchVideo">搜索</el-button>
      <el-button type="primary" @click="videoCreate">创建</el-button>
    </el-header>
    <el-main>
      <el-table
        :data="videoList"
        style="width: 100%"
        stripe
        highlight-current-row
        v-loading="loading"
      >
        <el-table-column label="名称" prop="videoName"></el-table-column>
        <el-table-column label="视频链接" prop="videoUrl">
          <!--<template slot-scope="scope">-->
          <!--<video :src="scope.row.videoUrl" controls="controls"></video>-->
          <!--</template>-->
        </el-table-column>
        <el-table-column label="类型" prop="typeName">
        </el-table-column>
        <el-table-column label="内容" prop="videoContent">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-link type="primary" @click="videoEdit(scope.row)">编辑 &nbsp;</el-link>
            <el-link type="primary" @click="videoDelete(scope.row.videoCode)">删除 &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="videoForm" ref="videoForm" :rules="videoRules" label-width="180px">
        <el-form-item label="名称:" prop="videoName">
          <el-input v-model="videoForm.videoName" maxlength="100" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="视频链接:" prop="videoUrl">
          <el-input v-model="videoForm.videoUrl" maxlength="255" show-word-limit></el-input>
          <div>视频链接提取方法:
            <div>1.电脑打开qq视频链接
              2.鼠标移动至视频左下角分享按钮
              3.点击复制通用代码
              4.取复制内容中src的值
            </div>
          </div>
        </el-form-item>
        <el-form-item label="类型:" prop="videoTypeCode">
          <el-select v-model="videoForm.videoTypeCode" placeholder="请选择">
            <el-option
              v-for="item in videoTypeList"
              :key="item.videoTypeCode"
              :label="item.typeName"
              :value="item.videoTypeCode">
              <span style="float: left">{{ item.typeName }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px" v-if="item.machine===1">软件</span>
              <span style="float: right; color: #8492a6; font-size: 13px" v-if="item.machine===0">硬件</span>
            </el-option>

          </el-select>
        </el-form-item>
        <el-form-item label="内容描述:" prop="videoContent">
          <el-input type="textarea" maxlength="100" show-word-limit v-model="videoForm.videoContent"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('videoForm')">提交</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 = {
    videoTypeListUrl: '/tianbao_edu_api/admin/videoType/list',
    videoListUrl: '/tianbao_edu_api/admin/video/list',
    videoSaveUrl: '/tianbao_edu_api/admin/video/save',
    videoDelUrl: '/tianbao_edu_api/admin/video/delete',
  }

  export default {
    components: {UploadItem},
    data() {
      return {
        videoList: [],
        total: 0,
        loading: false,
        queryForm: {
          page: 1,
          size: 10,
          videoName: '',
          videoTypeCode:''
        },
        dialogVisible: false,
        title: '',
        videoForm: {},
        videoRules: {
          videoName: [{required: true, message: '请输入名称', trigger: 'blur'}],
          videoUrl: [{required: true, message: '上传缩略图', trigger: 'blur'}],
          videoTypeCode: [{required: true, message: '请选择', trigger: 'blur'}],
          videoContent:[{required: true, message: '请填写', trigger: 'blur'}]
        },
        videoTypeList: []
      }
    },
    methods: {
      initVideo() {
        this.loading = true
        request.get(urls.videoListUrl, this.queryForm).then(data => {
          this.loading = false
          this.videoList = data.content.list
          this.total = data.content.total
        }).catch(() => {

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

        })
      },
      searchVideo(){
        this.queryForm.page=1
        this.initVideo()
      },
      videoEdit(row) {
        this.title = '编辑'
        this.dialogVisible = true
        this.videoForm = JSON.parse(JSON.stringify(row))
      },
      videoDelete(code) {
        this.$confirm('是否永远删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let form = {
            videoCode: code
          }
          request.post(urls.videoDelUrl, form).then(data => {
            this.initVideo()
            this.$message.success("删除成功")
          }).catch(() => {

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

        })

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

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

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

    },
    created() {
      this.initVideo();
      this.initVideoType();
    }
  }
</script>

<style scoped>

</style>