You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
5.7 KiB

3 years ago
3 years ago
3 years ago
  1. <template>
  2. <div class="mod-oss">
  3. <el-dialog
  4. :title="title"
  5. :visible.sync="visible"
  6. width="800px"
  7. :append-to-body="true">
  8. <el-form :inline="true" >
  9. <el-form-item>
  10. <el-input v-model="fileMappingDto.fileName"></el-input>
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" @click="getDataList()">查询</el-button>
  14. </el-form-item>
  15. </el-form>
  16. <el-table
  17. :data="dataList"
  18. border
  19. :height="tableHeight"
  20. v-loading="dataListLoading"
  21. style="width: 100%;">
  22. <el-table-column
  23. prop="fileName"
  24. header-align="center"
  25. align="left"
  26. label="文件名">
  27. </el-table-column>
  28. <el-table-column
  29. prop="createdBy"
  30. header-align="center"
  31. align="left"
  32. width="180"
  33. label="创建人">
  34. </el-table-column>
  35. <el-table-column
  36. prop="createDate"
  37. header-align="center"
  38. align="left"
  39. width="180"
  40. label="创建时间">
  41. </el-table-column>
  42. <el-table-column
  43. fixed="right"
  44. header-align="center"
  45. align="center"
  46. width="150"
  47. label="操作">
  48. <template slot-scope="scope">
  49. <a @click="fileDownload(scope.row)">下载</a>
  50. <a @click="filePreview(scope.row)" v-if="showPreview(scope.row)">预览</a>
  51. </template>
  52. </el-table-column>
  53. </el-table>
  54. </el-dialog>
  55. <el-dialog append-to-body v-if="pdfVisible" title="预览" :visible.sync="pdfVisible" center width="60%">
  56. <iframe :src="this.pdfUrl" frameborder="0" width="100%" :height="height"></iframe>
  57. </el-dialog>
  58. </div>
  59. </template>
  60. <script>
  61. import axios from "axios";
  62. import Vue from "vue";
  63. export default {
  64. data() {
  65. return {
  66. menuId: '',
  67. height: '',
  68. title: '',
  69. uploadShow: false,
  70. tableHeight: 365,
  71. visible: false,
  72. pdfUrl: '',
  73. pdfVisible: false,
  74. dataForm: {
  75. fileName: ''
  76. },
  77. dataList: [],
  78. pageIndex: 1,
  79. pageSize: 200,
  80. totalPage: 0,
  81. dataListLoading: false,
  82. dataListSelections: [],
  83. configVisible: false,
  84. uploadVisible: false,
  85. fileMappingDto: {
  86. fileId: '',
  87. fileType: '',
  88. orderRef1: '',
  89. orderRef2: '',
  90. orderRef3: '',
  91. }
  92. }
  93. },
  94. components: {
  95. },
  96. mounted() {
  97. this.$nextTick(() => {
  98. this.height = (window.innerHeight*0.82);
  99. })
  100. },
  101. activated() {
  102. this.getDataList()
  103. },
  104. methods: {
  105. // 是否能预览
  106. showPreview(val){
  107. if (val.fileSuffix=='jpg' || val.fileSuffix=='png' || val.fileSuffix=='gif' || val.fileSuffix=='pdf' ){
  108. return true
  109. }
  110. return false
  111. },
  112. // 初始化
  113. init(val) {
  114. this.fileMappingDto = val
  115. this.title = val.fileType
  116. if (val.fileType == '功能帮助文档'){
  117. this.title = this.title+" - "+this.$route.meta.title
  118. }
  119. this.visible = true
  120. this.getDataList()
  121. },
  122. // 预览
  123. filePreview(row) {
  124. this.pdfVisible = true
  125. this.pdfUrl = '/file/' + row.newFileName
  126. },
  127. // 文件下载
  128. fileDownload(row) {
  129. axios.get('/ftp/file/downFtpFile/' + row.id, {
  130. responseType: 'blob',
  131. headers: {
  132. 'Content-Type': 'application/json',
  133. 'token': Vue.cookie.get('token')
  134. }
  135. }).then(({data}) => {
  136. // 不限制文件下载类型
  137. const blob = new Blob([data], {type: "application/octet-stream"})
  138. // 下载文件名称
  139. const fileName = row.fileName
  140. // a标签下载
  141. const linkNode = document.createElement('a')
  142. linkNode.download = fileName // a标签的download属性规定下载文件的名称
  143. linkNode.style.display = 'none'
  144. linkNode.href = URL.createObjectURL(blob) // 生成一个Blob URL
  145. // if(val == 'Y'){
  146. // this.pdfVisible = true
  147. // this.pdfUrl = linkNode.href
  148. // }else {
  149. document.body.appendChild(linkNode)
  150. linkNode.click() // 模拟在按钮上的一次鼠标单击
  151. URL.revokeObjectURL(linkNode.href) // 释放URL 对象
  152. document.body.removeChild(linkNode)
  153. // }
  154. })
  155. },
  156. downloadFile(fileName, data) {
  157. if (!data) {
  158. return;
  159. }
  160. let url = window.URL.createObjectURL(new Blob([data]));
  161. let link = document.createElement('a');
  162. link.style.display = 'none';
  163. link.href = url;
  164. link.setAttribute('download', fileName);
  165. document.body.appendChild(link);
  166. link.click();
  167. },
  168. // 获取数据列表
  169. getDataList() {
  170. this.dataListLoading = true
  171. this.$http({
  172. url: this.$http.adornUrl('/sys/oss/list'),
  173. method: 'get',
  174. params: this.$http.adornParams({
  175. 'page': this.pageIndex,
  176. 'limit': this.pageSize,
  177. 'fileName': this.fileMappingDto.fileName,
  178. 'fileType': this.fileMappingDto.fileType,
  179. 'orderRef1': this.fileMappingDto.orderRef1,
  180. 'orderRef2': this.fileMappingDto.orderRef2,
  181. 'orderRef3': this.fileMappingDto.orderRef3,
  182. })
  183. }).then(({data}) => {
  184. if (data && data.code === 0) {
  185. this.dataList = data.page.list
  186. this.totalPage = data.page.totalCount
  187. } else {
  188. this.dataList = []
  189. this.totalPage = 0
  190. }
  191. this.dataListLoading = false
  192. })
  193. },
  194. // 每页数
  195. sizeChangeHandle(val) {
  196. this.pageSize = val
  197. this.pageIndex = 1
  198. this.getDataList()
  199. },
  200. // 当前页
  201. currentChangeHandle(val) {
  202. this.pageIndex = val
  203. this.getDataList()
  204. },
  205. }
  206. }
  207. </script>