fileBox.vue 42 KB

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