Your Name
2022-06-27 0a3027eccd3b0bb6542e5fc831f7e02740dcfc95
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<template>
    <div class="list-adapt-container">
        <el-card shadow="hover" header="列表自适应演示(改变窗口查看效果)">
            <div class="flex-warp" v-if="tableData.data.length > 0">
                <el-row :gutter="15">
                    <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb15" v-for="(v, k) in tableData.data" :key="k" @click="onTableItemClick(v)">
                        <div class="flex-warp-item">
                            <div class="flex-warp-item-box">
                                <div class="item-img">
                                    <img :src="v.img" />
                                </div>
                                <div class="item-txt">
                                    <div class="item-txt-title">{{ v.title }}</div>
                                    <div class="item-txt-other">
                                        <div style="width: 100%">
                                            <div class="item-txt-msg mb10">
                                                <span>评价 {{ v.evaluate }}</span>
                                                <span class="ml10">收藏 {{ v.collection }}</span>
                                            </div>
                                            <div class="item-txt-msg item-txt-price">
                                                <span class="font-price">
                                                    <span>¥</span>
                                                    <span class="font">{{ v.price }}</span>
                                                </span>
                                                <span>月销{{ v.monSales }}笔</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </el-col>
                </el-row>
            </div>
            <el-empty v-else description="暂无数据"></el-empty>
            <template v-if="tableData.data.length > 0">
                <el-pagination
                    style="text-align: right"
                    background
                    @size-change="onHandleSizeChange"
                    @current-change="onHandleCurrentChange"
                    :page-sizes="[10, 20, 30]"
                    :current-page="tableData.param.pageNum"
                    :page-size="tableData.param.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="tableData.total"
                >
                </el-pagination>
            </template>
        </el-card>
    </div>
</template>
 
<script lang="ts">
import { toRefs, reactive, defineComponent } from 'vue';
import { useRouter } from 'vue-router';
import { filterList } from './mock';
 
// 定义接口来定义对象的类型
interface ListAdaptRow {
    img: string;
    title: string;
    evaluate: string;
    collection: string;
    price: string;
    monSales: string;
    id: number;
}
interface TableDataState {
    tableData: {
        data: Array<ListAdaptRow>;
        total: number;
        loading: boolean;
        param: {
            pageNum: number;
            pageSize: number;
        };
    };
}
 
export default defineComponent({
    name: 'pagesListAdapt',
    setup() {
        const router = useRouter();
        const state = reactive<TableDataState>({
            tableData: {
                data: filterList,
                total: 99,
                loading: false,
                param: {
                    pageNum: 1,
                    pageSize: 10,
                },
            },
        });
        // 当前列表项点击
        const onTableItemClick = (v: ListAdaptRow) => {
            router.push({
                path: '/pages/filteringDetails',
                query: { id: v.id },
            });
        };
        // 分页点击
        const onHandleSizeChange = (val: number) => {
            state.tableData.param.pageSize = val;
        };
        // 分页点击
        const onHandleCurrentChange = (val: number) => {
            state.tableData.param.pageNum = val;
        };
        return {
            onTableItemClick,
            onHandleSizeChange,
            onHandleCurrentChange,
            ...toRefs(state),
        };
    },
});
</script>
 
<style scoped lang="scss">
.flex-warp {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    margin: 0 -5px;
    .flex-warp-item {
        padding: 5px;
        width: 100%;
        height: 360px;
        .flex-warp-item-box {
            border: 1px solid var(--next-border-color-light);
            width: 100%;
            height: 100%;
            border-radius: 2px;
            display: flex;
            flex-direction: column;
            transition: all 0.3s ease;
            &:hover {
                cursor: pointer;
                border: 1px solid var(--el-color-primary);
                transition: all 0.3s ease;
                box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.03);
                .item-txt-title {
                    color: var(--el-color-primary) !important;
                    transition: all 0.3s ease;
                }
                .item-img {
                    img {
                        transition: all 0.3s ease;
                        transform: translateZ(0) scale(1.05);
                    }
                }
            }
            .item-img {
                width: 100%;
                height: 215px;
                overflow: hidden;
                img {
                    transition: all 0.3s ease;
                    width: 100%;
                    height: 100%;
                }
            }
            .item-txt {
                flex: 1;
                padding: 15px;
                display: flex;
                flex-direction: column;
                overflow: hidden;
                .item-txt-title {
                    text-overflow: ellipsis;
                    overflow: hidden;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                    display: -webkit-box;
                    color: #666666;
                    transition: all 0.3s ease;
                    &:hover {
                        color: var(--el-color-primary);
                        text-decoration: underline;
                        transition: all 0.3s ease;
                    }
                }
                .item-txt-other {
                    flex: 1;
                    align-items: flex-end;
                    display: flex;
                    .item-txt-msg {
                        font-size: 12px;
                        color: #8d8d91;
                    }
                    .item-txt-price {
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        .font-price {
                            color: #ff5000;
                            .font {
                                font-size: 22px;
                            }
                        }
                    }
                }
            }
        }
    }
}
</style>