|
@@ -0,0 +1,152 @@
|
|
|
+<script lang="ts" setup>
|
|
|
+/**
|
|
|
+ * @Name: InfoCard.vue
|
|
|
+ * @Description: 电脑信息卡片
|
|
|
+ * @Author: xinyan
|
|
|
+ */
|
|
|
+
|
|
|
+import { ref } from 'vue';
|
|
|
+import { ElIcon, ElMessage } from 'element-plus';
|
|
|
+import { Delete, EditPen, Picture as IconPicture, Search } from '@element-plus/icons-vue';
|
|
|
+import { useResponse } from '/@/utils/useResponse';
|
|
|
+import * as api from '/@/views/computer-information/api';
|
|
|
+import { useRouter } from 'vue-router';
|
|
|
+import { usePagination } from '/@/utils/usePagination';
|
|
|
+import { useElTableData } from '/@/utils/useElTable';
|
|
|
+
|
|
|
+const router = useRouter();
|
|
|
+const cardItems = ref([]);
|
|
|
+const loading = ref();
|
|
|
+const { tableData, currentPage, pageSize ,total } = usePagination(fetchCardData)
|
|
|
+
|
|
|
+// 分页参数
|
|
|
+// const currentPage = ref(1);
|
|
|
+// const pageSize = ref(10);
|
|
|
+// const total = ref(0);
|
|
|
+
|
|
|
+async function fetchCardData() {
|
|
|
+ const query = {
|
|
|
+ page: currentPage.value,
|
|
|
+ limit: pageSize.value,
|
|
|
+ };
|
|
|
+ await useElTableData(api.getCardData, query, tableData, total, loading)
|
|
|
+ // const res = await useResponse(query, api.getCardData, loading);
|
|
|
+ // tableData.value = res.data;
|
|
|
+ // total.value = res.total;
|
|
|
+ // currentPage.value = res.page;
|
|
|
+ // pageSize.value = res.limit;
|
|
|
+}
|
|
|
+
|
|
|
+// 编辑和删除的事件处理
|
|
|
+const editItem = (item) => {
|
|
|
+ router.push({
|
|
|
+ path: '/computer/edit',
|
|
|
+ query: { computerNumber: item.computerNumber }
|
|
|
+ })
|
|
|
+};
|
|
|
+
|
|
|
+const deleteItem = (item) => {
|
|
|
+ ElMessage({
|
|
|
+ message: `删除 ${item.computerNumber}`,
|
|
|
+ type: 'warning',
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+// 处理图片地址
|
|
|
+const getImageUrl = (images) => {
|
|
|
+ // 如果有图片,返回第一个图片的 image_url,否则返回占位图
|
|
|
+ return images.length > 0 ? images[0].image_url : 'https://via.placeholder.com/150';
|
|
|
+};
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ fetchCardData();
|
|
|
+});
|
|
|
+</script>
|
|
|
+
|
|
|
+<template>
|
|
|
+ <!-- 卡片展示区域 -->
|
|
|
+ <div class="card-container">
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col v-for="(item, index) in tableData" :key="index" :span="4" class="my-2.5">
|
|
|
+ <el-card class="item-card" shadow="hover">
|
|
|
+ <el-image :src="getImageUrl(item.images)" alt="电脑图片" class="card-image">
|
|
|
+ <template #error>
|
|
|
+ <el-icon class="card-image" style="font-size: 4rem">
|
|
|
+ <icon-picture />
|
|
|
+ </el-icon>
|
|
|
+ </template>
|
|
|
+ </el-image>
|
|
|
+ <div class="card-content">
|
|
|
+ <div>
|
|
|
+ <span style="color: #808d97">电脑编号: </span>
|
|
|
+ <span>{{ item.computerNumber }}</span>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <span style="color: #808d97">所属店铺: </span>
|
|
|
+ <span>{{ item.shopName }}</span>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="card-footer">
|
|
|
+ <el-button :icon="Search" circle type="primary" @click="editItem(item)" />
|
|
|
+ <el-button :icon="EditPen" circle type="primary" @click="editItem(item)" />
|
|
|
+ <el-button :icon="Delete" circle type="danger" @click="deleteItem(item)" />
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
+ <div class="pagination-container">
|
|
|
+ <!--<el-pagination-->
|
|
|
+ <!-- v-model:current-page="currentPage"-->
|
|
|
+ <!-- :page-size="pageSize"-->
|
|
|
+ <!-- :page-sizes="[10, 25, 50,100,200]"-->
|
|
|
+ <!-- :total="total"-->
|
|
|
+ <!-- background-->
|
|
|
+ <!-- layout="total,sizes,prev, next, jumper"-->
|
|
|
+ <!-- small-->
|
|
|
+ <!--/>-->
|
|
|
+ <el-pagination
|
|
|
+ v-model:current-page="currentPage"
|
|
|
+ v-model:page-size="pageSize"
|
|
|
+ :page-sizes="[10, 20, 30, 50, 100, 200]"
|
|
|
+ :total="total"
|
|
|
+ layout="sizes, prev, pager, next, total"
|
|
|
+ background
|
|
|
+ @change="handlePageChange"/>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+.card-container {
|
|
|
+ margin-bottom: 20px;
|
|
|
+}
|
|
|
+
|
|
|
+.item-card {
|
|
|
+ border-radius: 10px;
|
|
|
+ overflow: hidden;
|
|
|
+ position: relative;
|
|
|
+}
|
|
|
+
|
|
|
+.card-image {
|
|
|
+ width: 100%;
|
|
|
+ height: 150px;
|
|
|
+ object-fit: cover;
|
|
|
+}
|
|
|
+
|
|
|
+.card-content {
|
|
|
+ padding: 10px;
|
|
|
+ font-size: 14px;
|
|
|
+}
|
|
|
+
|
|
|
+.card-footer {
|
|
|
+ display: flex;
|
|
|
+ justify-content: flex-end;
|
|
|
+ padding: 10px;
|
|
|
+}
|
|
|
+
|
|
|
+.pagination-container {
|
|
|
+ display: flex;
|
|
|
+ justify-content: flex-end;
|
|
|
+ // margin-bottom: 20px;
|
|
|
+}
|
|
|
+</style>
|