JMoreUpload.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view>
  3. <view class="title" v-if="title">{{ title }}</view>
  4. <view class="upload-pane">
  5. <view class="left">
  6. <view @click="chooseImg" class="upload">+</view>
  7. <view class="img-wrapper" v-for="item in imgs" :key="item">
  8. <img class="iamge-background img" :src="item" mode="" />
  9. <JIcon
  10. @click="removeBackground(item)"
  11. class="delete-icon"
  12. width="40"
  13. height="40"
  14. type="delete"
  15. ></JIcon>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import { IMG_UPLOAD_URL } from "../../config";
  23. export default {
  24. props: {
  25. title: String,
  26. imgs: {
  27. type: Array,
  28. required: true,
  29. },
  30. },
  31. methods: {
  32. removeBackground(item) {
  33. console.log(item);
  34. const _this = this;
  35. uni.showModal({
  36. title: "提示",
  37. content: "确定删除当前图片吗?",
  38. success: function (res) {
  39. if (res.confirm) {
  40. _this.$emit("delete", item);
  41. }
  42. },
  43. });
  44. },
  45. chooseImg() {
  46. const _this = this;
  47. uni.chooseImage({
  48. success: (chooseImageRes) => {
  49. uni.uploadFile({
  50. url: IMG_UPLOAD_URL,
  51. filePath: chooseImageRes.tempFiles[0].path,
  52. name: "file",
  53. success: (uploadFileRes) => {
  54. _this.$emit("upload", JSON.parse(uploadFileRes.data).data.url);
  55. },
  56. });
  57. },
  58. });
  59. },
  60. },
  61. };
  62. </script>
  63. <style lang="less" scoped>
  64. .title {
  65. color: #3d3d3d;
  66. font-size: 24upx;
  67. margin: 48upx 0 20upx 0;
  68. }
  69. .upload-pane {
  70. border: 1upx solid #d8d8d8;
  71. padding: 32upx 24upx;
  72. box-sizing: border-box;
  73. border-radius: 20upx;
  74. display: flex;
  75. justify-content: space-between;
  76. align-items: flex-end;
  77. .delete-icon {
  78. width: 32upx;
  79. height: 36upx;
  80. }
  81. .left {
  82. display: flex;
  83. justify-content: flex-start;
  84. align-items: center;
  85. flex-wrap: wrap;
  86. }
  87. .upload {
  88. margin: 0;
  89. width: 160upx;
  90. // height: 160upx;
  91. background-color: #ececec;
  92. border-radius: 20upx;
  93. color: #767676;
  94. text-align: center;
  95. line-height: 160upx;
  96. font-size: 60upx;
  97. margin-right: 40upx;
  98. margin-bottom: 20upx;
  99. }
  100. .iamge-background {
  101. width: 160upx;
  102. height: 160upx;
  103. object-fit: cover;
  104. }
  105. .img-wrapper {
  106. margin-right: 40upx;
  107. position: relative;
  108. .delete-icon {
  109. position: absolute;
  110. top: -10upx;
  111. right: -10px;
  112. border-radius: 50%;
  113. background-color: #ffffff;
  114. }
  115. .img {
  116. border-radius: 20upx;
  117. margin-bottom: 20upx;
  118. }
  119. }
  120. }
  121. </style>