index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--视频类型-->
  5. <el-col :span="4" :xs="24">
  6. <div class="head-container">
  7. <el-input v-model="deptName" placeholder="请输入部门名称" clearable size="small" prefix-icon="el-icon-search" style="margin-bottom: 20px" />
  8. </div>
  9. <div class="head-container">
  10. <el-tree
  11. :data="deptOptions"
  12. :props="defaultProps"
  13. :expand-on-click-node="false"
  14. :filter-node-method="filterNode"
  15. ref="tree"
  16. default-expand-all
  17. highlight-current
  18. @node-click="handleNodeClick"
  19. />
  20. </div>
  21. </el-col>
  22. <!--视频数据-->
  23. <el-col :span="20" :xs="24">
  24. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  25. <el-form-item label="视频标题" prop="title">
  26. <el-input
  27. v-model="queryParams.title"
  28. placeholder="请输入视频标题"
  29. clearable
  30. size="small"
  31. style="width: 240px"
  32. @keyup.enter.native="handleQuery"
  33. />
  34. </el-form-item>
  35. <el-form-item label="上架状态" prop="title">
  36. <el-select v-model="queryParams.shelfStatus" placeholder="请选择状态">
  37. <el-option label="全部" :value="null"> </el-option>
  38. <el-option label="已上架" :value="0"> </el-option>
  39. <el-option label="未上架" :value="1"> </el-option>
  40. </el-select>
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  44. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  45. </el-form-item>
  46. </el-form>
  47. <el-row :gutter="10" class="mb8">
  48. <el-col :span="1.5">
  49. <el-button v-if="pid != 0" type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:user:add']"
  50. >新增</el-button
  51. >
  52. </el-col>
  53. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  54. </el-row>
  55. <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
  56. <el-table-column label="视频id" align="center" prop="id" />
  57. <el-table-column label="视频标题" align="center" prop="title" />
  58. <el-table-column label="视频描述" align="center" prop="videoDescribe" />
  59. <!-- <el-table-column label="视频预览" align="center" width="300px">
  60. <template slot-scope="scope">
  61. <video :src="scope.row.fileUrl" class="videoPreview" :poster="scope.row.coverFileUrl" controls preload="meta"></video>
  62. </template>
  63. </el-table-column> -->
  64. <el-table-column label="视频封面" align="center" width="200px">
  65. <template slot-scope="scope">
  66. <div>
  67. <el-card :body-style="{ padding: '0 0 5px' }">
  68. <img :src="scope.row.coverFileUrl" class="imgPreview" />
  69. <el-button type="primary" size="mini" @click="videoPreview(scope.row.fileUrl)" :disabled="!scope.row.fileUrl">预览视频</el-button>
  70. </el-card>
  71. </div>
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="视频时长" align="center">
  75. <template slot-scope="scope">
  76. <span>{{ new Date(scope.row.videoDuration * 1000).toISOString().slice(11, 19) }}</span>
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="视频分类" align="center" prop="teachingVideoTypeName" :show-overflow-tooltip="true" />
  80. <el-table-column label="上架状态" align="center">
  81. <template slot-scope="scope">
  82. <el-switch v-model="scope.row.shelfStatus" :active-value="0" :inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
  83. </template>
  84. </el-table-column>
  85. <el-table-column label="创建时间" align="center" prop="createTime" width="160">
  86. <template slot-scope="scope">
  87. <span>{{ parseTime(scope.row.createTime) }}</span>
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
  91. <template slot-scope="scope">
  92. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:user:edit']"
  93. >修改</el-button
  94. >
  95. <el-button
  96. v-if="scope.row.userId !== 1"
  97. size="mini"
  98. type="text"
  99. icon="el-icon-delete"
  100. @click="handleDelete(scope.row)"
  101. v-hasPermi="['system:user:remove']"
  102. >删除</el-button
  103. >
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  108. </el-col>
  109. </el-row>
  110. <!-- 添加或修改参数配置对话框 -->
  111. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  112. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  113. <el-row>
  114. <el-col :span="24">
  115. <el-form-item label="视频标题" prop="title">
  116. <el-input v-model="form.title" placeholder="请输入视频标题" />
  117. </el-form-item>
  118. </el-col>
  119. </el-row>
  120. <el-row>
  121. <el-col :span="24">
  122. <el-form-item label="视频描述">
  123. <el-input v-model="form.videoDescribe" type="textarea" placeholder="请输入内容"></el-input>
  124. </el-form-item>
  125. </el-col>
  126. </el-row>
  127. <el-row>
  128. <el-col :span="12">
  129. <el-form-item label="视频文件">
  130. <input type="file" accept="video/*" ref="videoFile" @change="fileUpload" />
  131. </el-form-item>
  132. </el-col>
  133. <el-col :span="12">
  134. <el-form-item v-if="form.userId == undefined" label="上传进度">
  135. <el-progress
  136. :text-inside="true"
  137. :stroke-width="24"
  138. :percentage="videoPercentage"
  139. :status="form.vodVideoFileId ? 'success' : ''"
  140. ></el-progress>
  141. </el-form-item>
  142. </el-col>
  143. </el-row>
  144. <el-row>
  145. <el-col :span="12">
  146. <el-form-item label="视频封面">
  147. <input type="file" accept="image/*" ref="coverFile" @change="coverUpload" :disabled="form.vodVideoFileId == null" />
  148. </el-form-item>
  149. </el-col>
  150. <el-col :span="12">
  151. <el-form-item v-if="form.userId == undefined" label="上传进度">
  152. <el-progress
  153. :text-inside="true"
  154. :stroke-width="24"
  155. :percentage="imagePercentage"
  156. :status="form.coverFileId ? 'success' : ''"
  157. ></el-progress>
  158. </el-form-item>
  159. </el-col>
  160. </el-row>
  161. </el-form>
  162. <div slot="footer" class="dialog-footer">
  163. <el-button type="primary" @click="submitForm">确 定</el-button>
  164. <el-button @click="cancel">取 消</el-button>
  165. </div>
  166. </el-dialog>
  167. </div>
  168. </template>
  169. <script>
  170. import { listUser, getUser, delVideo, addUser, updateUser, changeUserStatus, uploadCover } from '@/api/teachingVideo/index'
  171. import { treeselect } from '@/api/videoType'
  172. import Treeselect from '@riophae/vue-treeselect'
  173. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  174. import { vodSignature } from '@/api/upload'
  175. import TcVod from 'vod-js-sdk-v6'
  176. import VideoPreview from '@/components/VideoPreview/index'
  177. export default {
  178. name: 'User',
  179. components: { Treeselect },
  180. data() {
  181. return {
  182. pid: 0,
  183. teachingVideoTypeId: 0,
  184. videoPercentage: 0,
  185. imagePercentage: 0,
  186. mediaFile: null,
  187. coverFile: null,
  188. tcVod: null,
  189. // 遮罩层
  190. loading: true,
  191. // 选中数组
  192. ids: [],
  193. // 非单个禁用
  194. single: true,
  195. // 非多个禁用
  196. multiple: true,
  197. // 显示搜索条件
  198. showSearch: true,
  199. // 总条数
  200. total: 0,
  201. // 用户表格数据
  202. userList: null,
  203. // 弹出层标题
  204. title: '',
  205. // 部门树选项
  206. deptOptions: undefined,
  207. // 是否显示弹出层
  208. open: false,
  209. // 部门名称
  210. deptName: undefined,
  211. // 日期范围
  212. dateRange: [],
  213. // 状态数据字典
  214. statusOptions: [],
  215. // 表单参数
  216. form: {},
  217. defaultProps: {
  218. children: 'children',
  219. label: 'typeName'
  220. },
  221. // 查询参数
  222. queryParams: {
  223. pageNum: 1,
  224. pageSize: 10
  225. },
  226. // 表单校验
  227. rules: {
  228. userName: [{ required: true, message: '用户名称不能为空', trigger: 'blur' }]
  229. }
  230. }
  231. },
  232. watch: {
  233. // 根据名称筛选部门树
  234. deptName(val) {
  235. this.$refs.tree.filter(val)
  236. }
  237. },
  238. async created() {
  239. this.tcVod = new TcVod({
  240. getSignature: vodSignature
  241. })
  242. this.getList()
  243. this.getTreeselect()
  244. this.getDicts('sys_normal_disable').then(response => {
  245. this.statusOptions = response.data
  246. })
  247. },
  248. methods: {
  249. videoPreview(videoSrc) {
  250. VideoPreview(videoSrc)
  251. },
  252. //上传视频
  253. fileUpload(e) {
  254. this.mediaFile = e.target.files[0]
  255. if (!this.mediaFile.type.includes('video')) {
  256. this.msgError('请选择视频文件')
  257. return false
  258. }
  259. this.videoPercentage = 0
  260. const uploader = this.tcVod.upload({
  261. mediaFile: this.mediaFile // 媒体文件(视频或音频或图片),类型为 File
  262. })
  263. uploader.on('media_progress', info => {
  264. this.videoPercentage = Math.floor(info.percent * 100 * 100) / 100
  265. })
  266. uploader.done().then(doneResult => {
  267. this.$set(this.form, 'vodVideoFileId', doneResult.fileId)
  268. })
  269. },
  270. //上传封面
  271. async coverUpload(e) {
  272. this.coverFile = e.target.files[0]
  273. if (!this.coverFile.type.includes('image')) {
  274. this.msgError('请选择视频文件')
  275. return false
  276. }
  277. this.imagePercentage = 0
  278. let formData = new FormData()
  279. formData.append('coverFile', this.coverFile)
  280. formData.append('fileId', this.form.vodVideoFileId)
  281. let { data } = await uploadCover(formData, e => {
  282. this.imagePercentage = Math.floor((e.loaded / e.total) * 100 * 100) / 100
  283. })
  284. this.$set(this.form, 'coverFileId', data.fileId)
  285. },
  286. /** 查询用户列表 */
  287. getList() {
  288. this.loading = true
  289. listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  290. this.userList = response.rows
  291. this.total = response.total
  292. this.loading = false
  293. })
  294. },
  295. /** 查询部门下拉树结构 */
  296. getTreeselect() {
  297. treeselect().then(response => {
  298. this.deptOptions = response.data
  299. })
  300. },
  301. // 筛选节点
  302. filterNode(value, data) {
  303. if (!value) return true
  304. return data.typeName.indexOf(value) !== -1
  305. },
  306. // 节点单击事件
  307. handleNodeClick(data) {
  308. this.queryParams.teachingVideoTypeId = data.id
  309. this.teachingVideoTypeId = data.id
  310. this.pid = data.pid
  311. this.getList()
  312. },
  313. // 用户状态修改
  314. handleStatusChange(row) {
  315. let text = row.shelfStatus === 0 ? '上架' : '下架'
  316. this.$confirm('确认要"' + text + '""' + row.title + '"视频吗?', '警告', {
  317. confirmButtonText: '确定',
  318. cancelButtonText: '取消',
  319. type: 'warning'
  320. })
  321. .then(() => {
  322. return changeUserStatus(row.id, row.shelfStatus)
  323. })
  324. .then(() => {
  325. this.msgSuccess(text + '成功')
  326. })
  327. .catch(() => {
  328. row.shelfStatus = row.shelfStatus === '0' ? '1' : '0'
  329. })
  330. },
  331. // 取消按钮
  332. cancel() {
  333. this.open = false
  334. this.reset()
  335. },
  336. // 表单重置
  337. reset() {
  338. this.form = {}
  339. // this.$refs.videoFile.resetFields()
  340. // this.$refs.coverFile.resetFields()
  341. this.videoPercentage = 0
  342. this.imagePercentage = 0
  343. this.resetForm('form')
  344. },
  345. /** 搜索按钮操作 */
  346. handleQuery() {
  347. this.queryParams.page = 1
  348. this.getList()
  349. },
  350. /** 重置按钮操作 */
  351. resetQuery() {
  352. this.dateRange = []
  353. this.resetForm('queryForm')
  354. this.handleQuery()
  355. },
  356. // 多选框选中数据
  357. handleSelectionChange(selection) {
  358. this.ids = selection.map(item => item.userId)
  359. this.single = selection.length != 1
  360. this.multiple = !selection.length
  361. },
  362. /** 新增按钮操作 */
  363. handleAdd() {
  364. this.reset()
  365. this.getTreeselect()
  366. this.open = true
  367. this.title = '添加视频'
  368. },
  369. /** 修改按钮操作 */
  370. handleUpdate(row) {
  371. this.reset()
  372. this.getTreeselect()
  373. const userId = row.id || this.ids
  374. getUser(userId).then(response => {
  375. this.form = response.data
  376. this.open = true
  377. this.title = '修改视频信息'
  378. })
  379. },
  380. /**校验form */
  381. validate: function(form) {
  382. console.log(form)
  383. if (!form.title) {
  384. this.msgError('标题必填')
  385. return false
  386. }
  387. if (!form.vodVideoFileId) {
  388. this.msgError('视频未上传成功')
  389. return false
  390. }
  391. if (!form.coverFileId) {
  392. this.msgError('封面未上传成功')
  393. return false
  394. }
  395. return true
  396. },
  397. /** 提交按钮 */
  398. submitForm: function() {
  399. if (this.validate(this.form)) {
  400. if (this.form.id != undefined) {
  401. let data = {
  402. teachingVideoTypeId: this.form.teachingVideoTypeId,
  403. id: this.form.id,
  404. title: this.form.title,
  405. videoDescribe: this.form.videoDescribe,
  406. videoFileId: this.form.vodVideoFileId,
  407. coverFileId: this.form.coverFileId
  408. }
  409. updateUser(data).then(response => {
  410. this.msgSuccess('修改成功')
  411. this.open = false
  412. this.getList()
  413. })
  414. } else {
  415. let data = {
  416. teachingVideoTypeId: this.teachingVideoTypeId,
  417. id: this.form.id,
  418. title: this.form.title,
  419. videoDescribe: this.form.videoDescribe,
  420. videoFileId: this.form.vodVideoFileId,
  421. coverFileId: this.form.coverFileId
  422. }
  423. addUser(data).then(response => {
  424. this.msgSuccess('新增成功')
  425. this.open = false
  426. this.getList()
  427. })
  428. }
  429. }
  430. },
  431. /** 删除按钮操作 */
  432. handleDelete(row) {
  433. console.log(row)
  434. const userIds = row.id
  435. this.$confirm('是否确认删除id为"' + userIds + '"的数据项?', '警告', {
  436. confirmButtonText: '确定',
  437. cancelButtonText: '取消',
  438. type: 'warning'
  439. })
  440. .then(function() {
  441. console.log('确定')
  442. return delVideo(userIds)
  443. })
  444. .then(() => {
  445. this.getList()
  446. this.msgSuccess('删除成功')
  447. })
  448. }
  449. }
  450. }
  451. </script>
  452. <style lang="scss" scoped>
  453. .videoPreview {
  454. object-fit: contain;
  455. height: 180px;
  456. }
  457. .imgPreview {
  458. object-fit: contain;
  459. width: 200px;
  460. }
  461. </style>