(component): 新增 table 组件 even 属性, 用于开启斑马条纹

This commit is contained in:
就眠儀式 2022-06-26 23:24:05 +08:00
parent 129106705e
commit b1b3397951
3 changed files with 58 additions and 2 deletions

View File

@ -27,7 +27,7 @@
.layui-table-tool, .layui-table-tool,
.layui-table-total, .layui-table-total,
.layui-table-total tr, .layui-table-total tr,
.layui-table[lay-even] tr:nth-child(even) { .layui-table.layui-table-even tr:nth-child(even) {
background-color: var(--global-neutral-color-1); background-color: var(--global-neutral-color-1);
} }

View File

@ -29,6 +29,7 @@ export interface LayTableProps {
childrenColumnName?: string; childrenColumnName?: string;
height?: number; height?: number;
maxHeight?: string; maxHeight?: string;
even?: boolean;
} }
const props = withDefaults(defineProps<LayTableProps>(), { const props = withDefaults(defineProps<LayTableProps>(), {
@ -39,6 +40,7 @@ const props = withDefaults(defineProps<LayTableProps>(), {
dataSource: () => [], dataSource: () => [],
selectedKeys: () => [], selectedKeys: () => [],
maxHeight: "auto", maxHeight: "auto",
even: false,
}); });
const tableId = uuidv4(); const tableId = uuidv4();
@ -364,7 +366,7 @@ props.dataSource.map((value: any) => {
:style="{ height: height, maxHeight: maxHeight }" :style="{ height: height, maxHeight: maxHeight }"
ref="tableBody" ref="tableBody"
> >
<table class="layui-table" :lay-size="size"> <table class="layui-table" :class="{'layui-table-even': props.even}" :lay-size="size">
<colgroup> <colgroup>
<col v-if="checkbox" class="layui-table-col-special" /> <col v-if="checkbox" class="layui-table-col-special" />
<template v-for="column in columns" :key="column"> <template v-for="column in columns" :key="column">

View File

@ -476,6 +476,60 @@ export default {
::: :::
::: title 斑马条纹
:::
::: demo 通过 `even` 属性, 开启斑马条纹, 默认为 false。
<template>
<lay-table :columns="columns1" :dataSource="dataSource1" even></lay-table>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const columns1 = [
{
title:"账户",
width:"200px",
key:"username"
},{
title:"密码",
width: "180px",
key:"password"
},{
title:"年龄",
width: "180px",
key:"age"
},{
title:"备注",
width: "180px",
key:"remark",
ellipsisTooltip: true,
}
]
const dataSource1 = [
{username:"root", password:"root", age:"18", remark: 'layui - vue谐音类 UI) '},
{username:"root", password:"root", age:"18", remark: 'layui - vue谐音类 UI) '},
{username:"woow", password:"woow", age:"20", remark: 'layui - vue谐音类 UI) '},
{username:"woow", password:"woow", age:"20", remark: 'layui - vue谐音类 UI) '},
{username:"woow", password:"woow", age:"20", remark: 'layui - vue谐音类 UI) '}
]
return {
columns1,
dataSource1
}
}
}
</script>
:::
::: title Table 属性 ::: title Table 属性
::: :::