index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="附件名称" prop="imageName">
  5. <el-input v-model="queryParams.imageName" placeholder="请输入附件名称" clearable size="small"
  6. @keyup.enter.native="handleQuery" />
  7. </el-form-item>
  8. <!-- <el-form-item label="附件简介" prop="imageIntroduce">
  9. <el-input v-model="queryParams.imageIntroduce" placeholder="请输入附件简介" clearable size="small"
  10. @keyup.enter.native="handleQuery" />
  11. </el-form-item> -->
  12. <el-form-item label="附件类型" prop="type">
  13. <el-select v-model="queryParams.type" placeholder="请选择附件类型" clearable size="small">
  14. <el-option v-for="dict in dict.type.image_type" :key="dict.value" :label="dict.label" :value="dict.value" />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item label="附件状态" prop="status">
  18. <el-select v-model="queryParams.status" placeholder="请选择附件状态">
  19. <el-option v-for="dict in dict.type.image_status" :key="dict.value" :label="dict.label"
  20. :value="dict.value"></el-option>
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  25. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  26. </el-form-item>
  27. </el-form>
  28. <el-row :gutter="10" class="mb8">
  29. <el-col :span="1.5">
  30. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  31. v-hasPermi="['system:image:add']">新增</el-button>
  32. </el-col>
  33. <el-col :span="1.5">
  34. <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
  35. v-hasPermi="['system:image:edit']">修改</el-button>
  36. </el-col>
  37. <el-col :span="1.5">
  38. <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
  39. v-hasPermi="['system:image:remove']">删除</el-button>
  40. </el-col>
  41. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  42. </el-row>
  43. <el-table v-loading="loading" :data="imageList" @selection-change="handleSelectionChange" :max-height="tableMaxHeight">
  44. <el-table-column type="selection" width="55" align="center" />
  45. <!-- <el-table-column label="附件ID" align="center" prop="imageId" /> -->
  46. <el-table-column label="附件名称" align="center" prop="imageName" />
  47. <el-table-column label="附件内容" align="center" prop="imageContent" width="110px">
  48. <template slot-scope="scope">
  49. <img @click="imagew(scope.row.imageContent)" :src="defaultSettings.urls + '/prod-api' + scope.row.imageContent"
  50. style="width: 100px;height: 100px;" />
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="附件简介" align="center" prop="imageIntroduce" />
  54. <el-table-column label="附件类型" align="center" prop="type">
  55. <template slot-scope="scope">
  56. <dict-tag :options="dict.type.image_type" :value="scope.row.type" />
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="附件状态" align="center" prop="status">
  60. <template slot-scope="scope">
  61. <dict-tag :options="dict.type.image_status" :value="scope.row.status" />
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="备注" align="center" prop="remark" />
  65. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  66. <template slot-scope="scope">
  67. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  68. v-hasPermi="['system:image:edit']">修改</el-button>
  69. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  70. v-hasPermi="['system:image:remove']">删除</el-button>
  71. </template>
  72. </el-table-column>
  73. </el-table>
  74. <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
  75. @pagination="getList" />
  76. <!-- 添加或修改附件信息对话框 -->
  77. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  78. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  79. <el-row>
  80. <el-col :span="12">
  81. <el-form-item label="附件名称" prop="imageName">
  82. <el-input v-model="form.imageName" placeholder="请输入附件名称" />
  83. </el-form-item>
  84. </el-col>
  85. <el-col :span="12">
  86. <el-form-item label="附件类型" prop="type">
  87. <el-select v-model="form.type" placeholder="请选择附件类型">
  88. <el-option v-for="dict in dict.type.image_type" :key="dict.value" :label="dict.label"
  89. :value="dict.value"></el-option>
  90. </el-select>
  91. </el-form-item>
  92. </el-col>
  93. <el-col :span="12">
  94. <el-form-item label="附件简介" prop="imageIntroduce">
  95. <el-input v-model="form.imageIntroduce" placeholder="请输入附件简介" />
  96. </el-form-item>
  97. </el-col>
  98. <el-col :span="12">
  99. <el-form-item label="附件状态" prop="status">
  100. <el-select v-model="form.status" placeholder="请选择附件状态">
  101. <el-option v-for="dict in dict.type.image_status" :key="dict.value" :label="dict.label"
  102. :value="dict.value"></el-option>
  103. </el-select>
  104. </el-form-item>
  105. </el-col>
  106. <el-col :span="24">
  107. <el-form-item label="附件内容">
  108. <fileUploads v-model="form.imageContent" />
  109. </el-form-item>
  110. </el-col>
  111. <el-col :span="24">
  112. <el-form-item label="备注" prop="remark">
  113. <el-input v-model="form.remark" placeholder="请输入备注" />
  114. </el-form-item>
  115. </el-col>
  116. </el-row>
  117. </el-form>
  118. <div slot="footer" class="dialog-footer">
  119. <el-button type="primary" @click="submitForm">确 定</el-button>
  120. <el-button @click="cancel">取 消</el-button>
  121. </div>
  122. </el-dialog>
  123. <el-dialog title="图片预览" :visible.sync="opende" width="1000px" append-to-body style="text-align: center;">
  124. <img :src="defaultSettings.urls + '/prod-api'+ urls" style="width: 80%;" v-if="jeuhse == false">
  125. <video-player v-if="jeuhse == true" style="width: 960px; " class="video-player vjs-custom-skin" ref="videoPlayer" name="videoPlayer" id="video"
  126. :playsinline="true" :options="playerOptions" @play="onPlayerPlay($event)"
  127. @pause="onPlayerPause($event)" @ended="onPlayerEnded($event)" @waiting="onPlayerWaiting($event)"
  128. @timeupdate="onPlayerTimeupdate($event)" @statechanged="playerStateChanged($event)"
  129. @canplaythrough="onPlayerCanplaythrough($event)" @ready="playerReadied"></video-player>
  130. </el-dialog>
  131. </div>
  132. </template>
  133. <script>
  134. import {
  135. listImage,
  136. getImage,
  137. delImage,
  138. addImage,
  139. updateImage
  140. } from "@/api/system/image";
  141. const defaultSettings = require("@/settings.js");
  142. import {
  143. videoPlayer
  144. } from "vue-video-player";
  145. import "video.js/dist/video-js.css";
  146. import "vue-video-player/src/custom-theme.css";
  147. export default {
  148. name: "showVideo",
  149. dicts: ['image_type', 'image_status' ,],
  150. components: {
  151. videoPlayer
  152. },
  153. data() {
  154. return {
  155. // 遮罩层
  156. loading: true,
  157. process: process.env.VUE_APP_BASE_API,
  158. // 选中数组
  159. ids: [],
  160. // 非单个禁用
  161. single: true,
  162. // 非多个禁用
  163. multiple: true,
  164. // 显示搜索条件
  165. showSearch: true,
  166. // 总条数
  167. total: 0,
  168. // 附件信息表格数据
  169. imageList: [],
  170. del: [],
  171. urls: '',
  172. // 弹出层标题
  173. title: "",
  174. // 是否显示弹出层
  175. open: false,
  176. defaultSettings,
  177. // 查询参数
  178. queryParams: {
  179. pageNum: 1,
  180. pageSize: 10,
  181. imageName: null,
  182. imageIntroduce: null,
  183. status: null,
  184. type: null,
  185. isDel: null,
  186. },
  187. // 表单参数
  188. form: {},
  189. // 表单校验
  190. rules: {
  191. imageName: [{
  192. required: true,
  193. message: "附件名称不能为空",
  194. trigger: "blur"
  195. }],
  196. },
  197. opende: false,
  198. playTime: '',
  199. current: '',
  200. playerOptions: {
  201. playbackRates: [0.5, 1.0, 1.5, 2.0], // 可选的播放速度
  202. autoplay: false, // 如果为true,浏览器准备好时开始回放。
  203. muted: false, // 默认情况下将会消除任何音频。
  204. loop: false, // 是否视频一结束就重新开始。
  205. preload: "auto", // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
  206. language: "zh-CN",
  207. aspectRatio: "16:9", // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
  208. fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
  209. sources: [{
  210. type: "video/mp4", // 类型
  211. src: "" // url地址
  212. }],
  213. poster: "", // 封面地址
  214. notSupportedMessage: "此视频暂无法播放,请稍后再试", // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
  215. controlBar: {
  216. timeDivider: true, // 当前时间和持续时间的分隔符
  217. durationDisplay: true, // 显示持续时间
  218. remainingTimeDisplay: false, // 是否显示剩余时间功能
  219. fullscreenToggle: true ,// 是否显示全屏按钮
  220. }
  221. },
  222. jeuhse:false,
  223. tableMaxHeight:300
  224. };
  225. },
  226. created() {
  227. this.getList();
  228. window.onresize = () => {
  229. this.changeTableMaxHeight()
  230. }
  231. this.changeTableMaxHeight()
  232. },
  233. destroyed () {
  234. window.onresize = null
  235. },
  236. mounted() {
  237. window.onresize = () => {
  238. this.changeTableMaxHeight()
  239. }
  240. this.changeTableMaxHeight()
  241. },
  242. methods: {
  243. /** 查询附件信息列表 */
  244. getList() {
  245. this.loading = true;
  246. listImage(this.queryParams).then(response => {
  247. this.imageList = response.rows;
  248. // this.imageList.filter( router =>{
  249. // //  #响应成功的数据中提取url赋值给变量url
  250. // this.url = router.imageContent;
  251. // //       #将url赋值给src
  252. //       this.playerOptions['sources'][0]['src'] = defaultSettings.urls + this.url;
  253. // })
  254. this.total = response.total;
  255. this.loading = false;
  256. });
  257. },
  258. // 图片预览列表
  259. imagew(index) {
  260. this.urls = index
  261. this.opende = true
  262. var hyeowc = index
  263. console.log(hyeowc)
  264. var indexde = index.lastIndexOf("\.");
  265. hyeowc=hyeowc.substring(indexde+1,hyeowc.length);
  266. console.log(hyeowc);
  267. if(hyeowc == "mp3" || hyeowc == "mp4"){
  268. this.jeuhse = true //视频
  269. }else{
  270. this.jeuhse = false //图片
  271. }
  272. this.playerOptions['sources'][0]['src'] = defaultSettings.urls + this.urls;
  273. },
  274. // 取消按钮
  275. cancel() {
  276. this.open = false;
  277. this.reset();
  278. },
  279. // 表单重置
  280. reset() {
  281. this.form = {
  282. imageId: null,
  283. imageName: null,
  284. imageContent: null,
  285. imageIntroduce: null,
  286. status: null,
  287. type: null,
  288. isDel: null,
  289. createBy: null,
  290. createTime: null,
  291. updateBy: null,
  292. updateTime: null,
  293. remark: null
  294. };
  295. this.resetForm("form");
  296. },
  297. /** 搜索按钮操作 */
  298. handleQuery() {
  299. this.queryParams.pageNum = 1;
  300. this.getList();
  301. },
  302. /** 重置按钮操作 */
  303. resetQuery() {
  304. this.resetForm("queryForm");
  305. this.handleQuery();
  306. },
  307. // 多选框选中数据
  308. handleSelectionChange(selection) {
  309. this.ids = selection.map(item => item.imageId)
  310. this.single = selection.length !== 1
  311. this.multiple = !selection.length
  312. },
  313. /** 新增按钮操作 */
  314. handleAdd() {
  315. this.reset();
  316. this.open = true;
  317. this.title = "添加附件信息";
  318. },
  319. /** 修改按钮操作 */
  320. handleUpdate(row) {
  321. this.reset();
  322. const imageId = row.imageId || this.ids
  323. getImage(imageId).then(response => {
  324. this.form = response.data;
  325. this.open = true;
  326. this.title = "修改附件信息";
  327. });
  328. },
  329. /** 提交按钮 */
  330. submitForm() {
  331. this.$refs["form"].validate(valid => {
  332. if (valid) {
  333. if (this.form.imageId != null) {
  334. updateImage(this.form).then(response => {
  335. this.$modal.msgSuccess("修改成功");
  336. this.open = false;
  337. this.getList();
  338. });
  339. } else {
  340. addImage(this.form).then(response => {
  341. this.$modal.msgSuccess("新增成功");
  342. this.open = false;
  343. this.getList();
  344. });
  345. }
  346. }
  347. });
  348. },
  349. /** 删除按钮操作 */
  350. handleDelete(row) {
  351. const imageIds = row.imageId || this.ids;
  352. this.$modal.confirm('是否确认删除附件信息编号为"' + imageIds + '"的数据项?').then(function() {
  353. return delImage(imageIds);
  354. }).then(() => {
  355. this.getList();
  356. this.$modal.msgSuccess("删除成功");
  357. }).catch(() => {});
  358. },
  359. /** 导出按钮操作 */
  360. handleExport() {
  361. this.download('system/image/export', {
  362. ...this.queryParams
  363. }, `image_${new Date().getTime()}.xlsx`)
  364. },
  365. // 获取屏幕高度
  366. showFilterForm () {
  367. this.filterActive = !this.filterActive
  368. this.changeTableMaxHeight()
  369. },
  370. changeTableMaxHeight () {
  371. let height = document.body.offsetHeight // 网页可视区域高度
  372. // if (this.filterActive) {
  373. // this.tableMaxHeight = height - 320
  374. // } else {
  375. this.tableMaxHeight = height - 250
  376. // }
  377. console.log(height)
  378. },
  379. // 播放回调
  380. onPlayerPlay(player) {
  381. console.log("player play!", player);
  382. },
  383. // 暂停回调
  384. onPlayerPause(player) {
  385. console.log("player pause!", player);
  386. },
  387. // 视频播完回调
  388. onPlayerEnded($event) {
  389. // console.log(player);
  390. },
  391. // DOM元素上的readyState更改导致播放停止
  392. onPlayerWaiting(player) {
  393. let time = localStorage.getItem("cacheTime")
  394. if(player.cache_.currentTime - Number(time) > 0.1){
  395. this.current = Number(time)
  396. this.playerReadied(player)
  397. }else{
  398. this.current = player.cache_.currentTime
  399. }
  400. },
  401. // 已开始播放回调
  402. onPlayerPlaying($event) {
  403. // console.log(player)
  404. },
  405. // 当播放器在当前播放位置下载数据时触发
  406. onPlayerLoadeddata($event) {
  407. // console.log(player)
  408. },
  409. // // 当前播放位置发生变化时触发。
  410. onPlayerTimeupdate(player) {
  411. this.playTime = player.cache_.currentTime
  412. let playTime = player.cache_.currentTime
  413. setTimeout(function () {
  414. localStorage.setItem("cacheTime",playTime)
  415. },500)
  416. let time = localStorage.getItem("cacheTime")
  417. if(player.cache_.currentTime - Number(time) > 2){
  418. this.current = Number(time)
  419. this.playerReadied(player)
  420. }else{
  421. this.current = player.cache_.currentTime
  422. }
  423. },
  424. //媒体的readyState为HAVE_FUTURE_DATA或更高
  425. onPlayerCanplay(player) {
  426. // console.log('player Canplay!', player)
  427. },
  428. //媒体的readyState为HAVE_ENOUGH_DATA或更高。这意味着可以在不缓冲的情况下播放整个媒体文件。
  429. onPlayerCanplaythrough(player) {
  430. // console.log('player Canplaythrough!', player)
  431. },
  432. //播放状态改变回调
  433. playerStateChanged(playerCurrentState) {
  434. // console.log('player current update state', playerCurrentState)
  435. },
  436. //将侦听器绑定到组件的就绪状态。与事件监听器的不同之处在于,如果ready事件已经发生,它将立即触发该函数。。
  437. playerReadied(player) {
  438. // console.log('example player 1 readied', player);
  439. player.currentTime(this.current)
  440. }
  441. // }
  442. }
  443. };
  444. </script>
  445. <style type="text/css" lang="scss">
  446. .vjs-custom-skin > .video-js .vjs-big-play-button {
  447. background-color: rgba(0,0,0,0.45);
  448. font-size: 3.0em;
  449. /* border-radius: 50%; */
  450. height: 1.5em !important;
  451. line-height:1.5em !important;
  452. margin-top: -1em !important;
  453. }
  454. /*这里用了第三方vue-video-player插件,但这个插件有bug,设置globalSetting:{controls:true}隐藏进度条不生效,故可设置插件样式进行隐藏vjs-progress-contro*/
  455. .vjs-progress-control {
  456. /*visibility:hidden; // 隐藏进度条*/
  457. }
  458. </style>