Skip to content

Commit

Permalink
feat:TTable新增对齐方式demo及列宽自动适应单元格显示内容demo
Browse files Browse the repository at this point in the history
  • Loading branch information
wocwin committed Aug 8, 2024
1 parent c5792f9 commit 4293f0d
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 8 deletions.
102 changes: 102 additions & 0 deletions docs/.vuepress/components/docsComponents/TTable/align.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<template>
<t-layout-page>
<t-layout-page-item>
<t-table title="对齐方式" :table="table" :align="align" :columns="table.columns">
<template #title>
<el-radio-group v-model="align" size="small" style="margin-bottom: 15px">
<el-radio-button label="left">左对齐</el-radio-button>
<el-radio-button label="center">居中</el-radio-button>
<el-radio-button label="right">右对齐</el-radio-button>
</el-radio-group>
</template>
<template #toolbar>
<el-button size="default" type="danger" @click="setDateLeft">点击{{ setDate }}左对齐</el-button>
<el-button size="default" type="primary" @click="setNameRight">点击{{ setName }}右对齐</el-button>
</template>
</t-table>
</t-layout-page-item>
</t-layout-page>
</template>

<script>
export default {
data() {
return {
align: 'center',
setDate: '设置日期',
setName: '设置姓名',
table: {
data: [
{
id: "1",
date: "2019-09-25",
date1: "2019-09-26",
name: "张三",
status: "2",
address: "广东省广州市天河区"
},
{
id: "2",
date: "2019-09-26",
date1: "2019-09-27",
name: "张三1",
status: "1",
address: "广东省广州市天广东省广州市天河区2广东省广州市天河区2河区2"
},
{
id: "3",
date: "2019-09-26",
date1: "2019-09-28",
name: "张三1",
status: "1",
address: "广东省广州市天广东省广州市天河区2广东省广州市天河区2河区2"
},
{
id: "4",
date: "2019-09-26",
date1: "2019-09-29",
name: "张三1",
status: "1",
address: "广东省广州市天广东省广州市天河区2广东省广州市天河区2河区2"
}
],
columns: [
{ prop: "name", label: "姓名", minWidth: "100", align: "" },
{ prop: "date", label: "日期", minWidth: "180", align: "" },
{ prop: "status", label: "状态", minWidth: "80" },
{ prop: "address", label: "地址", minWidth: "220" }
]
},
}
},
methods: {
setDateLeft() {
this.table.columns.forEach(item => {
if (item.prop === "date") {
if (item.align == "left") {
item.align = ""
this.setDate = "设置日期"
} else {
this.setDate = "取消日期"
item.align = "left"
}
}
})
},
setNameRight() {
this.table.columns.forEach(item => {
if (item.prop === "name") {
if (item.align == "right") {
item.align = ""
this.setName = "设置姓名"
} else {
this.setName = "取消姓名"
item.align = "right"
}
}
})
}
},
}
</script>
48 changes: 48 additions & 0 deletions docs/.vuepress/components/docsComponents/TTable/allShow.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<t-layout-page>
<t-layout-page-item>
<t-table :table="table" :columns="table.columns" />
</t-layout-page-item>
</t-layout-page>
</template>

<script>
export default {
data() {
return {
table: {
data: [
{
id: '1',
date: '2019-09-25',
name: '张三',
status: '2',
address: '广东省广州市天河区'
},
{
id: '2',
date: '2019-09-26',
name: '张三1',
status: '1',
address: '广东省广州市天广东省广州市天河区2广东省广州市天广东省广州市天河区2'
},
{
id: '3',
date: '2019-09-27',
name: '张三2',
status: '3',
address: '广东省广州市天河区3'
}
],
columns: [
{ prop: 'name', label: '姓名', minWidth: '100' },
{ prop: 'date', label: '日期', minWidth: '180' },
{ prop: 'address', label: '设置allShow自动显示列宽', allShow: true },
{ prop: 'date', label: '日期', minWidth: '180' },
]
},
}
}
}
</script>
2 changes: 2 additions & 0 deletions docs/.vuepress/components/docsComponents/TTable/base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
title="此排序仅可点击图标才生效"
:table="table"
:columns="columns"
:header-cell-style="{background: 'red',height: '50px'}"
:row-style="{ height: '52px'}"
size="mini"
:rowClassName="rowClassName"
/>
Expand Down
2 changes: 2 additions & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ module.exports = {
'TTable/pageCheck', // 基本复选--翻页选中
'TTable/firstRadioOrIndex', // 显示单选框和序列号
'TTable/firstSelectionOrIndex', //显示多选框和序列号
'TTable/allShow', //列宽自动适应单元格显示内容
'TTable/align', //对齐方式
'TTable/expand', // 展开行
'TTable/pagination', // 分页
'TTable/virtual', // 虚拟列表
Expand Down
14 changes: 14 additions & 0 deletions docs/baseComponents/TTable/align.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 对齐方式

---

<common-code-format>
<docsComponents-TTable-align slot="source"></docsComponents-TTable-align>
配置

`TTable`组件中添加`align:'center'`设置整个 table 对齐方式

`columns`中设置`align`设置每列对齐方式(`columns优先级`高于`整体的对齐方式`)----`align`可选值`left``center``right`<br/>

<<< @/docs/.vuepress/components/docsComponents/TTable/align.vue
</common-code-format>
11 changes: 11 additions & 0 deletions docs/baseComponents/TTable/allShow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 列宽自动适应单元格显示内容

---

<common-code-format>
<docsComponents-TTable-allShow slot="source"></docsComponents-TTable-allShow>

`columns`中设置`allShow:true`此列会自适应宽度显示单元格内容

<<< @/docs/.vuepress/components/docsComponents/TTable/allShow.vue
</common-code-format>
4 changes: 4 additions & 0 deletions docs/baseComponents/TTable/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
| ---currentPage | 是否需要显示切换页条数 | Number | - |
| columns | 表头信息 | Array | [] |
| ----sort | 排序 (设置:sort:true| Boolean | false |
| ----allShow | 是否开启列宽自动适应单元格显示内容 | Boolean | false |
| ----align | 设置每列对齐方式,此优先级`高于`整体的对齐方式` | string | 'center' |
| ----headerRequired | 是否显示表头必填'\*' | Boolean | false |
| ----renderHeader | 列标题 Label 区域渲染使用的可以用 jsx 方式 | Function | - |
| ----allShow | 自动根据内容撑满列宽(默认取自己设置的minWidth,设置allShow:true,自动根据内容撑满列宽) | Boolean | - |
Expand All @@ -57,6 +59,7 @@
| ----configEdit | 表格编辑配置(开启编辑功能有效) | Object | - |
| ----------rules | 规则(可依据 elementUI el-form 配置————对应 columns 的 prop 值) | Object | - |
| ----------label | placeholder 显示 | String | - |
| ----------className | 每一项的自定义class | String | - |
| ----------editComponent | 组件名称可直接指定全局注册的组件,也可引入第三方组件 | String | input |
| ----------bind | 第三方 UI 的 Attributes及tooltip的Attributes | Object | - |
| ----------eventHandle | 第三方 UI 的 事件(返回两个参数,第一个自己自带,第二个 scope) | Object | - |
Expand Down Expand Up @@ -107,6 +110,7 @@
| rowClassName | 行的 className 的回调方法,也可以使用字符串为所有行设置一个固定的 className。 | Function({row, rowIndex})/String | - |
| isSlotToolbar | TAdaptivePage组件是否使用了Toolbar插槽 | Boolean | - |
| isSlotTitle | TAdaptivePage组件是否使用了title插槽 | Boolean | - |
| align | 整体对齐方式 (选值`left``center``right`) | String | 'center' |

## Methods 方法(继承el-table的所有方法)

Expand Down
8 changes: 6 additions & 2 deletions packages/table/src/TTableColumn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:prop="item.prop"
:label="item.label"
:type="item.type"
:align="item.align || 'center'"
:align="item.align || align"
:fixed="item.fixed"
:min-width="item['min-width'] || item.minWidth || item.width"
>
Expand All @@ -26,7 +26,7 @@
:width="val.allShow ? flexColumnWidth(val.prop,table.data,index,val['min-width'] || val.minWidth || val.width) : val.width"
:sortable="val.sort"
:render-header="val.renderHeader||(val.headerRequired&&renderHeader)"
:align="val.align || 'center'"
:align="val.align || align"
:fixed="val.fixed"
:show-overflow-tooltip="val.noShowTip"
v-bind="{...val.bind,...$attrs}"
Expand Down Expand Up @@ -98,6 +98,10 @@ export default {
default: () => {
return {}
}
},
align: {
type: String,
default: 'center'
}
},
methods: {
Expand Down
18 changes: 12 additions & 6 deletions packages/table/src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
width: table.firstColumn.width || 55,
label: table.firstColumn.label,
fixed: table.firstColumn.fixed,
align: table.firstColumn.align || 'center',
align: table.firstColumn.align || align,
'reserve-selection': table.firstColumn.isPaging || false,
selectable: table.firstColumn.selectable || selectable,
...table.firstColumn.bind,
Expand All @@ -124,7 +124,7 @@
(table.firstColumn.type === 'expand' && '') ||
'',
fixed: table.firstColumn.fixed,
align: table.firstColumn.align || 'center',
align: table.firstColumn.align || align,
...table.firstColumn.bind,
...$attrs,
}"
Expand Down Expand Up @@ -159,7 +159,7 @@
width: item.width || 55,
label: item.label,
fixed: item.fixed,
align: item.align || 'center',
align: item.align || align,
'reserve-selection': item.isPaging || false,
selectable: item.selectable || selectable,
...item.bind,
Expand All @@ -180,7 +180,7 @@
(item.type === 'expand' && '') ||
'',
fixed: item.fixed,
align: item.align || 'center',
align: item.align || align,
...item.bind,
...$attrs,
}"
Expand Down Expand Up @@ -221,7 +221,7 @@
:class-name="item.allShow&&!isEditCell?'flex_column_width':''"
:width="item.allShow&&!isEditCell ? flexColumnWidth(item.prop,table.data,index,item['min-width'] || item.minWidth || item.width) : item.width"
:sortable="item.sort || sortable"
:align="item.align || 'center'"
:align="item.align || align"
:fixed="item.fixed"
:show-overflow-tooltip="isShowOverflowTooltip(item)"
v-bind="{ ...item.bind, ...$attrs }"
Expand Down Expand Up @@ -381,6 +381,7 @@
:key="index + 'i'"
:item="item"
:table="table"
:align="align"
:tableRef="$refs['el-table']"
>
<template v-for="(index, name) in $slots" v-slot:[name]>
Expand All @@ -400,7 +401,7 @@
:min-width="table.operatorConfig && table.operatorConfig.minWidth"
:width="table.operatorConfig && table.operatorConfig.width"
:align="
(table.operatorConfig && table.operatorConfig.align) || 'center'
(table.operatorConfig && table.operatorConfig.align) || align
"
v-bind="{
...(table.operatorConfig && table.operatorConfig.bind),
Expand Down Expand Up @@ -541,6 +542,11 @@ export default {
type: String,
default: '保存'
},
// table 全局对齐方式,可选项'left' | 'center' | 'right'
align: {
type: String,
default: 'center'
},
// 是否开启tree树形结构样式
isShowTreeStyle: Boolean,
// 表格标题
Expand Down

0 comments on commit 4293f0d

Please sign in to comment.