Skip to content

Commit 5a41058

Browse files
kagolgitee-org
authored andcommitted
!260 feat(table): 增加样式 api
Merge pull request !260 from 无声/dev-table
2 parents 89965ec + 8af3622 commit 5a41058

File tree

6 files changed

+72
-19
lines changed

6 files changed

+72
-19
lines changed

devui/table/src/header/header.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@
1616
}
1717
}
1818
}
19+
20+
.header-bg {
21+
thead.devui-thead {
22+
tr {
23+
background: var(--devui-list-item-hover-bg, #f2f5fc);
24+
}
25+
}
26+
}

devui/table/src/table.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@
2424
text-align: center;
2525
}
2626
}
27+
28+
.table-layout-auto {
29+
table-layout: auto;
30+
}

devui/table/src/table.type.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ export const TableProps = {
99
type: Boolean,
1010
default: false,
1111
},
12+
headerBg:{
13+
type: Boolean,
14+
default: false
15+
},
16+
tableLayout:{
17+
type: String as PropType<'fixed' | 'auto'>,
18+
default: 'fixed'
19+
}
1220
};
1321

1422
export type TablePropsTypes = ExtractPropTypes<typeof TableProps>;

devui/table/src/use-table.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export function useTable(props: TablePropsTypes): any {
55
const classes = computed(() => ({
66
'devui-table': true,
77
'devui-table-striped': props.striped,
8+
'header-bg': props.headerBg,
9+
'table-layout-auto': props.tableLayout === 'auto'
810
}));
911

1012
return { classes };

docs/.vitepress/devui-theme/styles/layout.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ tr {
183183
border-top: 1px solid $devui-dividing-line;
184184
}
185185

186-
tr:nth-child(2n) {
187-
background-color: $devui-area;
188-
}
189-
190186
th,
191187
td {
192188
border: 1px solid $devui-dividing-line;

docs/components/table/index.md

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,27 @@
6262

6363
:::
6464

65-
### 斑马纹表格
65+
### 表格样式
6666

67-
:::demo 通过`d-table`组件上的`striped`属性,可设置带斑马纹的表格,更容易区分不同行的数据。
67+
:::demo
6868

6969
```vue
7070
<template>
71-
<d-table striped :data="stripedTableData">
71+
<div class="table-btn-groups">
72+
<div class="table-btn">
73+
自动表格布局:
74+
<d-switch v-model:checked="tableLayout" />
75+
</div>
76+
<div class="table-btn">
77+
斑马纹:
78+
<d-switch v-model:checked="striped" />
79+
</div>
80+
<div class="table-btn">
81+
表头背景色:
82+
<d-switch v-model:checked="headerBg" />
83+
</div>
84+
</div>
85+
<d-table :table-layout="tableLayout?'auto':'fixed'" :striped="striped" :header-bg="headerBg" :data="stripedTableData">
7286
<d-column field="firstName" header="First Name"></d-column>
7387
<d-column field="lastName" header="Last Name"></d-column>
7488
<d-column field="gender" header="Gender"></d-column>
@@ -82,7 +96,9 @@
8296
8397
export default defineComponent({
8498
setup() {
85-
99+
const tableLayout = ref(false)
100+
const striped = ref(false)
101+
const headerBg = ref(false)
86102
const stripedTableData = ref([
87103
{
88104
firstName: 'Mark',
@@ -110,10 +126,27 @@
110126
}
111127
])
112128
113-
return { stripedTableData }
129+
return {
130+
stripedTableData,
131+
striped,
132+
headerBg,
133+
tableLayout
134+
}
114135
}
115136
})
116137
</script>
138+
139+
<style lang="scss">
140+
.table-btn-groups{
141+
display: flex;
142+
margin-bottom: 1rem;
143+
}
144+
.table-btn{
145+
display: flex;
146+
flex-direction: column;
147+
justify-content: space-between;
148+
}
149+
</style>
117150
```
118151

119152
:::
@@ -182,16 +215,18 @@
182215

183216
### d-table Props
184217

185-
| 参数 | 类型 | 默认值 | 说明 |
186-
| ------- | --------- | ------- | ------------------ |
187-
| data | `Array` | `[]` | 显示的数据 |
188-
| striped | `Boolean` | `false` | 是否显示斑马纹间隔 |
218+
| 参数 | 类型 | 默认值 | 说明 |
219+
| ------------ | ------------------- | --------- | ------------------------ |
220+
| data | `Array` | `[]` | 显示的数据 |
221+
| striped | `Boolean` | `false` | 是否显示斑马纹间隔 |
222+
| header-bg | `Boolean` | `false` | 可选,表头是否显示背景色 |
223+
| table-layout | `String` | `'fixed'` | 表格布局,可选值为`'auto'`|
189224

190225
### d-column Props
191226

192-
| 参数 | 类型 | 默认值 | 说明 |
193-
| ------ | ------------------ | ------ | ---------------------- |
194-
| header | `String` | `-` | 对应列的标题 |
195-
| field | `String` | `-` | 对应列内容的字段名 |
196-
| width | `String \| Number` | `-` | 对应列的宽度,单位`px` |
197-
| min-width | `String \| Number` | `-` | 对应列的最小宽度,单位`px` |
227+
| 参数 | 类型 | 默认值 | 说明 |
228+
| --------- | ------------------ | ------ | -------------------------- |
229+
| header | `String` | `-` | 对应列的标题 |
230+
| field | `String` | `-` | 对应列内容的字段名 |
231+
| width | `String \| Number` | `-` | 对应列的宽度,单位`px` |
232+
| min-width | `String \| Number` | `-` | 对应列的最小宽度,单位`px` |

0 commit comments

Comments
 (0)