file.vue 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. <template>
  2. <div class="c_box" v-loading="isloading">
  3. <!-- <div class="mask"></div> -->
  4. <div v-if="!checkJson">暂未设置题目</div>
  5. <div v-else class="choice_box">
  6. <!-- <div class="title"><div>{{ `(${option[checkJson.type].name})` }}</div><div v-html="checkJson.title"></div></div> -->
  7. <div class="c_title">
  8. <div class="title" style="display: flex;align-items: center;">
  9. <!-- + `(${option[checkJson.type].name})` -->
  10. <span class="g_t_index" style="min-width: fit-content;">{{ tindex + 1}}</span>
  11. <span>{{ checkJson.title }}</span>
  12. <span
  13. style="color: #efa030;min-width: fit-content;"
  14. v-if="checkJson.score"
  15. >({{ "分值:" + checkJson.score + "分" }})</span
  16. >
  17. </div>
  18. <!-- </div><div v-html="checkJson.title"></div> -->
  19. <div class="p_box" v-if="checkJson.file && checkJson.file.length > 1">
  20. <span class="btnU" @click="uploadCourse">批量下载</span>
  21. </div>
  22. <div class="p_box" v-if="isTeacher == 1 && checkJson.score">
  23. <el-input
  24. v-model="checkJson.score2"
  25. class="c_input"
  26. @change="numberPan"
  27. placeholder="请输入得分"
  28. ></el-input
  29. ><span style="margin: 0 10px;">/</span
  30. ><span>{{ checkJson.score }}分</span>
  31. </div>
  32. <div class="p_box" v-if="isTeacher == 2 && checkJson.score2">
  33. <span>{{ checkJson.score2 }}分</span
  34. ><span style="margin: 0 10px;">/</span
  35. ><span>{{ checkJson.score }}分</span>
  36. </div>
  37. </div>
  38. <div
  39. class="detail"
  40. v-if="checkJson.detail"
  41. v-html="checkJson.detail"
  42. style="color: #00000066;margin-top: 5px;"
  43. ></div>
  44. <div class="choices">
  45. <div class="file_box" v-if="checkJson.mobanFile && checkJson.mobanFile.length" v-loading="loading">
  46. <div class="file_item" v-for="(item, index) in checkJson.mobanFile" :key="index">
  47. <div class="file_name">{{ item.name }}</div>
  48. <div class="file_btns">
  49. <div class="file_btn" @click="downloadMobanFile(index)">下载</div>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. <div class="choices">
  55. <div class="uploadBtn" v-if="checktype == 1">
  56. <div class="btn" @click.stop="addImg($event)">
  57. <span :style="isN == 1 ? 'font-size: 12px;' : ''"
  58. >添加本地文件</span
  59. >
  60. <input
  61. type="file"
  62. accept="*"
  63. style="display: none"
  64. multiple="multiple"
  65. @change="beforeUpload($event)"
  66. />
  67. </div>
  68. <div class="btn" @click="openFileBox()">
  69. <span :style="isN == 1 ? 'font-size: 12px;' : ''"
  70. >从资源库添加</span
  71. >
  72. </div>
  73. <div class="switch">
  74. <el-switch active-color="#3681fc" v-model="isTong"> </el-switch>
  75. <span
  76. :style="isN == 1 ? 'font-size: 12px;' : ''"
  77. @click="isTong = !isTong"
  78. >同步至资源库</span
  79. >
  80. </div>
  81. </div>
  82. <div class="binfo_input">
  83. <div class="fileBox" v-if="(checkJson.file && checkJson.file.length) || this.uploadList.length">
  84. <div class="fileC">
  85. <div
  86. class="file"
  87. v-for="(item, index) in checkJson.file"
  88. :key="index"
  89. v-loading="downLoading == item.url"
  90. @click.stop="checkFile(item)"
  91. >
  92. <img
  93. class="del"
  94. src="../../../../../assets/icon/fileIcon/deleteworks.png"
  95. @click.stop="delFile(index)"
  96. v-if="checktype == 1"
  97. />
  98. <img
  99. class="download"
  100. src="../../../../../assets/icon/fileIcon/download.png"
  101. @click.stop="downloadFile(item)"
  102. :style="{ right: checktype != 1 ? '10px' : '45px' }"
  103. />
  104. <img class="img" :src="wordIcon" alt="" v-if="item.type == 1" />
  105. <img
  106. class="img"
  107. :src="videoIcon"
  108. alt=""
  109. v-if="item.type == 2"
  110. />
  111. <img class="img" :src="item.url" alt="" v-if="item.type == 3" />
  112. <img class="img" :src="wordIcon" alt="" v-if="item.type == 4" />
  113. <img class="img" :src="fileIcon" alt="" v-if="item.type == 5" />
  114. <div class="name">
  115. <el-tooltip
  116. :content="item.name"
  117. placement="top"
  118. effect="dark"
  119. >
  120. <span>{{ item.name }}</span>
  121. </el-tooltip>
  122. </div>
  123. </div>
  124. <div
  125. class="file"
  126. v-for="(item, index) in uploadList"
  127. :key="item.index"
  128. >
  129. <img
  130. class="del"
  131. src="../../../../../assets/icon/fileIcon/delFile.svg"
  132. @click.stop="delUploadFile(item)"
  133. />
  134. <img class="img" :src="wordIcon" alt="" v-if="item.type == 1" />
  135. <img
  136. class="img"
  137. :src="videoIcon"
  138. alt=""
  139. v-if="item.type == 2"
  140. />
  141. <img class="img" :src="fileIcon" alt="" v-if="item.type == 3" />
  142. <img class="img" :src="wordIcon" alt="" v-if="item.type == 4" />
  143. <img class="img" :src="fileIcon" alt="" v-if="item.type == 5" />
  144. <div class="uploadProgress">
  145. <div>{{ item.progress.value }}%</div>
  146. <span>上传中...</span>
  147. </div>
  148. <div class="name">
  149. <el-tooltip
  150. :content="item.name"
  151. placement="top"
  152. effect="dark"
  153. >
  154. <span>{{ item.name }}</span>
  155. </el-tooltip>
  156. </div>
  157. <!-- {{ item }} -->
  158. </div>
  159. </div>
  160. <!-- <div class="btn" @click.stop="openFileBox()" v-if="checktype == 1">
  161. <span>点击添加文件</span>
  162. <input type="file" accept="*" style="display: none" @change="beforeUpload($event)" />
  163. </div> -->
  164. </div>
  165. <div class="uploadQ" v-else-if="checktype == 1">
  166. <span>待填写者上传</span>
  167. <!-- <input type="file" accept="*" style="display: none" @change="beforeUpload($event)" /> -->
  168. </div>
  169. <div class="uploadQ" v-else>
  170. <span>暂无添加附件</span>
  171. </div>
  172. <div v-if="proVisible" class="mask">
  173. <div class="progressBox">
  174. <div class="lbox">
  175. <img src="../../../../../assets/loading.gif" />上传中,请稍后
  176. </div>
  177. <!-- <div style="margin-bottom: 10px">
  178. <span>{{
  179. isFinishSize
  180. }}M</span>
  181. /
  182. <span>{{
  183. isAllSize
  184. }}M</span>
  185. </div>
  186. <el-progress :text-inside="true" :stroke-width="20" :percentage="progress
  187. ? progress
  188. : 0
  189. " style="width: 80%"></el-progress> -->
  190. </div>
  191. </div>
  192. </div>
  193. <!-- <textarea :readonly="checktype == 2" rows="2" v-autoHeight="68" class="binfo_input binfo_textarea" cols v-model="checkJson.answer2"
  194. placeholder=""></textarea> -->
  195. </div>
  196. </div>
  197. <wpdf :dialogVisiblePdf.sync="dialogVisiblePdf" :url="wurl"></wpdf>
  198. <wVideo :dialogVisibleVideo.sync="dialogVisibleVideo" :url="wurl"></wVideo>
  199. <wOffice
  200. :dialogVisibleOffice.sync="dialogVisibleOffice"
  201. :url="wurl"
  202. ></wOffice>
  203. <checkfile
  204. :dialogVisiblefile.sync="dialogVisiblefile"
  205. @setCheckJson="setCheckJson"
  206. ></checkfile>
  207. <uploadFile
  208. v-for="(item, index) in uploadList"
  209. :ref="`uploadFileRef${item.index}`"
  210. :key="item.index"
  211. :index="item.index"
  212. @progressUpdate="progressUpdate"
  213. @success="uploadSuccess"
  214. />
  215. </div>
  216. </template>
  217. <script>
  218. import "../../../../../common/aws-sdk-2.235.1.min.js";
  219. import videoIcon from "../../../../../assets/icon/fileIcon/isVideo.png";
  220. import wordIcon from "../../../../../assets/icon/fileIcon/isWord.png";
  221. import fileIcon from "../../../../../assets/icon/fileIcon/word2.png";
  222. import wpdf from "../../../test/file/wPdf2.vue";
  223. import wVideo from "../../../test/file/wVideo.vue";
  224. import wOffice from "../../../test/file/wOffice.vue";
  225. import checkfile from "../../../test/file/checkfile.vue";
  226. import JSZip from "jszip";
  227. import FileSaver from "file-saver";
  228. import uploadFile from "./uploadFile.vue";
  229. import { v4 as uuidv4 } from "uuid";
  230. const getFile = url => {
  231. return new Promise((resolve, reject) => {
  232. var credentials = {
  233. accessKeyId: "AKIATLPEDU37QV5CHLMH",
  234. secretAccessKey: "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"
  235. }; //秘钥形式的登录上传
  236. window.AWS.config.update(credentials);
  237. window.AWS.config.region = "cn-northwest-1"; //设置区域
  238. let url2 = url;
  239. let _url2 = "";
  240. if (
  241. url2.indexOf("https://view.officeapps.live.com/op/view.aspx?src=") != -1
  242. ) {
  243. _url2 = url2.split(
  244. "https://view.officeapps.live.com/op/view.aspx?src="
  245. )[1];
  246. } else {
  247. _url2 = url2;
  248. }
  249. var s3 = new window.AWS.S3({ params: { Bucket: "ccrb" } });
  250. let name = decodeURIComponent(
  251. _url2.split("https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/")[1].replace(/\+/g, ' ')
  252. );
  253. var params = {
  254. Bucket: "ccrb",
  255. Key: name
  256. };
  257. s3.getObject(params, function(err, data) {
  258. if (err) {
  259. console.log(err, err.stack);
  260. resolve({ data: 1 });
  261. } else {
  262. resolve({ data: data.Body });
  263. console.log(data);
  264. } // sxuccessful response
  265. });
  266. // axios({
  267. });
  268. };
  269. export default {
  270. components: {
  271. wpdf,
  272. wVideo,
  273. wOffice,
  274. checkfile,
  275. uploadFile
  276. },
  277. props: {
  278. tindex: {
  279. type: Number
  280. },
  281. cJson: {
  282. type: Object
  283. },
  284. checktype: {
  285. type: Number,
  286. default: 1
  287. },
  288. see: {
  289. type: Boolean,
  290. default: false
  291. },
  292. isTeacher: {
  293. type: Number,
  294. default: 2
  295. }
  296. },
  297. data() {
  298. return {
  299. option: {
  300. 1: { name: "附件" }
  301. },
  302. userid: this.$route.query.userid,
  303. isN: this.$route.query.isN,
  304. checkJson: undefined,
  305. progress: 0,
  306. isFinishSize: 0,
  307. proVisible: false,
  308. isAllSize: 0,
  309. videoIcon: videoIcon,
  310. wordIcon: wordIcon,
  311. fileIcon: fileIcon,
  312. downLoading: "",
  313. dialogVisiblePdf: false,
  314. dialogVisibleVideo: false,
  315. dialogVisibleOffice: false,
  316. dialogVisiblefile: false,
  317. wurl: "",
  318. isloading: false,
  319. isTong: false,
  320. uploadList: [],
  321. loading: false
  322. };
  323. },
  324. watch: {
  325. checkJson: {
  326. handler(newValue) {
  327. this.$emit("update:cJson", newValue);
  328. },
  329. deep: true
  330. },
  331. cJson: {
  332. handler(newValue, oldVal) {
  333. if (
  334. newValue.file &&
  335. this.checkJson.file &&
  336. newValue.file.length !== this.checkJson.file.length
  337. ) {
  338. this.checkJson = this.depthCopy(newValue);
  339. this.$forceUpdate();
  340. } else if (newValue.file && !this.checkJson.file) {
  341. this.checkJson = this.depthCopy(newValue);
  342. this.$forceUpdate();
  343. } else if (!newValue.file && this.checkJson.file) {
  344. this.checkJson = this.depthCopy(newValue);
  345. this.$forceUpdate();
  346. } else if (JSON.stringify(newValue) !== JSON.stringify(oldVal)) {
  347. this.checkJson = this.depthCopy(newValue);
  348. this.$forceUpdate();
  349. }
  350. },
  351. deep: true
  352. }
  353. },
  354. methods: {
  355. depthCopy(s) {
  356. return JSON.parse(JSON.stringify(s));
  357. },
  358. openFileBox() {
  359. this.dialogVisiblefile = true;
  360. },
  361. addImg(e) {
  362. var el = e.currentTarget;
  363. el.getElementsByTagName("input")[0].click();
  364. e.target.value = "";
  365. },
  366. numberPan() {
  367. if (/[^\d]/.test(this.checkJson.score2) || this.checkJson.score2 < 0) {
  368. this.$message.error("请输入大于0的数字");
  369. this.checkJson.score2 = "";
  370. }
  371. if (parseInt(this.checkJson.score2) > parseInt(this.checkJson.score)) {
  372. this.$message.error("不能输入大于得分的数字");
  373. this.checkJson.score2 = this.checkJson.score;
  374. }
  375. },
  376. beforeUpload(event, type) {
  377. // const loading = this.openLoading();
  378. let file = "";
  379. let cfindex2 = 0;
  380. for (var cfindex = 0; cfindex < event.target.files.length; cfindex++) {
  381. file = event.target.files[cfindex];
  382. let _type = 2;
  383. var imgA = [
  384. "png",
  385. "jpg",
  386. "jpeg",
  387. "bmp",
  388. "gif",
  389. "webp",
  390. "psd",
  391. "svg",
  392. "tiff"
  393. ];
  394. var fileA = [
  395. "DOC",
  396. "DOCX",
  397. "DOCM",
  398. "DOTM",
  399. "DOTX",
  400. "PPTX",
  401. "PPSX",
  402. "PPT",
  403. "PPS",
  404. "PPTM",
  405. "POTM",
  406. "PPAM",
  407. "POTX",
  408. "PPSM",
  409. "XLSX",
  410. "XLS"
  411. ];
  412. var videoA = [
  413. "AVI",
  414. "NAVI",
  415. "MPEG",
  416. "ASF",
  417. "MOV",
  418. "WMV",
  419. "3GP",
  420. "RM",
  421. "RMVB",
  422. "FLV",
  423. "F4V",
  424. "H.264",
  425. "H.265",
  426. "REAL VIDEO",
  427. "MKV",
  428. "WebM",
  429. "HDDVD",
  430. "MP4",
  431. "MPG",
  432. "M4V",
  433. "MGV",
  434. "OGV",
  435. "QTM",
  436. "STR",
  437. "AMC",
  438. "DVX",
  439. "EVO",
  440. "DAT",
  441. "OGG",
  442. "OGM"
  443. ];
  444. if (
  445. fileA.indexOf(
  446. file.name.split(".")[
  447. file.name.split(".").length - 1
  448. ].toLocaleUpperCase()
  449. ) != -1
  450. ) {
  451. _type = 1; //word 文件
  452. } else if (
  453. videoA.indexOf(
  454. file.name.split(".")[
  455. file.name.split(".").length - 1
  456. ].toLocaleUpperCase()
  457. ) != -1
  458. ) {
  459. _type = 2; //视频
  460. } else if (
  461. imgA.indexOf(
  462. file.name.split(".")[
  463. file.name.split(".").length - 1
  464. ].toLocaleLowerCase()
  465. ) != -1
  466. ) {
  467. _type = 3; //图片
  468. } else if (
  469. "pdf".indexOf(
  470. file.name.split(".")[
  471. file.name.split(".").length - 1
  472. ].toLocaleLowerCase()
  473. ) != -1
  474. ) {
  475. _type = 4; //pdf
  476. } else {
  477. _type = 5; //文件
  478. }
  479. this.uploadList.push({
  480. index: uuidv4(),
  481. file: file,
  482. name:file.name,
  483. type:_type,
  484. progress: { status: "", value: 0,key:"",uploadid:"" }
  485. });
  486. }
  487. this.$nextTick(() => {
  488. this.uploadList.forEach(i => {
  489. this.$refs[`uploadFileRef${i.index}`][0].awsupload({ file: i.file });
  490. });
  491. });
  492. // var credentials = {
  493. // accessKeyId: "AKIATLPEDU37QV5CHLMH",
  494. // secretAccessKey: "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",
  495. // }; //秘钥形式的登录上传
  496. // window.AWS.config.update(credentials);
  497. // window.AWS.config.region = "cn-northwest-1"; //设置区域
  498. // var bucket = new window.AWS.S3({ params: { Bucket: "ccrb" } }); //选择桶
  499. // var _this = this;
  500. // // _this.progress = 0;
  501. // _this.proVisible = true;
  502. // // _this.isFinishSize = 0;
  503. // // _this.isAllSize = (file.size / 1024 / 1024).toFixed(2);
  504. // let _name = file.name
  505. // let size = file.size;
  506. // _this.$forceUpdate();
  507. // if (file) {
  508. // var params = {
  509. // Key:
  510. // file.name.split(".")[0] +
  511. // new Date().getTime() +
  512. // "." +
  513. // file.name.split(".")[file.name.split(".").length - 1],
  514. // ContentType: file.type,
  515. // Body: file,
  516. // "Access-Control-Allow-Credentials": "*",
  517. // ACL: "public-read",
  518. // }; //key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
  519. // var options = {
  520. // partSize: 2048 * 1024 * 1024,
  521. // queueSize: 2,
  522. // leavePartsOnError: true,
  523. // };
  524. // bucket
  525. // .upload(params, options)
  526. // .on("httpUploadProgress", function (evt) {
  527. // //这里可以写进度条
  528. // // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
  529. // // _this.progress = parseInt((evt.loaded / evt.total) * 100);
  530. // // _this.isFinishSize = (evt.loaded / 1024 / 1024).toFixed(2);
  531. // // _this.$forceUpdate();
  532. // })
  533. // .send(function (err, data) {
  534. // cfindex2++;
  535. // // _this.progress = 100;
  536. // // _this.isFinishSize = _this.isAllSize;
  537. // // _this.$forceUpdate();
  538. // // setTimeout(() => {
  539. // // _this.proVisible = false;
  540. // // _this.$forceUpdate();
  541. // // }, 1000);
  542. // setTimeout(() => {
  543. // if (
  544. // cfindex2 == event.target.files.length ||
  545. // cfindex2 > event.target.files.length
  546. // ) {
  547. // _this.proVisible = false;
  548. // }
  549. // }, 1000);
  550. // // loading.close();
  551. // if (err) {
  552. // _this.$message.error("上传失败");
  553. // } else {
  554. // let _type = 2;
  555. // var imgA = [
  556. // "png",
  557. // "jpg",
  558. // "jpeg",
  559. // "bmp",
  560. // "gif",
  561. // "webp",
  562. // "psd",
  563. // "svg",
  564. // "tiff",
  565. // ];
  566. // var fileA = [
  567. // "DOC",
  568. // "DOCX",
  569. // "DOCM",
  570. // "DOTM",
  571. // "DOTX",
  572. // "PPTX",
  573. // "PPSX",
  574. // "PPT",
  575. // "PPS",
  576. // "PPTM",
  577. // "POTM",
  578. // "PPAM",
  579. // "POTX",
  580. // "PPSM",
  581. // "XLSX",
  582. // "XLS",
  583. // ];
  584. // var videoA = [
  585. // "AVI",
  586. // "NAVI",
  587. // "MPEG",
  588. // "ASF",
  589. // "MOV",
  590. // "WMV",
  591. // "3GP",
  592. // "RM",
  593. // "RMVB",
  594. // "FLV",
  595. // "F4V",
  596. // "H.264",
  597. // "H.265",
  598. // "REAL VIDEO",
  599. // "MKV",
  600. // "WebM",
  601. // "HDDVD",
  602. // "MP4",
  603. // "MPG",
  604. // "M4V",
  605. // "MGV",
  606. // "OGV",
  607. // "QTM",
  608. // "STR",
  609. // "AMC",
  610. // "DVX",
  611. // "EVO",
  612. // "DAT",
  613. // "OGG",
  614. // "OGM",
  615. // ];
  616. // if (
  617. // fileA.indexOf(
  618. // data.Location.split(".")[
  619. // data.Location.split(".").length - 1
  620. // ].toLocaleUpperCase()
  621. // ) != -1
  622. // ) {
  623. // _type = 1; //word 文件
  624. // } else if (
  625. // videoA.indexOf(
  626. // data.Location.split(".")[
  627. // data.Location.split(".").length - 1
  628. // ].toLocaleUpperCase()
  629. // ) != -1
  630. // ) {
  631. // _type = 2; //视频
  632. // } else if (
  633. // imgA.indexOf(
  634. // data.Location.split(".")[
  635. // data.Location.split(".").length - 1
  636. // ].toLocaleLowerCase()
  637. // ) != -1
  638. // ) {
  639. // _type = 3; //图片
  640. // } else if (
  641. // 'pdf'.indexOf(
  642. // data.Location.split(".")[
  643. // data.Location.split(".").length - 1
  644. // ].toLocaleLowerCase()
  645. // ) != -1
  646. // ) {
  647. // _type = 4; //pdf
  648. // } else {
  649. // _type = 5; //文件
  650. // }
  651. // if (_this.checkJson.file) {
  652. // _this.checkJson.file.push({
  653. // name: _name,
  654. // url: data.Location,
  655. // type: _type,
  656. // });
  657. // } else {
  658. // _this.checkJson.file = []
  659. // _this.checkJson.file.push({
  660. // name: _name,
  661. // url: data.Location,
  662. // type: _type,
  663. // });
  664. // }
  665. // if(_this.isTong){
  666. // let _file = {
  667. // name: _name,
  668. // url: data.Location,
  669. // type: _type,
  670. // size: _this.formatFileSize(size)
  671. // }
  672. // _this.addSource(_file)
  673. // }
  674. // _this.$forceUpdate();
  675. // _this.$emit('update:cJson', _this.checkJson)
  676. // console.log(_this.checkJson);
  677. // console.log(data.Location);
  678. // }
  679. // });
  680. // }
  681. // }
  682. },
  683. delUploadFile(item){
  684. this.$refs[`uploadFileRef${item.index}`][0].stopUpload();
  685. this.$refs[`uploadFileRef${item.index}`][0].abortMultipartUpload(item.progress.key,item.progress.uploadid);
  686. this.uploadList = this.uploadList.filter(i => i.index != item.index);
  687. },
  688. // 上传文件进度条
  689. progressUpdate(res) {
  690. this.uploadList.find(i => i.index == res.index).progress.status =
  691. res.status;
  692. this.uploadList.find(i => i.index == res.index).progress.value =
  693. res.percent;
  694. this.uploadList.find(i => i.index == res.index).progress.key = res.key;
  695. this.uploadList.find(i => i.index == res.index).progress.uploadid = res.uploadid;
  696. },
  697. //上传文件成功
  698. uploadSuccess(res) {
  699. let data = res.data;
  700. let _name = this.uploadList.find(i => i.index == res.index).file.name;
  701. let size = this.uploadList.find(i => i.index == res.index).file.size;
  702. let _type =this.uploadList.find(i => i.index == res.index).type
  703. if (this.checkJson.file) {
  704. this.checkJson.file.push({
  705. name: _name,
  706. url: data.Location,
  707. type: _type
  708. });
  709. } else {
  710. this.checkJson.file = [];
  711. this.checkJson.file.push({
  712. name: _name,
  713. url: data.Location,
  714. type: _type
  715. });
  716. }
  717. if (this.isTong) {
  718. let _file = {
  719. name: _name,
  720. url: data.Location,
  721. type: _type,
  722. size: this.formatFileSize(size)
  723. };
  724. this.addSource(_file);
  725. }
  726. this.$forceUpdate();
  727. this.$emit("update:cJson", this.checkJson);
  728. this.uploadList = this.uploadList.filter(i => i.index != res.index);
  729. console.log(this.checkJson);
  730. console.log(data.Location);
  731. },
  732. addSource(file) {
  733. let params = [
  734. {
  735. n: file.name,
  736. file: file.url,
  737. type: file.type,
  738. pid: "0",
  739. uid: this.userid,
  740. size: file.size
  741. }
  742. ];
  743. this.ajax
  744. .post(this.$store.state.api + "addSourceFile", params)
  745. .then(res => {
  746. // if (_ctype == 2) {
  747. // this.$message.success('上传成功');
  748. // }
  749. })
  750. .catch(err => {
  751. console.error(err);
  752. });
  753. },
  754. formatFileSize(bytes) {
  755. if (bytes < 1024) {
  756. return bytes + "B";
  757. } else if (bytes < 1048576) {
  758. return (bytes / 1024).toFixed(2) + "KB";
  759. } else if (bytes < 1073741824) {
  760. return (bytes / 1048576).toFixed(2) + "MB";
  761. } else {
  762. return (bytes / 1073741824).toFixed(2) + "GB";
  763. }
  764. },
  765. downloadMobanFile(index){
  766. this.loading = true;
  767. let file = this.checkJson.mobanFile[index]
  768. getFile(file.url).then((data) => {
  769. this.loading = false;
  770. if (data.data != 1) {
  771. // 下载文件, 并存成ArrayBuffer对象
  772. const file_name =file.name; // 获取文件名
  773. const file_data = data.data; // 获取文件数据
  774. let url = window.URL.createObjectURL(new Blob([file_data]));
  775. let a = document.createElement("a");
  776. a.name = file_name;
  777. a.href = url;
  778. a.download = file_name;
  779. a.click();
  780. console.log(data);
  781. this.$message.success("下载成功");
  782. }else {
  783. this.$message.error("下载失败");
  784. }
  785. });
  786. },
  787. downloadFile(f) {
  788. var credentials = {
  789. accessKeyId: "AKIATLPEDU37QV5CHLMH",
  790. secretAccessKey: "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"
  791. }; //秘钥形式的登录上传
  792. window.AWS.config.update(credentials);
  793. window.AWS.config.region = "cn-northwest-1"; //设置区域
  794. let url2 = f.url;
  795. let _url2 = "";
  796. if (
  797. url2.indexOf("https://view.officeapps.live.com/op/view.aspx?src=") != -1
  798. ) {
  799. _url2 = url2.split(
  800. "https://view.officeapps.live.com/op/view.aspx?src="
  801. )[1];
  802. } else {
  803. _url2 = url2;
  804. }
  805. let _this = this;
  806. _this.downLoading = _url2;
  807. var s3 = new window.AWS.S3({ params: { Bucket: "ccrb" } });
  808. let name = decodeURIComponent(
  809. _url2.split("https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/")[1].replace(/\+/g, ' ')
  810. );
  811. var params = {
  812. Bucket: "ccrb",
  813. Key: name
  814. };
  815. s3.getObject(params, function(err, data) {
  816. _this.downLoading = "";
  817. if (err) console.log(err, err.stack);
  818. // an error occurred
  819. else {
  820. let url = window.URL.createObjectURL(new Blob([data.Body]));
  821. let a = document.createElement("a");
  822. a.name = f.name;
  823. a.href = url;
  824. a.download = f.name;
  825. a.click();
  826. console.log(data);
  827. } // sxuccessful response
  828. });
  829. },
  830. setCheckJson(name, url, type) {
  831. if (this.checkJson.file) {
  832. this.checkJson.file.push({
  833. name: name,
  834. url: url,
  835. type: type
  836. });
  837. } else {
  838. this.checkJson.file = [];
  839. this.checkJson.file.push({
  840. name: name,
  841. url: url,
  842. type: type
  843. });
  844. }
  845. this.$forceUpdate();
  846. },
  847. checkFile(item) {
  848. if (item.type == 3) {
  849. this.$hevueImgPreview(item.url);
  850. } else if (item.type == 5) {
  851. this.downloadFile(item);
  852. } else if (item.type == 1) {
  853. this.dialogVisibleOffice = true;
  854. this.wurl = item.url;
  855. } else if (item.type == 2) {
  856. this.dialogVisibleVideo = true;
  857. this.wurl = item.url;
  858. } else if (item.type == 4) {
  859. this.dialogVisiblePdf = true;
  860. this.wurl = item.url;
  861. }
  862. },
  863. delFile(index) {
  864. this.checkJson.file.splice(index, 1);
  865. this.$emit("update:cJson", this.checkJson);
  866. this.$forceUpdate();
  867. },
  868. uploadCourse() {
  869. this.isloading = true;
  870. const _chapInfo = this.checkJson.file;
  871. let url = [];
  872. for (let i = 0; i < _chapInfo.length; i++) {
  873. url.push({
  874. name: _chapInfo[i].name,
  875. url: _chapInfo[i].url
  876. });
  877. }
  878. console.log(url);
  879. this.downLoadAll(url);
  880. },
  881. downLoadAll(url) {
  882. const data = url; // 需要下载打包的路径, 可以是本地相对路径, 也可以是跨域的全路径
  883. const zip = new JSZip();
  884. const cache = {};
  885. const promises = [];
  886. data.forEach(item => {
  887. const promise = getFile(item.url).then(data => {
  888. if (data.data != 1) {
  889. // 下载文件, 并存成ArrayBuffer对象
  890. const file_name = item.name; // 获取文件名
  891. zip.file(file_name, data.data, { binary: true }); // 逐个添加文件
  892. cache[file_name] = data.data;
  893. }
  894. });
  895. promises.push(promise);
  896. });
  897. Promise.all(promises).then(() => {
  898. zip.generateAsync({ type: "blob" }).then(content => {
  899. // 生成二进制流
  900. FileSaver.saveAs(content, "附件.zip"); // 利用file-saver保存文件 自定义文件名
  901. setTimeout(() => {
  902. this.isloading = false;
  903. }, 2000);
  904. });
  905. });
  906. }
  907. },
  908. mounted() {
  909. this.checkJson = this.cJson ? this.depthCopy(this.cJson) : undefined;
  910. }
  911. };
  912. </script>
  913. <style scoped>
  914. .c_box {
  915. width: 100%;
  916. position: relative;
  917. padding-left: 45px;
  918. }
  919. /* .mask {
  920. position: absolute;
  921. height: 100%;
  922. width: 100%;
  923. z-index: 2;
  924. } */
  925. .choice_box {
  926. white-space: pre-line;
  927. }
  928. .choice_box > .title {
  929. font-weight: bold;
  930. width: 100%;
  931. word-break: break-all;
  932. }
  933. .choice_box > .choices {
  934. margin-top: 10px;
  935. }
  936. .binfo_input {
  937. width: 100%;
  938. margin: 0;
  939. padding: 10px;
  940. display: block;
  941. min-width: 0;
  942. outline: none;
  943. box-sizing: border-box;
  944. background: none;
  945. border: none;
  946. border-radius: 5px;
  947. background: #fff;
  948. font-size: 16px;
  949. resize: none;
  950. font-family: "Microsoft YaHei";
  951. min-height: 120px;
  952. /* border: 1px solid #3682fc00; */
  953. border: 1.5px solid #e0e0e0;
  954. position: relative;
  955. }
  956. .binfo_input > .uploadQ {
  957. /* border: 1.5px dashed #dfdfdf; */
  958. height: 120px;
  959. width: 100%;
  960. display: flex;
  961. align-items: center;
  962. justify-content: center;
  963. /* background: #f9fafb; */
  964. background-color: #fff;
  965. font-size: 22px;
  966. color: rgb(124, 124, 124);
  967. border-radius: 5px;
  968. cursor: pointer;
  969. }
  970. .mask {
  971. background-color: rgb(0 0 0 / 30%);
  972. /* position: fixed; */
  973. position: absolute;
  974. top: 0;
  975. left: 0;
  976. width: 100%;
  977. height: 100%;
  978. z-index: 90;
  979. display: flex;
  980. align-items: center;
  981. justify-content: center;
  982. }
  983. .progressBox {
  984. width: 300px;
  985. height: 150px;
  986. background: #fff;
  987. border-radius: 10px;
  988. box-shadow: 0 0 6px 1px #bfbfbf;
  989. display: flex;
  990. align-items: center;
  991. justify-content: center;
  992. flex-direction: column;
  993. position: relative;
  994. color: #6c6c6c;
  995. }
  996. .progressBox >>> .el-progress-bar__outer {
  997. background-color: #d1dfff !important;
  998. }
  999. .progressBox .lbox {
  1000. height: 50px;
  1001. font-size: 19px;
  1002. display: flex;
  1003. align-items: center;
  1004. color: #747474;
  1005. }
  1006. .progressBox .lbox img {
  1007. width: 40px;
  1008. margin-right: 20px;
  1009. }
  1010. .closeCss {
  1011. position: absolute;
  1012. top: 8px;
  1013. right: 8px;
  1014. cursor: pointer;
  1015. width: 20px;
  1016. height: 20px;
  1017. }
  1018. .closeCss > img {
  1019. width: 100%;
  1020. height: 100%;
  1021. }
  1022. .binfo_input > .fileBox {
  1023. }
  1024. .binfo_input > .fileBox .fileC {
  1025. display: flex;
  1026. flex-wrap: wrap;
  1027. width: 100%;
  1028. cursor: pointer;
  1029. }
  1030. .binfo_input > .fileBox .fileC > .file {
  1031. width: 200px;
  1032. height: 140px;
  1033. margin: 10px 10px 10px 0px;
  1034. border-radius: 15px;
  1035. box-shadow: rgb(223, 218, 218) 0px 0px 6px 1px;
  1036. overflow: hidden;
  1037. margin-right: 15px;
  1038. position: relative;
  1039. display: flex;
  1040. flex-direction: column;
  1041. }
  1042. .binfo_input > .fileBox .fileC > .file > .img {
  1043. width: 100%;
  1044. height: calc(100% - 35px);
  1045. object-fit: cover;
  1046. }
  1047. .binfo_input > .fileBox .fileC > .file > .del {
  1048. position: absolute;
  1049. width: 25px;
  1050. top: 10px;
  1051. right: 10px;
  1052. cursor: pointer;
  1053. z-index: 10;
  1054. }
  1055. .binfo_input > .fileBox .fileC > .file > .download {
  1056. position: absolute;
  1057. width: 25px;
  1058. top: 10px;
  1059. right: 35px;
  1060. cursor: pointer;
  1061. opacity: 0.8;
  1062. }
  1063. .binfo_input > .fileBox .fileC > .file > .name {
  1064. height: 35px;
  1065. width: 100%;
  1066. background: #f9f9f9;
  1067. display: flex;
  1068. align-items: center;
  1069. padding: 0 10px;
  1070. box-sizing: border-box;
  1071. }
  1072. .binfo_input > .fileBox .fileC > .file > .name > span {
  1073. display: block;
  1074. text-overflow: ellipsis;
  1075. max-width: 100%;
  1076. white-space: nowrap;
  1077. overflow: hidden;
  1078. }
  1079. .binfo_input > .fileBox .btn {
  1080. width: 100%;
  1081. height: 40px;
  1082. background: #007bff;
  1083. color: #fff;
  1084. border-radius: 15px;
  1085. margin-top: 10px;
  1086. display: flex;
  1087. align-items: center;
  1088. justify-content: center;
  1089. cursor: pointer;
  1090. }
  1091. .choice_box > .c_title {
  1092. display: flex;
  1093. justify-content: space-between;
  1094. }
  1095. .choice_box > .c_title .title {
  1096. font-weight: bold;
  1097. width: 100%;
  1098. word-break: break-all;
  1099. }
  1100. .choice_box > .c_title .p_box {
  1101. margin-left: 5px;
  1102. min-width: fit-content;
  1103. display: flex;
  1104. align-items: center;
  1105. }
  1106. .p_box > .btnU {
  1107. color: #fff;
  1108. background-color: #0061ff;
  1109. padding: 0 24px;
  1110. font-size: 14px;
  1111. min-width: 64px;
  1112. font-weight: 500;
  1113. border-radius: 4px;
  1114. box-sizing: border-box;
  1115. border: none;
  1116. cursor: pointer;
  1117. transition: all 0.2s ease-in-out;
  1118. height: 36px;
  1119. display: flex;
  1120. align-items: center;
  1121. justify-content: center;
  1122. line-height: 1;
  1123. }
  1124. .c_input {
  1125. width: 90px;
  1126. }
  1127. .c_input >>> .el-input__inner {
  1128. padding: 0 5px;
  1129. text-align: right;
  1130. }
  1131. .uploadBtn {
  1132. display: flex;
  1133. margin-bottom: 10px;
  1134. align-items: center;
  1135. width: 100%;
  1136. justify-content: flex-end;
  1137. }
  1138. .uploadBtn .btn {
  1139. display: flex;
  1140. cursor: pointer;
  1141. align-items: center;
  1142. height: 30px;
  1143. padding: 0 8px;
  1144. background: #fff;
  1145. color: #3681fc;
  1146. border: 1px solid #3681fc;
  1147. box-sizing: border-box;
  1148. border-radius: 4px;
  1149. font-size: 14px;
  1150. align-items: center;
  1151. margin-right: 10px;
  1152. }
  1153. .uploadBtn .switch {
  1154. display: flex;
  1155. align-items: center;
  1156. cursor: pointer;
  1157. }
  1158. .uploadBtn .switch > span {
  1159. margin-left: 5px;
  1160. }
  1161. .uploadProgress{
  1162. position: absolute;
  1163. width: 100%;
  1164. height: calc(100% - 35px);
  1165. background-color: #0000008a;
  1166. display: flex;
  1167. top: 0;
  1168. flex-direction: column;
  1169. justify-content: center;
  1170. align-items: center;
  1171. color: #fff;
  1172. }
  1173. .uploadProgress>div{
  1174. font-size: 20px;
  1175. font-weight: bold;
  1176. margin-bottom: 10px;
  1177. }
  1178. .file_box {
  1179. /* padding: 0 0 0 15px; */
  1180. width: 100%;
  1181. box-sizing: border-box;
  1182. margin: 10px 0;
  1183. }
  1184. .file_item {
  1185. display: flex;
  1186. width: 100%;
  1187. padding: 5px;
  1188. box-sizing: border-box;
  1189. border-radius: 5px;
  1190. }
  1191. .file_item+.file_item {
  1192. margin-top: 10px;
  1193. }
  1194. .file_name {
  1195. color: #747474;
  1196. }
  1197. .file_item:hover{
  1198. background: #eee;
  1199. }
  1200. .file_btns {
  1201. margin-left: auto;
  1202. display: flex;
  1203. align-items: center;
  1204. }
  1205. .file_btn+.file_btn {
  1206. margin-left: 10px;
  1207. }
  1208. .file_btn {
  1209. color: #3681fc;
  1210. cursor: pointer;
  1211. }
  1212. .g_t_index{
  1213. color: #3681FC;
  1214. font-size: 28px;
  1215. font-weight: bold;
  1216. position: relative;
  1217. margin-right: 30px;
  1218. margin-left: -40px;
  1219. }
  1220. .g_t_index+span{
  1221. font-weight: bold;
  1222. font-size: 18px;
  1223. }
  1224. .g_t_index::after{
  1225. content: "";
  1226. width: 18px;
  1227. height: 2px;
  1228. position: absolute;
  1229. right: -18px;
  1230. top: 50%;
  1231. transform: translateY(-50%);
  1232. background: #3681FC;
  1233. }
  1234. .g_t_index::before{
  1235. content: "";
  1236. width: 6px;
  1237. height: 6px;
  1238. border-right: 2px solid #3681FC;
  1239. border-top: 2px solid #3681FC;
  1240. position: absolute;
  1241. right: -15px;
  1242. top: 50%;
  1243. transform: rotate(45deg) translateY(-5px);
  1244. }
  1245. </style>