index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item>
  5. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  6. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  7. </el-form-item>
  8. </el-form>
  9. <el-row :gutter="10" class="mb8">
  10. <el-col :span="1.5">
  11. <el-button
  12. type="primary"
  13. plain
  14. icon="el-icon-plus"
  15. size="mini"
  16. @click="handleAdd"
  17. v-hasPermi="['video:AUXILIARYVIDEO:add']"
  18. >新增
  19. </el-button>
  20. </el-col>
  21. <el-col :span="1.5">
  22. <el-button
  23. type="success"
  24. plain
  25. icon="el-icon-edit"
  26. size="mini"
  27. :disabled="single"
  28. @click="handleUpdate"
  29. v-hasPermi="['video:AUXILIARYVIDEO:edit']"
  30. >修改
  31. </el-button>
  32. </el-col>
  33. <el-col :span="1.5">
  34. <el-button
  35. type="danger"
  36. plain
  37. icon="el-icon-delete"
  38. size="mini"
  39. :disabled="multiple"
  40. @click="handleDelete"
  41. v-hasPermi="['video:AUXILIARYVIDEO:remove']"
  42. >删除
  43. </el-button>
  44. </el-col>
  45. <el-col :span="1.5">
  46. <el-button
  47. type="warning"
  48. plain
  49. icon="el-icon-download"
  50. size="mini"
  51. @click="handleExport"
  52. v-hasPermi="['video:AUXILIARYVIDEO:export']"
  53. >导出
  54. </el-button>
  55. </el-col>
  56. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  57. </el-row>
  58. <el-table v-loading="loading" :data="AUXILIARYVIDEOList" @selection-change="handleSelectionChange">
  59. <el-table-column type="selection" width="55" align="center"/>
  60. <el-table-column label="标题" align="center" prop="title">
  61. </el-table-column>
  62. <el-table-column label="封面" align="center" prop="cover">
  63. </el-table-column>
  64. <el-table-column label="视频地址" align="center" prop="sourcePath">
  65. </el-table-column>
  66. <el-table-column label="是否置顶" align="center" prop="topFlat">
  67. </el-table-column>
  68. <el-table-column label="排序" align="center" prop="sort">
  69. </el-table-column>
  70. <el-table-column label="创建时间" align="center" prop="createTime">
  71. </el-table-column>
  72. <el-table-column label="创建人" align="center" prop="createBy">
  73. </el-table-column>
  74. <el-table-column label="修改时间" align="center" prop="updateTime">
  75. </el-table-column>
  76. <el-table-column label="来源" align="center" prop="sourceFrom">
  77. </el-table-column>
  78. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  79. <template slot-scope="scope">
  80. <el-button
  81. size="mini"
  82. type="text"
  83. icon="el-icon-edit"
  84. @click="handleUpdate(scope.row)"
  85. v-hasPermi="['video:AUXILIARYVIDEO:edit']"
  86. >修改
  87. </el-button>
  88. <el-button
  89. size="mini"
  90. type="text"
  91. icon="el-icon-delete"
  92. @click="handleDelete(scope.row)"
  93. v-hasPermi="['video:AUXILIARYVIDEO:remove']"
  94. >删除
  95. </el-button>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. <pagination
  100. v-show="total>0"
  101. :total="total"
  102. :page.sync="queryParams.pageNum"
  103. :limit.sync="queryParams.pageSize"
  104. @pagination="getList"
  105. />
  106. <el-dialog title="视频预览" :append-to-body="true" :visible.sync="dialogVisible" width="50%">
  107. <video :src="videoUrl" controls width="100%" height="auto"></video>
  108. </el-dialog>
  109. <el-dialog :title="title" :visible.sync="open" title="Dialog Title">
  110. <el-row :gutter="15">
  111. <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
  112. <el-col :span="17">
  113. <el-form-item label="视频文件" prop="sourcePath" required>
  114. <el-upload ref="sourcePath"
  115. :file-list="sourcePathfileList"
  116. :multiple="false"
  117. :limit="1"
  118. :action="sourcePathAction"
  119. list-type="picture"
  120. accept="video/*">
  121. <el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
  122. </el-upload>
  123. </el-form-item>
  124. </el-col>
  125. <el-col :span="20">
  126. <el-form-item label="标题" prop="title">
  127. <el-input v-model="formData.title" placeholder="请输入标题" clearable :style="{width: '100%'}">
  128. </el-input>
  129. </el-form-item>
  130. </el-col>
  131. <el-col :span="20">
  132. <el-form-item label="来源" prop="sourceFrom">
  133. <el-input v-model="formData.sourceFrom" placeholder="请输入来源" clearable :style="{width: '100%'}">
  134. </el-input>
  135. </el-form-item>
  136. </el-col>
  137. <el-col :span="17">
  138. <el-form-item label="置顶" prop="topFlat">
  139. <el-radio-group v-model="formData.topFlat" size="medium">
  140. <el-radio v-for="(item, index) in topFlatOptions" :key="index" :label="item.value"
  141. :disabled="item.disabled">{{ item.label }}
  142. </el-radio>
  143. </el-radio-group>
  144. </el-form-item>
  145. </el-col>
  146. </el-form>
  147. </el-row>
  148. <div slot="footer">
  149. <el-button @click="close">取消</el-button>
  150. <el-button type="primary" @click="handleConfirm">确定</el-button>
  151. </div>
  152. </el-dialog>
  153. </div>
  154. </template>
  155. <script>
  156. import {getAUXILIARYVIDEO, listAUXILIARYVIDEO} from "@/api/auxiliary/auxiliary";
  157. export default {
  158. name: "AUXILIARYVIDEO",
  159. data() {
  160. return {
  161. // 根路径
  162. baseURL: process.env.VUE_APP_BASE_API,
  163. formData: {
  164. sourcePath: null,
  165. cover: null,
  166. title: undefined,
  167. sourceFrom: undefined,
  168. topFlat: 1,
  169. },
  170. rules: {
  171. title: [{
  172. required: true,
  173. message: '请输入标题',
  174. trigger: 'blur'
  175. }],
  176. sourceFrom: [],
  177. },
  178. sourcePathAction: process.env.VUE_APP_BASE_API + '/portal_api/common/uploadVideo',
  179. sourcePathfileList: [],
  180. coverAction: 'https://jsonplaceholder.typicode.com/posts/',
  181. coverfileList: [],
  182. topFlatOptions: [{
  183. "label": "是",
  184. "value": 1
  185. }, {
  186. "label": "否",
  187. "value": 0
  188. }],
  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. AUXILIARYVIDEOList: [],
  203. // 弹出层标题
  204. title: "",
  205. // 是否显示弹出层
  206. open: false,
  207. // 查询参数
  208. queryParams: {
  209. pageNum: 1,
  210. pageSize: 10,
  211. id: null,
  212. title: null,
  213. cover: null,
  214. sourcePath: null,
  215. topFlat: null,
  216. sort: null,
  217. createTime: null,
  218. createBy: null,
  219. updateTime: null,
  220. updateBy: null,
  221. sourceFrom: null
  222. },
  223. fileList: [],
  224. dialogVisible: false,
  225. videoUrl: '',
  226. // 表单参数
  227. form: {},
  228. };
  229. },
  230. created() {
  231. this.getList();
  232. },
  233. methods: {
  234. handleConfirm() {
  235. this.$refs['elForm'].validate(valid => {
  236. if (!valid) return
  237. this.close()
  238. })
  239. },
  240. handleBeforeUpload(file) {
  241. console.log(file.size);
  242. // 清空之前的上传记录,只保留最新上传的视频
  243. this.fileList = [file];
  244. // 执行截图操作
  245. this.captureThumbnail(file);
  246. return false; // 禁止自动上传
  247. },
  248. handleUploadSuccess(response, file) {
  249. // 上传成功后处理
  250. this.$message.success('上传成功');
  251. // 可以在这里保存视频的相关信息,如视频地址等
  252. },
  253. handleUploadError(err, file) {
  254. // 上传失败处理
  255. this.$message.error('上传失败,请重试');
  256. },
  257. captureThumbnail(file) {
  258. const video = document.createElement('video');
  259. video.preload = 'metadata';
  260. console.log(111);
  261. console.log(video);
  262. // 监听视频加载元数据完成事件
  263. video.onloadedmetadata = () => {
  264. // 创建 canvas 元素用于绘制截图
  265. const canvas = document.createElement('canvas');
  266. canvas.width = video.videoWidth;
  267. canvas.height = video.videoHeight;
  268. const ctx = canvas.getContext('2d');
  269. // 在 canvas 上绘制视频第一帧
  270. ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
  271. // 生成截图的 base64 数据 URL
  272. const thumbnailUrl = canvas.toDataURL('image/jpeg');
  273. // 打印截图的数据 URL
  274. console.log(thumbnailUrl);
  275. // 显示截图
  276. this.dialogVisible = true;
  277. this.videoUrl = thumbnailUrl;
  278. };
  279. video.src = URL.createObjectURL(file);
  280. },
  281. /** 查询通关视频列表 */
  282. getList() {
  283. this.loading = true;
  284. listAUXILIARYVIDEO(this.queryParams).then(response => {
  285. this.AUXILIARYVIDEOList = response.rows;
  286. this.total = response.total;
  287. this.loading = false;
  288. });
  289. },
  290. // 取消按钮
  291. cancel() {
  292. this.open = false;
  293. this.reset();
  294. },
  295. // 表单重置
  296. reset() {
  297. this.form = {
  298. id: null,
  299. title: null,
  300. cover: null,
  301. sourcePath: null,
  302. topFlat: null,
  303. sort: null,
  304. sourceFrom: null
  305. };
  306. this.resetForm("form");
  307. },
  308. /** 搜索按钮操作 */
  309. handleQuery() {
  310. this.queryParams.pageNum = 1;
  311. this.getList();
  312. },
  313. /** 重置按钮操作 */
  314. resetQuery() {
  315. this.resetForm("queryForm");
  316. this.handleQuery();
  317. },
  318. // 多选框选中数据
  319. handleSelectionChange(selection) {
  320. this.ids = selection.map(item => item.id)
  321. this.single = selection.length !== 1
  322. this.multiple = !selection.length
  323. },
  324. /** 新增按钮操作 */
  325. handleAdd() {
  326. this.reset();
  327. this.open = true;
  328. this.title = "添加通关视频";
  329. },
  330. /** 修改按钮操作 */
  331. handleUpdate(row) {
  332. this.reset();
  333. const id = row.id || this.ids
  334. getAUXILIARYVIDEO(id).then(response => {
  335. this.form = response.data;
  336. this.open = true;
  337. this.title = "修改通关视频";
  338. });
  339. },
  340. /** 提交按钮 */
  341. submitForm() {
  342. this.$refs["form"].validate(valid => {
  343. if (valid) {
  344. if (this.form.id != null) {
  345. updateAUXILIARYVIDEO(this.form).then(response => {
  346. this.$modal.msgSuccess("修改成功");
  347. this.open = false;
  348. this.getList();
  349. });
  350. } else {
  351. addAUXILIARYVIDEO(this.form).then(response => {
  352. this.$modal.msgSuccess("新增成功");
  353. this.open = false;
  354. this.getList();
  355. });
  356. }
  357. }
  358. });
  359. },
  360. /** 删除按钮操作 */
  361. handleDelete(row) {
  362. const ids = row.id || this.ids;
  363. this.$modal.confirm('是否确认删除通关视频编号为"' + ids + '"的数据项?').then(function () {
  364. return delAUXILIARYVIDEO(ids);
  365. }).then(() => {
  366. this.getList();
  367. this.$modal.msgSuccess("删除成功");
  368. }).catch(() => {
  369. });
  370. },
  371. /** 导出按钮操作 */
  372. handleExport() {
  373. this.download('video/AUXILIARYVIDEO/export', {
  374. ...this.queryParams
  375. }, `AUXILIARYVIDEO_${new Date().getTime()}.xlsx`)
  376. }
  377. }
  378. };
  379. </script>