index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div class="upimgList">
  3. <div class="upimg" v-for="(i,s) in imgs" :key="s">
  4. <img :src="i" class="logo" alt="" srcset="" />
  5. <div class="del iconfont" @click="del">&#xe609;</div>
  6. </div>
  7. <div v-if="!imgs.length" class="upimg flex_c flex_ac flex_jc flex_wrap" @click="upimg">
  8. <div class="upico iconfont">&#xe674;</div>
  9. <div class="upmsg">最多{{ count }}张</div>
  10. </div>
  11. <center-popup ref="centerPopup" :title="Popuptitle" @confirmClick="delimg" />
  12. </div>
  13. </template>
  14. <script>
  15. import centerPopup from "@/pagesB/components/centerPopup/centerPopup"
  16. export default {
  17. name: "upimgList",
  18. props: {
  19. count: {
  20. type: Number,
  21. default: 1
  22. },
  23. value: {
  24. type: String,
  25. default: ""
  26. }
  27. },
  28. components: { centerPopup },
  29. data() {
  30. return {
  31. imgs: [],
  32. Popuptitle: "",
  33. Popuptitle: "",
  34. delinx: "", // 要删除的图片索引
  35. };
  36. },
  37. methods: {
  38. upimg() {
  39. let that = this
  40. uni.chooseMedia({
  41. count: that.count,
  42. mediaType: ["image"],
  43. sizeType: ["compressed"],
  44. sourceType: ["album", "camera"],
  45. success: async (res) => {
  46. let arr = [];
  47. for (const it of res.tempFiles) {
  48. let url = await that.$up(it.tempFilePath)
  49. arr.push(url)
  50. }
  51. that.imgs = arr; that.emitI(arr);
  52. },
  53. });
  54. },
  55. del(inx) {
  56. this.delinx = inx
  57. this.Popuptitle = "确认要删除这张图片吗?"
  58. this.$refs.centerPopup.open()
  59. },
  60. delimg() {
  61. this.imgs.splice(this.delinx, 1)
  62. this.emitI(this.imgs)
  63. this.$refs.centerPopup.close()
  64. },
  65. emitI(arr){
  66. let va = ""
  67. if(this.count == 1) va = arr[0]
  68. else va = JSON.stringify(arr)
  69. this.$emit("input", va);
  70. },
  71. },
  72. watch: {
  73. value: {
  74. immediate: true,
  75. deep: true,
  76. handler(str) {
  77. if (str) this.imgs = JSON.parse(str)
  78. }
  79. }
  80. },
  81. onLoad(da) {},
  82. onShow() {},
  83. mounted() {},
  84. };
  85. </script>
  86. <style scoped lang='scss'>
  87. .upimgList {
  88. display: grid;
  89. justify-content: space-between;
  90. grid-template-columns: repeat(auto-fill, 170rpx);
  91. grid-gap: 0 1px;
  92. }
  93. .upimg {
  94. width: 170rpx;
  95. height: 130rpx;
  96. font-size: 23rpx;
  97. border-radius: 15rpx;
  98. border: 2rpx dashed #999;
  99. color: #999;
  100. margin-bottom: 6rpx;
  101. position: relative;
  102. .upico {
  103. color: #999;
  104. font-size: 70rpx;
  105. }
  106. .logo {
  107. width: 100%;
  108. height: 100%;
  109. border-radius: 15rpx;
  110. }
  111. .del {
  112. position: absolute;
  113. top: 6rpx;
  114. right: 6px;
  115. color: #fff;
  116. padding: 6rpx 12rpx;
  117. font-weight: 600;
  118. border-radius: 12rpx;
  119. background-color: rgba($color: #f20, $alpha: 0.6);
  120. }
  121. }
  122. </style>