| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- const n = `<template>
- <div class="s-list-basic-layout" ref="layoutRef">
- <a-spin :spinning="spinning">
- <div class="s-list-basic-layout-main">
- <div class="s-list-basic-content" v-if="!$slots.empty">
- <div class="filter-wrap" ref="filtersRef">
- <div class="filter-content" v-if="$slots.filter">
- <div class="filter">
- <slot name="filter" />
- </div>
- <a class="filter-more-btn" v-if="$slots.filterMore" @click="toggleFilter">
- {{ !isMoreFilter ? $l('更多筛选') : $l('收起筛选') }}
- <double-right-outlined
- style="font-size: 12px; transform: rotate(90deg)"
- v-if="!isMoreFilter"
- />
- <double-right-outlined style="font-size: 12px; transform: rotate(-90deg)" v-else />
- </a>
- <div class="reset-wrap" v-if="$slots.filter">
- <a-tooltip
- placement="top"
- :overlayStyle="{ maxWidth: '500px' }"
- :mouseEnterDelay="1.5"
- :mouseLeaveDelay="0.5"
- >
- <template #title>
- <span>{{ $l('条件重置') }}</span>
- </template>
- <a-button style="padding-bottom: 2px" @click="filterReset">
- <template #icon>
- <sync-outlined />
- </template>
- </a-button>
- </a-tooltip>
- </div>
- </div>
- <div class="filter-more-content" v-if="$slots.filterMore" v-show="isMoreFilter">
- <slot name="filterMore" />
- </div>
- <div class="desc-wrap" v-if="$slots.desc">
- <slot name="desc" />
- </div>
- </div>
- <div class="table-content">
- <div class="tabs-wrap" v-if="$slots.tabs" ref="tabsRef">
- <slot name="tabs" />
- </div>
- <div class="table-container">
- <s-table
- ref="table"
- size="middle"
- :scroll="{ y: tableScrollPx, x: '100%' }"
- :pageSize="pageSize"
- :rowKey="rowKey"
- :columns="renderColumns"
- :data="loadData"
- v-model:expanded-row-keys="expandedRowKeys"
- :rowSelection="
- showSelection || isSelection
- ? { selectedRowKeys: selectedRowKeys, onChange: onSelectChange }
- : null
- "
- :showPagination="showPagination"
- >
- <!-- 自定义单元格:template 渲染同名插槽、isClick 渲染可点击、action 渲染操作列 -->
- <template #bodyCell="scope">
- <template v-if="scope.column">
- <slot
- v-if="isTemplateColumn(scope.column.dataIndex)"
- :name="scope.column.dataIndex"
- :text="scope.text"
- :record="scope.record"
- :index="scope.index"
- :item="getColumn(scope.column.dataIndex)"
- />
- <a
- v-else-if="isClickColumn(scope.column.dataIndex)"
- @click="tableColCallback(scope.column.dataIndex, scope.record)"
- >{{ getCellText(scope.text) }}</a
- >
- <slot
- v-else-if="scope.column.dataIndex === 'action'"
- name="action"
- :record="scope.record"
- />
- </template>
- </template>
- </s-table>
- </div>
- </div>
- </div>
- <div class="s-list-basic-content" v-else>
- <slot name="empty" />
- </div>
- </div>
- <div class="other">
- <slot name="other" />
- </div>
- </a-spin>
- </div>
- </template>
- <script setup>
- import { nextTick, onActivated, onMounted, ref, watch } from 'vue'
- defineOptions({ name: 'SListBasicLayout' })
- const props = defineProps({
- // 列表 checkbox 列
- isSelection: {
- type: Boolean,
- default: false
- },
- // 是否显示分页
- showPagination: {
- type: Boolean,
- default: true
- },
- // 表格列配置
- columns: {
- type: Array,
- default: () => []
- },
- // 行主键字段名
- rowKey: {
- type: [Function, String],
- default: 'id'
- },
- // 取数函数,返回 { list, total }
- loadData: {
- type: Function,
- required: true
- },
- // 每页条数
- pSize: {
- type: [String, Number],
- default: 10
- },
- // 初始勾选的表格行 key
- selectedRowKeysArr: {
- type: Array,
- default: () => []
- }
- })
- const emit = defineEmits(['reset', 'tableColCallback'])
- // ---------- 模板 ref ----------
- const layoutRef = ref(null)
- const filtersRef = ref(null)
- const tabsRef = ref(null)
- const table = ref(null)
- // ---------- 状态 ----------
- const isMoreFilter = ref(false)
- // 表体滚动高度:仅作为 scroll.y 同步值(初值兜底),布局高度完全由 CSS flex 决定
- const tableScrollPx = ref(300)
- const spinning = ref(false)
- const pageSize = ref(10)
- const showSelection = ref(false)
- const selectedRowKeys = ref([])
- const expandedRowKeys = ref([])
- const renderColumns = ref([])
- // ---------- watch ----------
- watch(
- () => props.columns,
- () => initComponent()
- )
- watch(
- () => props.selectedRowKeysArr,
- (v) => {
- selectedRowKeys.value = v || []
- },
- { immediate: true }
- )
- // ---------- 方法 ----------
- function initTable() {
- pageSize.value = props.pSize
- renderColumns.value = props.columns.map((i) => {
- if (
- (i.template || i.isClick || (i.dataIndex === 'action' && !i.customRender)) &&
- !i.scopedSlots
- ) {
- i.scopedSlots = { customRender: i.dataIndex }
- }
- return i
- })
- nextTick(syncTableHeight)
- }
- function initComponent() {
- initTable()
- }
- function toggleFilter() {
- isMoreFilter.value = !isMoreFilter.value
- nextTick(syncTableHeight)
- }
- // 查询条件重置
- function filterReset() {
- emit('reset')
- }
- function reload() {
- table.value && table.value.refresh(true)
- }
- // 表格可点击列事件回调
- function tableColCallback(field, item) {
- emit('tableColCallback', field, item)
- }
- function onSelectChange(keys) {
- selectedRowKeys.value = keys
- }
- // 按 dataIndex 取列配置
- function getColumn(dataIndex) {
- return renderColumns.value.find((i) => i.dataIndex === dataIndex)
- }
- // 该列是否使用自定义插槽(列 dataIndex 即插槽名)
- function isTemplateColumn(dataIndex) {
- const col = getColumn(dataIndex)
- return !!(col && col.template)
- }
- // 该列是否为可点击列
- function isClickColumn(dataIndex) {
- const col = getColumn(dataIndex)
- return !!(col && col.isClick)
- }
- // 可点击列显示文本:对象取 name,其它原样
- function getCellText(text) {
- if (text === null || text === undefined) return ''
- if (typeof text === 'object') return text.name === undefined ? '' : text.name
- return text
- }
- // 布局高度全部交给 CSS flex,这里只把撑出来的真实表体高度同步给 scroll.y(antd 靠它启用固定表头)
- function syncTableHeight() {
- const el = table.value && table.value.$el
- const bodyEl = el && el.querySelector('.ant-table-body')
- const h = bodyEl && bodyEl.clientHeight
- if (h) tableScrollPx.value = Math.max(h - 8, 0)
- }
- // ---------- 生命周期 ----------
- onMounted(() => {
- initComponent()
- })
- // keep-alive 切回来时 DOM 重新可见,下一帧补同步一次
- onActivated(() => {
- nextTick(syncTableHeight)
- })
- defineExpose({
- reload,
- table,
- spinning,
- selectedRowKeys,
- filterReset,
- toggleFilter
- })
- <\/script>
- <style lang="less" scoped>
- // 高度实现:纯 CSS flex,零 JS 测量。
- // 根撑满父容器 → 主区吃剩余 → 内容区竖排 → 表格链条逐层贯通到表体。
- // 前提:父容器有确定高度(基座 BasicLayout 的 router-view 已带 height)。
- .s-list-basic-layout {
- height: 100%;
- min-height: 0;
- display: flex;
- flex-direction: column;
- overflow: hidden;
- }
- // 根节点外还包了一层 a-spin,需要把剩余高度透传下去
- .s-list-basic-layout > :deep(.ant-spin-nested-loading),
- .s-list-basic-layout > :deep(.ant-spin-container) {
- flex: 1 1 auto;
- min-height: 0;
- display: flex;
- flex-direction: column;
- }
- .s-list-basic-layout-main {
- flex: 1 1 auto;
- min-height: 0;
- display: flex;
- justify-content: flex-start;
- // stretch 让内容栏撑满主区高度;flex-start 会让它退回内容高度
- align-items: stretch;
- border-radius: 6px;
- background-color: var(--s-bg-color-container);
- overflow: hidden;
- }
- .s-list-basic-content {
- flex: 1 1 auto;
- min-width: 0;
- min-height: 0;
- padding: 24px;
- overflow: hidden;
- box-sizing: border-box;
- display: flex;
- flex-direction: column;
- }
- // 表格区吃掉内容区剩余高度;与 SListLayout 同一套撑满链路
- .table-content {
- flex: 1 1 auto;
- min-width: 0;
- min-height: 0;
- width: 100%;
- display: flex;
- flex-direction: column;
- }
- .table-container {
- flex: 1 1 auto;
- min-width: 0;
- min-height: 0;
- display: flex;
- flex-direction: column;
- overflow: hidden;
- // STable 自带的 .table-wrapper 不能漏,漏了整条链断掉、表体撑不开
- :deep(.table-wrapper),
- :deep(.ant-table-wrapper),
- :deep(.ant-spin-nested-loading),
- :deep(.ant-spin-container),
- :deep(.ant-table),
- :deep(.ant-table-container) {
- flex: 1 1 auto;
- min-height: 0;
- display: flex;
- flex-direction: column;
- }
- :deep(.ant-table-header) {
- flex: 0 0 auto;
- }
- :deep(.ant-table-body) {
- flex: 1 1 auto;
- min-height: 0;
- // antd 把 scroll.y 写成 inline max-height,会卡住 flex 撑出来的高度
- max-height: none !important;
- }
- :deep(.ant-table-pagination.ant-pagination) {
- flex: 0 0 auto;
- margin: 0;
- padding: 16px 0;
- border-top: 1px solid var(--s-border-color-split);
- box-sizing: border-box;
- }
- }
- .filter-wrap {
- flex: 0 0 auto;
- padding: 0 0 24px;
- box-sizing: border-box;
- .filter-content {
- height: 32px;
- display: flex;
- justify-content: flex-start;
- align-items: center;
- }
- }
- .filter-more-content {
- margin-top: 16px;
- }
- .desc-wrap {
- padding: 16px 0 0;
- box-sizing: border-box;
- }
- .reset-wrap {
- flex: 1;
- margin-left: 24px;
- text-align: right;
- }
- </style>
- `;
- export {
- n as default
- };
|