feat(table): 新增 id 与 selectedKeys, checkbox 属性, 待完善多选框逻辑

This commit is contained in:
就眠仪式 2021-10-11 06:20:09 +08:00
parent e433135913
commit e72455f61d
2 changed files with 35 additions and 32 deletions

View File

@ -126,7 +126,8 @@ export default {
::: demo ::: demo
<template> <template>
<lay-table :columns="columns" :dataSource="dataSource" default-toolbar="true"> {{selectedKeys}}
<lay-table :columns="columns" id="id" :dataSource="dataSource" default-toolbar="true" :selectedKeys="selectedKeys" checkbox="true">
<template v-slot:toolbar> <template v-slot:toolbar>
<lay-button>新增</lay-button> <lay-button>新增</lay-button>
<lay-button>删除</lay-button> <lay-button>删除</lay-button>
@ -146,6 +147,8 @@ import { ref } from 'vue'
export default { export default {
setup() { setup() {
const selectedKeys = ref(['1'])
const columns = [ const columns = [
{ {
title:"账户", title:"账户",
@ -170,16 +173,26 @@ export default {
] ]
const dataSource = [ const dataSource = [
{username:"root", password:"root", age:"18"}, {id:"1", username:"root", password:"root", age:"18"},
{username:"woow", password:"woow", age:"20"} {id:"2", username:"woow", password:"woow", age:"20"}
] ]
return { return {
columns, columns,
dataSource dataSource,
selectedKeys,
} }
} }
} }
</script> </script>
::: :::
| | | |
|--|--|--|
| columns | 列配置 | -- |
| dataSource | 数据源 | -- |
| checkbox | 开启复现框 | -- |
| id | 主键 | -- |
| selectKeys | 选中项 | -- |
| default-toolbar | 开启工具栏 | -- |

View File

@ -27,19 +27,9 @@
<table cellspacing="0" cellpadding="0" border="0" class="layui-table"> <table cellspacing="0" cellpadding="0" border="0" class="layui-table">
<thead> <thead>
<tr> <tr>
<th class="layui-table-col-special"> <th class="layui-table-col-special" v-if="checkbox">
<div class="layui-table-cell laytable-cell-checkbox"> <div class="layui-table-cell laytable-cell-checkbox">
<input <lay-checkbox skin="primary" v-model="tableSelectedKeys" label="all"></lay-checkbox>
type="checkbox"
name="layTableCheckbox"
lay-skin="primary"
/>
<div
class="layui-unselect layui-form-checkbox"
lay-skin="primary"
>
<i class="layui-icon layui-icon-ok"></i>
</div>
</div> </div>
</th> </th>
<th v-for="column in columns" :key="column"> <th v-for="column in columns" :key="column">
@ -59,19 +49,9 @@
<tbody> <tbody>
<template v-for="data in dataSource" :key="data"> <template v-for="data in dataSource" :key="data">
<tr> <tr>
<td class="layui-table-col-special"> <td class="layui-table-col-special" v-if="checkbox">
<div class="layui-table-cell laytable-cell-checkbox"> <div class="layui-table-cell laytable-cell-checkbox">
<input <lay-checkbox skin="primary" v-model="tableSelectedKeys" :label="data[id]"></lay-checkbox>
type="checkbox"
name="layTableCheckbox"
lay-skin="primary"
/>
<div
class="layui-unselect layui-form-checkbox"
lay-skin="primary"
>
<i class="layui-icon layui-icon-ok"></i>
</div>
</div> </div>
</td> </td>
@ -125,16 +105,26 @@
</div> </div>
</template> </template>
<script setup name="LayTable" lang="ts"> <script setup name="LayTable" lang="ts">
import { defineProps, useSlots } from 'vue' import { defineProps, ref, useSlots, watch, withDefaults, defineEmits } from 'vue'
const props = const props = withDefaults(
defineProps<{ defineProps<{
columns?: Object[] columns?: Object[]
dataSource?: Object[] dataSource?: Object[]
skin?: string skin?: string
page?: Object page?: Object
defaultToolbar?: Boolean defaultToolbar?: Boolean
}>() checkbox?: Boolean
id?: string,
selectedKeys: Array<String>
}>(),
{
id: "id",
selectedKeys: function() { return [] }
}
)
const tableSelectedKeys = ref(props.selectedKeys)
const emit = defineEmits(['change']) const emit = defineEmits(['change'])