You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

upload-car-img.vue 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="upload-car-img">
  3. <view class="picture-wrapper" @click="cardImageOcr">
  4. <view class="bg">
  5. <view class="">
  6. <view class="name"> {{dataList.title}} </view>
  7. <view class="value"> {{dataList.hint}} </view>
  8. </view>
  9. <image v-if="!uploadimges" class="icon" :src="handleImg(dataList.placeholderImg)">
  10. </image>
  11. <image v-else class="icon" :src="uploadimges"></image>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script lang='ts' setup>
  17. import {
  18. ref
  19. } from 'vue'
  20. import {
  21. translate
  22. } from '@/utils/getLessLimitSizeImage'
  23. import {
  24. fileURL
  25. } from '@/utils/network/api.js';
  26. const props = defineProps({
  27. dataList: {
  28. type: Object,
  29. default: () => {
  30. return {}
  31. }
  32. }
  33. })
  34. const handleImg = (url) => {
  35. // 判断如果头部为http开头
  36. const reg = /^https?:\/\/.*$/
  37. if (reg.test(url)) {
  38. return url
  39. } else {
  40. return fileURL + url
  41. }
  42. }
  43. const emits = defineEmits(['uploadImgHandle'])
  44. let uploadimges = ref('')
  45. const cardImageOcr = () => {
  46. uni.chooseImage({
  47. count: 1, //只能选取一张照片
  48. sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
  49. sourceType: ["camera", "album"], //从相册选择
  50. success: function(res) {
  51. // console.log(res.tempFiles[0]);
  52. uploadimges.value = res.tempFiles[0].path
  53. // 压缩图片
  54. translate(res.tempFiles[0].path, 0.5, imgURL => {
  55. uploadimges.value = imgURL
  56. emits('uploadImgHandle', {
  57. path: imgURL,
  58. fileName: res.tempFiles[0].name
  59. })
  60. })
  61. }
  62. })
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. .picture-wrapper {
  67. margin: 10rpx 30rpx;
  68. .bg {
  69. background: #ffffff;
  70. box-shadow: 0rpx 4rpx 13rpx 3rpx rgba(223, 223, 223, 0.8);
  71. border-radius: 20rpx;
  72. padding: 40rpx;
  73. display: flex;
  74. // align-items: center;
  75. justify-content: space-between;
  76. .name {
  77. font-size: 34rpx;
  78. font-family: Microsoft YaHei;
  79. font-weight: 400;
  80. color: #000000;
  81. line-height: 34rpx;
  82. }
  83. .value {
  84. margin-top: 20rpx;
  85. font-size: 24rpx;
  86. font-family: Microsoft YaHei;
  87. font-weight: 400;
  88. color: #999999;
  89. line-height: 24rpx;
  90. }
  91. .tip {
  92. margin-top: 20rpx;
  93. text-align: center;
  94. width: 110rpx;
  95. height: 40rpx;
  96. background: rgba(33, 190, 177, 0.2);
  97. border-radius: 6rpx;
  98. .tip-value {
  99. font-size: 20rpx;
  100. font-family: Microsoft YaHei;
  101. font-weight: 400;
  102. color: #0a8f8a;
  103. line-height: 40rpx;
  104. opacity: 1;
  105. }
  106. }
  107. }
  108. .icon {
  109. width: 294rpx;
  110. height: 188rpx;
  111. }
  112. }
  113. .upload-car-bottom {
  114. font-size: 28rpx;
  115. }
  116. </style>