wangzhibo
4 天以前 10595d8632f959d0954d1939243196f4eed02372
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<template>
    <cl-image
        :src="resizeImage(current, 300)"
        :radius="radius"
        :size="size"
        :background-color="backgroundColor"
        @tap="toGoods"
    >
        <view class="zoom" @tap.stop="preview()" v-if="zoom">
            <text class="shop-icon-zoom"></text>
        </view>
    </cl-image>
</template>
 
<script lang="ts" setup>
import { isEmpty } from "lodash-es";
import { computed, type PropType } from "vue";
import { useCool, useUpload } from "/@/cool";
 
const props = defineProps({
    item: {
        type: Object as PropType<Eps.GoodsInfoEntity>,
        default: () => ({}),
    },
    spec: {
        type: Object as PropType<Eps.GoodsSpecEntity>,
        default: () => ({}),
    },
    size: [Number, String, Array],
    radius: {
        type: [Number, String],
        default: 24,
    },
    backgroundColor: String,
    link: {
        type: Boolean,
        default: true,
    },
    zoom: Boolean,
});
 
const { router } = useCool();
const { resizeImage } = useUpload();
 
const urls = computed(() => {
    if (props.spec) {
        const arr = props.spec.images || [];
 
        if (!isEmpty(arr)) {
            return arr;
        }
    }
 
    return [props.item.mainPic];
});
 
const current = computed(() => urls.value[0]);
 
// 商品详情
function toGoods() {
    if (props.link) {
        router.push({
            path: "/pages/goods/detail",
            query: {
                id: props.item.id,
                specId: props.spec?.id,
            },
        });
    }
}
 
// 大图预览
function preview() {
    uni.previewImage({
        urls: urls.value,
        current: current.value,
    });
}
</script>
 
<style lang="scss" scoped>
.zoom {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: 8rpx;
    top: 8rpx;
    height: 30rpx;
    width: 30rpx;
    background-color: rgba(60, 60, 60, 0.7);
    color: #fff;
    font-size: 18rpx;
    border-radius: 100%;
}
</style>