import-dialog.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. <div slot="tip" class="el-upload__tip"
  17. >只能上传excel文件,或批量上传打包成zip、rar压缩文件,单文件不超过10mb</div
  18. >
  19. </el-upload>
  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 { importBatch } from '@/api/system/file/index.js';
  38. export default {
  39. props: {
  40. // eslint-disable-next-line vue/require-prop-type-constructor
  41. defModule: ''
  42. },
  43. //注册组件
  44. data() {
  45. return {
  46. showViewer: false, // 显示查看器
  47. dialogVisible: false,
  48. uploadShow: false,
  49. module: '',
  50. attaments: [], //上传文件
  51. file: ''
  52. };
  53. },
  54. created() {},
  55. methods: {
  56. open() {
  57. this.attaments = [];
  58. this.module = '';
  59. this.dialogVisible = true;
  60. },
  61. //删除附件
  62. delFileList(index) {
  63. this.attaments.splice(index, 1);
  64. },
  65. //上传限制
  66. beforeUpload(file) {
  67. const isLt10M = file.size / 1024 / 1024 < 10;
  68. if (!isLt10M) {
  69. this.$message.error('导入单文件大小不能超过 10MB!');
  70. }
  71. return isLt10M;
  72. },
  73. //图片上传
  74. handlSuccess(param) {
  75. this.file = param.file;
  76. this.attaments.push(param.file);
  77. },
  78. // 文件上传
  79. async upload() {
  80. if (this.attaments.length == 0) {
  81. return this.$message.warning('文件不能为空!');
  82. }
  83. this.module = this.$props.defModule;
  84. await importBatch({
  85. module: this.module,
  86. multiPartFiles: this.attaments
  87. });
  88. this.$message.success('操作成功!');
  89. this.dialogVisible = false;
  90. this.$emit('success');
  91. }
  92. }
  93. };
  94. </script>
  95. <style lang="scss">
  96. .zw-table-header {
  97. float: right;
  98. }
  99. .imgs-box .imgs-p {
  100. height: 30px;
  101. background: #f0f3f3;
  102. line-height: 30px;
  103. width: 372px;
  104. margin-bottom: 5px;
  105. padding: 0 10px;
  106. display: flex;
  107. justify-content: space-between;
  108. }
  109. .zw-criterion-normal {
  110. padding: 20px 0 0 0;
  111. }
  112. .el-main {
  113. overflow: hidden;
  114. }
  115. </style>