uploadDown.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div class="back-box">
  3. <div v-for="item in infolist" :key="item.id" @click="downcheck(item)">
  4. <i class="iconfont icon-word" v-if="item.type === 'word'"></i>
  5. <i class="iconfont icon-excel" v-if="item.type === 'excel'"></i>
  6. <i class="iconfont icon-ppt" v-if="item.type === 'ppt'"></i>
  7. <i class="iconfont icon-wenjian" v-if="item.type === 'wenjian'"></i>
  8. <i class="el-icon-picture" v-if="item.type === 'png'"></i>
  9. <el-tooltip
  10. class="item"
  11. effect="dark"
  12. :content="item.fileName"
  13. placement="right"
  14. :enterable="false"
  15. >
  16. <span class="tab-long">{{ item.fileName }}</span>
  17. </el-tooltip>
  18. <div class="seedown" v-if="datalist.type === 2">
  19. <a @click="uploaddown(item)">下载</a>
  20. <a @click="uploadsee(item)">预览</a>
  21. </div>
  22. </div>
  23. <div class="if-box-top" v-if="ifrshow" @keyup.esc="ifrshow = false">
  24. <i class="el-icon-close" @click="ifrshow = false"></i>
  25. <iframe height="100%" width="100%" :src="srcsc"> </iframe>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. export default {
  31. props: ["datalist", "dialogStatus"],
  32. data() {
  33. return {
  34. infolist: [],
  35. status: false,
  36. srcsc: "",
  37. ifrshow: false,
  38. };
  39. },
  40. methods: {
  41. downcheck(v) {
  42. if (this.datalist.type === 1) {
  43. this.uploaddown(v);
  44. }
  45. },
  46. uploadsee(v) {
  47. let url = encodeURIComponent(v.callPath);
  48. this.srcsc = "http://114.215.71.182:8012/onlinePreview?url=" + url;
  49. this.ifrshow = true;
  50. // window.open('http://114.215.71.182:8012/onlinePreview?url=' + url);
  51. },
  52. //下载e
  53. uploaddown(v) {
  54. let fileData = v;
  55. this.$http({
  56. url: this.datalist.url,
  57. method: "post",
  58. headers: {
  59. "Content-Type": "application/json",
  60. },
  61. responseType: "blob",
  62. data: { id: fileData.id, fileName: fileData.fileName },
  63. }).then((response) => {
  64. if (window.navigator && window.navigator.msSaveOrOpenBlob) {
  65. let blob = new Blob([response.data], {
  66. type: "application/vnd.ms-excel",
  67. });
  68. window.navigator.msSaveOrOpenBlob(blob, fileData.fileName);
  69. } else {
  70. /* 火狐谷歌的文件下载方式 */
  71. var blob = new Blob([response.data]);
  72. var downloadElement = document.createElement("a");
  73. var href = window.URL.createObjectURL(blob);
  74. downloadElement.href = href;
  75. downloadElement.download = fileData.fileName;
  76. document.body.appendChild(downloadElement);
  77. downloadElement.click();
  78. document.body.removeChild(downloadElement);
  79. window.URL.revokeObjectURL(href);
  80. }
  81. });
  82. },
  83. dataHandle() {
  84. this.infolist = this.datalist.attList;
  85. if (this.infolist) {
  86. for (let i = 0; i < this.infolist.length; i++) {
  87. let f = this.infolist[i].fileName.split(".");
  88. let type = f[f.length - 1];
  89. if (type === "doc" || type === "docx") {
  90. this.infolist[i].type = "word";
  91. } else if (type === "ppt") {
  92. this.infolist[i].type = "ppt";
  93. } else if (type === "xlsx" || type === "xls") {
  94. this.infolist[i].type = "excel";
  95. } else if (
  96. type === "png" ||
  97. type === "jpg" ||
  98. type === "svg" ||
  99. type === "gif" ||
  100. type === "psd"
  101. ) {
  102. this.infolist[i].type = "png";
  103. } else {
  104. this.infolist[i].type = "wenjian";
  105. }
  106. }
  107. }
  108. },
  109. },
  110. mounted() {
  111. this.dataHandle();
  112. console.log(this.infolist);
  113. },
  114. created() {},
  115. watch: {
  116. dialogStatus() {
  117. this.$forceUpdate();
  118. let _this = this;
  119. _this.dataHandle();
  120. },
  121. },
  122. };
  123. </script>
  124. <style scoped lang="scss">
  125. .if-box-top {
  126. background: #fff;
  127. width: 80vw;
  128. height: 80vh;
  129. margin-top: 10vh;
  130. margin-left: 10vw;
  131. }
  132. .iconfont {
  133. font-size: 42px;
  134. }
  135. .icon-excel {
  136. color: #67db63;
  137. }
  138. .icon-word {
  139. color: #ff654e;
  140. }
  141. .icon-ppt {
  142. color: #ff8943;
  143. }
  144. .icon-wenjian {
  145. color: #ccc;
  146. }
  147. .el-icon-picture {
  148. font-size: 36px;
  149. color: #ccc;
  150. background: #fff;
  151. padding: 4px 2px;
  152. margin-bottom: 2px;
  153. border-radius: 3px;
  154. }
  155. .back-box {
  156. margin-top: 20px;
  157. background: #f2f2f2;
  158. padding: 20px;
  159. div {
  160. display: inline-block;
  161. text-align: center;
  162. margin-right: 20px;
  163. cursor: pointer;
  164. span {
  165. display: block;
  166. width: 80px;
  167. overflow: hidden;
  168. padding-top: 5px;
  169. margin: 0 10px;
  170. overflow: hidden;
  171. text-overflow: ellipsis;
  172. display: -webkit-box; /* 将对象作为弹性伸缩盒子模型显示 */
  173. -webkit-line-clamp: 1; /* 控制最多显示几行 */
  174. -webkit-box-orient: vertical; /* 设置或检索伸缩盒对象的子元素的排列方式 */
  175. }
  176. }
  177. .seedown {
  178. margin: 0;
  179. margin-top: 5px;
  180. a {
  181. font-size: 12px;
  182. padding: 2px 5px;
  183. border: 1px solid transparent;
  184. color: #999;
  185. }
  186. a:hover {
  187. color: #0b82ff;
  188. }
  189. }
  190. }
  191. </style>