CategoryImags.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="certification-card">
  3. <view class="serve-box flex_c_s">
  4. <view>{{ viewStatus ? '已' : '请' }}上传图片({{ fileCount }}/6)</view>
  5. <view class="decs">注:第一张用于封面展示</view>
  6. </view>
  7. <view class="serve-img-contnt">
  8. <view class="serve-img" v-for="item in files" :key="item">
  9. <view class="img-close" @click="deleteImg(item)" v-if="viewStatus"></view>
  10. <view class="serve-is-img flex_c_c">
  11. <image-viewer :src="item" :width="170" :height="230" :preview="true"></image-viewer>
  12. </view>
  13. </view>
  14. <view class="serve-up-img flex_c_c" @click="upImg" v-if="fileCount < 3 && viewStatus">
  15. <up-icon name="plus" color="#C9CDD4" size="16"></up-icon>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script setup>
  21. import { computed, ref, watch } from 'vue';
  22. import { wxUploadFile } from '@/utils/wxRequest.js';
  23. import { provide, inject } from 'vue'
  24. import ImageViewer from './image-viewer.vue'
  25. const viewStatus = inject('viewStatus');
  26. const formData = inject('formData');
  27. console.log("TCL: formData", formData)
  28. const fileList = ref([]);
  29. const maxImgCount = 3;
  30. const fileCount = computed(() => {
  31. return formData.projectImages ? formData.projectImages.length : 0;
  32. });
  33. const files = computed(() => {
  34. return formData.projectImages || [];
  35. });
  36. const deleteImg = (url) => {
  37. fileList.value = fileList.value.filter(item => item.url !== url);
  38. uni.$u.debounce(changeFile, 300)
  39. };
  40. const upImg = async () => {
  41. try {
  42. const res = await wxUploadFile('img', maxImgCount);
  43. fileCount.value < 3 ? fileList.value = [...fileList.value, ...res] : uni.showToast({
  44. title: `最多可上传${maxImgCount}个资质证件!`,
  45. icon: 'none',
  46. });
  47. } catch (error) {
  48. console.log("TCL: upImg -> error", error)
  49. } finally {
  50. uni.$u.debounce(changeFile, 300)
  51. }
  52. }
  53. // 存储上传的文件
  54. const changeFile = () => {
  55. formData.projectImages = fileList.value.map(item => item.url);
  56. }
  57. </script>
  58. <style lang="scss" scoped>
  59. @import "./index.scss";
  60. .decs {
  61. font-family: PingFang SC;
  62. font-size: 28rpx;
  63. font-weight: normal;
  64. line-height: 40rpx;
  65. letter-spacing: normal;
  66. color: rgba(0, 0, 0, 0.5);
  67. }
  68. .serve-is-img {
  69. height: 230rpx !important;
  70. }
  71. .serve-img:first-child {
  72. position: relative;
  73. &::before {
  74. content: '';
  75. // width: 170rpx;
  76. // height: 230rpx;
  77. position: absolute;
  78. left: 0px;
  79. top: 0px;
  80. right: 0;
  81. bottom: 0;
  82. background: rgba(216, 216, 216, 0.6);
  83. z-index: 2;
  84. }
  85. &::after {
  86. content: '封面展示';
  87. // width: 170rpx;
  88. // height: 230rpx;
  89. position: absolute;
  90. left: 0px;
  91. top: 0px;
  92. right: 0;
  93. bottom: 0;
  94. z-index: 3;
  95. font-family: PingFang SC;
  96. font-size: 28rpx;
  97. font-weight: normal;
  98. line-height: 40rpx;
  99. letter-spacing: normal;
  100. color: rgba(0, 0, 0, 0.6);
  101. display: flex;
  102. align-items: center;
  103. justify-content: center;
  104. }
  105. }
  106. .serve-up-img {
  107. padding: 90rpx 0;
  108. }
  109. </style>