wujingjing
2024-08-29 19b778d2d04bed31ce2e1f167c6ff2fda9906421
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<template>
    <div class="lazy-img-container layout-pd">
        <div class="flex-warp w100" v-if="data.length > 0">
            <el-row :gutter="15" class="w100">
                <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15" v-for="(v, k) in data" :key="k" @click="onTableItemClick(v)">
                    <div class="flex-warp-item">
                        <div class="flex-warp-item-box" :class="{ 'item-box-active': activeItem?.id === v.id }">
                            <div class="item-img h100" v-loading="v.loading">
                                <img :data-img="v.url" :data-key="k" :data-lazy-img-list="k" />
                            </div>
                        </div>
                    </div>
                </el-col>
            </el-row>
        </div>
        <el-empty v-else description="暂无数据"></el-empty>
        <template v-if="data.length > 0 && showPage">
            <el-pagination
                style="text-align: right"
                background
                @size-change="onHandleSizeChange"
                @current-change="onHandleCurrentChange"
                :page-sizes="[10, 20, 30]"
                :current-page="state.tableData.param.pageNum"
                :page-size="state.tableData.param.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="state.tableData.total"
            >
            </el-pagination>
        </template>
    </div>
</template>
 
<script setup lang="ts">
import { reactive, onMounted, ref, toRefs } from 'vue';
import other from '/@/utils/other';
import { ImgPickItem } from '/@/components/image/imagePicker/imagePicker';
 
const props = defineProps({
    activeItem: {
        type: Object,
        default: {},
    },
    showPage: {
        type: Boolean,
        default: false,
    },
    data: {
        type: Array<ImgPickItem>,
        default: [],
    },
});
const { activeItem } = toRefs(props);
 
const emits = defineEmits<{
    (event: 'click', item): void;
}>();
 
const state = reactive({
    tableData: {
        total: 20,
        loading: false,
        param: {
            pageNum: 1,
            pageSize: 10,
        },
    },
});
 
// 当前列表项点击
const onTableItemClick = (v) => {
    emits('click', v);
};
// 分页点击
const onHandleSizeChange = (val: number) => {
    state.tableData.param.pageSize = val;
};
// 分页点击
const onHandleCurrentChange = (val: number) => {
    state.tableData.param.pageNum = val;
};
// 页面加载时
onMounted(() => {
    other.lazyImg('[data-lazy-img-list]', props.data);
});
</script>
 
<style scoped lang="scss">
.lazy-img-container {
    .flex-warp {
        display: flex;
        flex-wrap: wrap;
        align-content: flex-start;
        margin: 0 -5px;
        .flex-warp-item {
            padding: 5px;
            width: 100%;
            height: 120px;
            .flex-warp-item-box {
                width: 100%;
                height: 100%;
                border-radius: 2px;
                display: flex;
                flex-direction: column;
 
                &:hover {
                    cursor: pointer;
                }
 
                .item-img {
                    width: 100%;
                    height: 215px;
                    overflow: hidden;
                    img {
                        width: 100%;
                        height: 100%;
                    }
                }
            }
        }
    }
}
.item-box-active {
    border: 5px solid var(--el-color-primary);
}
</style>