Commit 9f9b39bb authored by Cai Wei's avatar Cai Wei

feat(*): 修改表格样式

parent 65e7e260
<template> <template>
<div class="common-table"> <div class="common-table">
<el-table :data="currentPageData" v-bind="$attrs" style="width: 100%"> <el-table
ref="tableRef"
:data="currentPageData"
v-bind="$attrs"
border
:height="tableHeight"
>
<template v-for="column in columns" :key="column.prop"> <template v-for="column in columns" :key="column.prop">
<el-table-column v-bind="column"> <el-table-column v-bind="column">
<template #default="scope"> <template #default="scope">
...@@ -23,7 +29,7 @@ ...@@ -23,7 +29,7 @@
v-model:page-size="pageSize" v-model:page-size="pageSize"
:page-sizes="pageSizes" :page-sizes="pageSizes"
:total="total" :total="total"
layout="total, prev, pager, next, sizes, jumper" layout="total, prev, pager, next, sizes, jumper"
@size-change="handleSizeChange" @size-change="handleSizeChange"
@current-change="handleCurrentChange" @current-change="handleCurrentChange"
:total-text="paginationTexts.total || '总计'" :total-text="paginationTexts.total || '总计'"
...@@ -36,7 +42,7 @@ ...@@ -36,7 +42,7 @@
</template> </template>
<script setup> <script setup>
import { ref, computed, watch } from "vue"; import { ref, computed, watch, onMounted, onUnmounted, nextTick } from "vue";
const props = defineProps({ const props = defineProps({
// 表格数据 // 表格数据
...@@ -66,22 +72,20 @@ const props = defineProps({ ...@@ -66,22 +72,20 @@ const props = defineProps({
type: Number, type: Number,
default: 10, default: 10,
}, },
// 分页布局
paginationLayout: {
type: String,
default: "total, sizes, prev, pager, next, jumper",
},
// 分页器文字配置 // 分页器文字配置
paginationTexts: { paginationTexts: {
type: Object, type: Object,
default: () => ({ default: () => ({
total: "总计", // 总计xxx条 total: "总计",
sizeChange: "条/页", // 每页显示数量的文字 sizeChange: "条/页",
prev: "上一页", jumper: "前往",
next: "下一页",
jumper: "前往", // 跳转文字
}), }),
}, },
// 表格最小高度
minHeight: {
type: Number,
default: 300,
},
}); });
const emit = defineEmits([ const emit = defineEmits([
...@@ -90,6 +94,45 @@ const emit = defineEmits([ ...@@ -90,6 +94,45 @@ const emit = defineEmits([
"pagination-change", "pagination-change",
]); ]);
// 表格引用
const tableRef = ref(null);
// 表格容器引用
const tableHeight = ref(props.minHeight);
// 计算表格高度
const calculateTableHeight = () => {
nextTick(() => {
if (!tableRef.value) return;
const parentHeight = tableRef.value.$el.parentElement.offsetHeight;
const paginationHeight = props.showPagination ? 70 : 0; // 分页器高度 + margin
const calculatedHeight = parentHeight - paginationHeight;
tableHeight.value = Math.max(calculatedHeight, props.minHeight);
});
};
// 监听窗口大小变化
const handleResize = () => {
calculateTableHeight();
};
onMounted(() => {
calculateTableHeight();
window.addEventListener("resize", handleResize);
});
onUnmounted(() => {
window.removeEventListener("resize", handleResize);
});
// 监听数据变化重新计算高度
watch(
() => props.data,
() => {
nextTick(calculateTableHeight);
},
{ deep: true }
);
// 分页相关 // 分页相关
const currentPage = ref(1); const currentPage = ref(1);
const pageSize = ref(props.defaultPageSize); const pageSize = ref(props.defaultPageSize);
...@@ -108,6 +151,7 @@ const handleSizeChange = (val) => { ...@@ -108,6 +151,7 @@ const handleSizeChange = (val) => {
pageSize.value = val; pageSize.value = val;
currentPage.value = 1; currentPage.value = 1;
emitPaginationChange(); emitPaginationChange();
nextTick(calculateTableHeight);
}; };
const handleCurrentChange = (val) => { const handleCurrentChange = (val) => {
...@@ -138,11 +182,21 @@ watch( ...@@ -138,11 +182,21 @@ watch(
<style lang="scss" scoped> <style lang="scss" scoped>
.common-table { .common-table {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
:deep(.el-table) {
flex: 1;
}
.pagination-container { .pagination-container {
margin-top: 20px; margin-top: 20px;
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
padding: 10px 0; padding: 10px 0;
height: 32px; // 固定分页器高度
} }
} }
</style> </style>
...@@ -152,4 +206,13 @@ watch( ...@@ -152,4 +206,13 @@ watch(
.el-table__body { .el-table__body {
width: 100% !important; width: 100% !important;
} }
.el-table {
// 设置表头样式
th.el-table__cell {
background-color: #f5f7fa !important;
color: #606266;
font-weight: 600;
}
}
</style> </style>
...@@ -66,48 +66,49 @@ ...@@ -66,48 +66,49 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
<div class="table-box">
<common-table
:data="tableData"
:columns="tableColumns"
:default-page-size="10"
@pagination-change="handlePaginationChange"
:pagination-texts="{
total: '共',
sizeChange: '条/页',
prev: '前一页',
next: '后一页',
jumper: '跳至',
}"
>
<template #status="{ row }">
<el-tag :type="getStatusType(row.status)" effect="light">
{{ row.status }}
</el-tag>
</template>
<common-table <template #healthScore="{ row }">
:data="tableData" <span :style="{ color: getHealthScoreColor(row.healthScore) }">
:columns="tableColumns" {{ row.healthScore }}
:default-page-size="10" </span>
@pagination-change="handlePaginationChange" </template>
:pagination-texts="{
total: '共',
sizeChange: '条/页',
prev: '前一页',
next: '后一页',
jumper: '跳至',
}"
>
<template #status="{ row }">
<el-tag :type="getStatusType(row.status)" effect="light">
{{ row.status }}
</el-tag>
</template>
<template #healthScore="{ row }"> <template #operation="{ row }">
<span :style="{ color: getHealthScoreColor(row.healthScore) }"> <el-button type="primary" link @click="handleView(row)">
{{ row.healthScore }} 查看详情
</span> </el-button>
</template> <el-button type="primary" link @click="handleEdit(row)">
编辑
<template #operation="{ row }"> </el-button>
<el-button type="primary" link @click="handleView(row)"> </template>
查看详情 </common-table>
</el-button> </div>
<el-button type="primary" link @click="handleEdit(row)">
编辑
</el-button>
</template>
</common-table>
</div> </div>
</div> </div>
</template> </template>
<script setup> <script setup>
import { ref, onMounted, onBeforeUnmount } from "vue"; import { ref, onMounted, onBeforeUnmount } from "vue";
import CommonTable from "@/components/CommonTable/index.vue"; import CommonTable from "@/components/commonTable/index.vue";
const formInline = ref({ const formInline = ref({
deviceName: "", deviceName: "",
...@@ -329,6 +330,10 @@ onBeforeUnmount(() => {}); ...@@ -329,6 +330,10 @@ onBeforeUnmount(() => {});
align-items: center; align-items: center;
margin-bottom: 16px; margin-bottom: 16px;
} }
.table-box {
width: 100%;
height: calc(100vh - 400px);
}
} }
.default-btn { .default-btn {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment