feat(table): 添加表格排序和选择功能支持
- 在KitPageArgs中新增OrderBy排序参数类,支持字段转下划线和排序绑定 - 修改SystemDictService.searchDict方法,集成排序参数处理逻辑 - 更新CuteDragTable和CuteSimpleTable组件,添加排序和选择功能 - 新增表格上方工具栏插槽和选择计数显示 - 优化前端表格组件的排序事件处理和数据刷新逻辑
This commit is contained in:
@@ -6,6 +6,19 @@
|
||||
-->
|
||||
<template>
|
||||
<div>
|
||||
<el-row>
|
||||
<el-col v-if="showSelect" :span="2" class="selection-box">
|
||||
已选 <font class="selection-count">{{ crud.selection && crud.selection.length }}</font> 条
|
||||
</el-col>
|
||||
<el-col :span="11" style="text-align: left">
|
||||
<!-- 通过 <template v-slot:batchArea> 插槽,数据表格上方左侧 添加 批量操作入口 -->
|
||||
<slot name="batchArea" />
|
||||
</el-col>
|
||||
<el-col :span="11" style="text-align: left">
|
||||
<!-- 通过 <template v-slot:toolArea> 插槽,数据表格上方右侧 添加 工具入口,比如导出 -->
|
||||
<slot name="toolArea" />
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-table
|
||||
ref="table"
|
||||
v-loading="crud.loading"
|
||||
@@ -17,9 +30,12 @@
|
||||
style="width: 100%;"
|
||||
:height="height"
|
||||
:max-height="height"
|
||||
highlight-current-row
|
||||
highlight-selection-row
|
||||
@sort-change="onTableSortChange"
|
||||
@selection-change="onTableSelectionChange"
|
||||
>
|
||||
<el-table-column v-if="mode === 'multi'" type="selection" width="55" />
|
||||
<el-table-column v-if="showSelect" type="selection" width="55" />
|
||||
<slot />
|
||||
<el-pagination
|
||||
v-if="paging"
|
||||
@@ -60,10 +76,10 @@ export default {
|
||||
required: false,
|
||||
default: null
|
||||
},
|
||||
mode: {
|
||||
type: String,
|
||||
showSelect: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: 'none'
|
||||
default: false
|
||||
},
|
||||
paging: {
|
||||
type: Boolean,
|
||||
@@ -95,7 +111,9 @@ export default {
|
||||
console.log('on-page-change', currentPage, pageSize)
|
||||
// this.$emit('onPageChange', currentPage, pageSize, total)
|
||||
this.refresh()
|
||||
}
|
||||
},
|
||||
orderBy: '',
|
||||
selection: []
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -109,6 +127,8 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
refresh() {
|
||||
this.crud.orderBy = ''
|
||||
this.crud.selection = []
|
||||
this.initData()
|
||||
this.initDragTable()
|
||||
},
|
||||
@@ -118,6 +138,10 @@ export default {
|
||||
if (this.paramsTransform) {
|
||||
params = this.paramsTransform(this.pageProps)
|
||||
}
|
||||
// 排序字段
|
||||
if (this.crud.orderBy) {
|
||||
params.orderBy = this.crud.orderBy
|
||||
}
|
||||
if (this.fetch) {
|
||||
try {
|
||||
this.crud.loading = true
|
||||
@@ -134,14 +158,37 @@ export default {
|
||||
this.crud.dataSource = response.content
|
||||
}
|
||||
return response
|
||||
} catch (e) {
|
||||
console.error('CuteDragTable请求远程数据异常', e)
|
||||
this.pageProps.total = 0
|
||||
this.crud.dataSource = []
|
||||
} finally {
|
||||
this.crud.loading = false
|
||||
}
|
||||
}
|
||||
},
|
||||
onTableSelectionChange(selection) {
|
||||
this.crud.selection = selection
|
||||
this.$emit('selection-change', selection)
|
||||
},
|
||||
getDataSource() {
|
||||
return this.crud.dataSource
|
||||
},
|
||||
onTableSortChange(sortProps) {
|
||||
const prop = sortProps.prop
|
||||
const order = sortProps.order
|
||||
let result
|
||||
if (order === 'ascending') {
|
||||
result = { column: prop, orderType: 'asc' }
|
||||
} else if (order === 'descending') {
|
||||
result = { column: prop, orderType: 'desc' }
|
||||
} else {
|
||||
result = { column: prop, orderType: 'desc' }
|
||||
}
|
||||
// this.$emit('order-change', result)
|
||||
this.crud.orderBy = result
|
||||
this.refresh()
|
||||
},
|
||||
initDragTable() {
|
||||
const that = this
|
||||
const table = that.$refs.table.$el.querySelectorAll('.el-table__body-wrapper > table > tbody')[0]
|
||||
@@ -163,11 +210,24 @@ export default {
|
||||
data.forEach((item, index) => {
|
||||
item.orderNum = index + 1
|
||||
})
|
||||
},
|
||||
getDataSource() {
|
||||
return this.crud.dataSource
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import "~@/assets/styles/variables.scss";
|
||||
|
||||
.selection-box {
|
||||
text-align: left;
|
||||
font-size: 12px;
|
||||
padding-left: 10px;
|
||||
min-height: 26.7px;
|
||||
max-height: 26.7px;
|
||||
padding-top: 7px;
|
||||
}
|
||||
|
||||
.selection-count {
|
||||
color: $menuActiveText;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -6,6 +6,19 @@
|
||||
-->
|
||||
<template>
|
||||
<div>
|
||||
<el-row>
|
||||
<el-col v-if="showSelect" :span="2" class="selection-box">
|
||||
已选 <font class="selection-count">{{ crud.selection && crud.selection.length }}</font> 条
|
||||
</el-col>
|
||||
<el-col :span="11" style="text-align: left">
|
||||
<!-- 通过 <template v-slot:batchArea> 插槽,数据表格上方左侧 添加 批量操作入口 -->
|
||||
<slot name="batchArea" />
|
||||
</el-col>
|
||||
<el-col :span="11" style="text-align: right">
|
||||
<!-- 通过 <template v-slot:toolArea> 插槽,数据表格上方右侧 添加 工具入口,比如导出 -->
|
||||
<slot name="toolArea" />
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-table
|
||||
ref="table"
|
||||
v-loading="crud.loading"
|
||||
@@ -17,9 +30,12 @@
|
||||
style="width: 100%;"
|
||||
:height="height"
|
||||
:max-height="height"
|
||||
highlight-current-row
|
||||
highlight-selection-row
|
||||
@sort-change="onTableSortChange"
|
||||
@selection-change="onTableSelectionChange"
|
||||
>
|
||||
<el-table-column v-if="mode === 'multi'" type="selection" width="55" />
|
||||
<el-table-column v-if="showSelect" type="selection" width="55" />
|
||||
<slot />
|
||||
</el-table>
|
||||
<el-pagination
|
||||
@@ -60,10 +76,10 @@ export default {
|
||||
required: false,
|
||||
default: null
|
||||
},
|
||||
mode: {
|
||||
type: String,
|
||||
showSelect: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: 'none'
|
||||
default: false
|
||||
},
|
||||
paging: {
|
||||
type: Boolean,
|
||||
@@ -100,7 +116,9 @@ export default {
|
||||
console.log('on-page-change', currentPage, pageSize)
|
||||
// this.$emit('onPageChange', currentPage, pageSize, total)
|
||||
this.refresh()
|
||||
}
|
||||
},
|
||||
orderBy: '',
|
||||
selection: []
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -117,6 +135,8 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
refresh() {
|
||||
this.crud.orderBy = ''
|
||||
this.crud.selection = []
|
||||
this.initData()
|
||||
},
|
||||
async initData() {
|
||||
@@ -125,6 +145,10 @@ export default {
|
||||
if (this.paramsTransform) {
|
||||
params = this.paramsTransform(this.pageProps)
|
||||
}
|
||||
// 排序字段
|
||||
if (this.crud.orderBy) {
|
||||
params.orderBy = this.crud.orderBy
|
||||
}
|
||||
if (this.fetch) {
|
||||
try {
|
||||
this.crud.loading = true
|
||||
@@ -141,15 +165,55 @@ export default {
|
||||
this.crud.dataSource = response.content
|
||||
}
|
||||
return response
|
||||
} catch (e) {
|
||||
console.error('CuteSimpleTable请求远程数据异常', e)
|
||||
this.pageProps.total = 0
|
||||
this.crud.dataSource = []
|
||||
} finally {
|
||||
this.crud.loading = false
|
||||
}
|
||||
}
|
||||
},
|
||||
onTableSelectionChange(selection) {
|
||||
this.crud.selection = selection
|
||||
this.$emit('selection-change', selection)
|
||||
},
|
||||
getDataSource() {
|
||||
return this.crud.dataSource
|
||||
},
|
||||
onTableSortChange(sortProps) {
|
||||
const prop = sortProps.prop
|
||||
const order = sortProps.order
|
||||
let result
|
||||
if (order === 'ascending') {
|
||||
result = { column: prop, orderType: 'asc' }
|
||||
} else if (order === 'descending') {
|
||||
result = { column: prop, orderType: 'desc' }
|
||||
} else {
|
||||
result = { column: prop, orderType: 'desc' }
|
||||
}
|
||||
// this.$emit('order-change', result)
|
||||
this.crud.orderBy = result
|
||||
this.refresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import "~@/assets/styles/variables.scss";
|
||||
|
||||
.selection-box {
|
||||
text-align: left;
|
||||
font-size: 12px;
|
||||
padding-left: 10px;
|
||||
min-height: 26.7px;
|
||||
max-height: 26.7px;
|
||||
padding-top: 7px;
|
||||
}
|
||||
|
||||
.selection-count {
|
||||
color: $menuActiveText;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
label-position="right"
|
||||
label-width="80px"
|
||||
:rules="form.rules"
|
||||
size="mini"
|
||||
>
|
||||
<el-form-item label="模糊查询" prop="blurry">
|
||||
<el-input v-model="form.model.blurry" clearable />
|
||||
@@ -24,9 +25,9 @@
|
||||
<!-- params-transform: 组装查询参数 -->
|
||||
<!-- responseTransform: 组装表格对象。对响应结果做处理 -->
|
||||
<!-- primary-key: 主键 -->
|
||||
<!-- data-source: 数据源。当data-source不为空时,以data-source的数据为主 -->
|
||||
<!-- mode: 模式。不传默认,传multi为多选 -->
|
||||
<!-- showSelect: 是否多选。不传默认false,传true为多选 -->
|
||||
<!-- @selection-change: 当且仅当mode为multi时启用 -->
|
||||
<!-- @order-change: 当排序字段被单击,el-table-column 需添加 sortable="custom" 属性 -->
|
||||
<cute-drag-table
|
||||
ref="instance"
|
||||
:fetch="curd.fetch"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
label-position="right"
|
||||
label-width="80px"
|
||||
:rules="form.rules"
|
||||
size="mini"
|
||||
>
|
||||
<el-form-item label="模糊查询" prop="blurry">
|
||||
<el-input v-model="form.model.blurry" clearable />
|
||||
@@ -28,18 +29,26 @@
|
||||
<!-- params-transform: 组装查询参数 -->
|
||||
<!-- responseTransform: 组装表格对象。对响应结果做处理 -->
|
||||
<!-- primary-key: 主键 -->
|
||||
<!-- mode: 模式。不传默认,传multi为多选 -->
|
||||
<!-- showSelect: 是否多选。不传默认false,传true为多选 -->
|
||||
<!-- @selection-change: 当且仅当mode为multi时启用 -->
|
||||
<!-- @order-change: 当排序字段被单击,el-table-column 需添加 sortable="custom" 属性 -->
|
||||
<cute-simple-table
|
||||
ref="instance"
|
||||
:fetch="curd.fetch"
|
||||
:params-transform="curd.paramsTransform"
|
||||
primary-key="id"
|
||||
:page-props="curd.pageProps"
|
||||
show-select
|
||||
>
|
||||
<template v-slot:batchArea>
|
||||
<cute-button type="primary">批量绑定</cute-button>
|
||||
</template>
|
||||
<template v-slot:toolArea>
|
||||
<cute-button type="primary">导出</cute-button>
|
||||
</template>
|
||||
<el-table-column prop="name" label="名称" />
|
||||
<el-table-column prop="description" label="描述" />
|
||||
<el-table-column prop="createTime" label="创建时间" :formatter="FormatRowDateTimeStr" />
|
||||
<el-table-column prop="createTime" label="创建时间" sortable="custom" :formatter="FormatRowDateTimeStr" />
|
||||
<el-table-column prop="createBy" label="创建人" />
|
||||
<el-table-column label="操作" width="150" min-width="150" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
@@ -50,7 +59,13 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
</cute-simple-table>
|
||||
<cute-form-dialog ref="dialogForm" :model="createFormModel" :rules="createFormRules" title="演示:表单对话框" @submit="onDialogFormSubmit">
|
||||
<cute-form-dialog
|
||||
ref="dialogForm"
|
||||
:model="createFormModel"
|
||||
:rules="createFormRules"
|
||||
title="演示:表单对话框"
|
||||
@submit="onDialogFormSubmit"
|
||||
>
|
||||
<el-form-item label="活动名称" prop="name" label-width="100px">
|
||||
<el-input v-model="createFormModel.name" placeholder="请输入" style="width: 100%" />
|
||||
</el-form-item>
|
||||
@@ -61,7 +76,14 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</cute-form-dialog>
|
||||
<cute-form-drawer ref="drawerFrom" :model="createFormModel" :rules="createFormRules" title="演示:表单抽屉" @submit="onDrawerFormSubmit">
|
||||
<cute-form-drawer
|
||||
ref="drawerFrom"
|
||||
:model="createFormModel"
|
||||
:rules="createFormRules"
|
||||
title="演示:表单抽屉"
|
||||
width="45%"
|
||||
@submit="onDrawerFormSubmit"
|
||||
>
|
||||
<el-form-item label="活动名称" prop="name" label-width="100px">
|
||||
<el-input v-model="createFormModel.name" placeholder="请输入" style="width: 100%" />
|
||||
</el-form-item>
|
||||
@@ -71,6 +93,12 @@
|
||||
<el-option label="区域二" value="beijing" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="活动模式" prop="modeList" label-width="100px">
|
||||
<cute-transfer v-model="createFormModel.modeList" :data-source="modeDataSource">
|
||||
<el-table-column prop="name" label="姓名" />
|
||||
<el-table-column prop="description" label="备注" />
|
||||
</cute-transfer>
|
||||
</el-form-item>
|
||||
</cute-form-drawer>
|
||||
</div>
|
||||
</template>
|
||||
@@ -81,12 +109,21 @@ import DictService from '@/api/system/dict'
|
||||
import CuteFormDialog from '@/views/components/dev/CuteFormDialog'
|
||||
import CuteFormDrawer from '@/views/components/dev/CuteFormDrawer'
|
||||
import { FormatRowDateTimeStr } from '@/utils/CsUtil'
|
||||
import CuteButton from '@/views/components/dev/CuteButton.vue'
|
||||
import CuteTransfer from '@/views/components/dev/CuteTransfer.vue'
|
||||
|
||||
export default {
|
||||
name: 'CuteSimpleTableDemo',
|
||||
components: { CuteFormDrawer, CuteFormDialog, CuteSimpleTable },
|
||||
components: { CuteTransfer, CuteButton, CuteFormDrawer, CuteFormDialog, CuteSimpleTable },
|
||||
data() {
|
||||
return {
|
||||
modeDataSource: [
|
||||
{ id: 1, name: '小明', description: '小明牛P' },
|
||||
{ id: 2, name: '小明', description: '小明牛P' },
|
||||
{ id: 3, name: '小明', description: '小明牛P' },
|
||||
{ id: 4, name: '小明', description: '小明牛P' },
|
||||
{ id: 5, name: '小明', description: '小明牛P' }
|
||||
],
|
||||
form: {
|
||||
model: {
|
||||
blurry: ''
|
||||
@@ -137,7 +174,8 @@ export default {
|
||||
},
|
||||
createFormModel: {
|
||||
name: '',
|
||||
region: ''
|
||||
region: '',
|
||||
modeList: []
|
||||
},
|
||||
createFormRules: {
|
||||
name: [
|
||||
|
||||
Reference in New Issue
Block a user