|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <template>
- <view :class="className" :style="style" class="cu-form-group">
- <view class="grid col-4 grid-square flex-sub">
- <view
- v-for="(path, index) in value"
- @tap="viewImg"
- :key="index"
- class="bg-img"
- >
- <image :src="path" mode="aspectFill"></image>
- <view
- v-if="!readonly"
- @tap.stop="delImg(index)"
- class="cu-tag bg-red"
- style="height: 24px; width: 24px"
- >
- <l-icon
- type="close"
- style="width: 18px; height: 24px; font-size: 24px"
- />
- </view>
- </view>
-
- <view
- v-if="!readonly && value.length < Number(number)"
- @tap="chooseImg"
- class="solids"
- >
- <l-icon type="cameraadd" />
- </view>
- </view>
- </view>
- </template>
-
- <script>
- export default {
- name: "l-upload",
-
- props: {
- number: { default: 1 },
- readonly: {},
- value: { default: () => [] },
- },
-
- methods: {
- delImg(index) {
- const newList = JSON.parse(JSON.stringify(this.value));
- newList.splice(index, 1);
- this.$emit("input", newList);
- this.$emit("change");
- this.$emit("del");
- },
-
- chooseImg() {
- uni.chooseImage({
- count: Number(this.number),
- sizeType: ["original", "compressed"],
- sourceType: ["album", "camera"],
- success: ({ tempFilePaths }) => {
- const newList = JSON.parse(JSON.stringify(this.value || [])).concat(
- tempFilePaths
- );
- this.$emit("input", newList);
- this.$emit("change");
- this.$emit("add");
- },
- });
- },
-
- viewImg(index) {
- uni.previewImage({
- urls: this.value,
- current: this.value[index],
- });
- },
- },
- };
- </script>
|