Merge pull request #2497 from jumpserver/pr@dev@perf_table_select

pref: 优化表单选择,搜索后,已选择的会清空
This commit is contained in:
老广
2023-02-02 16:40:01 +08:00
committed by GitHub
4 changed files with 52 additions and 44 deletions

View File

@@ -8,12 +8,12 @@
<el-table <el-table
ref="table" ref="table"
v-loading="loading" v-loading="loading"
v-bind="tableAttrs"
:data="data" :data="data"
:row-class-name="rowClassName" :row-class-name="rowClassName"
v-bind="tableAttrs"
@select="selectStrategy.onSelect"
v-on="$listeners" v-on="$listeners"
@selection-change="selectStrategy.onSelectionChange" @selection-change="selectStrategy.onSelectionChange"
@select="selectStrategy.onSelect"
@select-all="selectStrategy.onSelectAll($event, canSelect)" @select-all="selectStrategy.onSelectAll($event, canSelect)"
@sort-change="onSortChange" @sort-change="onSortChange"
> >
@@ -91,28 +91,28 @@
<!--非树--> <!--非树-->
<template v-else> <template v-else>
<el-data-table-column v-if="hasSelection" type="selection" :align="selectionAlign" :selectable="canSelect" /> <el-data-table-column v-if="hasSelection" :align="selectionAlign" :selectable="canSelect" type="selection" />
<el-data-table-column <el-data-table-column
v-for="col in columns" v-for="col in columns"
:key="col.prop" :key="col.prop"
:formatter="typeof col.formatter === 'function' ? col.formatter : null"
:filters="col.filters || null"
:filter-multiple="false"
:filter-method="typeof col.filterMethod === 'function' ? col.filterMethod : null" :filter-method="typeof col.filterMethod === 'function' ? col.filterMethod : null"
:filter-multiple="false"
:filters="col.filters || null"
:formatter="typeof col.formatter === 'function' ? col.formatter : null"
v-bind="{align: columnsAlign, ...col}" v-bind="{align: columnsAlign, ...col}"
> >
<template v-if="col.formatter && typeof col.formatter !== 'function'" v-slot:default="{row, column, index}"> <template v-if="col.formatter && typeof col.formatter !== 'function'" v-slot:default="{row, column, index}">
<div <div
:is="col.formatter" :is="col.formatter"
:key="row.id" :key="row.id"
:table-data="data" :cell-value="row[col.prop]"
:row="row" :col="col"
:column="column" :column="column"
:index="index" :index="index"
:url="url"
:reload="getList" :reload="getList"
:col="col" :row="row"
:cell-value="row[col.prop]" :table-data="data"
:url="url"
/> />
</template> </template>
</el-data-table-column> </el-data-table-column>
@@ -122,12 +122,12 @@
<el-pagination <el-pagination
v-if="hasPagination" v-if="hasPagination"
:current-page="page"
:page-sizes="paginationSizes"
:page-size="size"
:total="total"
:background="paginationBackground" :background="paginationBackground"
:current-page="page"
:layout="paginationLayout" :layout="paginationLayout"
:page-size="size"
:page-sizes="paginationSizes"
:total="total"
v-bind="extraPaginationAttrs" v-bind="extraPaginationAttrs"
@size-change="handleSizeChange" @size-change="handleSizeChange"
@current-change="handleCurrentChange" @current-change="handleCurrentChange"
@@ -135,18 +135,18 @@
<the-dialog <the-dialog
ref="dialog" ref="dialog"
:new-title="dialogNewTitle" :button-size="buttonSize"
:dialog-attrs="dialogAttrs"
:edit-title="dialogEditTitle" :edit-title="dialogEditTitle"
:view-title="dialogViewTitle"
:form="form" :form="form"
:form-attrs="formAttrs" :form-attrs="formAttrs"
:dialog-attrs="dialogAttrs" :new-title="dialogNewTitle"
:button-size="buttonSize" :view-title="dialogViewTitle"
@confirm="onConfirm" @confirm="onConfirm"
> >
<template v-slot="scope"> <template v-slot="scope">
<!-- @slot 表单作用域插槽当编辑查看时传入row新增时row=null --> <!-- @slot 表单作用域插槽当编辑查看时传入row新增时row=null -->
<slot name="form" :row="scope.row" /> <slot :row="scope.row" name="form" />
</template> </template>
</the-dialog> </the-dialog>
</template> </template>
@@ -166,6 +166,7 @@ import getLocatedSlotKeys from './utils/extract-keys'
import transformSearchImmediatelyItem from './utils/search-immediately-item' import transformSearchImmediatelyItem from './utils/search-immediately-item'
import isFalsey from './utils/is-falsey' import isFalsey from './utils/is-falsey'
import merge from 'deepmerge' import merge from 'deepmerge'
const defaultFirstPage = 1 const defaultFirstPage = 1
const noPaginationDataPath = 'payload' const noPaginationDataPath = 'payload'
@@ -267,7 +268,8 @@ export default {
*/ */
beforeSearch: { beforeSearch: {
type: Function, type: Function,
default() {} default() {
}
}, },
/** /**
* 单选, 适用场景: 不可以批量删除 * 单选, 适用场景: 不可以批量删除
@@ -706,7 +708,8 @@ export default {
}, },
extraPaginationAttrs: { extraPaginationAttrs: {
type: Object, type: Object,
default: () => {} default: () => {
}
}, },
hasSelection: { hasSelection: {
type: Boolean, type: Boolean,
@@ -1036,6 +1039,7 @@ export default {
} else { } else {
this.innerQuery = merge(this.innerQuery, attrs) this.innerQuery = merge(this.innerQuery, attrs)
} }
this.selected.splice(0, this.selected.length)
return this.getList() return this.getList()
}, },
searchDate(attrs) { searchDate(attrs) {
@@ -1198,7 +1202,9 @@ export default {
remain === 0 && remain === 0 &&
this.page === lastPage && this.page === lastPage &&
this.page > defaultFirstPage this.page > defaultFirstPage
) { this.page-- } ) {
this.page--
}
}, },
// 树形table相关 // 树形table相关

View File

@@ -2,8 +2,8 @@
<DataActions <DataActions
v-if="hasLeftActions" v-if="hasLeftActions"
:actions="iActions" :actions="iActions"
v-bind="$attrs"
class="header-action" class="header-action"
v-bind="$attrs"
/> />
</template> </template>
@@ -44,7 +44,8 @@ export default {
canBulkUpdate: defaultTrue, canBulkUpdate: defaultTrue,
handleBulkUpdate: { handleBulkUpdate: {
type: Function, type: Function,
default: () => {} default: () => {
}
}, },
hasMoreActions: defaultTrue, hasMoreActions: defaultTrue,
tableUrl: { tableUrl: {
@@ -53,7 +54,8 @@ export default {
}, },
reloadTable: { reloadTable: {
type: Function, type: Function,
default: () => {} default: () => {
}
}, },
performBulkDelete: { performBulkDelete: {
type: Function, type: Function,

View File

@@ -1,23 +1,23 @@
<template> <template>
<div class="table-header clearfix" :class="device"> <div :class="device" class="table-header clearfix">
<slot name="header"> <slot name="header">
<LeftSide <LeftSide
v-if="hasLeftActions" v-if="hasLeftActions"
class="left-side"
:selected-rows="selectedRows" :selected-rows="selectedRows"
:table-url="tableUrl" :table-url="tableUrl"
class="left-side"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="$listeners"
/> />
<RightSide <RightSide
v-if="hasRightActions" v-if="hasRightActions"
class="right-side"
:selected-rows="selectedRows" :selected-rows="selectedRows"
:table-url="tableUrl" :table-url="tableUrl"
class="right-side"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="$listeners"
/> />
<div class="search" :class="searchClass"> <div :class="searchClass" class="search">
<AutoDataSearch <AutoDataSearch
v-if="hasSearch" v-if="hasSearch"
class="right-side-item action-search" class="right-side-item action-search"
@@ -26,8 +26,8 @@
/> />
<DatetimeRangePicker <DatetimeRangePicker
v-if="hasDatePicker" v-if="hasDatePicker"
v-bind="datePicker"
class="datepicker" class="datepicker"
v-bind="datePicker"
@dateChange="handleDateChange" @dateChange="handleDateChange"
/> />
</div> </div>

View File

@@ -1,20 +1,20 @@
<template> <template>
<div> <div>
<TableAction <TableAction
:table-url="tableUrl"
:search-table="search"
:date-pick="handleDateChange" :date-pick="handleDateChange"
:selected-rows="selectedRows"
:reload-table="reloadTable" :reload-table="reloadTable"
:search-table="search"
:selected-rows="selectedRows"
:table-url="tableUrl"
v-bind="iHeaderActions" v-bind="iHeaderActions"
/> />
<IBox class="table-content"> <IBox class="table-content">
<AutoDataTable <AutoDataTable
ref="dataTable" ref="dataTable"
:filter-table="filter"
:config="iTableConfig" :config="iTableConfig"
@selection-change="handleSelectionChange" :filter-table="filter"
v-on="$listeners" v-on="$listeners"
@selection-change="handleSelectionChange"
/> />
</IBox> </IBox>
</div> </div>