library.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <template>
  2. <div class="pb_content" style="overflow: auto">
  3. <div class="pb_head top">
  4. <span>素材库</span>
  5. <div v-if="choose == 0" @click="addImg($event)">
  6. <input
  7. type="file"
  8. accept="image/*"
  9. capture="camera"
  10. style="display: none"
  11. @change="beforeUpload1($event, 1)"
  12. />
  13. <div class="uploadThing">上传图片</div>
  14. </div>
  15. <div v-if="choose == 1" @click="addImg($event)">
  16. <input
  17. type="file"
  18. accept="video/mp4,video/quicktime,video/x-msvideo"
  19. capture="camera"
  20. style="display: none"
  21. @change="beforeUpload2($event, 2)"
  22. />
  23. <div class="uploadThing">上传视频</div>
  24. </div>
  25. <div v-if="choose == 2" @click="addImg($event)">
  26. <input
  27. type="file"
  28. accept="application/pdf,.ppt,.pptx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
  29. style="display: none"
  30. @change="beforeUpload2($event, 3)"
  31. />
  32. <div class="uploadThing">上传附件</div>
  33. </div>
  34. </div>
  35. <div class="pb_content_body" style="height: 70%">
  36. <div class="student_head">
  37. <div class="three">
  38. <div :class="choose == 0 ? 'choose' : ''" @click="sMtl(0)">图片</div>
  39. <div :class="choose == 1 ? 'choose' : ''" @click="sMtl(1)">视频</div>
  40. <div :class="choose == 2 ? 'choose' : ''" @click="sMtl(2)">附件</div>
  41. </div>
  42. </div>
  43. <div class="student_table">
  44. <div v-if="this.choose == 0" class="boxCss">
  45. <div class="out_box" v-for="(item, index) in chapInfo" :key="index">
  46. <div class="tup">
  47. <img
  48. :src="
  49. item.chapdataInfo ? JSON.parse(item.chapdataInfo).url : mtp
  50. "
  51. alt=""
  52. @click="
  53. handlePictureCardPreview(JSON.parse(item.chapdataInfo).url)
  54. "
  55. />
  56. <div class="deleteWord" @click="deleteM(item.id)">
  57. <img src="../../assets/icon/delete.png" alt="" />
  58. </div>
  59. </div>
  60. <div class="bottom_box">
  61. <div>
  62. {{
  63. item.chapdataInfo
  64. ? JSON.parse(item.chapdataInfo).name
  65. : "图片暂无名称"
  66. }}
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <div v-if="this.choose == 1" class="boxCss">
  72. <div class="out_box" v-for="(item, index) in chapInfo" :key="index">
  73. <div class="tup">
  74. <img
  75. :src="msp"
  76. alt=""
  77. @click="
  78. handlePictureCardPreview1(JSON.parse(item.chapdataInfo).url)
  79. "
  80. />
  81. <div class="deleteWord" @click="deleteM(item.id)">
  82. <img src="../../assets/icon/delete.png" alt="" />
  83. </div>
  84. </div>
  85. <div class="bottom_box">
  86. <div>
  87. {{
  88. item.chapdataInfo
  89. ? JSON.parse(item.chapdataInfo).name
  90. : "图片暂无名称"
  91. }}
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. <div v-if="this.choose == 2" class="boxCss">
  97. <div class="out_box" v-for="(item, index) in chapInfo" :key="index">
  98. <div class="tup">
  99. <img
  100. :src="mfj"
  101. alt=""
  102. @click="downFile(JSON.parse(item.chapdataInfo).url)"
  103. />
  104. <div class="deleteWord" @click="deleteM(item.id)">
  105. <img src="../../assets/icon/delete.png" alt="" />
  106. </div>
  107. </div>
  108. <div class="bottom_box">
  109. <div>
  110. {{
  111. item.chapdataInfo
  112. ? JSON.parse(item.chapdataInfo).name
  113. : "图片暂无名称"
  114. }}
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. <div class="student_page">
  121. <el-pagination
  122. background
  123. layout="prev, pager, next"
  124. :page-size="10"
  125. :total="total"
  126. v-if="page && chapInfo.length"
  127. @current-change="handleCurrentChange"
  128. >
  129. </el-pagination>
  130. </div>
  131. </div>
  132. <el-dialog :visible.sync="pictureDialog" size="tiny">
  133. <img width="100%" :src="dialogImageUrl" alt="" />
  134. </el-dialog>
  135. <el-dialog :visible.sync="vedioDialog" size="tiny">
  136. <video-player
  137. class="video-player vjs-custom-skin"
  138. ref="videoPlayer"
  139. :playsinline="true"
  140. :options="playerO"
  141. @play="onPlayerPlay($event)"
  142. style="width: 100%; height: 100%"
  143. ></video-player>
  144. </el-dialog>
  145. <div v-if="proVisible" class="mask">
  146. <div class="progressBox">
  147. <div class="lbox">
  148. <img :src="require('../../assets/loading.gif')" />Uploading
  149. </div>
  150. <el-progress
  151. :text-inside="true"
  152. :stroke-width="20"
  153. :percentage="progress"
  154. style="width: 80%"
  155. ></el-progress>
  156. </div>
  157. </div>
  158. </div>
  159. </template>
  160. <script>
  161. export default {
  162. data() {
  163. return {
  164. choose: 0,
  165. chapInfo: [],
  166. cImgInfo: [],
  167. isLoading: false,
  168. noneBtnImg: false,
  169. mtp: require("../../assets/tup1.png"),
  170. msp: require("../../assets/sp1.png"),
  171. mfj: require("../../assets/uploadImg.png"),
  172. page: 1,
  173. total: 0,
  174. dialogImageUrl: "",
  175. userid: this.$route.query.userid,
  176. pictureDialog: false,
  177. vedioDialog: false,
  178. playerOptions: {
  179. playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
  180. autoplay: false, //如果true,浏览器准备好时开始回放。
  181. muted: false, // 默认情况下将会消除任何音频。
  182. loop: false, // 导致视频一结束就重新开始。
  183. preload: "auto", // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
  184. language: "zh-CN",
  185. aspectRatio: "16:9", // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
  186. fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
  187. sources: [
  188. {
  189. type: "video/mp4", //这里的种类支持很多种:基本视频格式、直播、流媒体等,具体可以参看git网址项目 || "video/ogg"|| "video/webm"
  190. src: "", //url地址require("../../assets/media/aaa.mp4")
  191. },
  192. ],
  193. // poster: require("../../assets/tu31.png"), //你的封面地址
  194. // poster: dataRes.imgUrl, //你的封面地址
  195. notSupportedMessage: "此视频暂无法播放,请稍后再试", //允许覆盖Video.js无法播放媒体源时显示的默认信息。
  196. controlBar: {
  197. timeDivider: true, //当前时间和持续时间的分隔符
  198. durationDisplay: true, //显示持续时间
  199. remainingTimeDisplay: false, //是否显示剩余时间功能
  200. fullscreenToggle: true, //全屏按钮
  201. },
  202. },
  203. playerO: {},
  204. proVisible: false,
  205. progress: 0,
  206. };
  207. },
  208. methods: {
  209. handleCurrentChange(val) {
  210. this.page = val;
  211. this.selectMtl();
  212. },
  213. addImg(e) {
  214. var el = e.currentTarget;
  215. el.getElementsByTagName("input")[0].click();
  216. },
  217. imgChange(file, fileList, type) {
  218. var _tmp = this.chapInfo;
  219. this.noneBtnImg = _tmp.length >= 1;
  220. },
  221. downFile(url) {
  222. window.open(url);
  223. },
  224. beforeUpload1(event, type) {
  225. var file = event.target.files[0];
  226. var credentials = {
  227. accessKeyId: "AKIATLPEDU37QV5CHLMH",
  228. secretAccessKey: "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",
  229. }; //秘钥形式的登录上传
  230. window.AWS.config.update(credentials);
  231. window.AWS.config.region = "cn-northwest-1"; //设置区域
  232. var bucket = new window.AWS.S3({ params: { Bucket: "ccrb" } }); //选择桶
  233. var _this = this;
  234. _this.progress = 0;
  235. _this.proVisible = true;
  236. if (file) {
  237. var params = {
  238. Key:
  239. file.name.split(".")[0] +
  240. new Date().getTime() +
  241. "." +
  242. file.name.split(".")[file.name.split(".").length - 1],
  243. ContentType: file.type,
  244. Body: file,
  245. "Access-Control-Allow-Credentials": "*",
  246. ACL: "public-read",
  247. }; //key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
  248. var options = {
  249. partSize: 2048 * 1024 * 1024,
  250. queueSize: 2,
  251. leavePartsOnError: true,
  252. };
  253. bucket
  254. .upload(params, options)
  255. .on("httpUploadProgress", function (evt) {
  256. //这里可以写进度条
  257. // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
  258. _this.progress = parseInt((evt.loaded * 80) / evt.total);
  259. })
  260. .send(function (err, data) {
  261. _this.progress = 100;
  262. setTimeout(() => {
  263. _this.proVisible = false;
  264. }, 1000);
  265. if (err) {
  266. var a = _this.$refs.upload1.uploadFiles;
  267. a.splice(a.length - 1, a.length);
  268. _this.$message.error("上传失败");
  269. } else {
  270. _this.cImgInfo.push({
  271. name: file.name,
  272. url: data.Location,
  273. });
  274. _this.addMtl();
  275. _this.cImgInfo = [];
  276. _this.selectMtl();
  277. _this.imgChange(null, null, type);
  278. console.log(data.Location);
  279. }
  280. });
  281. }
  282. },
  283. handlePictureCardPreview(url) {
  284. this.dialogImageUrl = url;
  285. this.pictureDialog = true;
  286. },
  287. handlePictureCardPreview1(url) {
  288. this.playerO = {};
  289. this.playerOptions.poster = "";
  290. this.playerOptions.sources[0].src = url;
  291. this.playerO = this.playerOptions;
  292. // this.dialogImageUrl = url;
  293. this.vedioDialog = true;
  294. },
  295. beforeUpload2(event, type) {
  296. var file = event.target.files[0];
  297. var credentials = {
  298. accessKeyId: "AKIATLPEDU37QV5CHLMH",
  299. secretAccessKey: "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",
  300. }; //秘钥形式的登录上传
  301. window.AWS.config.update(credentials);
  302. window.AWS.config.region = "cn-northwest-1"; //设置区域
  303. var bucket = new window.AWS.S3({ params: { Bucket: "ccrb" } }); //选择桶
  304. var _this = this;
  305. if (file) {
  306. var params = {
  307. Key:
  308. file.name.split(".")[0] +
  309. new Date().getTime() +
  310. "." +
  311. file.name.split(".")[file.name.split(".").length - 1],
  312. ContentType: file.type,
  313. Body: file,
  314. "Access-Control-Allow-Credentials": "*",
  315. ACL: "public-read",
  316. }; //key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
  317. var options = {
  318. partSize: 2048 * 1024 * 1024,
  319. queueSize: 2,
  320. leavePartsOnError: true,
  321. };
  322. bucket
  323. .upload(params, options)
  324. .on("httpUploadProgress", function (evt) {
  325. //这里可以写进度条
  326. // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
  327. })
  328. .send(function (err, data) {
  329. if (err) {
  330. var a = _this.$refs.upload1.uploadFiles;
  331. a.splice(a.length - 1, a.length);
  332. _this.$message.error("上传失败");
  333. } else {
  334. if (type == 2) {
  335. _this.cImgInfo.push({
  336. name: file.name,
  337. url: data.Location,
  338. });
  339. _this.addMtl();
  340. _this.cImgInfo = [];
  341. _this.selectMtl();
  342. _this.imgChange(null, null, type);
  343. } else if (type == 3) {
  344. _this.cImgInfo.push({
  345. name: file.name,
  346. url: data.Location,
  347. });
  348. _this.addMtl();
  349. _this.cImgInfo = [];
  350. _this.selectMtl();
  351. _this.imgChange(null, null, type);
  352. }
  353. console.log(data.Location);
  354. }
  355. });
  356. }
  357. },
  358. addMtl() {
  359. let params = {
  360. cInfo: this.cImgInfo[0],
  361. t: this.choose,
  362. cBy: this.userid,
  363. };
  364. this.ajax
  365. .get(this.$store.state.api + "addMtl", params)
  366. .then((res) => {
  367. this.$message.success("上传素材成功");
  368. })
  369. .catch((err) => {
  370. console.error(err);
  371. });
  372. },
  373. sMtl(type) {
  374. this.choose = type;
  375. this.selectMtl();
  376. },
  377. selectMtl() {
  378. this.isLoading = true;
  379. let params = {
  380. t: parseInt(this.choose),
  381. uid: this.userid,
  382. page: this.page,
  383. };
  384. this.ajax
  385. .get(this.$store.state.api + "selectMtl2", params)
  386. .then((res) => {
  387. this.isLoading = false;
  388. this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
  389. this.chapInfo = res.data[0];
  390. })
  391. .catch((err) => {
  392. this.isLoading = false;
  393. console.error(err);
  394. });
  395. },
  396. deleteM(id) {
  397. this.isLoading = true;
  398. let params = {
  399. id: id,
  400. };
  401. this.ajax
  402. .get(this.$store.state.api + "deleteM", params)
  403. .then((res) => {
  404. this.isLoading = false;
  405. this.$message.success("删除成功");
  406. this.selectMtl();
  407. })
  408. .catch((err) => {
  409. this.isLoading = false;
  410. console.error(err);
  411. });
  412. },
  413. onPlayerPlay() {},
  414. },
  415. created() {
  416. this.selectMtl();
  417. },
  418. };
  419. </script>
  420. <style scoped>
  421. /* .student_button {
  422. display: flex;
  423. overflow: hidden;
  424. height: 40px;
  425. } */
  426. .student_head >>> .el-button--primary {
  427. background-color: #2268bc;
  428. }
  429. .student_head {
  430. display: flex;
  431. justify-content: space-between;
  432. }
  433. .three {
  434. display: flex;
  435. flex-direction: row;
  436. justify-content: space-between;
  437. width: 200px;
  438. height: 30px;
  439. }
  440. .three > div {
  441. cursor: pointer;
  442. }
  443. .choose {
  444. border-bottom: 5px solid #3994fd;
  445. }
  446. .student_table {
  447. width: 100%;
  448. height: 100%;
  449. background: #f2f2f2;
  450. margin-top: 10px;
  451. }
  452. .tup {
  453. width: 200px;
  454. height: 191px;
  455. margin: 0 auto;
  456. position: relative;
  457. }
  458. .tup:hover .deleteWord {
  459. display: block;
  460. }
  461. .deleteWord {
  462. width: 25px;
  463. height: 25px;
  464. position: absolute;
  465. right: -25px;
  466. top: -10px;
  467. cursor: pointer;
  468. display: none;
  469. }
  470. .tup > img,
  471. .deleteWord > img {
  472. width: 100%;
  473. height: 100%;
  474. }
  475. .out_box {
  476. display: flex;
  477. flex-direction: column;
  478. flex-wrap: nowrap;
  479. width: 250px;
  480. padding: 10px 0;
  481. background: #fff;
  482. margin: 0 25px 15px 0;
  483. }
  484. .bottom_box {
  485. display: flex;
  486. text-align: center;
  487. margin: 0 auto;
  488. padding: 10px 0 5px 0;
  489. }
  490. .bottom_box > div:nth-child(1) {
  491. white-space: nowrap;
  492. text-overflow: ellipsis;
  493. overflow: hidden;
  494. word-break: break-all;
  495. width: 200px;
  496. }
  497. .uploadThing {
  498. background: #2268bc;
  499. width: 90px;
  500. height: 35px;
  501. color: #fff;
  502. font-size: 12px;
  503. text-align: center;
  504. line-height: 35px;
  505. cursor: pointer;
  506. border-radius: 4px;
  507. }
  508. .top {
  509. display: flex;
  510. justify-content: space-between;
  511. }
  512. .student_page {
  513. margin-top: 30px;
  514. }
  515. .boxCss {
  516. padding: 15px 5px;
  517. display: flex;
  518. flex-direction: row;
  519. flex-wrap: wrap;
  520. min-height: 250px;
  521. }
  522. .mask {
  523. background-color: rgba(0, 0, 0, 0);
  524. position: fixed;
  525. top: 0;
  526. left: 0;
  527. width: 100%;
  528. height: 100%;
  529. z-index: 20000;
  530. display: flex;
  531. align-items: center;
  532. justify-content: center;
  533. }
  534. .progressBox {
  535. width: 500px;
  536. height: 180px;
  537. background: #fff;
  538. border-radius: 10px;
  539. box-shadow: 0 0 6px 1px #bfbfbf;
  540. display: flex;
  541. align-items: center;
  542. justify-content: center;
  543. flex-direction: column;
  544. }
  545. .progressBox .lbox {
  546. height: 100px;
  547. font-size: 19px;
  548. display: flex;
  549. align-items: center;
  550. }
  551. .progressBox .lbox img {
  552. width: 40px;
  553. margin-right: 20px;
  554. }
  555. .progressBox >>> .el-progress-bar__outer {
  556. background-color: #d1dfff !important;
  557. }
  558. </style>