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.

101 lines
2.8 KiB

4 years ago
4 years ago
  1. <template>
  2. <el-dialog
  3. title="上传文件"
  4. append-to-body
  5. width="478px"
  6. :close-on-click-modal="false"
  7. @close="closeHandle"
  8. :visible.sync="visible">
  9. <el-upload
  10. drag
  11. :action="url"
  12. :before-upload="beforeUploadHandle"
  13. :on-success="successHandle"
  14. multiple
  15. :file-list="fileList"
  16. style="text-align: center;">
  17. <i class="el-icon-upload"></i>
  18. <div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
  19. <div class="el-upload__tip" slot="tip">预览只支持.jpg.png.gif.pdf格式</div>
  20. </el-upload>
  21. </el-dialog>
  22. </template>
  23. <script>
  24. import {updateOssRef} from '@/api/oss/oss.js'
  25. export default {
  26. data() {
  27. return {
  28. visible: false,
  29. url: '',
  30. num: 0,
  31. successNum: 0,
  32. fileList: [],
  33. folder: '系统文件',
  34. fileMappingDto: {
  35. fileType: '',
  36. orderRef1: '',
  37. orderRef2: '',
  38. orderRef3: '',
  39. }
  40. }
  41. },
  42. methods: {
  43. init(val) {
  44. this.url = this.$http.adornUrl(`/api/ftp/file/upload?token=${this.$cookie.get('token')}&folder=` + this.folder)
  45. this.visible = true
  46. this.fileMappingDto = val
  47. },
  48. // 上传之前
  49. beforeUploadHandle(file) {
  50. // if (file.type !== 'image/jpg' && file.type !== 'image/jpeg' && file.type !== 'image/png' && file.type !== 'image/gif') {
  51. // this.$message.error('只支持jpg、png、gif格式的图片!')
  52. // return false
  53. // }
  54. this.num++
  55. },
  56. // 上传成功
  57. successHandle(response, file, fileList) {
  58. this.fileList = fileList
  59. this.successNum++
  60. if (response && response.code === 0) {
  61. if (this.num === this.successNum) {
  62. // 回写文件的订单属性
  63. let ossRet = response.ossEntity
  64. let ossTo = {
  65. id: ossRet.id,
  66. fileType: this.fileMappingDto.fileType,
  67. orderRef1: this.fileMappingDto.orderRef1,
  68. orderRef2: this.fileMappingDto.orderRef2,
  69. orderRef3: this.fileMappingDto.orderRef3,
  70. fileTypeCode: 1,
  71. fileSuffix: file.name.substring(file.name.indexOf(".")+1),
  72. }
  73. updateOssRef(ossTo).then(({data}) => {
  74. if (data.code == 0) {
  75. this.$confirm('操作成功, 是否继续操作?', '提示', {
  76. confirmButtonText: '确定',
  77. cancelButtonText: '取消',
  78. type: 'warning'
  79. }).catch(() => {
  80. this.visible = false
  81. })
  82. }else {
  83. this.$message.warning('上传失败,请重新上传')
  84. }
  85. })
  86. }
  87. } else {
  88. this.$message.error(response.msg)
  89. }
  90. },
  91. // 弹窗关闭时
  92. closeHandle() {
  93. this.fileList = []
  94. this.$emit('refreshDataList')
  95. }
  96. }
  97. }
  98. </script>