plm前端
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.

257 lines
7.3 KiB

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