filemanager copy.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div>
  3. <el-form :model="form">
  4. <el-form-item :label="name">
  5. <el-row>
  6. <el-col :span="1.5">
  7. <el-input v-model="fileName" placeholder="待上传" readonly />
  8. </el-col>
  9. <el-col :span="1.5" v-show="!fileUrlid">
  10. <el-button type="info" plain icon="el-icon-upload2" size="small" @click="uploadAccessory(field)">
  11. 上传
  12. </el-button>
  13. </el-col>
  14. <el-col :span="1.5" v-show="fileUrlid" >
  15. <el-button type="success" plain icon="el-icon-download" size="small" @click="exportAccessory">
  16. 下载
  17. </el-button>
  18. </el-col>
  19. <el-col :span="1.5" v-show="fileUrlid">
  20. <el-button size="small" type="danger" plain icon="el-icon-delete" @click="deleteAccessory(field)">
  21. 删除
  22. </el-button>
  23. </el-col>
  24. </el-row>
  25. </el-form-item>
  26. </el-form>
  27. <!-- 上传对话框 -->
  28. <el-dialog
  29. :title="upload.title"
  30. :visible.sync="upload.open"
  31. width="400px"
  32. append-to-body
  33. >
  34. <el-upload
  35. ref="upload"
  36. :limit="1"
  37. accept=".xlsx, .xls, .doc, .docx, .word, .wordx, .png, .jpg, .gif, .txt"
  38. :headers="upload.headers"
  39. :action="upload.url + '?boId=' + form.id + '&flag=' + upload.flag + '&boType=' + form.boType"
  40. :disabled="upload.isUploading"
  41. :on-progress="handleFileUploadProgress"
  42. :on-success="handleFileSuccess"
  43. :auto-upload="false"
  44. drag
  45. >
  46. <i class="el-icon-upload"></i>
  47. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  48. </el-upload>
  49. <div slot="footer" class="dialog-footer">
  50. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  51. <el-button @click="upload.open = false">取 消</el-button>
  52. </div>
  53. </el-dialog>
  54. </div>
  55. </template>
  56. <script>
  57. import {delAccessory} from "@/api/business/spd/bo/basic";
  58. import axios from "axios";
  59. import { getToken } from "@/utils/auth";
  60. export default {
  61. name: "filemanager",
  62. props: ["form","name","fileName","fileUrlid","field"],
  63. data() {
  64. return {
  65. // 上传参数
  66. upload: {
  67. // 是否显示弹出层
  68. open: false,
  69. // 弹出层标题
  70. title: "",
  71. // 是否禁用上传
  72. isUploading: false,
  73. // 上传类型
  74. flag: "",
  75. // 设置上传的请求头部
  76. headers: { Authorization: "Bearer " + getToken() },
  77. // 上传的地址
  78. url: process.env.VUE_APP_BASE_API + "/mk/bo/basic/upload",
  79. },
  80. };
  81. },
  82. created() {
  83. },
  84. methods: {
  85. //上传附件公共方法
  86. uploadAccessory(f) {
  87. // this.upload.title = "上传附件";
  88. this.upload.open = true;
  89. this.upload.flag = f;
  90. },
  91. // 提交上传文件
  92. submitFileForm() {
  93. this.$refs.upload.submit();
  94. },
  95. // 文件上传中处理
  96. handleFileUploadProgress(event, file, fileList) {
  97. this.upload.isUploading = true;
  98. },
  99. // 文件上传成功处理
  100. handleFileSuccess(response, file, fileList) {
  101. this.upload.open = false;
  102. this.upload.isUploading = false;
  103. this.$refs.upload.clearFiles();
  104. this.$alert(
  105. "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
  106. response.msg +
  107. "</div>",
  108. "上传结果",
  109. { dangerouslyUseHTMLString: true }
  110. );
  111. this.$emit('reload');
  112. },
  113. //下载附件
  114. exportAccessory() {
  115. let resUrl = "https://sy.derom.com/document-center/fastdfs/download?id=" + this.fileUrlid;
  116. axios
  117. .create({
  118. timeout: 3000,
  119. responseType: "blob", // 响应类型, 将响应数据转换为二进制数据
  120. headers: {},
  121. })
  122. .get(resUrl)
  123. .then((res) => {
  124. console.log(res);
  125. // 地址转换
  126. let url = window.URL.createObjectURL(res.data);
  127. const a = document.createElement("a");
  128. a.setAttribute("href", url);
  129. a.setAttribute("download", this.fileName);
  130. document.body.append(a);
  131. a.click();
  132. document.body.removeChild(a);
  133. });
  134. },
  135. //删除附件
  136. deleteAccessory(f) {
  137. this.$modal
  138. .confirm("是否确认删除?")
  139. .then(function () {})
  140. .then(() => {
  141. delAccessory(this.form.id, f, this.form.boType,this.fileUrlid).then((res) => {
  142. console.log('删除返回',res);
  143. this.$emit('reload');
  144. });
  145. })
  146. .catch(() => {});
  147. },
  148. },
  149. };
  150. </script>