index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="updata-img">
  3. <view class="updata-title-box">
  4. <view class="updata-title-title font-title ">{{ data.title }} <span style="color: #f56c6c;"
  5. v-if="data.required">*</span> </view>
  6. <view class="updata-title-text font-text ">{{ data.text }}</view>
  7. </view>
  8. <!-- <view class="updata-img-box" @click="updataFile">
  9. <image :src="img" style="width: 117px;height: 75px;" />
  10. </view> -->
  11. <view class="upload-box">
  12. <view class="upload-img-item" v-for="(item, index) in fileList" :key="item.url">
  13. <view class="delete-icon" @click="deletePic(index)"><up-icon name="close-circle-fill" color="#f64a1f"
  14. size="18"></up-icon></view>
  15. <img class="upload-img" :src="item.url" :alt="item.fileName" srcset="">
  16. </view>
  17. <img src="/static/img/upload.png" alt="" class="upload-img" @click="uploadClick('img')"
  18. v-if="fileList.length < 10">
  19. </view>
  20. </view>
  21. </template>
  22. <script setup>
  23. import { ref } from 'vue';
  24. import { wxUploadFile } from '@/utils/wxRequest.js'
  25. const props = defineProps({
  26. data: {
  27. type: Object,
  28. default: {
  29. title: '上传头像',
  30. text: '上传您的头像',
  31. img: "/static/img/updata-user-img.png"
  32. },
  33. },
  34. });
  35. const emit = defineEmits(['onSubmit']);
  36. const fileList = ref([]);
  37. // 删除图片
  38. const deletePic = (index) => {
  39. fileList.value.splice(index, 1);
  40. getFile();
  41. };
  42. const uploadClick = async (type) => {
  43. const res = await wxUploadFile(type);
  44. fileList.value = [...fileList.value, ...res];
  45. getFile();
  46. console.log('xxxxres', res, fileList.value);
  47. }
  48. function getFile() {
  49. const img_urls = fileList.value.map(item => item.url).join(',');
  50. console.log('img_urls',img_urls);
  51. emit('onSubmit', { key: props.data.key, url: img_urls })
  52. return img_urls
  53. }
  54. defineExpose({
  55. getFile,
  56. });
  57. </script>
  58. <style lang="scss" scoped>
  59. .updata-img {
  60. border-radius: 8px;
  61. background: rgba(255, 255, 255, 1);
  62. // height: 100px;
  63. padding: 16px;
  64. display: flex;
  65. align-content: center;
  66. justify-content: space-between;
  67. flex-direction: column;
  68. .updata-title-box {
  69. display: flex;
  70. align-content: center;
  71. flex-direction: column;
  72. justify-content: space-evenly;
  73. margin-bottom: 12px;
  74. }
  75. }
  76. .upload-img {
  77. height: 68px;
  78. width: 68px;
  79. margin-right: 12px;
  80. margin-bottom: 12px;
  81. }
  82. .upload-box {
  83. display: flex;
  84. flex-wrap: wrap;
  85. .upload-img-item {
  86. position: relative;
  87. .delete-icon {
  88. position: absolute;
  89. top: -7px;
  90. right: 7px;
  91. z-index: 1;
  92. }
  93. }
  94. }
  95. </style>