2021-10-09 02:41:52 +00:00
|
|
|
<template>
|
2021-10-13 16:49:27 +00:00
|
|
|
<div id="lay-table">
|
|
|
|
<table class="layui-hide" lay-filter="test" />
|
2021-10-09 02:41:52 +00:00
|
|
|
<div
|
|
|
|
class="layui-form layui-border-box layui-table-view layui-table-view-1"
|
|
|
|
>
|
2021-10-12 03:30:07 +00:00
|
|
|
<div v-if="defaultToolbar || slot.toolbar" class="layui-table-tool">
|
2021-10-10 16:57:32 +00:00
|
|
|
<div class="layui-table-tool-temp">
|
|
|
|
<div class="layui-btn-container">
|
2021-10-12 03:30:07 +00:00
|
|
|
<slot name="toolbar" />
|
2021-10-10 16:57:32 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-12 03:30:07 +00:00
|
|
|
<div v-if="defaultToolbar" class="layui-table-tool-self">
|
2021-10-09 02:41:52 +00:00
|
|
|
<div class="layui-inline" title="筛选列" lay-event="LAYTABLE_COLS">
|
2021-10-12 03:30:07 +00:00
|
|
|
<i class="layui-icon layui-icon-cols" />
|
2021-10-09 02:41:52 +00:00
|
|
|
</div>
|
2021-10-13 16:49:27 +00:00
|
|
|
<div class="layui-inline" title="打印" lay-event="LAYTABLE_PRINT" @click="print()">
|
2021-10-12 03:30:07 +00:00
|
|
|
<i class="layui-icon layui-icon-print" />
|
2021-10-09 02:41:52 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="layui-table-box">
|
|
|
|
<div class="layui-table-header">
|
|
|
|
<table cellspacing="0" cellpadding="0" border="0" class="layui-table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2021-10-12 03:30:07 +00:00
|
|
|
<th v-if="checkbox" class="layui-table-col-special">
|
2021-10-09 21:48:45 +00:00
|
|
|
<div class="layui-table-cell laytable-cell-checkbox">
|
2021-10-11 07:46:44 +00:00
|
|
|
<lay-checkbox
|
2021-10-13 16:12:38 +00:00
|
|
|
v-model:checked="allChecked"
|
2021-10-12 03:30:07 +00:00
|
|
|
skin="primary"
|
2021-10-11 07:46:44 +00:00
|
|
|
label="all"
|
2021-10-13 16:12:38 +00:00
|
|
|
@change="changeAll"
|
2021-10-12 03:30:07 +00:00
|
|
|
/>
|
2021-10-09 02:41:52 +00:00
|
|
|
</div>
|
|
|
|
</th>
|
2021-10-09 21:48:45 +00:00
|
|
|
<th v-for="column in columns" :key="column">
|
|
|
|
<div
|
|
|
|
class="layui-table-cell"
|
|
|
|
:style="{ width: column.width }"
|
|
|
|
>
|
|
|
|
<span>{{ column.title }}</span>
|
2021-10-09 02:41:52 +00:00
|
|
|
</div>
|
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
<div class="layui-table-body layui-table-main">
|
|
|
|
<table cellspacing="0" cellpadding="0" border="0" class="layui-table">
|
|
|
|
<tbody>
|
2021-10-09 21:48:45 +00:00
|
|
|
<template v-for="data in dataSource" :key="data">
|
|
|
|
<tr>
|
2021-10-12 03:30:07 +00:00
|
|
|
<td v-if="checkbox" class="layui-table-col-special">
|
2021-10-09 21:48:45 +00:00
|
|
|
<div class="layui-table-cell laytable-cell-checkbox">
|
2021-10-13 16:12:38 +00:00
|
|
|
<table-item-checkbox
|
2021-10-12 03:30:07 +00:00
|
|
|
skin="primary"
|
2021-10-11 07:46:44 +00:00
|
|
|
:label="data[id]"
|
2021-10-13 16:12:38 +00:00
|
|
|
v-model="tableSelectedKeys"
|
|
|
|
>
|
|
|
|
</table-item-checkbox>
|
2021-10-09 02:41:52 +00:00
|
|
|
</div>
|
2021-10-09 21:48:45 +00:00
|
|
|
</td>
|
2021-10-10 07:22:07 +00:00
|
|
|
<template v-for="column in columns" :key="column">
|
|
|
|
<template v-if="column.customSlot">
|
|
|
|
<td>
|
|
|
|
<div
|
|
|
|
:style="{ width: column.width }"
|
|
|
|
style="padding: 0px 16px"
|
|
|
|
>
|
2021-10-12 03:30:07 +00:00
|
|
|
<slot :name="column.customSlot" :data="data" />
|
2021-10-10 07:22:07 +00:00
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</template>
|
2021-10-10 16:57:32 +00:00
|
|
|
|
2021-10-10 07:22:07 +00:00
|
|
|
<template
|
|
|
|
v-for="(value, key, index) in data"
|
2021-10-12 03:30:07 +00:00
|
|
|
v-else
|
2021-10-10 07:22:07 +00:00
|
|
|
:key="index"
|
|
|
|
>
|
2021-10-09 21:48:45 +00:00
|
|
|
<td v-if="column.key == key">
|
|
|
|
<div
|
|
|
|
:style="{ width: column.width }"
|
|
|
|
style="padding: 0px 16px"
|
|
|
|
>
|
|
|
|
<span v-if="column.slot">
|
2021-10-12 03:30:07 +00:00
|
|
|
<slot :name="column.slot" :data="data" />
|
2021-10-09 21:48:45 +00:00
|
|
|
</span>
|
|
|
|
<span v-else> {{ value }} </span>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
</tr>
|
|
|
|
</template>
|
2021-10-09 02:41:52 +00:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-10 16:44:00 +00:00
|
|
|
<div v-if="page" class="layui-table-page">
|
2021-10-10 16:57:32 +00:00
|
|
|
<lay-page
|
|
|
|
:total="page.total"
|
|
|
|
:limit="page.limit"
|
2021-10-12 03:30:07 +00:00
|
|
|
show-page
|
|
|
|
show-limit
|
|
|
|
show-skip
|
2021-10-10 16:57:32 +00:00
|
|
|
@jump="change"
|
2021-10-12 03:30:07 +00:00
|
|
|
/>
|
2021-10-09 02:41:52 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2021-10-13 16:12:38 +00:00
|
|
|
<script setup name="LayTable"></script>
|
|
|
|
<script setup lang="ts">
|
|
|
|
import tableItemCheckbox from './component/checkbox.vue'
|
2021-10-11 07:46:44 +00:00
|
|
|
import {
|
|
|
|
defineProps,
|
|
|
|
ref,
|
|
|
|
useSlots,
|
|
|
|
watch,
|
|
|
|
withDefaults,
|
|
|
|
defineEmits,
|
|
|
|
} from 'vue'
|
2021-10-12 03:30:07 +00:00
|
|
|
import { Recordable } from '/@src/module/type'
|
2021-10-09 17:07:37 +00:00
|
|
|
|
2021-10-10 22:20:09 +00:00
|
|
|
const props = withDefaults(
|
2021-10-09 17:07:37 +00:00
|
|
|
defineProps<{
|
2021-10-11 07:46:44 +00:00
|
|
|
id?: string
|
2021-10-09 21:48:45 +00:00
|
|
|
skin?: string
|
2021-10-12 03:30:07 +00:00
|
|
|
page?: Recordable
|
|
|
|
checkbox?: boolean
|
|
|
|
columns?: Recordable[]
|
|
|
|
dataSource: Recordable[]
|
|
|
|
defaultToolbar?: boolean
|
|
|
|
selectedKeys: Array<string>
|
2021-10-10 22:20:09 +00:00
|
|
|
}>(),
|
|
|
|
{
|
2021-10-11 07:46:44 +00:00
|
|
|
id: 'id',
|
|
|
|
dataSource: function () {
|
|
|
|
return []
|
|
|
|
},
|
|
|
|
selectedKeys: function () {
|
|
|
|
return []
|
|
|
|
},
|
2021-10-10 22:20:09 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-10-13 16:12:38 +00:00
|
|
|
const emit = defineEmits(['change', 'update:selectedKeys'])
|
2021-10-09 17:07:37 +00:00
|
|
|
|
2021-10-13 16:12:38 +00:00
|
|
|
const slot = useSlots()
|
|
|
|
const slots = slot.default && slot.default()
|
|
|
|
|
|
|
|
const allChecked = ref(false)
|
|
|
|
const tableSelectedKeys = ref([...props.selectedKeys])
|
|
|
|
|
|
|
|
const changeAll = function ({ checked, value }: any) {
|
|
|
|
const ids = props.dataSource.map((item: any) => {
|
|
|
|
return item[props.id]
|
|
|
|
})
|
|
|
|
tableSelectedKeys.value.splice(0, ids.length)
|
|
|
|
if (checked) {
|
|
|
|
ids.forEach((id) => {
|
|
|
|
tableSelectedKeys.value.push(id)
|
2021-10-11 07:46:44 +00:00
|
|
|
})
|
2021-10-13 16:12:38 +00:00
|
|
|
}
|
2021-10-13 16:49:27 +00:00
|
|
|
emit('update:selectedKeys', tableSelectedKeys.value)
|
2021-10-13 16:12:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
watch(
|
|
|
|
tableSelectedKeys,
|
|
|
|
function () {
|
|
|
|
if (tableSelectedKeys.value.length === props.dataSource.length) {
|
|
|
|
allChecked.value = true
|
|
|
|
} else {
|
|
|
|
allChecked.value = false
|
2021-10-12 03:30:07 +00:00
|
|
|
}
|
2021-10-13 16:49:27 +00:00
|
|
|
emit('update:selectedKeys', tableSelectedKeys.value)
|
2021-10-11 07:46:44 +00:00
|
|
|
},
|
|
|
|
{ deep: true }
|
|
|
|
)
|
2021-10-11 06:23:33 +00:00
|
|
|
|
2021-10-10 16:57:32 +00:00
|
|
|
const change = function (page: any) {
|
|
|
|
emit('change', page)
|
2021-10-10 16:44:00 +00:00
|
|
|
}
|
2021-10-13 16:49:27 +00:00
|
|
|
|
|
|
|
const print = function () {
|
|
|
|
let subOutputRankPrint = document.getElementById('lay-table') as HTMLElement
|
|
|
|
let newContent = subOutputRankPrint.innerHTML
|
|
|
|
let oldContent = document.body.innerHTML
|
|
|
|
document.body.innerHTML = newContent
|
|
|
|
window.print()
|
|
|
|
window.location.reload()
|
|
|
|
document.body.innerHTML = oldContent
|
|
|
|
}
|
2021-10-12 03:30:07 +00:00
|
|
|
</script>
|