studyLibrary.vue 13 KB

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