checkfile.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. <template>
  2. <el-dialog title="上传文件" :visible.sync="dialogVisiblefile" :append-to-body="true" width="600px"
  3. :before-close="handleClose" class="dialog_diy">
  4. <div class="fileCss">
  5. <div>
  6. <button class="info_btn" @click="addImg($event)">
  7. 选择本地文件
  8. <input type="file" accept="*" style="display: none" multiple="multiple" @change="beforeUpload" />
  9. </button>
  10. <div class="spanName">选择本地文件</div>
  11. </div>
  12. <!-- <div>
  13. <el-button @click="openFile">选择素材库文件</el-button>
  14. <div class="spanName">选择素材库文件</div>
  15. </div> -->
  16. </div>
  17. <div v-if="proVisible" class="mask">
  18. <div class="progressBox">
  19. <div class="lbox">
  20. <img src="../../../../assets/loading.gif" />上传中,请稍后
  21. </div>
  22. <!-- <div style="margin-bottom: 10px">
  23. <span>{{
  24. isFinishSize
  25. }}M</span>
  26. /
  27. <span>{{
  28. isAllSize
  29. }}M</span>
  30. </div>
  31. <el-progress :text-inside="true" :stroke-width="20" :percentage="progress
  32. ? progress
  33. : 0
  34. " style="width: 80%"></el-progress> -->
  35. </div>
  36. </div>
  37. <el-dialog title="选择素材库文件" :visible.sync="dialogVisiblefile2" :append-to-body="true" width="710px"
  38. :before-close="handleClose2" class="dialog_diy">
  39. <div class="file_box">
  40. <div class="student_head">
  41. <div class="three">
  42. <div :class="choose == 0 ? 'choose' : ''" @click="sMtl(0)">图片</div>
  43. <div :class="choose == 1 ? 'choose' : ''" @click="sMtl(1)">视频</div>
  44. <div :class="choose == 2 ? 'choose' : ''" @click="sMtl(2)">附件</div>
  45. </div>
  46. </div>
  47. <div class="student_table" v-loading="isLoading">
  48. <div v-if="this.choose == 0" class="boxCss">
  49. <div class="out_box" v-for="(item, index) in chapInfo" :key="index">
  50. <div class="tup">
  51. <img :src="item.chapdataInfo ? JSON.parse(item.chapdataInfo).url : mtp
  52. " alt="" @click="checkJson(JSON.parse(item.chapdataInfo))" />
  53. <div class="deleteWord">
  54. <img src="../../../../assets/icon/delete.png" alt="" />
  55. </div>
  56. </div>
  57. <div class="bottom_box">
  58. <el-tooltip :content="item.chapdataInfo
  59. ? JSON.parse(item.chapdataInfo).name
  60. : '暂无名称'" placement="top" effect="dark">
  61. <div>
  62. {{
  63. item.chapdataInfo
  64. ? JSON.parse(item.chapdataInfo).name
  65. : "暂无名称"
  66. }}
  67. </div>
  68. </el-tooltip>
  69. </div>
  70. </div>
  71. </div>
  72. <div v-if="this.choose == 1" class="boxCss">
  73. <div class="out_box" v-for="(item, index) in chapInfo" :key="index">
  74. <div class="tup">
  75. <img :src="msp" alt="" @click="checkJson(JSON.parse(item.chapdataInfo))" />
  76. <div class="deleteWord">
  77. <img src="../../../../assets/icon/delete.png" alt="" />
  78. </div>
  79. </div>
  80. <div class="bottom_box">
  81. <el-tooltip :content="item.chapdataInfo
  82. ? JSON.parse(item.chapdataInfo).name
  83. : '暂无名称'" placement="top" effect="dark">
  84. <div>
  85. {{
  86. item.chapdataInfo
  87. ? JSON.parse(item.chapdataInfo).name
  88. : "暂无名称"
  89. }}
  90. </div>
  91. </el-tooltip>
  92. </div>
  93. </div>
  94. </div>
  95. <div v-if="this.choose == 2" class="boxCss">
  96. <div class="out_box" v-for="(item, index) in chapInfo" :key="index">
  97. <div class="tup">
  98. <img :src="mfj" alt="" @click="checkJson(JSON.parse(item.chapdataInfo))" />
  99. <div class="deleteWord">
  100. <img src="../../../../assets/icon/delete.png" alt="" />
  101. </div>
  102. </div>
  103. <div class="bottom_box">
  104. <el-tooltip :content="item.chapdataInfo
  105. ? JSON.parse(item.chapdataInfo).name
  106. : '暂无名称'" placement="top" effect="dark">
  107. <div>
  108. {{
  109. item.chapdataInfo
  110. ? JSON.parse(item.chapdataInfo).name
  111. : "暂无名称"
  112. }}
  113. </div>
  114. </el-tooltip>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. <div class="student_page">
  120. <el-pagination background layout="prev, pager, next" :page-size="10" :total="total"
  121. v-if="page && chapInfo.length" @current-change="handleCurrentChange">
  122. </el-pagination>
  123. </div>
  124. </div>
  125. </el-dialog>
  126. </el-dialog>
  127. </template>
  128. <script>
  129. export default {
  130. props: {
  131. dialogVisiblefile: {
  132. type: Boolean,
  133. default: false
  134. },
  135. },
  136. data() {
  137. return {
  138. progress: 0,
  139. isFinishSize: 0,
  140. proVisible: false,
  141. isAllSize: 0,
  142. dialogVisiblefile2: false,
  143. userid: this.$route.query.userid,
  144. page: 1,
  145. isLoading: false,
  146. total: 0,
  147. chapInfo: [],
  148. choose: 0,
  149. mtp: require("../../../../assets/tup1.png"),
  150. msp: require("../../../../assets/icon/fileIcon/isVideo.png"),
  151. mfj: require("../../../../assets/icon/fileIcon/word2.png"),
  152. };
  153. },
  154. methods: {
  155. handleClose(done) {
  156. this.close();
  157. done();
  158. },
  159. handleClose2(done) {
  160. done();
  161. },
  162. close() {
  163. this.$emit("update:dialogVisiblefile", false);
  164. },
  165. openFile() {
  166. this.dialogVisiblefile2 = true
  167. this.selectMtl();
  168. },
  169. sMtl(choose) {
  170. this.choose = choose
  171. this.page = 1
  172. this.selectMtl()
  173. },
  174. handleCurrentChange(val) {
  175. this.page = val
  176. this.selectMtl()
  177. },
  178. selectMtl() {
  179. this.isLoading = true;
  180. let params = {
  181. t: this.choose,
  182. uid: this.userid,
  183. page: this.page,
  184. };
  185. this.ajax
  186. .get(this.$store.state.api + "selectMtl2", params)
  187. .then((res) => {
  188. this.isLoading = false;
  189. this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
  190. this.chapInfo = res.data[0];
  191. })
  192. .catch((err) => {
  193. this.isLoading = false;
  194. console.error(err);
  195. });
  196. },
  197. addImg(e) {
  198. var el = e.currentTarget;
  199. el.getElementsByTagName("input")[0].click();
  200. e.target.value = "";
  201. },
  202. beforeUpload(event, type) {
  203. // const loading = this.openLoading();
  204. let cfindex2 = 0;
  205. for (var cfindex = 0; cfindex < event.target.files.length; cfindex++) {
  206. let file = event.target.files[cfindex];
  207. var credentials = {
  208. accessKeyId: "AKIATLPEDU37QV5CHLMH",
  209. secretAccessKey: "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",
  210. }; //秘钥形式的登录上传
  211. window.AWS.config.update(credentials);
  212. window.AWS.config.region = "cn-northwest-1"; //设置区域
  213. var bucket = new window.AWS.S3({ params: { Bucket: "ccrb" } }); //选择桶
  214. var _this = this;
  215. // _this.progress = 0;
  216. _this.proVisible = true;
  217. // _this.isFinishSize = 0;
  218. // _this.isAllSize = (file.size / 1024 / 1024).toFixed(2);
  219. _this.$forceUpdate();
  220. if (file) {
  221. var params = {
  222. Key:
  223. file.name.split(".")[0] +
  224. new Date().getTime() +
  225. "." +
  226. file.name.split(".")[file.name.split(".").length - 1],
  227. ContentType: file.type,
  228. Body: file,
  229. "Access-Control-Allow-Credentials": "*",
  230. ACL: "public-read",
  231. }; //key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
  232. var options = {
  233. partSize: 2048 * 1024 * 1024,
  234. queueSize: 2,
  235. leavePartsOnError: true,
  236. };
  237. bucket
  238. .upload(params, options)
  239. .on("httpUploadProgress", function (evt) {
  240. //这里可以写进度条
  241. // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
  242. // _this.progress = parseInt((evt.loaded / evt.total) * 100);
  243. // _this.isFinishSize = (evt.loaded / 1024 / 1024).toFixed(2);
  244. // _this.$forceUpdate();
  245. })
  246. .send(function (err, data) {
  247. cfindex2++;
  248. // _this.progress = 100;
  249. // _this.isFinishSize = _this.isAllSize;
  250. // _this.$forceUpdate();
  251. // setTimeout(() => {
  252. // _this.proVisible = false;
  253. // _this.$forceUpdate();
  254. // }, 1000);
  255. setTimeout(() => {
  256. if (
  257. cfindex2 == event.target.files.length - 1 ||
  258. cfindex2 > event.target.files.length - 1
  259. ) {
  260. _this.proVisible = false;
  261. _this.close();
  262. }
  263. }, 1000);
  264. // loading.close();
  265. if (err) {
  266. _this.$message.error("上传失败");
  267. } else {
  268. let _type = 2;
  269. var imgA = [
  270. "png",
  271. "jpg",
  272. "jpeg",
  273. "bmp",
  274. "gif",
  275. "webp",
  276. "psd",
  277. "svg",
  278. "tiff",
  279. ];
  280. var fileA = [
  281. "DOC",
  282. "DOCX",
  283. "DOCM",
  284. "DOTM",
  285. "DOTX",
  286. "PPTX",
  287. "PPSX",
  288. "PPT",
  289. "PPS",
  290. "PPTM",
  291. "POTM",
  292. "PPAM",
  293. "POTX",
  294. "PPSM",
  295. "XLSX",
  296. "XLS",
  297. ];
  298. var videoA = [
  299. "AVI",
  300. "NAVI",
  301. "MPEG",
  302. "ASF",
  303. "MOV",
  304. "WMV",
  305. "3GP",
  306. "RM",
  307. "RMVB",
  308. "FLV",
  309. "F4V",
  310. "H.264",
  311. "H.265",
  312. "REAL VIDEO",
  313. "MKV",
  314. "WebM",
  315. "HDDVD",
  316. "MP4",
  317. "MPG",
  318. "M4V",
  319. "MGV",
  320. "OGV",
  321. "QTM",
  322. "STR",
  323. "AMC",
  324. "DVX",
  325. "EVO",
  326. "DAT",
  327. "OGG",
  328. "OGM",
  329. ];
  330. if (
  331. fileA.indexOf(
  332. data.Location.split(".")[
  333. data.Location.split(".").length - 1
  334. ].toLocaleUpperCase()
  335. ) != -1
  336. ) {
  337. _type = 1; //word 文件
  338. } else if (
  339. videoA.indexOf(
  340. data.Location.split(".")[
  341. data.Location.split(".").length - 1
  342. ].toLocaleUpperCase()
  343. ) != -1
  344. ) {
  345. _type = 2; //视频
  346. } else if (
  347. imgA.indexOf(
  348. data.Location.split(".")[
  349. data.Location.split(".").length - 1
  350. ].toLocaleLowerCase()
  351. ) != -1
  352. ) {
  353. _type = 3; //图片
  354. } else if (
  355. 'pdf'.indexOf(
  356. data.Location.split(".")[
  357. data.Location.split(".").length - 1
  358. ].toLocaleLowerCase()
  359. ) != -1
  360. ) {
  361. _type = 4; //pdf
  362. } else {
  363. _type = 5; //文件
  364. }
  365. // if (_this.checkJson.file) {
  366. // _this.checkJson.file.push({
  367. // name: file.name,
  368. // url: data.Location,
  369. // type: _type,
  370. // });
  371. // } else {
  372. // _this.checkJson.file = []
  373. // _this.checkJson.file.push({
  374. // name: file.name,
  375. // url: data.Location,
  376. // type: _type,
  377. // });
  378. // }
  379. _this.$emit("setCheckJson", file.name, data.Location, _type);
  380. _this.$forceUpdate();
  381. console.log(_this.checkJson);
  382. console.log(data.Location);
  383. }
  384. });
  385. }
  386. }
  387. },
  388. checkJson(json) {
  389. let _type = 2;
  390. let url = "https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/"+encodeURIComponent(json.url.split(
  391. "https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/"
  392. )[1]);
  393. let name = json.name
  394. var imgA = [
  395. "png",
  396. "jpg",
  397. "jpeg",
  398. "bmp",
  399. "gif",
  400. "webp",
  401. "psd",
  402. "svg",
  403. "tiff",
  404. ];
  405. var fileA = [
  406. "DOC",
  407. "DOCX",
  408. "DOCM",
  409. "DOTM",
  410. "DOTX",
  411. "PPTX",
  412. "PPSX",
  413. "PPT",
  414. "PPS",
  415. "PPTM",
  416. "POTM",
  417. "PPAM",
  418. "POTX",
  419. "PPSM",
  420. "XLSX",
  421. "XLS",
  422. ];
  423. var videoA = [
  424. "AVI",
  425. "NAVI",
  426. "MPEG",
  427. "ASF",
  428. "MOV",
  429. "WMV",
  430. "3GP",
  431. "RM",
  432. "RMVB",
  433. "FLV",
  434. "F4V",
  435. "H.264",
  436. "H.265",
  437. "REAL VIDEO",
  438. "MKV",
  439. "WebM",
  440. "HDDVD",
  441. "MP4",
  442. "MPG",
  443. "M4V",
  444. "MGV",
  445. "OGV",
  446. "QTM",
  447. "STR",
  448. "AMC",
  449. "DVX",
  450. "EVO",
  451. "DAT",
  452. "OGG",
  453. "OGM",
  454. ];
  455. if (
  456. fileA.indexOf(
  457. url.split(".")[
  458. url.split(".").length - 1
  459. ].toLocaleUpperCase()
  460. ) != -1
  461. ) {
  462. _type = 1; //word 文件
  463. } else if (
  464. videoA.indexOf(
  465. url.split(".")[
  466. url.split(".").length - 1
  467. ].toLocaleUpperCase()
  468. ) != -1
  469. ) {
  470. _type = 2; //视频
  471. } else if (
  472. imgA.indexOf(
  473. url.split(".")[
  474. url.split(".").length - 1
  475. ].toLocaleLowerCase()
  476. ) != -1
  477. ) {
  478. _type = 3; //图片
  479. } else if (
  480. 'pdf'.indexOf(
  481. url.split(".")[
  482. url.split(".").length - 1
  483. ].toLocaleLowerCase()
  484. ) != -1
  485. ) {
  486. _type = 4; //pdf
  487. } else {
  488. _type = 5; //文件
  489. }
  490. this.$emit("setCheckJson", name, url, _type);
  491. this.dialogVisiblefile2 = false
  492. this.close();
  493. }
  494. }
  495. };
  496. </script>
  497. <style scoped>
  498. .dialog_diy>>>.el-dialog {
  499. /* height: 100%; */
  500. margin: 10vh auto !important;
  501. }
  502. .dialog_diy>>>.el-dialog__header {
  503. background: #454545 !important;
  504. padding: 15px 20px;
  505. }
  506. .dialog_diy>>>.el-dialog__body {
  507. height: calc(100% - 124px);
  508. box-sizing: border-box;
  509. padding: 0px;
  510. }
  511. .dialog_diy>>>.el-dialog__title {
  512. color: #fff;
  513. }
  514. .dialog_diy>>>.el-dialog__headerbtn {
  515. top: 19px;
  516. }
  517. .dialog_diy>>>.el-dialog__headerbtn .el-dialog__close {
  518. color: #fff;
  519. }
  520. .dialog_diy>>>.el-dialog__headerbtn .el-dialog__close:hover {
  521. color: #fff;
  522. }
  523. .dialog_diy>>>.el-dialog__body,
  524. .dialog_diy>>>.el-dialog__footer {
  525. background: #fafafa;
  526. }
  527. .fileCss {
  528. width: 100%;
  529. display: flex;
  530. flex-direction: row;
  531. flex-wrap: nowrap;
  532. justify-content: space-around;
  533. align-items: center;
  534. padding: 40px 0;
  535. box-sizing: border-box;
  536. }
  537. .fileCss>div {
  538. display: flex;
  539. flex-direction: column;
  540. align-items: center;
  541. }
  542. .fileCss .spanName {
  543. margin-top: 10px
  544. }
  545. .info_btn,
  546. .teacherWord {
  547. color: #fff;
  548. background-color: #0f7eff;
  549. padding: 8px 24px;
  550. font-size: 0.9375rem;
  551. box-shadow: 0px 1px 3px 0px rgb(0 0 0 / 20%), 0px 2px 2px 0px rgb(0 0 0 / 14%),
  552. 0px 3px 1px -2px rgb(0 0 0 / 12%);
  553. min-width: 64px;
  554. font-weight: 500;
  555. border-radius: 4px;
  556. box-sizing: border-box;
  557. border: none;
  558. cursor: pointer;
  559. }
  560. .mask {
  561. background-color: rgb(0 0 0 / 30%);
  562. /* position: fixed; */
  563. position: absolute;
  564. top: 0;
  565. left: 0;
  566. width: 100%;
  567. height: 100%;
  568. z-index: 90;
  569. display: flex;
  570. align-items: center;
  571. justify-content: center;
  572. }
  573. .progressBox {
  574. width: 300px;
  575. height: 150px;
  576. background: #fff;
  577. border-radius: 10px;
  578. box-shadow: 0 0 6px 1px #bfbfbf;
  579. display: flex;
  580. align-items: center;
  581. justify-content: center;
  582. flex-direction: column;
  583. position: relative;
  584. color: #6c6c6c;
  585. }
  586. .progressBox>>>.el-progress-bar__outer {
  587. background-color: #d1dfff !important;
  588. }
  589. .progressBox .lbox {
  590. height: 50px;
  591. font-size: 19px;
  592. display: flex;
  593. align-items: center;
  594. color: #747474;
  595. }
  596. .progressBox .lbox img {
  597. width: 40px;
  598. margin-right: 20px;
  599. }
  600. .closeCss {
  601. position: absolute;
  602. top: 8px;
  603. right: 8px;
  604. cursor: pointer;
  605. width: 20px;
  606. height: 20px;
  607. }
  608. .closeCss>img {
  609. width: 100%;
  610. height: 100%;
  611. }
  612. .file_box {
  613. width: 100%;
  614. padding: 15px;
  615. box-sizing: border-box;
  616. }
  617. .student_head>>>.el-button--primary {
  618. background-color: #2268bc;
  619. }
  620. .student_head {
  621. display: flex;
  622. justify-content: space-between;
  623. }
  624. .three {
  625. display: flex;
  626. flex-direction: row;
  627. justify-content: space-between;
  628. width: 200px;
  629. height: 30px;
  630. }
  631. .three>div {
  632. cursor: pointer;
  633. }
  634. .choose {
  635. border-bottom: 5px solid #3994fd;
  636. }
  637. .student_table {
  638. width: 100%;
  639. height: 100%;
  640. background: #f2f2f2;
  641. margin-top: 10px;
  642. }
  643. .tup {
  644. width: calc(100% - 20px);
  645. height: 120px;
  646. margin: 0 auto;
  647. position: relative;
  648. }
  649. .out_box:hover .deleteWord {
  650. /* display: block; */
  651. }
  652. .deleteWord {
  653. width: 25px;
  654. height: 25px;
  655. position: absolute;
  656. right: -25px;
  657. top: -10px;
  658. cursor: pointer;
  659. display: none;
  660. }
  661. .tup>img,
  662. .deleteWord>img {
  663. width: 100%;
  664. height: 100%;
  665. object-fit: cover;
  666. }
  667. .out_box {
  668. display: flex;
  669. flex-direction: column;
  670. flex-wrap: nowrap;
  671. width: 216px;
  672. padding: 10px 0;
  673. background: #fff;
  674. margin: 0 10px 10px 0;
  675. height: fit-content;
  676. cursor: pointer;
  677. }
  678. .out_box:nth-child(3n){
  679. margin-right: 0;
  680. }
  681. .bottom_box {
  682. display: flex;
  683. text-align: center;
  684. margin: 0 auto;
  685. padding: 10px 0 5px 0;
  686. }
  687. .bottom_box>div:nth-child(1) {
  688. white-space: nowrap;
  689. text-overflow: ellipsis;
  690. overflow: hidden;
  691. word-break: break-all;
  692. width: 200px;
  693. }
  694. .uploadThing {
  695. background: #2268bc;
  696. width: 90px;
  697. height: 35px;
  698. color: #fff;
  699. font-size: 12px;
  700. text-align: center;
  701. line-height: 35px;
  702. cursor: pointer;
  703. border-radius: 4px;
  704. }
  705. .top {
  706. display: flex;
  707. justify-content: space-between;
  708. }
  709. .student_page {
  710. margin-top: 30px;
  711. }
  712. .boxCss {
  713. padding: 15px 5px;
  714. display: flex;
  715. flex-direction: row;
  716. flex-wrap: wrap;
  717. min-height: 250px;
  718. }
  719. </style>