upload-dialog.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <!-- 上传 -->
  3. <el-dialog title="文件上传" :visible.sync="dialogVisible" width="40%">
  4. <el-form label-width="110px" class="zw-criterion">
  5. <el-form-item label="选择文件">
  6. <el-upload
  7. class="avatar-uploader"
  8. action="#"
  9. :show-file-list="false"
  10. :http-request="handlSuccess"
  11. :before-upload="beforeUpload"
  12. >
  13. <el-button icon="el-icon-plus" size="small" type="primary"
  14. >文件上传</el-button
  15. >
  16. </el-upload>
  17. </el-form-item>
  18. <el-form-item label="模块名">
  19. <DictSelection v-model="module" dictName="文件模块"></DictSelection>
  20. </el-form-item>
  21. <el-form-item label="">
  22. <div class="imgs-box">
  23. <p v-for="(item, index) in attaments" :key="index" class="imgs-p">
  24. <span> {{ item.name }}</span>
  25. <el-link @click="delFileList(index)" type="primary">删除</el-link>
  26. </p>
  27. </div>
  28. </el-form-item>
  29. </el-form>
  30. <div slot="footer" class="dialog-footer">
  31. <el-button size="small" @click="dialogVisible = false">关 闭</el-button>
  32. <el-button size="small" @click="upload" type="primary">上 传</el-button>
  33. </div>
  34. </el-dialog>
  35. </template>
  36. <script>
  37. import { uploadBatch } from '@/api/system/file/index.js';
  38. export default {
  39. //注册组件
  40. data () {
  41. return {
  42. showViewer: false, // 显示查看器
  43. dialogVisible: false,
  44. uploadShow: false,
  45. attaments: [], //上传文件
  46. module: '',
  47. file: ''
  48. };
  49. },
  50. created () {},
  51. methods: {
  52. open () {
  53. this.attaments = [];
  54. this.module = '';
  55. this.dialogVisible = true;
  56. },
  57. //删除附件
  58. delFileList (index) {
  59. this.attaments.splice(index, 1);
  60. },
  61. //上传限制
  62. beforeUpload (file) {
  63. const isLt10M = file.size / 1024 / 1024 < 10;
  64. if (!isLt10M) {
  65. this.$message.error('上传文件大小不能超过 10MB!');
  66. }
  67. return isLt10M;
  68. },
  69. //图片上传
  70. handlSuccess (param) {
  71. this.file = param.file;
  72. this.attaments.push(param.file);
  73. },
  74. // 文件上传
  75. async upload () {
  76. if (this.attaments.length == 0) {
  77. return this.$message.warning('文件不能为空!');
  78. }
  79. if (!this.module) {
  80. return this.$message.warning('模块名不能为空!');
  81. }
  82. await uploadBatch({
  83. module: this.module,
  84. multiPartFiles: this.attaments
  85. });
  86. this.$message.success('操作成功!');
  87. this.dialogVisible = false;
  88. this.$emit('success');
  89. }
  90. }
  91. };
  92. </script>
  93. <style lang="scss">
  94. .zw-table-header {
  95. float: right;
  96. }
  97. .imgs-box .imgs-p {
  98. height: 30px;
  99. background: #f0f3f3;
  100. line-height: 30px;
  101. width: 372px;
  102. margin-bottom: 5px;
  103. padding: 0 10px;
  104. display: flex;
  105. justify-content: space-between;
  106. }
  107. .zw-criterion-normal {
  108. padding: 20px 0 0 0;
  109. }
  110. .el-main {
  111. overflow: hidden;
  112. }
  113. </style>