library.vue 17 KB

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