perf(table): 新增 size 配置, 支持不同尺寸

This commit is contained in:
就眠仪式 2021-10-20 14:07:03 +08:00
parent e04b53988a
commit ba6de34bdb
5 changed files with 103 additions and 21 deletions

View File

@ -68,6 +68,6 @@ export default {
::: field 容器属性 ::: field 容器属性
::: :::
| Name | Description | Accepted Values | | Name | Description | Accepted Values |
| ----- | ------ | -------------- | | ----- | ------ | -------------- |
| fluid | 流模式 | `true` `false` | | fluid | 流模式 | `true` `false` |

View File

@ -1,3 +1,6 @@
::: field 基础使用
:::
::: demo ::: demo
<template> <template>
@ -55,6 +58,69 @@ export default {
::: :::
::: field 不同尺寸
:::
::: demo
<template>
<lay-table :columns="columns" :dataSource="dataSource" size="lg">
<template v-slot:username="{ data }"> {{data.username}} </template>
<template v-slot:password="{ data }"> {{data.password}} </template>
<template v-slot:operator="{ data }">
<lay-button >修改</lay-button>
<lay-button type="primary">删除</lay-button>
</template>
</lay-table>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const columns = [
{
title:"账户",
width:"200px",
slot:"username",
key:"username"
},{
title:"密码",
width: "180px",
slot:"password",
key:"password"
},{
title:"年龄",
width: "180px",
key:"age"
},{
title:"操作",
width: "180px",
customSlot:"operator",
key:"operator"
}
]
const dataSource = [
{username:"root", password:"root", age:"18"},
{username:"woow", password:"woow", age:"20"}
]
return {
columns,
dataSource
}
}
}
</script>
:::
::: field 开启分页
:::
::: demo ::: demo
<template> <template>
@ -123,6 +189,9 @@ export default {
::: :::
::: field 完整表格
:::
::: demo ::: demo
<template> <template>
@ -202,7 +271,8 @@ export default {
| checkbox | 开启复现框 | -- | | checkbox | 开启复现框 | -- |
| id | 主键 | -- | | id | 主键 | -- |
| selectedKeys ( v-model ) | 选中项 | -- | | selectedKeys ( v-model ) | 选中项 | -- |
| default-toolbar | 开启工具栏 | -- | | default-toolbar | 开启工具栏 | `lg` `md` `sm` |
| size | 尺寸 | -- |
::: field table slots ::: field table slots

View File

@ -15,19 +15,20 @@
<script setup name="LayCollapseItem" lang="ts"> <script setup name="LayCollapseItem" lang="ts">
import { defineProps, inject, ref } from 'vue' import { defineProps, inject, ref } from 'vue'
const props = defineProps<{ const props =
id: string defineProps<{
title: string id: string
}>() title: string
}>()
const openKeys = inject("openKeys") as String[] const openKeys = inject('openKeys') as String[]
const isShow = ref(openKeys.includes(props.id)) const isShow = ref(openKeys.includes(props.id))
const showHandle = function () { const showHandle = function () {
isShow.value = !isShow.value isShow.value = !isShow.value
if(openKeys.indexOf(props.id) != -1) { if (openKeys.indexOf(props.id) != -1) {
openKeys.splice(openKeys.indexOf(props.id),1) openKeys.splice(openKeys.indexOf(props.id), 1)
} else { } else {
openKeys.push(props.id) openKeys.push(props.id)
} }

View File

@ -21,7 +21,7 @@
</div> </div>
<div class="layui-table-box"> <div class="layui-table-box">
<div class="layui-table-header"> <div class="layui-table-header">
<table cellspacing="0" cellpadding="0" border="0" class="layui-table" lay-size="sm"> <table class="layui-table" :lay-size="size">
<thead> <thead>
<tr> <tr>
<th v-if="checkbox" class="layui-table-col-special"> <th v-if="checkbox" class="layui-table-col-special">
@ -47,7 +47,7 @@
</table> </table>
</div> </div>
<div class="layui-table-body layui-table-main"> <div class="layui-table-body layui-table-main">
<table cellspacing="0" cellpadding="0" border="0" class="layui-table" lay-size="sm"> <table class="layui-table" :lay-size="size">
<tbody> <tbody>
<template v-for="data in dataSource" :key="data"> <template v-for="data in dataSource" :key="data">
<tr> <tr>
@ -64,9 +64,7 @@
<template v-for="column in columns" :key="column"> <template v-for="column in columns" :key="column">
<template v-if="column.customSlot"> <template v-if="column.customSlot">
<td class="layui-table-cell"> <td class="layui-table-cell">
<div <div :style="{ width: column.width }">
:style="{ width: column.width }"
>
<slot :name="column.customSlot" :data="data" /> <slot :name="column.customSlot" :data="data" />
</div> </div>
</td> </td>
@ -78,9 +76,7 @@
:key="index" :key="index"
> >
<td class="layui-table-cell" v-if="column.key == key"> <td class="layui-table-cell" v-if="column.key == key">
<div <div :style="{ width: column.width }">
:style="{ width: column.width }"
>
<span v-if="column.slot"> <span v-if="column.slot">
<slot :name="column.slot" :data="data" /> <slot :name="column.slot" :data="data" />
</span> </span>
@ -103,12 +99,25 @@
show-limit show-limit
show-skip show-skip
@jump="change" @jump="change"
/> >
<template v-slot:prev
><lay-icon type="layui-icon-left"></lay-icon
></template>
<template v-slot:next
><lay-icon type="layui-icon-right"></lay-icon
></template>
</lay-page>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script setup name="LayTable"></script>
<script lang="ts">
export default {
name: 'LayTable',
}
</script>
<script setup lang="ts"> <script setup lang="ts">
import tableItemCheckbox from './component/checkbox.vue' import tableItemCheckbox from './component/checkbox.vue'
import { import {
@ -125,6 +134,7 @@ const props = withDefaults(
defineProps<{ defineProps<{
id?: string id?: string
skin?: string skin?: string
size?: string
page?: Recordable page?: Recordable
checkbox?: boolean checkbox?: boolean
columns?: Recordable[] columns?: Recordable[]
@ -139,7 +149,8 @@ const props = withDefaults(
}, },
selectedKeys: function () { selectedKeys: function () {
return [] return []
} },
size: 'md',
} }
) )