Skip to content

Commit ab73dba

Browse files
authored
feat(Table): 表格支持sm/md/lg三种大小 (DevCloudFE#353)
* feat(Table): 使用Rem规范修改Table组件样式命名 * refactor(Table): TD和TH组件从body、header中抽离,解决一个文件定义多个组件的eslint报错 * feat(Table): 完成Table组件合并单元格功能 * feat(Table): 修改函数命名 * feat(Table): 表格支持sm/md/lg三种大小
1 parent eb51e6e commit ab73dba

File tree

8 files changed

+94
-30
lines changed

8 files changed

+94
-30
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
.devui-table {
44
&__tbody {
55
tr {
6-
font-size: $devui-font-size-card-title;
6+
font-size: $devui-font-size;
77
color: $devui-text;
8-
border: none;
9-
border-bottom: 1px solid $devui-dividing-line;
108
background-color: $devui-base-bg;
119

1210
&.hover-enabled:hover {
1311
background-color: $devui-list-item-hover-bg;
1412
}
1513

1614
td {
17-
padding: 10px;
15+
background-clip: padding-box;
16+
vertical-align: middle;
17+
word-wrap: break-word;
18+
word-break: normal;
19+
line-height: 24px;
1820
border: none;
21+
border-bottom: 1px solid $devui-dividing-line;
1922
}
2023
}
2124
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default defineComponent({
1818

1919
const renderCheckbox = (index: number) =>
2020
table.props.checkable ? (
21-
<td {...tdAttrs.value}>
21+
<td class={ns.e('checkable-cell')} {...tdAttrs.value}>
2222
<Checkbox v-model={checkList.value[index]} />
2323
</td>
2424
) : null;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
font-size: $devui-font-size-card-title;
77
color: $devui-text;
88
font-weight: 700;
9-
border: none;
10-
border-bottom: 1px solid $devui-line;
119
background-color: $devui-base-bg;
1210

1311
th {
1412
text-align: left;
15-
padding: 0;
1613
border: none;
14+
border-bottom: 1px solid $devui-line;
1715
}
1816
}
1917

packages/devui-vue/devui/table/src/components/header/header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export default defineComponent({
1616
const thAttrs = computed(() => (isFixedLeft.value ? { class: `${ns.m('sticky-cell')} left`, style: 'left:0;' } : null));
1717
const checkbox = computed(() =>
1818
table.props.checkable ? (
19-
<th {...thAttrs.value}>
20-
<Checkbox style="padding:10px;" v-model={checkAll.value} halfchecked={halfChecked.value} />
19+
<th class={ns.e('checkable-cell')} {...thAttrs.value}>
20+
<Checkbox v-model={checkAll.value} halfchecked={halfChecked.value} />
2121
</th>
2222
) : null
2323
);

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

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const TableProps = {
4040
validator(value: string): boolean {
4141
return value === 'sm' || value === 'md' || value === 'lg';
4242
},
43+
default: 'sm',
4344
},
4445
rowHoveredHighlight: {
4546
type: Boolean,
@@ -51,7 +52,7 @@ export const TableProps = {
5152
},
5253
checkable: {
5354
type: Boolean,
54-
default: true,
55+
default: false,
5556
},
5657
tableLayout: {
5758
type: String as PropType<'fixed' | 'auto'>,

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
table-layout: fixed;
1111
width: 100%;
1212
border-spacing: 0;
13+
border-collapse: separate;
1314
border: none;
1415
margin: 0;
1516
padding: 0;
@@ -42,4 +43,38 @@
4243
&--layout-auto {
4344
table-layout: auto;
4445
}
46+
47+
&--sm {
48+
tbody > tr > td {
49+
padding: 7px 20px 8px;
50+
51+
&.devui-table__checkable-cell {
52+
padding: 8px;
53+
}
54+
}
55+
56+
thead > tr > th.devui-table__checkable-cell {
57+
padding: 8px;
58+
}
59+
}
60+
61+
&--md {
62+
tbody > tr > td {
63+
padding: 11px 20px 12px;
64+
}
65+
66+
thead > tr > th.devui-table__checkable-cell {
67+
padding: 8px 20px;
68+
}
69+
}
70+
71+
&--lg {
72+
tbody > tr > td {
73+
padding: 15px 20px 16px;
74+
}
75+
76+
thead > tr > th.devui-table__checkable-cell {
77+
padding: 8px 20px;
78+
}
79+
}
4580
}

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

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,16 @@ export default defineComponent({
8888
表头背景色:
8989
<d-switch v-model:checked="headerBg" />
9090
</div>
91+
<div class="table-btn">
92+
表格大小:
93+
<d-radio-group direction="row" v-model="size">
94+
<d-radio v-for="item in sizeList" :key="item.label" :value="item.value">
95+
{{ item.label }}
96+
</d-radio>
97+
</d-radio-group>
98+
</div>
9199
</div>
92-
<d-table :table-layout="tableLayout ? 'auto' : 'fixed'" :striped="striped" :header-bg="headerBg" :data="stripedTableData">
100+
<d-table :table-layout="tableLayout ? 'auto' : 'fixed'" :striped="striped" :header-bg="headerBg" :data="stripedTableData" :size="size">
93101
<d-column field="firstName" header="First Name"></d-column>
94102
<d-column field="lastName" header="Last Name"></d-column>
95103
<d-column field="gender" header="Gender"></d-column>
@@ -105,6 +113,21 @@ export default defineComponent({
105113
const tableLayout = ref(false);
106114
const striped = ref(false);
107115
const headerBg = ref(false);
116+
const size = ref('sm');
117+
const sizeList = [
118+
{
119+
label: 'Normal',
120+
value: 'sm',
121+
},
122+
{
123+
label: 'Middle',
124+
value: 'md',
125+
},
126+
{
127+
label: 'large',
128+
value: 'lg',
129+
},
130+
];
108131
const stripedTableData = ref([
109132
{
110133
firstName: 'Mark',
@@ -136,6 +159,8 @@ export default defineComponent({
136159
stripedTableData,
137160
striped,
138161
headerBg,
162+
size,
163+
sizeList,
139164
tableLayout,
140165
};
141166
},
@@ -145,12 +170,12 @@ export default defineComponent({
145170
<style lang="scss">
146171
.table-btn-groups {
147172
display: flex;
148-
margin-bottom: 1rem;
149173
}
150174
.table-btn {
151175
display: flex;
152-
flex-direction: column;
153-
justify-content: space-between;
176+
justify-content: flex-start;
177+
align-items: center;
178+
margin-right: 1rem;
154179
}
155180
</style>
156181
```
@@ -369,21 +394,22 @@ export default defineComponent({
369394

370395
### d-table 参数
371396

372-
| 参数 | 类型 | 默认值 | 说明 |
373-
| :-------------------- | :------------------ | :------ | :------------------------------ |
374-
| data | `Array` | [] | 显示的数据 |
375-
| striped | `Boolean` | false | 是否显示斑马纹间隔 |
376-
| max-width | `String` | -- | 表格最大宽度 |
377-
| max-height | `Boolean` | -- | 表格最大高度 |
378-
| table-width | `String` | -- | 表格宽度 |
379-
| table-height | `String` | -- | 表格高度 |
380-
| row-hovered-highlight | `Boolean` | true | 鼠标在该行上时,高亮该行 |
381-
| fix-header | `Boolean` | false | 固定头部 |
382-
| checkable | `Boolean` | false | 在每行的第一列展示一个 checkbox |
383-
| show-loading | `Boolean` | false | 显示加载动画 |
384-
| header-bg | `Boolean` | false | 头部背景 |
385-
| table-layout | `'fixed' \| 'auto'` | 'fixed' | 表格布局,可选值为'auto' |
386-
| span-method | `SpanMethod` | -- | 合并单元格的计算方法 |
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` | -- | 合并单元格的计算方法 |
387413

388414
### d-column 参数
389415

0 commit comments

Comments
 (0)