Skip to content

Commit 8817b0a

Browse files
authored
feat(Table): 新增borderType参数,支持设置表格边框类型 (DevCloudFE#355)
* feat(Table): 新增borderType参数,支持设置表格边框类型 * feat(Table): 删除注释代码
1 parent dceb469 commit 8817b0a

File tree

5 files changed

+101
-19
lines changed

5 files changed

+101
-19
lines changed

packages/devui-vue/devui/table/src/components/body/body.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
font-size: $devui-font-size;
77
color: $devui-text;
88
background-color: $devui-base-bg;
9+
border: none;
910

1011
&.hover-enabled:hover {
1112
background-color: $devui-list-item-hover-bg;

packages/devui-vue/devui/table/src/composable/use-table.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function useTable(props: TablePropsTypes): TableConfig {
1616
[ns.m('header-bg')]: props.headerBg,
1717
[ns.m('layout-auto')]: props.tableLayout === 'auto',
1818
[ns.m(`${props.size}`)]: true,
19+
[ns.m(`${props.borderType}`)]: props.borderType,
1920
}));
2021
const style: ComputedRef<CSSProperties> = computed(() => ({
2122
maxHeight: props.maxHeight,

packages/devui-vue/devui/table/src/table-types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { PropType, ExtractPropTypes, ComponentInternalInstance, InjectionKey } f
22
import { TableStore } from './store';
33

44
export type TableSize = 'sm' | 'md' | 'lg';
5+
export type BorderType = '' | 'bordered' | 'borderless';
56

67
export type SpanMethod = (data: {
78
row: any;
@@ -72,6 +73,10 @@ export const TableProps = {
7273
spanMethod: {
7374
type: Function as PropType<SpanMethod>,
7475
},
76+
borderType: {
77+
type: String as PropType<BorderType>,
78+
default: '',
79+
},
7580
};
7681

7782
export type TablePropsTypes = ExtractPropTypes<typeof TableProps>;

packages/devui-vue/devui/table/src/table.scss

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
table-layout: fixed;
1111
width: 100%;
1212
border-spacing: 0;
13-
border-collapse: separate;
13+
border-collapse: collapse;
1414
border: none;
1515
margin: 0;
1616
padding: 0;
@@ -77,4 +77,33 @@
7777
padding: 8px 20px;
7878
}
7979
}
80+
81+
&--borderless {
82+
tbody > tr > td {
83+
border-bottom: none;
84+
}
85+
}
86+
87+
&--bordered {
88+
tr {
89+
border-left: 1px solid $devui-dividing-line;
90+
91+
td {
92+
border-right: 1px solid $devui-dividing-line;
93+
}
94+
}
95+
96+
thead {
97+
tr {
98+
th:first-child {
99+
border-left: 1px solid $devui-dividing-line;
100+
}
101+
102+
th {
103+
border-top: 1px solid $devui-dividing-line;
104+
border-right: 1px solid $devui-dividing-line;
105+
}
106+
}
107+
}
108+
}
80109
}

packages/devui-vue/docs/components/table/index.md

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,23 @@ export default defineComponent({
9696
</d-radio>
9797
</d-radio-group>
9898
</div>
99+
<div class="table-btn">
100+
表格边框:
101+
<d-radio-group direction="row" v-model="borderType">
102+
<d-radio v-for="item in borderTypeList" :key="item.label" :value="item.value">
103+
{{ item.label }}
104+
</d-radio>
105+
</d-radio-group>
106+
</div>
99107
</div>
100-
<d-table :table-layout="tableLayout ? 'auto' : 'fixed'" :striped="striped" :header-bg="headerBg" :data="stripedTableData" :size="size">
108+
<d-table
109+
:table-layout="tableLayout ? 'auto' : 'fixed'"
110+
:striped="striped"
111+
:header-bg="headerBg"
112+
:data="stripedTableData"
113+
:size="size"
114+
:border-type="borderType"
115+
>
101116
<d-column field="firstName" header="First Name"></d-column>
102117
<d-column field="lastName" header="Last Name"></d-column>
103118
<d-column field="gender" header="Gender"></d-column>
@@ -114,6 +129,7 @@ export default defineComponent({
114129
const striped = ref(false);
115130
const headerBg = ref(false);
116131
const size = ref('sm');
132+
const borderType = ref('');
117133
const sizeList = [
118134
{
119135
label: 'Normal',
@@ -128,6 +144,20 @@ export default defineComponent({
128144
value: 'lg',
129145
},
130146
];
147+
const borderTypeList = [
148+
{
149+
label: 'Normal',
150+
value: '',
151+
},
152+
{
153+
label: 'Bordered',
154+
value: 'bordered',
155+
},
156+
{
157+
label: 'Borderless',
158+
value: 'borderless',
159+
},
160+
];
131161
const stripedTableData = ref([
132162
{
133163
firstName: 'Mark',
@@ -161,6 +191,8 @@ export default defineComponent({
161191
headerBg,
162192
size,
163193
sizeList,
194+
borderType,
195+
borderTypeList,
164196
tableLayout,
165197
};
166198
},
@@ -170,6 +202,7 @@ export default defineComponent({
170202
<style lang="scss">
171203
.table-btn-groups {
172204
display: flex;
205+
flex-wrap: wrap;
173206
}
174207
.table-btn {
175208
display: flex;
@@ -333,7 +366,7 @@ export default defineComponent({
333366

334367
```vue
335368
<template>
336-
<d-table :data="baseTableData" :span-method="spanMethod">
369+
<d-table :data="baseTableData" :span-method="spanMethod" border-type="bordered">
337370
<d-column field="firstName" header="First Name"></d-column>
338371
<d-column field="lastName" header="Last Name"></d-column>
339372
<d-column field="gender" header="Gender"></d-column>
@@ -394,22 +427,23 @@ export default defineComponent({
394427

395428
### d-table 参数
396429

397-
| 参数 | 类型 | 默认值 | 说明 |
398-
| :-------------------- | :--------------------- | :------ | :------------------------------------------ |
399-
| data | `array` | [] | 显示的数据 |
400-
| striped | `boolean` | false | 是否显示斑马纹间隔 |
401-
| size | `'sm' \| 'md' \| 'lg'` | 'sm' | 可选,表格大小,分别对应行高 40px,48px,56px |
402-
| max-width | `string` | -- | 表格最大宽度 |
403-
| max-height | `boolean` | -- | 表格最大高度 |
404-
| table-width | `string` | -- | 表格宽度 |
405-
| table-height | `string` | -- | 表格高度 |
406-
| row-hovered-highlight | `boolean` | true | 鼠标在该行上时,高亮该行 |
407-
| fix-header | `boolean` | false | 固定头部 |
408-
| checkable | `boolean` | false | 在每行的第一列展示一个 checkbox |
409-
| show-loading | `boolean` | false | 显示加载动画 |
410-
| header-bg | `boolean` | false | 头部背景 |
411-
| table-layout | `'fixed' \| 'auto'` | 'fixed' | 表格布局,可选值为'auto' |
412-
| span-method | `SpanMethod` | -- | 合并单元格的计算方法 |
430+
| 参数 | 类型 | 默认值 | 说明 |
431+
| :-------------------- | :------------------ | :------ | :--------------------------------------------------------------------- |
432+
| data | `array` | [] | 显示的数据 |
433+
| striped | `boolean` | false | 是否显示斑马纹间隔 |
434+
| size | `TableSize` | 'sm' | 可选,表格大小,分别对应行高 40px,48px,56px |
435+
| max-width | `string` | -- | 表格最大宽度 |
436+
| max-height | `boolean` | -- | 表格最大高度 |
437+
| table-width | `string` | -- | 表格宽度 |
438+
| table-height | `string` | -- | 表格高度 |
439+
| row-hovered-highlight | `boolean` | true | 鼠标在该行上时,高亮该行 |
440+
| fix-header | `boolean` | false | 固定头部 |
441+
| checkable | `boolean` | false | 在每行的第一列展示一个 checkbox |
442+
| show-loading | `boolean` | false | 显示加载动画 |
443+
| header-bg | `boolean` | false | 头部背景 |
444+
| table-layout | `'fixed' \| 'auto'` | 'fixed' | 表格布局,可选值为'auto' |
445+
| span-method | `SpanMethod` | -- | 合并单元格的计算方法 |
446+
| border-type | `BorderType` | '' | 可选,表格边框类型,默认有行边框;bordered: 全边框;borderless: 无边框 |
413447

414448
### d-column 参数
415449

@@ -431,6 +465,12 @@ export default defineComponent({
431465

432466
### 类型定义
433467

468+
#### TableSize
469+
470+
```typescript
471+
type TableSize = 'sm' | 'md' | 'lg';
472+
```
473+
434474
#### SpanMethod
435475

436476
```typescript
@@ -441,3 +481,9 @@ type SpanMethod = (data: {
441481
columnIndex: number;
442482
}) => number[] | { rowspan: number; colspan: number };
443483
```
484+
485+
#### BorderType
486+
487+
```typescript
488+
type BorderType = '' | 'bordered' | 'borderless';
489+
```

0 commit comments

Comments
 (0)