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.vue 1.8 KiB

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