uploadDown.vue 5.8 KB

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