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.
 
 
 
 
 
 

60 lines
1.5 KiB

  1. <template>
  2. <view class="cu-form-group">
  3. <view class="grid col-4 grid-square flex-sub">
  4. <view v-for="(path, index) in value" @tap="viewImg" :key="index" class="bg-img">
  5. <image :src="path" mode="aspectFill"></image>
  6. <view v-if="!readonly" @tap.stop="delImg(index)" class="cu-tag bg-red">
  7. <l-icon type="close" style="width: 18px;height: 24px;font-size: 24px;" />
  8. </view>
  9. </view>
  10. <view v-if="!readonly && value.length < Number(number)" @tap="chooseImg" class="solids">
  11. <l-icon type="cameraadd" />
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. name: 'l-upload',
  19. props: {
  20. number: { default: 1 },
  21. readonly: {},
  22. value: { default: () => [] }
  23. },
  24. methods: {
  25. delImg(index) {
  26. const newList = JSON.parse(JSON.stringify(this.value))
  27. newList.splice(index, 1)
  28. this.$emit('input', newList)
  29. this.$emit('change')
  30. this.$emit('del')
  31. },
  32. chooseImg() {
  33. uni.chooseImage({
  34. count: Number(this.number),
  35. sizeType: ['original', 'compressed'],
  36. sourceType: ['album', 'camera'],
  37. success: ({ tempFilePaths }) => {
  38. const newList = JSON.parse(JSON.stringify(this.value || [])).concat(tempFilePaths)
  39. this.$emit('input', newList)
  40. this.$emit('change')
  41. this.$emit('add')
  42. }
  43. })
  44. },
  45. viewImg(index) {
  46. uni.previewImage({
  47. urls: this.value,
  48. current: this.value[index]
  49. })
  50. }
  51. }
  52. }
  53. </script>