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.

102 lines
2.8 KiB

2 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(`/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. console.log(file)
  59. this.fileList = fileList
  60. this.successNum++
  61. if (response && response.code === 0) {
  62. if (this.num === this.successNum) {
  63. // 回写文件的订单属性
  64. let ossRet = response.ossEntity
  65. let ossTo = {
  66. id: ossRet.id,
  67. fileType: this.fileMappingDto.fileType,
  68. orderRef1: this.fileMappingDto.orderRef1,
  69. orderRef2: this.fileMappingDto.orderRef2,
  70. orderRef3: this.fileMappingDto.orderRef3,
  71. fileTypeCode: 1,
  72. fileSuffix: file.name.substring(file.name.indexOf(".")+1),
  73. }
  74. updateOssRef(ossTo).then(({data}) => {
  75. if (data.code == 0) {
  76. this.$confirm('操作成功, 是否继续操作?', '提示', {
  77. confirmButtonText: '确定',
  78. cancelButtonText: '取消',
  79. type: 'warning'
  80. }).catch(() => {
  81. this.visible = false
  82. })
  83. }else {
  84. this.$message.warning('上传失败,请重新上传')
  85. }
  86. })
  87. }
  88. } else {
  89. this.$message.error(response.msg)
  90. }
  91. },
  92. // 弹窗关闭时
  93. closeHandle() {
  94. this.fileList = []
  95. this.$emit('refreshDataList')
  96. }
  97. }
  98. }
  99. </script>