imgList.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div>
  3. <el-upload
  4. action="#"
  5. list-type="picture-card"
  6. :on-preview="handlePictureCardPreview"
  7. :on-remove="handleRemove"
  8. accept="image/png,image/jpeg,image/jpg"
  9. ref="uploadRef"
  10. :http-request="handlRequest"
  11. :before-upload="handlSuccess"
  12. :file-list="value"
  13. :multiple="true"
  14. >
  15. <i class="el-icon-plus"></i>
  16. </el-upload>
  17. <el-dialog :visible.sync="dialogVisible" append-to-body>
  18. <img width="100%" :src="dialogImageUrl" alt="" />
  19. </el-dialog>
  20. </div>
  21. </template>
  22. <script>
  23. import { uploadFile, removeFile } from '@/api/system/file/index.js';
  24. // import { getImageUrl } from '@/utils/file';
  25. export default {
  26. props: {
  27. value: {
  28. type: Object,
  29. default: () => []
  30. }
  31. },
  32. data() {
  33. return {
  34. dialogImageUrl: '',
  35. dialogVisible: false,
  36. fileList: []
  37. };
  38. },
  39. methods: {
  40. async handleRemove(file, fileList) {
  41. this.$emit('input', fileList);
  42. // if (!file.id) {
  43. // return;
  44. // }
  45. // await removeFile({ fileId: file.id });
  46. },
  47. handlePictureCardPreview(file) {
  48. this.dialogImageUrl = file.url;
  49. this.dialogVisible = true;
  50. },
  51. //图片添加
  52. async handlSuccess(file) {
  53. // console.log(params,'params')
  54. let res = await uploadFile({
  55. multiPartFile: file,
  56. module: 'main'
  57. });
  58. if (res?.data) {
  59. this.$emit('input', [...(this.value || []), res.data]);
  60. }
  61. },
  62. handlRequest() {
  63. return Promise.resolve();
  64. }
  65. }
  66. };
  67. </script>
  68. <style lang="scss" scoped>
  69. .img-view {
  70. width: 280px;
  71. height: 342px;
  72. display: flex;
  73. justify-content: center;
  74. align-items: center;
  75. border-width: 1px;
  76. border-style: solid;
  77. border-color: rgba(215, 215, 215, 1);
  78. img {
  79. max-width: 100%;
  80. max-height: 100%;
  81. }
  82. }
  83. .placeholder-box {
  84. width: 250px;
  85. height: 200px;
  86. text-align: center;
  87. background-color: rgba(242, 242, 242, 1);
  88. box-sizing: border-box;
  89. border-width: 1px;
  90. border-style: solid;
  91. border-color: rgba(215, 215, 215, 1);
  92. padding-top: 60px;
  93. img {
  94. width: 100px;
  95. height: 100px;
  96. }
  97. }
  98. .btn-box {
  99. display: flex;
  100. justify-content: space-around;
  101. }
  102. </style>