[新增功能] (#95)
1. @crud/CRUD.operation中增加对列隐藏(初始阶段)支持 2. @crud/CRUD.operation中增加对列忽略支持 3. @crud/CRUD.operation中列可见性控制选项顺序跟随表格列顺序变更 [代码完善] 1. 取消crud.props记录tableColumns 2. 调整表格列可见性控制时插入位置计算
This commit is contained in:
@@ -89,8 +89,8 @@
|
|||||||
全选
|
全选
|
||||||
</el-checkbox>
|
</el-checkbox>
|
||||||
<el-checkbox
|
<el-checkbox
|
||||||
v-for="item in crud.props.tableColumns"
|
v-for="item in tableColumns"
|
||||||
:key="item.label"
|
:key="item.property"
|
||||||
v-model="item.visible"
|
v-model="item.visible"
|
||||||
@change="handleCheckedTableColumnsChange(item)"
|
@change="handleCheckedTableColumnsChange(item)"
|
||||||
>
|
>
|
||||||
@@ -102,24 +102,93 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import CRUD, { crud } from '@crud/crud'
|
import CRUD, { crud } from '@crud/crud'
|
||||||
|
|
||||||
|
function sortWithRef(src, ref) {
|
||||||
|
const result = Object.assign([], ref)
|
||||||
|
let cursor = -1
|
||||||
|
src.forEach(e => {
|
||||||
|
const idx = result.indexOf(e)
|
||||||
|
if (idx === -1) {
|
||||||
|
cursor += 1
|
||||||
|
result.splice(cursor, 0, e)
|
||||||
|
} else {
|
||||||
|
cursor = idx
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mixins: [crud()],
|
mixins: [crud()],
|
||||||
props: {
|
props: {
|
||||||
permission: {
|
permission: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => { return {} }
|
default: () => { return {} }
|
||||||
|
},
|
||||||
|
hiddenColumns: {
|
||||||
|
type: Array,
|
||||||
|
default: () => { return [] }
|
||||||
|
},
|
||||||
|
ignoreColumns: {
|
||||||
|
type: Array,
|
||||||
|
default: () => { return [] }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
tableColumns: [],
|
||||||
allColumnsSelected: true,
|
allColumnsSelected: true,
|
||||||
allColumnsSelectedIndeterminate: false
|
allColumnsSelectedIndeterminate: false,
|
||||||
|
tableUnwatcher: null,
|
||||||
|
// 忽略下次表格列变动
|
||||||
|
ignoreNextTableColumnsChange: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
'crud.props.table'() {
|
||||||
|
this.updateTableColumns()
|
||||||
|
this.tableColumns.forEach(column => {
|
||||||
|
if (this.hiddenColumns.indexOf(column.property) !== -1) {
|
||||||
|
column.visible = false
|
||||||
|
this.updateColumnVisible(column)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
'crud.props.table.store.states.columns'() {
|
||||||
|
this.updateTableColumns()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.crud.updateProp('searchToggle', true)
|
this.crud.updateProp('searchToggle', true)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
updateTableColumns() {
|
||||||
|
const table = this.crud.getTable()
|
||||||
|
if (!table) {
|
||||||
|
this.tableColumns = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let cols = null
|
||||||
|
const columnFilter = e => e && e.type === 'default' && e.property && this.ignoreColumns.indexOf(e.property) === -1
|
||||||
|
const refCols = table.columns.filter(columnFilter)
|
||||||
|
if (this.ignoreNextTableColumnsChange) {
|
||||||
|
this.ignoreNextTableColumnsChange = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.ignoreNextTableColumnsChange = false
|
||||||
|
const columns = []
|
||||||
|
const fullTableColumns = table.$children.map(e => e.columnConfig).filter(columnFilter)
|
||||||
|
cols = sortWithRef(fullTableColumns, refCols)
|
||||||
|
cols.forEach(config => {
|
||||||
|
const column = {
|
||||||
|
property: config.property,
|
||||||
|
label: config.label,
|
||||||
|
visible: refCols.indexOf(config) !== -1
|
||||||
|
}
|
||||||
|
columns.push(column)
|
||||||
|
})
|
||||||
|
this.tableColumns = columns
|
||||||
|
},
|
||||||
toDelete(datas) {
|
toDelete(datas) {
|
||||||
this.$confirm(`确认删除选中的${datas.length}条数据?`, '提示', {
|
this.$confirm(`确认删除选中的${datas.length}条数据?`, '提示', {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
@@ -136,7 +205,7 @@ export default {
|
|||||||
this.allColumnsSelected = true
|
this.allColumnsSelected = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.crud.props.tableColumns.forEach(column => {
|
this.tableColumns.forEach(column => {
|
||||||
if (!column.visible) {
|
if (!column.visible) {
|
||||||
column.visible = true
|
column.visible = true
|
||||||
this.updateColumnVisible(column)
|
this.updateColumnVisible(column)
|
||||||
@@ -148,7 +217,7 @@ export default {
|
|||||||
handleCheckedTableColumnsChange(item) {
|
handleCheckedTableColumnsChange(item) {
|
||||||
let totalCount = 0
|
let totalCount = 0
|
||||||
let selectedCount = 0
|
let selectedCount = 0
|
||||||
this.crud.props.tableColumns.forEach(column => {
|
this.tableColumns.forEach(column => {
|
||||||
++totalCount
|
++totalCount
|
||||||
selectedCount += column.visible ? 1 : 0
|
selectedCount += column.visible ? 1 : 0
|
||||||
})
|
})
|
||||||
@@ -168,16 +237,13 @@ export default {
|
|||||||
const vm = table.$children.find(e => e.prop === item.property)
|
const vm = table.$children.find(e => e.prop === item.property)
|
||||||
const columnConfig = vm.columnConfig
|
const columnConfig = vm.columnConfig
|
||||||
if (item.visible) {
|
if (item.visible) {
|
||||||
let columnIndex = -1
|
|
||||||
// 找出合适的插入点
|
// 找出合适的插入点
|
||||||
table.store.states.columns.find(e => {
|
const columnIndex = this.tableColumns.indexOf(item)
|
||||||
columnIndex++
|
vm.owner.store.commit('insertColumn', columnConfig, columnIndex + 1, null)
|
||||||
return e.__index !== undefined && e.__index > columnConfig.__index
|
|
||||||
})
|
|
||||||
vm.owner.store.commit('insertColumn', columnConfig, columnIndex, null)
|
|
||||||
} else {
|
} else {
|
||||||
vm.owner.store.commit('removeColumn', columnConfig, null)
|
vm.owner.store.commit('removeColumn', columnConfig, null)
|
||||||
}
|
}
|
||||||
|
this.ignoreNextTableColumnsChange = true
|
||||||
},
|
},
|
||||||
toggleSearch() {
|
toggleSearch() {
|
||||||
this.crud.props.searchToggle = !this.crud.props.searchToggle
|
this.crud.props.searchToggle = !this.crud.props.searchToggle
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ function CRUD(options) {
|
|||||||
// 请求数据
|
// 请求数据
|
||||||
initData(crud.url, crud.getQueryParams()).then(data => {
|
initData(crud.url, crud.getQueryParams()).then(data => {
|
||||||
const table = crud.getTable()
|
const table = crud.getTable()
|
||||||
if (table.lazy) { // 懒加载子节点数据,清掉已加载的数据
|
if (table && table.lazy) { // 懒加载子节点数据,清掉已加载的数据
|
||||||
table.store.states.treeData = {}
|
table.store.states.treeData = {}
|
||||||
table.store.states.lazyTreeNodeMap = {}
|
table.store.states.lazyTreeNodeMap = {}
|
||||||
}
|
}
|
||||||
@@ -504,22 +504,7 @@ function CRUD(options) {
|
|||||||
},
|
},
|
||||||
attchTable() {
|
attchTable() {
|
||||||
const table = this.getTable()
|
const table = this.getTable()
|
||||||
const columns = []
|
|
||||||
table.columns.forEach((e, index) => {
|
|
||||||
if (!e.property || e.type !== 'default') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
e.__index = index
|
|
||||||
columns.push({
|
|
||||||
property: e.property,
|
|
||||||
index,
|
|
||||||
label: e.label,
|
|
||||||
visible: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
this.updateProp('tableColumns', columns)
|
|
||||||
this.updateProp('table', table)
|
this.updateProp('table', table)
|
||||||
|
|
||||||
const that = this
|
const that = this
|
||||||
table.$on('expand-change', (row, expanded) => {
|
table.$on('expand-change', (row, expanded) => {
|
||||||
if (!expanded) {
|
if (!expanded) {
|
||||||
|
|||||||
Reference in New Issue
Block a user