赫艾前端
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.

269 lines
8.3 KiB

4 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <div>
  3. <el-dialog v-drag
  4. :title="'附件列表'"
  5. :close-on-click-modal="false"
  6. width="666px"
  7. :visible.sync="visible">
  8. <el-form :model="dataForm" :inline="true" label-position="top" ref="dataForm"
  9. label-width="80px">
  10. <el-row style="margin-top: -5px">
  11. <el-col :span="24">
  12. <!-- <el-form-item label="附件">-->
  13. <!-- <el-input style="width: 305px; color: red" readonly v-model="dataForm.fileName"></el-input>-->
  14. <!-- </el-form-item>-->
  15. <el-form-item style="margin-top: 10px">
  16. <ftp-upload @childByValue="childByValue"></ftp-upload>
  17. </el-form-item>
  18. </el-col>
  19. </el-row>
  20. <el-row>
  21. <el-col :span="24">
  22. <span style="font-size: 12px">附件清单</span>
  23. <el-table
  24. :data="fileList"
  25. border
  26. :height="height"
  27. highlight-current-row
  28. style="width: 100%;">
  29. <el-table-column
  30. v-for="(item,index) in columnList" :key="index"
  31. :sortable="item.columnSortable"
  32. :prop="item.columnProp"
  33. :header-align="'center'"
  34. :show-overflow-tooltip="item.showOverflowTooltip"
  35. :align="item.align"
  36. :fixed="item.fixed==''?false:item.fixed"
  37. :width="item.columnWidth"
  38. :label="item.columnLabel">
  39. <template slot-scope="scope">
  40. <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
  41. <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
  42. style="width: 100px; height: 80px"/></span>
  43. </template>
  44. </el-table-column>
  45. <el-table-column
  46. fixed="right"
  47. header-align="center"
  48. align="center"
  49. width="80"
  50. label="操作">
  51. <template slot-scope="scope">
  52. <el-link type="text" size="small" @click="downFtpFile(scope.row)"> 下载 </el-link>
  53. <el-link type="text" size="small" @click="deleteHandle(scope.row.id)">| 删除</el-link>
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. </el-col>
  58. </el-row>
  59. </el-form>
  60. <span slot="footer" class="dialog-footer">
  61. <el-button type="primary" @click="visible = false">取消</el-button>
  62. </span>
  63. </el-dialog>
  64. </div>
  65. </template>
  66. <script>
  67. import {ossList,downFtpFileNotFtp} from '@/api/ftp/oss.js'
  68. import Vue from "vue";
  69. import FtpUpload from '@/views/modules/common/ftp-upload.vue'
  70. import axios from "axios";
  71. export default {
  72. data() {
  73. return {
  74. visible: false,
  75. height: 200,
  76. // 展示列集
  77. columnList: [
  78. {
  79. columnProp: "businessType",
  80. columnLabel: "附件类型",
  81. columnHidden: false,
  82. columnImage: false,
  83. columnSortable: false,
  84. columnWidth: 80,
  85. format: null,
  86. sortLv: 0,
  87. status: true,
  88. fixed: '',
  89. serialNumber: null,
  90. columnType: null,
  91. align: null
  92. },
  93. {
  94. columnProp: "fileName",
  95. columnLabel: "文件名",
  96. columnHidden: false,
  97. columnImage: false,
  98. columnSortable: false,
  99. columnWidth: null,
  100. format: null,
  101. sortLv: 0,
  102. status: true,
  103. fixed: '',
  104. serialNumber: null,
  105. columnType: null,
  106. align: null
  107. },
  108. {
  109. columnProp: "fileType",
  110. columnLabel: "文件类型",
  111. columnHidden: false,
  112. columnImage: false,
  113. columnSortable: false,
  114. columnWidth: 80,
  115. format: null,
  116. sortLv: 0,
  117. status: true,
  118. fixed: '',
  119. serialNumber: null,
  120. columnType: null,
  121. align: null
  122. },
  123. {
  124. columnProp: "createdBy",
  125. columnLabel: "上传人",
  126. columnHidden: false,
  127. columnImage: false,
  128. columnSortable: false,
  129. columnWidth: 100,
  130. format: null,
  131. sortLv: 0,
  132. status: true,
  133. fixed: '',
  134. serialNumber: null,
  135. columnType: null,
  136. align: null
  137. },
  138. {
  139. columnProp: "createDate",
  140. columnLabel: "上传时间",
  141. columnHidden: false,
  142. columnImage: false,
  143. columnSortable: false,
  144. columnWidth: 130,
  145. format: null,
  146. sortLv: 0,
  147. status: true,
  148. fixed: '',
  149. serialNumber: null,
  150. columnType: null,
  151. align: null
  152. }
  153. ],
  154. dataListSelections: [],
  155. dataForm: {},
  156. fileList: []
  157. }
  158. },
  159. components: {
  160. FtpUpload
  161. },
  162. methods: {
  163. init(val) {
  164. this.dataForm = val
  165. this.visible = true
  166. this.getDataList()
  167. },
  168. childByValue(childValue) {
  169. // childValue就是子组件传过来的值
  170. this.dataForm.fileName = childValue.fileName
  171. this.fileList.push(childValue)
  172. // 回写关键字段
  173. let dto = {
  174. id: childValue.id,
  175. orderRef1: this.dataForm.orderRef3,
  176. orderRef2: this.dataForm.orderRef3,
  177. orderRef3: this.dataForm.orderRef3,
  178. fileTypeCode: this.dataForm.fileTypeCode,
  179. businessType: '任务附件',
  180. }
  181. this.updateOrderRef(dto)
  182. },
  183. // 附件列表
  184. getDataList() {
  185. ossList(this.dataForm).then(({data}) => {
  186. if (data && data.code == 0) {
  187. this.fileList = data.data
  188. } else {
  189. this.fileList = []
  190. }
  191. })
  192. },
  193. // 回写关键字段
  194. updateOrderRef(val) {
  195. this.$http({
  196. url: this.$http.adornUrl('/sys/oss/uploadSysOss'),
  197. method: 'post',
  198. data: this.$http.adornData(val, false)
  199. }).then(({data}) => {
  200. if (data && data.code === 0) {
  201. this.$message.success('操作成功')
  202. this.getDataList()
  203. } else {
  204. this.$message.error(data.msg)
  205. }
  206. })
  207. },
  208. // 下载附件
  209. downFtpFile(row) {
  210. // axios.get('/api/ftp/file/downFtpFile/' + row.id, {
  211. // responseType: 'blob',
  212. // headers: {
  213. // 'Content-Type': 'application/json',
  214. // 'token': Vue.cookie.get('token')
  215. // }
  216. // }).then(({data}) => {
  217. downFtpFileNotFtp(row)
  218. .then(({data}) => {
  219. // 不限制文件下载类型
  220. const blob = new Blob([data], {type: "application/octet-stream"})
  221. // 下载文件名称
  222. const fileName = row.fileName
  223. // a标签下载
  224. const linkNode = document.createElement('a')
  225. linkNode.download = fileName // a标签的download属性规定下载文件的名称
  226. linkNode.style.display = 'none'
  227. linkNode.href = URL.createObjectURL(blob) // 生成一个Blob URL
  228. document.body.appendChild(linkNode)
  229. linkNode.click() // 模拟在按钮上的一次鼠标单击
  230. URL.revokeObjectURL(linkNode.href) // 释放URL 对象
  231. document.body.removeChild(linkNode)
  232. // }
  233. })
  234. },
  235. // 删除
  236. deleteHandle(id) {
  237. let ids = [id]
  238. this.$confirm(`确定进行[删除]操作?`, '提示', {
  239. confirmButtonText: '确定',
  240. cancelButtonText: '取消',
  241. type: 'warning'
  242. }).then(() => {
  243. this.$http({
  244. url: this.$http.adornUrl('/sys/oss/delete'),
  245. method: 'post',
  246. data: this.$http.adornData(ids, false)
  247. }).then(({data}) => {
  248. if (data && data.code === 0) {
  249. this.$message.success('操作成功')
  250. this.getDataList()
  251. } else {
  252. this.$message.error(data.msg)
  253. }
  254. })
  255. }).catch(() => {
  256. })
  257. }
  258. },
  259. created() {
  260. }
  261. }
  262. </script>