deleteUploadImg2.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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)" />
  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. data() {
  38. return {
  39. url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API,
  40. };
  41. },
  42. methods: {
  43. deleteImg(index, collectionItemId) {
  44. var fileName = {
  45. fileId: collectionItemId,
  46. };
  47. removeSummaryPhoto(fileName).then((res) => {
  48. if (res.code == 200) {
  49. this.$toast('删除成功!');
  50. this.imgs.splice(index, 1);
  51. } else {
  52. this.$toast('删除失败!');
  53. }
  54. });
  55. },
  56. previewsImg(index) {
  57. var arrimg = [];
  58. for (var imgi = 0; imgi < this.imgs.length; imgi++) {
  59. arrimg.push(this.imgs[imgi].fileUrl);
  60. }
  61. ImagePreview({
  62. images: arrimg,
  63. startPosition: index,
  64. onClose() {
  65. // do something
  66. },
  67. });
  68. },
  69. },
  70. };
  71. </script>
  72. <style lang="scss" scoped>
  73. .imgview2 {
  74. width: 100%;
  75. height: 80px;
  76. position: relative;
  77. display: inline-block;
  78. i {
  79. position: absolute;
  80. right: -2px;
  81. top: -3px;
  82. color: white;
  83. background: red;
  84. overflow: hidden;
  85. border-radius: 50%;
  86. }
  87. img {
  88. width: 100%;
  89. height: 100%;
  90. }
  91. }
  92. </style>