Skip to content

Commit

Permalink
refactor(Column): 重构ProTable,支持多级表头,优化高级查询表单样式 @0.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoooooo committed Mar 20, 2021
1 parent 88210a9 commit 9c306a6
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 306 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "element-pro-crud",
"version": "0.9.1-13",
"version": "0.9.2",
"author": "BoBo<[email protected]>",
"main": "lib/ProCrud.umd.min.js",
"files": [
Expand Down
33 changes: 0 additions & 33 deletions src/component/crud-table/src/CrudTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -639,38 +639,5 @@ export default defineComponent({
padding: 10px;
position: relative;
width: 100%;
h4 {
margin: 2px 30px 0px 0px;
padding-left: 15px;
font-weight: 500;
font-size: 18px;
}
.table-title {
float: left;
margin-left: 5px;
}
.table-title-absolute {
position: absolute;
top: 110px;
left: 10px;
}
.btn-bar {
float: right;
width: auto;
text-align: right;
& > div,
button {
float: right;
margin-left: 10px;
}
}
.dev-module {
display: inline-block;
margin-left: 20px;
line-height: 28px;
button {
padding: 0;
}
}
}
</style>
82 changes: 82 additions & 0 deletions src/component/pro-table/src/Column.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!--
* @file: 表格列单独封装,便于支持多级表头配置
* @author: BoBo
* @copyright: BoBo
* @Date: 2021-03-19 16:50:00
-->

<template>
<el-table-column
:column-key="column.columnKey"
:prop="column.prop"
:label="column.label"
:width="column.minWidth ? '-' : column.width || 140"
:min-width="column.minWidth || column.width || 140"
:fixed="column.fixed"
:render-header="column.renderHeader"
:sortable="column.sortable == 'false' ? false : column.sortable"
:sort-by="column.sortBy"
:sort-method="column.method"
:resizable="column.resizable"
:formatter="column.formatter"
:show-overflow-tooltip="column.showOverflowTooltip"
:align="column.align"
:header-align="column.headerAlign || column.align"
:class-name="column.className"
:label-class-name="column.labelClassName"
:selectable="column.selectable"
:reserve-selection="column.reserveSelection"
:filters="column.filters"
:filter-placement="column.filterPlacement"
:filter-multiple="column.filterMultiple"
:filter-method="column.filterMethod"
:filtered-value="column.filteredValue"
>
<!-- 操作列表头插槽 -->
<template slot="header" slot-scope="scope">
<slot v-if="$scopedSlots[`${column.prop}_header`]" :name="`${column.prop}_header`" :column="scope.column"></slot>
<span v-else>
{{ column.label }}
</span>
</template>
<!-- 插槽情况 -->
<template slot-scope="scope">
<!-- 自定义插槽 -->
<span v-if="column.slotName">
<slot :name="column.slotName" :row="scope.row" :prop="column.prop" :$index="scope.$index" />
</span>
<span v-else>
{{ scope.row[column.prop] }}
</span>
</template>
<!-- 列递归,便于支持多级表头 -->、
<template v-if="column.children && column.children.length > 0">
<Column :key="columnIndex" :column="column" v-for="(column, columnIndex) in column.children">
<!-- 表格插槽 -->
<template :slot="slotName" slot-scope="scope" v-for="(slotName) in Object.keys($scopedSlots)">
<slot :name="slotName" :column="scope.column" :row="scope.row" :prop="scope.prop"></slot>
</template>
</Column>
</template>
</el-table-column>
</template>

<script lang="ts">
import { defineComponent, PropType } from '@vue/composition-api';
import {
columnConfig,
} from '@/types/common';

export default defineComponent({
name: 'Column',
props: {
column: {
type: Object as PropType<columnConfig>,
default: () => ({}),
required: true,
},
},
});
</script>

<style></style>
57 changes: 10 additions & 47 deletions src/component/pro-table/src/ProTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,52 +51,13 @@
</template>
<el-table-column v-if="isMultiple" type="selection" reserve-selection align="center" header-align="center" width="55" :selectable="selectableFunc"> </el-table-column>
<el-table-column v-if="showColumnIndex" type="index" align="center" label="#" header-align="center" width="50"> </el-table-column>
<el-table-column
v-for="(column, columnIndex) in tableConfig.columns"
:key="columnIndex"
:column-key="column.columnKey"
:prop="column.prop"
:label="column.label"
:width="column.minWidth ? '-' : column.width || 140"
:min-width="column.minWidth || column.width || 140"
:fixed="column.fixed"
:render-header="column.renderHeader"
:sortable="column.sortable == 'false' ? false : column.sortable"
:sort-by="column.sortBy"
:sort-method="column.method"
:resizable="column.resizable"
:formatter="column.formatter"
:show-overflow-tooltip="column.showOverflowTooltip"
:align="column.align"
:header-align="column.headerAlign || column.align"
:class-name="column.className"
:label-class-name="column.labelClassName"
:selectable="column.selectable"
:reserve-selection="column.reserveSelection"
:filters="column.filters"
:filter-placement="column.filterPlacement"
:filter-multiple="column.filterMultiple"
:filter-method="column.filterMethod"
:filtered-value="column.filteredValue"
>
<!-- 操作列表头插槽 -->
<template slot="header" slot-scope="scope">
<slot v-if="$scopedSlots[`${column.prop}_header`]" :name="`${column.prop}_header`" :column="scope.column"></slot>
<span v-else>
{{ column.label }}
</span>
<!-- el-table-column单独封装,便于支持多级表头 -->
<Column :column="column" :key="columnIndex" v-for="(column, columnIndex) in tableConfig.columns">
<!-- 表格插槽 -->
<template :slot="slotName" slot-scope="scope" v-for="(slotName) in Object.keys($scopedSlots)">
<slot :name="slotName" :column="scope.column" :row="scope.row" :prop="scope.prop"></slot>
</template>
<!-- 插槽情况 -->
<template slot-scope="scope">
<!-- 自定义插槽 -->
<span v-if="column.slotName">
<slot :name="column.slotName" :row="scope.row" :prop="column.prop" :$index="scope.$index" />
</span>
<span v-else>
{{ scope.row[column.prop] }}
</span>
</template>
</el-table-column>
</Column>
</el-table>
<!-- 分页 -->
<div class="mt-8">
Expand All @@ -111,7 +72,7 @@
:total="total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
style="float:right"
style="float: right"
/>
</div>
</div>
Expand All @@ -131,6 +92,7 @@ import { Notification } from 'element-ui';
import { ElTable } from 'element-ui/types/table';
import SearchForm from './SearchForm.vue';
import { ProTableProps } from '../types/ProTable.types';
import Column from './Column.vue';

const STATUS = {
CREATE: 0,
Expand All @@ -145,6 +107,7 @@ export default defineComponent({
components: {
SearchForm,
SvgIcon,
Column,
},
props: {
// 查询模式
Expand Down Expand Up @@ -514,7 +477,7 @@ export default defineComponent({
}
.table-title-container-absolute {
position: absolute;
top: 110px;
top: 130px;
left: 10px;
}
.btn-bar {
Expand Down
87 changes: 33 additions & 54 deletions src/component/pro-table/src/SearchForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,37 @@
-->

<template>
<div class="search-form-container"
:style="{
float: searchMode === 'cover' ? 'none' : 'left'
}">
<div
class="search-form-container"
:style="{
float: searchMode === 'cover' ? 'none' : 'left',
}"
>
<template v-if="searchMode === 'popover'">
<el-input placeholder="请输入查询内容"
@clear="clearEvent"
clearable
@change="changeEvent"
v-model="searchContent"
class="input">
</el-input>
<el-button-group>
<el-button size="mini"
type="primary"
icon="el-icon-search"
@click="btnSearchOnClick()"
class="tool-btn">查询</el-button>
<!-- 高级查询表单 -->
<SeniorSearchForm v-if="showSeniorSearchFormButton"
:remoteFuncs="remoteFuncs"
@fetchSearch="getFetchParamsSearch"
:columns="columns">
</SeniorSearchForm>
<el-button size="mini"
icon="el-icon-refresh"
@click="clearEvent()"
class="tool-btn">清空</el-button>
</el-button-group>
<el-input placeholder="请输入查询内容" @clear="clearEvent" clearable size="mini" @change="changeEvent" v-model="searchContent" class="input"> </el-input>
<el-button size="mini" type="primary" icon="el-icon-search" @click="btnSearchOnClick()" class="tool-btn">查询</el-button>
<!-- 高级查询表单 -->
<SeniorSearchForm v-if="showSeniorSearchFormButton" :remoteFuncs="remoteFuncs" @fetchSearch="getFetchParamsSearch" :columns="columns"> </SeniorSearchForm>
<el-button size="mini" icon="el-icon-refresh" @click="clearEvent()" class="tool-btn">清空</el-button>
</template>
<template v-else>
<!-- 高级查询表单 -->
<SeniorSearchFormCover v-if="showSeniorSearchFormButton"
:remoteFuncs="remoteFuncs"
@fetchSearch="getFetchParamsSearch"
:columns="columns">
<SeniorSearchFormCover v-if="showSeniorSearchFormButton" :remoteFuncs="remoteFuncs" @fetchSearch="getFetchParamsSearch" :columns="columns">
<slot></slot>
</SeniorSearchFormCover>
</template>

<div class="tips">
<div
class="tips"
:style="{
float: searchMode === 'cover' ? 'right' : 'none',
}"
>
<!-- 提示当前查询内容 -->
<template v-if="isArray">
<el-tag v-for="(item, index) in paramsTips"
size="small"
effect="plain"
:key="index"
closable
@close="handleClose(item)">
{{ item.label + ":" + item.value }}
<span v-if="paramsTips && paramsTips.length > 0">当前查询: </span>
<el-tag v-for="(item, index) in paramsTips" size="small" effect="plain" :key="index" closable @close="handleClose(item)">
{{ item.label + ':' + item.value }}
</el-tag>
</template>
<template v-else>
Expand All @@ -66,6 +47,7 @@
</template>

<script lang="ts">
import { diGuiTree } from '@/utils/utils';
import { Component, Vue, Prop } from 'vue-property-decorator';
import SeniorSearchForm from './SeniorSearchForm.vue';
import SeniorSearchFormCover from './SeniorSearchFormCover.vue';
Expand Down Expand Up @@ -111,6 +93,10 @@ export default class SearchForm extends Vue {
return Array.isArray(this.paramsTips);
}

get seachableColumns() {
return diGuiTree()(this.columns);
}

// 标签关闭事件
handleClose(tag) {
this.paramsTips = this.paramsTips.filter(item => item.field !== tag.field);
Expand Down Expand Up @@ -144,7 +130,7 @@ export default class SearchForm extends Vue {
getParams() {
let params: any = [];
// 拿到所有字段
const props = this.columns.filter(item => item.searchable).map(item => item.prop);
const props = this.seachableColumns.map(item => item.prop);
const str = props.toString();
if (this.searchContent) {
params = [
Expand Down Expand Up @@ -201,7 +187,7 @@ export default class SearchForm extends Vue {
field: item.field,
value: item.value,
operator: item.operator,
label: this.columns.find(s => s.prop === item.field).label,
label: this.seachableColumns.find(s => s.prop === item.field).label,
}));
this.$emit('update:searchFormCondition', params);
this.$emit('click');
Expand All @@ -223,31 +209,24 @@ export default class SearchForm extends Vue {
<style rel="stylesheet/scss" lang="scss" scoped>
.search-form-container {
float: left;
.tool-btn {
/deep/.tool-btn {
display: inline;
height: 29px;
border-radius: 0;
margin-left: 10px;
}
/deep/.el-input__suffix {
top: -5px;
}
.input {
display: inline-block;
width: 300px;
/deep/ .el-input__inner {
height: 29px;
line-height: 29px;
border-radius: 0;
display: inline-block;
}
}
.tips {
display: inline-block;
vertical-align: 1px;
margin-left: 5px;
margin-left: 10px;
/deep/.el-tag {
border-radius: 0;
margin-right: 5px;
height: 28px!important;
line-height: 28px!important;
}
}
}
Expand Down
Loading

0 comments on commit 9c306a6

Please sign in to comment.