uploadMbh.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div>
  3. <el-upload
  4. class="upload-demo"
  5. action="string"
  6. :on-preview="handlePreview"
  7. :on-remove="handleRemove"
  8. :before-remove="beforeRemove"
  9. :before-upload="beforeUpload"
  10. multiple
  11. :file-list="fileList"
  12. :modal-append-to-body="false"
  13. drag
  14. ref="n_u_l_c"
  15. >
  16. <i class="el-icon-upload"></i>
  17. <div class="el-upload__text">点击上传</div>
  18. </el-upload>
  19. </div>
  20. </template>
  21. <script>
  22. import {strToFileList} from "@/utils/tv.js"
  23. export default {
  24. props:{
  25. fList :{required: false,type: String},
  26. },
  27. data() {
  28. return {
  29. fileList:[],
  30. params:{}
  31. }
  32. },
  33. methods: {
  34. handleRemove(file, fileList) {
  35. this.$emit("handleResult",{file, fileList});
  36. },
  37. handlePreview(file) {
  38. },
  39. beforeRemove(file, fileList) {
  40. return true;//this.$confirm(`确定移除 ${ file.name }?`);
  41. },
  42. beforeUpload(file){
  43. let query = new FormData();
  44. query.append("file", file);
  45. this.$http({
  46. url: "/bpm/api/upload",
  47. method: "post",
  48. headers: {"Content-Type": "application/json",},
  49. data: query,
  50. }).then((res) => {
  51. if(res.data.result===0){
  52. this.handleResult(res.data.body)
  53. }else{
  54. this.$message({ message: res.data.desc,type: 'error'});
  55. }
  56. });
  57. },
  58. handleResult(body){
  59. let file = {"name":body.fileName,"url":"/bmp/api/download?id=" + body.attchFileId,"attchFileId":body.attchFileId}
  60. this.fileList.push(file)
  61. let files = this.fileList
  62. this.$emit("handleResult",{file,files});
  63. },
  64. resetFile(fileList){
  65. this.fileList = fileList
  66. },
  67. getFileList(){
  68. return this.fileList
  69. },
  70. download(v) {
  71. let fileData = v;
  72. this.$http({
  73. url: '/bpm/api/download',
  74. method: "post",
  75. headers: {
  76. "Content-Type": "application/json",
  77. },
  78. responseType: "blob",
  79. data: {"id": fileData.id, "fileName": fileData.fileName},
  80. }).then((response) => {
  81. if (window.navigator && window.navigator.msSaveOrOpenBlob) {
  82. let blob = new Blob([response.data], {
  83. type: 'application/vnd.ms-excel'
  84. });
  85. window.navigator.msSaveOrOpenBlob(blob, fileData.fileName);
  86. } else {
  87. /* 火狐谷歌的文件下载方式 */
  88. var blob = new Blob([response.data])
  89. var downloadElement = document.createElement('a')
  90. var href = window.URL.createObjectURL(blob);
  91. downloadElement.href = href;
  92. downloadElement.download = fileData.fileName;
  93. document.body.appendChild(downloadElement);
  94. downloadElement.click();
  95. document.body.removeChild(downloadElement);
  96. window.URL.revokeObjectURL(href);
  97. }
  98. });
  99. },
  100. },
  101. watch:{
  102. itemId(){
  103. this.fileList = strToFileList(this.fList)
  104. },
  105. idx(){
  106. this.fileList = strToFileList(this.fList)
  107. }
  108. },
  109. created(){
  110. this.fileList = strToFileList(this.fList)
  111. }
  112. }
  113. </script>
  114. <style>
  115. </style>