index.vue 14 KB

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