deleteUploadImg2.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div>
  3. <van-col span="6" v-for="(urls, index) in imgs" :key="index">
  4. <div class="imgview2">
  5. <van-icon name="close" size="16" v-on:click="deleteImg(index, urls.id)" v-if="isEdit" />
  6. <img
  7. v-if="urls.type == '2'"
  8. :src="urls.fileUrl"
  9. width="100px"
  10. height="100px"
  11. @click="previewsImg(index)" />
  12. <img v-else :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)" />
  13. </div>
  14. </van-col>
  15. </div>
  16. <!-- <div style="padding: 10px 16px 0;">-->
  17. <!-- <div class="img-box" v-for="(urls, index) in imgs" :key="index">-->
  18. <!-- <van-icon name="clear" v-on:click="deleteImg(index,urls.id)"/>-->
  19. <!-- <img v-if="urls.type=='2'" :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)"/>-->
  20. <!-- <img v-else :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)"/>-->
  21. <!-- </div>-->
  22. <!-- </div>-->
  23. </template>
  24. <script>
  25. import { ImagePreview } from 'vant';
  26. import { removeSummaryPhoto, removePhoto } from '@/api/index';
  27. export default {
  28. name: 'deleteUploadImg',
  29. props: {
  30. imgs: {
  31. type: Array,
  32. default() {
  33. return [];
  34. },
  35. },
  36. // 是否允许补填
  37. isEdit: {
  38. type: Boolean,
  39. default: true,
  40. },
  41. // 是否请求接口删除
  42. isDelete: {
  43. type: Boolean,
  44. default: true,
  45. },
  46. },
  47. data() {
  48. return {
  49. url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API,
  50. };
  51. },
  52. methods: {
  53. deleteImg(index, collectionItemId) {
  54. var fileName = {
  55. fileId: collectionItemId,
  56. };
  57. if (this.isDelete) {
  58. removeSummaryPhoto(fileName).then((res) => {
  59. if (res.code == 200) {
  60. this.$toast('删除成功!');
  61. this.imgs.splice(index, 1);
  62. } else {
  63. this.$toast('删除失败!');
  64. }
  65. });
  66. } else {
  67. this.imgs.splice(index, 1);
  68. }
  69. },
  70. previewsImg(index) {
  71. var arrimg = [];
  72. for (var imgi = 0; imgi < this.imgs.length; imgi++) {
  73. arrimg.push(this.imgs[imgi].fileUrl);
  74. }
  75. ImagePreview({
  76. images: arrimg,
  77. startPosition: index,
  78. onClose() {
  79. // do something
  80. },
  81. });
  82. },
  83. },
  84. };
  85. </script>
  86. <style lang="scss" scoped>
  87. .imgview2 {
  88. width: 100%;
  89. height: 80px;
  90. position: relative;
  91. display: inline-block;
  92. i {
  93. position: absolute;
  94. right: -2px;
  95. top: -3px;
  96. color: white;
  97. background: red;
  98. overflow: hidden;
  99. border-radius: 50%;
  100. }
  101. img {
  102. width: 100%;
  103. height: 100%;
  104. }
  105. }
  106. </style>