Skip to content

Commit

Permalink
feat[docs]:新增TTable组件文档示例(表尾合计,表格大小等)
Browse files Browse the repository at this point in the history
  • Loading branch information
wocwin committed Jul 5, 2024
1 parent cbf10d9 commit 65525e4
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 23 deletions.
1 change: 0 additions & 1 deletion docs/components/TSelectTable/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ TSelectTable/isShowInput
| ---currentPage | 当前页数 | Number | - |
| columns | 表头信息 | Array | [] |
| ----bind | el-table-column Attributes | Object | - |
| ----noShowTip | 是否换行 (设置:noShowTip:true| Boolean | false |
| ----fixed | 列是否固定( left, right) | string, boolean | - |
| ----align | 对齐方式(left/center/right) | String | center |
| ----render | 返回三个参数(text:当前值,row:当前整条数据 ,index:当前行) | function | - |
Expand Down
31 changes: 28 additions & 3 deletions docs/components/TTable/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,45 @@
TTable/base
:::

### 斑马线表格
:::demo 在`t-table`标签中添加`stripe`
TTable/stripe
:::


### 边框表格

:::demo 在`table`对象中添加`border:true`
:::demo 在`table`标签中添加`border:true`
TTable/border
:::

### 表格大小
:::demo 在`table`标签中添加`size:'small'`设置表格大小,可选值`large``default``small`
TTable/size
:::

:::demo 在`TTable`组件中添加`align:'center'`设置整个 table 对齐方式,在`columns`中设置`align`设置每列对齐方式(`columns优先级`高于`整体的对齐方式`)----`align`可选值`left``center``right`
TTable/align
:::

### 对齐方式

:::demo 在`TTable`组件中添加`align:'center'`设置整个 table 对齐方式,在`columns`中设置`align`设置每列对齐方式(`columns优先级`高于`整体的对齐方式`)----`align`可选值`left``center``right`
TTable/align
:::

### 基本表尾合计

:::demo 在`TTable`标签中添加`show-summary`,默认情况下,对于合计行,第一列不进行数据求合操作,而是显示「合计」二字(可通过sum-text配置),其余列会将本列所有`数值`(不区分`Number``String`类型)进行求合操作,并显示出来。
TTable/showSummary
:::

### 自定义表尾合计

:::demo 在`TTable`标签中添加`show-summary`,自定义合计逻辑:使用 `summary-method` 并传入一个方法,返回一个数组,这个数组中的各项就会显示在合计行的各列中,可以是一个 VNode 或 String。
TTable/summaryMethod
:::

### 复选框表格

:::demo 在`table`对象中添加`firstColumn:{ type: 'selection', fixed: true }`
Expand Down Expand Up @@ -261,7 +288,6 @@ TTable/expand
| ----bind | el-table-column Attributes | Object | - |
| ----width | 对应列的宽度(固定的) | string / number | - |
| ----minWidth | 对应列的最小宽度(会把剩余宽度按比例分配给设置了 min-width 的列) | string / number | - |
| ----noShowTip | 是否换行 (设置:noShowTip:false 换行,不设置自动隐藏) | Boolean | - |
| ----slotName | 插槽显示此列数据(其值是具名作用域插槽 | String | - |
| ----isShowHidden | 是否动态显示隐藏列设置(隐藏/显示列) | Boolean | false |
| ----slotNameMerge | 合并表头插槽显示此列数据(其值是具名作用域插槽) | String | - |
Expand Down Expand Up @@ -292,7 +318,6 @@ TTable/expand
| tableTitle | 表格左上标题(为解决顶层容器会出现原生的 title 属性)同时存在优先展示插槽 | String /slot | - |
| isShowPagination | 是否显示分页(默认显示分页) | Boolean | true |
| isPaginationCumulative | 序列号显示是否分页累加 | Boolean | false |
| isTableColumnHidden | 是否开启合计行隐藏复选框/单选框 | Boolean | false |
| isCopy | 是否允许双击单元格复制 | Boolean | false |
| defaultRadioCol | 设置默认选中项(单选)defaultRadioCol 值必须大于 0! | Number | - |
| rowClickRadio | 是否开启点击整行选中单选框 | Boolean | true |
Expand Down
11 changes: 6 additions & 5 deletions docs/examples/TTable/multileHead.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ let table = ref({
prop: "address",
label: "地址换行",
minWidth: "180",
noShowTip: false
bind: {
"show-overflow-tooltip": false
}
}
]
}
Expand Down Expand Up @@ -133,7 +135,7 @@ let table = ref({
label: "表头合并2",
minWidth: "180",
children: [
{ prop: "address", label: "地址22", minWidth: "160", noShowTip: false },
{ prop: "address", label: "地址22", minWidth: "160" },
{
prop: "date",
label: "日期",
Expand All @@ -142,9 +144,8 @@ let table = ref({
}
]
},
{ prop: "address", label: "地址", minWidth: "220", noShowTip: false },
{ prop: "date1", label: "日期", minWidth: "180" },
{ prop: "address1", label: "地址", minWidth: "220" }
{ prop: "address", label: "地址", minWidth: "220" },
{ prop: "date1", label: "日期", minWidth: "180" }
]
})
</script>
6 changes: 6 additions & 0 deletions docs/examples/TTable/pageCheck.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ const table = ref({
{ prop: "shortRuleMore", label: "改余", minWidth: 120 },
{ prop: "shortRuleLess", label: "改损", minWidth: 120 },
{ prop: "materialSourceLabel", label: "数据来源", minWidth: "100" },
{ prop: "materialPropertyLabel1", label: "物料属性1", minWidth: 120 },
{ prop: "baseUnit1", label: "基本单位1", minWidth: 120 },
{ prop: "singleWeight1", label: "单重1", minWidth: 120 },
{ prop: "shortRuleMore1", label: "改余1", minWidth: 120 },
{ prop: "shortRuleLess1", label: "改损1", minWidth: 120 },
{ prop: "materialSourceLabel1", label: "数据来源1", minWidth: "100" },
{ prop: "updateTime", label: "最后更新日期", minWidth: 220 },
{ prop: "updateBy", label: "最后更新人", minWidth: 160 }
]
Expand Down
1 change: 0 additions & 1 deletion docs/examples/TTable/render.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ const table = ref({
return <span style="color:red">render for循环渲染</span>
},
minWidth: "180",
noShowTip: false,
render: (text, record) => {
return (
<div>
Expand Down
53 changes: 40 additions & 13 deletions docs/examples/TTable/selectionIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,21 @@
:columns="state.table.columns"
@selection-change="selectionChange"
:isShowPagination="false"
show-summary
:summary-method="getSummaries"
>
<template #toolbar>
<el-button
size="default"
type="danger"
@click="toggleSelection([state.table.data[1], state.table.data[2]])"
<el-button size="default" type="danger" @click="toggleSelection([state.table.data[1], state.table.data[2]])"
>点击选中第二第三项</el-button
>
<el-button
size="default"
type="primary"
:disabled="state.ids.length < 1"
@click="cancelSelect"
>取消选中</el-button
>
<el-button size="default" type="primary" :disabled="state.ids.length < 1" @click="cancelSelect">取消选中</el-button>
</template>
</t-table>
</t-layout-page-item>
</t-layout-page>
</template>

<script setup lang="ts">
<script setup lang="tsx">
import { ref, reactive } from "vue"
// 获取ref
const selectionTable: any = ref<HTMLElement | null>(null)
Expand All @@ -54,6 +47,7 @@ let state = reactive({
date1: "2019-09-26",
name: "张三",
status: "2",
num: 1,
address: "广东省广州市天河区"
},
{
Expand All @@ -62,6 +56,7 @@ let state = reactive({
date1: "2019-09-27",
name: "张三1",
status: "1",
num: 2,
address: "广东省广州市天广东省广州市天河区2广东省广州市天河区2河区2"
},
{
Expand All @@ -70,6 +65,7 @@ let state = reactive({
date1: "2019-09-28",
name: "张三1",
status: "1",
num: 3,
address: "广东省广州市天广东省广州市天河区2广东省广州市天河区2河区2"
},
{
Expand All @@ -78,18 +74,49 @@ let state = reactive({
date1: "2019-09-29",
name: "张三1",
status: "1",
num: 4,
address: "广东省广州市天广东省广州市天河区2广东省广州市天河区2河区2"
}
],
// 表头数据
columns: [
{ prop: "name", label: "姓名", minWidth: "100" },
{ prop: "date", label: "日期", minWidth: "180" },
{ prop: "status", label: "状态", minWidth: "80" },
{
prop: "status",
label: "状态",
minWidth: "80"
},
{ prop: "num", label: "数量", minWidth: "80" },
{ prop: "address", label: "地址", minWidth: "220" }
]
}
})
const getSummaries = (param: any) => {
const { columns, data } = param
const sums: any = []
columns.forEach((column: any, index: number) => {
if (index === 0) {
sums[index] = "合计"
return
}
const values = data.map((item: any) => Number(item[column.property === "num" ? column.property : ""]))
if (!values.every((value: any) => isNaN(value))) {
sums[index] = values.reduce((prev: any, curr: any) => {
const value = Number(curr)
if (!isNaN(value)) {
return prev + curr
} else {
return prev
}
}, 0)
sums[index] += ""
} else {
sums[index] = ""
}
})
return sums
}
// 选择复选框
const selectionChange = (val: any) => {
console.log("选择复选框", val)
Expand Down
66 changes: 66 additions & 0 deletions docs/examples/TTable/showSummary.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<template>
<t-layout-page>
<t-layout-page-item>
<t-table
title="表尾合计行"
sum-text="当页合计"
:table="table"
:columns="table.columns"
:isShowPagination="false"
show-summary
/>
</t-layout-page-item>
</t-layout-page>
</template>

<script setup lang="tsx">
import { ref } from "vue"
const table = ref({
data: [
{
id: "1",
date: "2019-09-25",
date1: "2019-09-26",
name: "张三",
status: "2",
num: 1,
address: "广东省广州市天河区"
},
{
id: "2",
date: "2019-09-26",
date1: "2019-09-27",
name: "张三1",
status: "1",
num: 2,
address: "广东省广州市天广东省广州市天河区2广东省广州市天河区2河区2"
},
{
id: "3",
date: "2019-09-26",
date1: "2019-09-28",
name: "张三1",
status: "1",
num: 3,
address: "广东省广州市天广东省广州市天河区2广东省广州市天河区2河区2"
},
{
id: "4",
date: "2019-09-26",
date1: "2019-09-29",
name: "张三1",
status: "1",
num: 4,
address: "广东省广州市天广东省广州市天河区2广东省广州市天河区2河区2"
}
],
// 表头数据
columns: [
{ prop: "name", label: "姓名", minWidth: "100" },
{ prop: "date", label: "日期", minWidth: "180" },
{ prop: "status", label: "状态", minWidth: "80" },
{ prop: "num", label: "数量", minWidth: "80" },
{ prop: "address", label: "地址", minWidth: "220" }
]
})
</script>
68 changes: 68 additions & 0 deletions docs/examples/TTable/size.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<template>
<t-layout-page>
<t-layout-page-item>
<el-radio-group v-model="size" size="small" style="margin-bottom: 15px">
<el-radio-button value="">默认</el-radio-button>
<el-radio-button value="large">Large</el-radio-button>
<el-radio-button value="default">Default</el-radio-button>
<el-radio-button value="small">Small</el-radio-button>
</el-radio-group>
<t-table
title="表格大小"
:table="table"
:size="size"
:columns="table.columns"
:isShowPagination="false"
/>
</t-layout-page-item>
</t-layout-page>
</template>

<script setup lang="ts">
import { ref } from "vue"
const size = ref("")
const table = ref({
border: true,
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" },
{ prop: "date", label: "日期", minWidth: "180" },
{ prop: "status", label: "状态", minWidth: "80" },
{ prop: "address", label: "地址", minWidth: "220" }
]
})
</script>
Loading

0 comments on commit 65525e4

Please sign in to comment.