style(table): 优化表格样式并添加全局美化

- 在 component.less 中添加了 ele-pro-table 的全局美化样式
- 调整了表格的列宽、对齐方式等样式
- 优化了表格的视觉效果,提高了可读性
This commit is contained in:
2025-08-11 13:19:22 +08:00
parent d0000fb391
commit c2d38ac946
2 changed files with 318 additions and 303 deletions

View File

@@ -1,2 +1,17 @@
/** 组件样式 */ /** 组件样式 */
//@input-item: 300px; //@input-item: 300px;
/* ele-pro-table 全局美化样式 */
.ele-pro-table .ant-table-thead > tr > th {
border-bottom: 2px solid #f0f0f0;
background-color: #fafafa;
font-weight: 600;
}
.ele-pro-table .ant-table-tbody > tr > td {
border-bottom: 1px solid #f5f5f5;
}
.ele-pro-table .ant-table-tbody > tr:hover > td {
background-color: #f8f9fa;
}

View File

@@ -1,334 +1,334 @@
<template> <template>
<a-page-header :title="getPageTitle()" @back="() => $router.go(-1)"> <a-page-header :title="getPageTitle()" @back="() => $router.go(-1)">
<a-card :bordered="false" :body-style="{ padding: '16px' }"> <a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table <ele-pro-table
ref="tableRef" ref="tableRef"
row-key="id" row-key="id"
:columns="columns" :columns="columns"
:datasource="datasource" :datasource="datasource"
:customRow="customRow" :customRow="customRow"
tool-class="ele-toolbar-form" tool-class="ele-toolbar-form"
class="sys-org-table" class="sys-org-table"
:scroll="{ x: 1400, y: 'calc(100vh - 320px)' }" :scroll="{ x: 1400, y: 'calc(100vh - 320px)' }"
size="middle" size="middle"
:pagination="{ :pagination="{
showSizeChanger: true, showSizeChanger: true,
showQuickJumper: true, showQuickJumper: true,
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条` showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`
}" }"
> >
<template #toolbar> <template #toolbar>
<search <search
@search="reload" @search="reload"
:selection="selection" :selection="selection"
@add="openEdit" @add="openEdit"
@remove="removeBatch" @remove="removeBatch"
@batchMove="openMove" @batchMove="openMove"
/> />
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'couponStatus'">
<a-tag v-if="record.deleted === 1" color="red">已删除</a-tag>
<a-tag v-else-if="record.enabled === 0" color="orange">已禁用</a-tag>
<a-tag v-else-if="record.isExpire === 1" color="gray">已过期</a-tag>
<a-tag v-else-if="record.status === 1" color="red">隐藏</a-tag>
<a-tag v-else color="green">正常</a-tag>
</template> </template>
<template #bodyCell="{ column, record }"> <template v-if="column.key === 'action'">
<template v-if="column.key === 'couponStatus'"> <a @click="openEdit(record)" class="ele-text-primary">
<a-tag v-if="record.deleted === 1" color="red">已删除</a-tag> <EditOutlined/>
<a-tag v-else-if="record.enabled === 0" color="orange">已禁用</a-tag> 编辑
<a-tag v-else-if="record.isExpire === 1" color="gray">已过期</a-tag> </a>
<a-tag v-else-if="record.status === 1" color="red">隐藏</a-tag> <a-divider type="vertical"/>
<a-tag v-else color="green">正常</a-tag> <a-popconfirm
</template> title="确定要删除此优惠券吗?"
<template v-if="column.key === 'action'"> @confirm="remove(record)"
<a-space> placement="topRight"
<a @click="openEdit(record)" class="ele-text-primary"> >
<EditOutlined /> 编辑 <a class="ele-text-danger">
</a> <DeleteOutlined/>
<a-divider type="vertical" /> 删除
<a-popconfirm </a>
title="确定要删除此优惠券吗?" </a-popconfirm>
@confirm="remove(record)"
placement="topRight"
>
<a class="ele-text-danger">
<DeleteOutlined /> 删除
</a>
</a-popconfirm>
</a-space>
</template>
</template> </template>
</ele-pro-table> </template>
</a-card> </ele-pro-table>
</a-card>
<!-- 编辑弹窗 --> <!-- 编辑弹窗 -->
<ShopCouponEdit v-model:visible="showEdit" :data="current" @done="reload" /> <ShopCouponEdit v-model:visible="showEdit" :data="current" @done="reload"/>
</a-page-header> </a-page-header>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { createVNode, ref } from 'vue'; import {createVNode, ref} from 'vue';
import { message, Modal } from 'ant-design-vue'; import {message, Modal} from 'ant-design-vue';
import { ExclamationCircleOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'; import {ExclamationCircleOutlined, EditOutlined, DeleteOutlined} from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro'; import type {EleProTable} from 'ele-admin-pro';
import { toDateString } from 'ele-admin-pro'; import {toDateString} from 'ele-admin-pro';
import type { import type {
DatasourceFunction, DatasourceFunction,
ColumnItem ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types'; } from 'ele-admin-pro/es/ele-pro-table/types';
import Search from './components/search.vue'; import Search from './components/search.vue';
import {getPageTitle} from '@/utils/common'; import {getPageTitle} from '@/utils/common';
import ShopCouponEdit from './components/shopCouponEdit.vue'; import ShopCouponEdit from './components/shopCouponEdit.vue';
import { pageShopCoupon, removeShopCoupon, removeBatchShopCoupon } from '@/api/shop/shopCoupon'; import {pageShopCoupon, removeShopCoupon, removeBatchShopCoupon} from '@/api/shop/shopCoupon';
import type { ShopCoupon, ShopCouponParam } from '@/api/shop/shopCoupon/model'; import type {ShopCoupon, ShopCouponParam} from '@/api/shop/shopCoupon/model';
// 表格实例 // 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null); const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据 // 表格选中数据
const selection = ref<ShopCoupon[]>([]); const selection = ref<ShopCoupon[]>([]);
// 当前编辑数据 // 当前编辑数据
const current = ref<ShopCoupon | null>(null); const current = ref<ShopCoupon | null>(null);
// 是否显示编辑弹窗 // 是否显示编辑弹窗
const showEdit = ref(false); const showEdit = ref(false);
// 是否显示批量移动弹窗 // 是否显示批量移动弹窗
const showMove = ref(false); const showMove = ref(false);
// 加载状态 // 加载状态
const loading = ref(true); const loading = ref(true);
// 表格数据源 // 表格数据源
const datasource: DatasourceFunction = ({ const datasource: DatasourceFunction = ({
page,
limit,
where,
orders,
filters
}) => {
if (filters) {
where.status = filters.status;
}
return pageShopCoupon({
...where,
...orders,
page, page,
limit, limit
where, });
orders, };
filters
}) => { // 表格列配置
if (filters) { const columns = ref<ColumnItem[]>([
where.status = filters.status; {
title: 'ID',
dataIndex: 'id',
key: 'id',
align: 'center',
width: 80,
fixed: 'left'
},
{
title: '优惠券名称',
dataIndex: 'name',
key: 'name',
align: 'left',
width: 150,
ellipsis: true,
fixed: 'left'
},
{
title: '类型',
dataIndex: 'type',
key: 'type',
align: 'center',
width: 100,
customRender: ({text}) => {
const typeMap: Record<number, string> = {
10: '满减券',
20: '折扣券',
30: '免费券'
};
return typeMap[text] || text;
} }
return pageShopCoupon({ },
...where, {
...orders, title: '优惠金额',
page, key: 'couponValue',
limit align: 'center',
width: 120,
customRender: ({record}) => {
if (record.type === 10) {
return `${record.reducePrice}`;
} else if (record.type === 20) {
return `${record.discount}`;
}
return '免费';
}
},
{
title: '最低消费',
dataIndex: 'minPrice',
key: 'minPrice',
align: 'center',
width: 100,
customRender: ({text}) => text ? `${text}` : '无门槛'
},
{
title: '有效期',
key: 'validity',
align: 'center',
width: 180,
customRender: ({record}) => {
if (record.expireType === 10) {
return `领取后${record.expireDay}`;
} else {
return `${toDateString(record.startTime, 'MM-dd')}${toDateString(record.endTime, 'MM-dd')}`;
}
}
},
{
title: '适用范围',
dataIndex: 'applyRange',
key: 'applyRange',
align: 'center',
width: 100,
customRender: ({text}) => {
const rangeMap: Record<number, string> = {
10: '全部商品',
20: '指定商品',
30: '指定分类'
};
return rangeMap[text] || text;
}
},
{
title: '发放情况',
key: 'issueInfo',
align: 'center',
width: 120,
customRender: ({record}) => {
const total = record.totalCount === -1 ? '无限' : record.totalCount;
return `${record.issuedCount}/${total}`;
}
},
{
title: '限领数量',
dataIndex: 'limitPerUser',
key: 'limitPerUser',
align: 'center',
width: 100,
customRender: ({text}) => text === -1 ? '无限制' : `${text}张/人`
},
{
title: '状态',
key: 'couponStatus',
align: 'center',
width: 100
},
{
title: '排序',
dataIndex: 'sortNumber',
key: 'sortNumber',
align: 'center',
width: 80,
sorter: true
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
width: 120,
sorter: true,
ellipsis: true,
customRender: ({text}) => toDateString(text, 'yyyy-MM-dd')
},
{
title: '操作',
key: 'action',
width: 150,
fixed: 'right',
align: 'center',
hideInSetting: true
}
]);
/* 搜索 */
const reload = (where?: ShopCouponParam) => {
selection.value = [];
tableRef?.value?.reload({where: where});
};
/* 打开编辑弹窗 */
const openEdit = (row?: ShopCoupon) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 删除单个 */
const remove = (row: ShopCoupon) => {
const hide = message.loading('请求中..', 0);
removeShopCoupon(row.id)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
}); });
}; };
// 表格列配置 /* 批量删除 */
const columns = ref<ColumnItem[]>([ const removeBatch = () => {
{ if (!selection.value.length) {
title: 'ID', message.error('请至少选择一条数据');
dataIndex: 'id', return;
key: 'id', }
align: 'center', Modal.confirm({
width: 80, title: '提示',
fixed: 'left' content: '确定要删除选中的记录吗?',
}, icon: createVNode(ExclamationCircleOutlined),
{ maskClosable: true,
title: '优惠券名称', onOk: () => {
dataIndex: 'name', const hide = message.loading('请求中..', 0);
key: 'name', removeBatchShopCoupon(selection.value.map((d) => d.id))
align: 'left', .then((msg) => {
width: 150, hide();
ellipsis: true, message.success(msg);
fixed: 'left' reload();
}, })
{ .catch((e) => {
title: '类型', hide();
dataIndex: 'type', message.error(e.message);
key: 'type', });
align: 'center',
width: 100,
customRender: ({ text }) => {
const typeMap: Record<number, string> = {
10: '满减券',
20: '折扣券',
30: '免费券'
};
return typeMap[text] || text;
}
},
{
title: '优惠金额',
key: 'couponValue',
align: 'center',
width: 120,
customRender: ({ record }) => {
if (record.type === 10) {
return `${record.reducePrice}`;
} else if (record.type === 20) {
return `${record.discount}`;
}
return '免费';
}
},
{
title: '最低消费',
dataIndex: 'minPrice',
key: 'minPrice',
align: 'center',
width: 100,
customRender: ({ text }) => text ? `${text}` : '无门槛'
},
{
title: '有效期',
key: 'validity',
align: 'center',
width: 180,
customRender: ({ record }) => {
if (record.expireType === 10) {
return `领取后${record.expireDay}`;
} else {
return `${toDateString(record.startTime, 'MM-dd')}${toDateString(record.endTime, 'MM-dd')}`;
}
}
},
{
title: '适用范围',
dataIndex: 'applyRange',
key: 'applyRange',
align: 'center',
width: 100,
customRender: ({ text }) => {
const rangeMap: Record<number, string> = {
10: '全部商品',
20: '指定商品',
30: '指定分类'
};
return rangeMap[text] || text;
}
},
{
title: '发放情况',
key: 'issueInfo',
align: 'center',
width: 120,
customRender: ({ record }) => {
const total = record.totalCount === -1 ? '无限' : record.totalCount;
return `${record.issuedCount}/${total}`;
}
},
{
title: '限领数量',
dataIndex: 'limitPerUser',
key: 'limitPerUser',
align: 'center',
width: 100,
customRender: ({ text }) => text === -1 ? '无限制' : `${text}张/人`
},
{
title: '状态',
key: 'couponStatus',
align: 'center',
width: 100
},
{
title: '排序',
dataIndex: 'sortNumber',
key: 'sortNumber',
align: 'center',
width: 80,
sorter: true
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
width: 120,
sorter: true,
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd')
},
{
title: '操作',
key: 'action',
width: 150,
fixed: 'right',
align: 'center',
hideInSetting: true
} }
]); });
};
/* 搜索 */ /* 查询 */
const reload = (where?: ShopCouponParam) => { const query = () => {
selection.value = []; loading.value = true;
tableRef?.value?.reload({ where: where }); };
};
/* 打开编辑弹窗 */ /* 自定义行属性 */
const openEdit = (row?: ShopCoupon) => { const customRow = (record: ShopCoupon) => {
current.value = row ?? null; return {
showEdit.value = true; // 行点击事件
}; onClick: () => {
// console.log(record);
/* 打开批量移动弹窗 */ },
const openMove = () => { // 行双击事件
showMove.value = true; onDblclick: () => {
}; openEdit(record);
/* 删除单个 */
const remove = (row: ShopCoupon) => {
const hide = message.loading('请求中..', 0);
removeShopCoupon(row.id)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
} }
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchShopCoupon(selection.value.map((d) => d.id))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
}; };
};
/* 查询 */ query();
const query = () => {
loading.value = true;
};
/* 自定义行属性 */
const customRow = (record: ShopCoupon) => {
return {
// 行点击事件
onClick: () => {
// console.log(record);
},
// 行双击事件
onDblclick: () => {
openEdit(record);
}
};
};
query();
</script> </script>
<script lang="ts"> <script lang="ts">
export default { export default {
name: 'ShopCoupon' name: 'ShopCoupon'
}; };
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>