1. 为CRUD.operation注入curd,免去属性传递 2. 表格界面零配置实现“表格列过滤显示”功能,弃用v-if方式 (#59)
⚡ CRUD优化
为CRUD.operation注入curd,免去属性传递
表格界面零配置实现“表格列过滤显示”功能,弃用v-if方式
This commit is contained in:
@@ -107,7 +107,7 @@ export default {
|
||||
props: {
|
||||
permission: {
|
||||
type: Object,
|
||||
default: null
|
||||
default: () => { return {} }
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@@ -136,19 +136,22 @@ export default {
|
||||
this.allColumnsSelected = true
|
||||
return
|
||||
}
|
||||
for (const key in this.crud.props.tableColumns) {
|
||||
this.crud.props.tableColumns[key].visible = val
|
||||
}
|
||||
this.crud.props.tableColumns.forEach(column => {
|
||||
if (!column.visible) {
|
||||
column.visible = true
|
||||
this.updateColumnVisible(column)
|
||||
}
|
||||
})
|
||||
this.allColumnsSelected = val
|
||||
this.allColumnsSelectedIndeterminate = false
|
||||
},
|
||||
handleCheckedTableColumnsChange(item) {
|
||||
let totalCount = 0
|
||||
let selectedCount = 0
|
||||
for (const key in this.crud.props.tableColumns) {
|
||||
this.crud.props.tableColumns.forEach(column => {
|
||||
++totalCount
|
||||
selectedCount += this.crud.props.tableColumns[key].visible ? 1 : 0
|
||||
}
|
||||
selectedCount += column.visible ? 1 : 0
|
||||
})
|
||||
if (selectedCount === 0) {
|
||||
this.crud.notify('请至少选择一列', CRUD.NOTIFICATION_TYPE.WARNING)
|
||||
this.$nextTick(function() {
|
||||
@@ -158,6 +161,23 @@ export default {
|
||||
}
|
||||
this.allColumnsSelected = selectedCount === totalCount
|
||||
this.allColumnsSelectedIndeterminate = selectedCount !== totalCount && selectedCount !== 0
|
||||
this.updateColumnVisible(item)
|
||||
},
|
||||
updateColumnVisible(item) {
|
||||
const table = this.crud.props.table
|
||||
const vm = table.$children.find(e => e.prop === item.property)
|
||||
const columnConfig = vm.columnConfig
|
||||
if (item.visible) {
|
||||
let columnIndex = -1
|
||||
// 找出合适的插入点
|
||||
table.store.states.columns.find(e => {
|
||||
columnIndex++
|
||||
return e.__index !== undefined && e.__index > columnConfig.__index
|
||||
})
|
||||
vm.owner.store.commit('insertColumn', columnConfig, columnIndex, null)
|
||||
} else {
|
||||
vm.owner.store.commit('removeColumn', columnConfig, null)
|
||||
}
|
||||
},
|
||||
toggleSearch() {
|
||||
this.crud.props.searchToggle = !this.crud.props.searchToggle
|
||||
|
||||
Reference in New Issue
Block a user