uploadImg.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="card card-file">
  3. <el-upload
  4. v-for="(item, index) in fileList"
  5. :key="index"
  6. :action="'#'"
  7. class="fileBox"
  8. :class="{big:$props.big,disabled:$props.disabled}"
  9. list-type="none"
  10. :show-file-list="false"
  11. :accept="acceptType"
  12. :on-change="(file, fileList) => changeFile(file, fileList, item)"
  13. :auto-upload="false"
  14. :disabled="$props.disabled"
  15. v-loading.lock="uploading"
  16. >
  17. <template slot="default">
  18. <img :src="item.path ? item.path : item.defaultPath" alt="">
  19. <div class="text mode">{{item.text}}</div>
  20. </template>
  21. </el-upload>
  22. <slot></slot>
  23. </div>
  24. </template>
  25. <script>
  26. import { $upload } from '@/service/main/index'
  27. import { mapGetters } from 'vuex'
  28. export default {
  29. props: {
  30. fileList: {
  31. require: true,
  32. type: Array
  33. },
  34. currentStatus: {
  35. require: true,
  36. // eslint-disable-next-line vue/require-prop-type-constructor
  37. type: Number | String
  38. },
  39. successStatus: {
  40. require: true,
  41. // eslint-disable-next-line vue/require-prop-type-constructor
  42. type: Number | String
  43. },
  44. acceptType: {
  45. type: String,
  46. default: '.jpg,.png'
  47. },
  48. big: {
  49. type: Boolean,
  50. default: false
  51. },
  52. disabled: {
  53. type: Boolean,
  54. default: false
  55. }
  56. },
  57. data() {
  58. return {
  59. uploading: false
  60. }
  61. },
  62. computed: {
  63. ...mapGetters({
  64. orgId: 'woporg',
  65. user: 'wopuser'
  66. })
  67. },
  68. mounted() {
  69. },
  70. methods: {
  71. changeFile(file, fileList, item) {
  72. const fileD = new FormData()
  73. fileD.append('file', file.raw)
  74. this.uploading = true
  75. $upload(fileD).then(res => {
  76. if (res.data.code === 0) {
  77. item.path = process.env.VUE_APP_FILE_URL + res.data.data
  78. this.$emit('uploadOrgPic', res.data.data, item.fileIndex)
  79. }
  80. this.uploading = false
  81. }).catch(() => { this.uploading = false })
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="scss" scoped>
  87. // .card {
  88. // margin: 12px;
  89. //}
  90. .card-file {
  91. display: inline-block;
  92. // padding-bottom: 36px;
  93. .fileBox {
  94. margin: 0 16px 0 0;
  95. &:last-child {
  96. margin: 0;
  97. }
  98. }
  99. }
  100. .fileBox {
  101. margin: 0 10px;
  102. position: relative;
  103. width: 216px;
  104. height: 140px;
  105. &.disabled {
  106. filter: grayscale(1);
  107. &::v-deep .el-upload {
  108. cursor: auto;
  109. }
  110. }
  111. &.big {
  112. width: 340px;
  113. height: 220px;
  114. .text {
  115. padding-top: 154px;
  116. }
  117. }
  118. &::v-deep .el-upload {
  119. width: 100%;
  120. height: 100%;
  121. }
  122. .text {
  123. position: absolute;
  124. left: 0; right: 0; top: 0; bottom: 0;
  125. margin: auto;
  126. padding-top: 94px;
  127. color: #868B9A;
  128. }
  129. .mode {
  130. background: rgba(25,25,25,0.2);
  131. color: #fff;
  132. }
  133. img {
  134. width: 100%;
  135. height: 100%;
  136. }
  137. }
  138. </style>