From cedb7c6c2f0f93b74bf2079185a578fceace062e Mon Sep 17 00:00:00 2001 From: Moxun Date: Tue, 24 Dec 2019 16:47:26 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=B8=BACRUD.operation=E6=B3=A8=E5=85=A5c?= =?UTF-8?q?urd=EF=BC=8C=E5=85=8D=E5=8E=BB=E5=B1=9E=E6=80=A7=E4=BC=A0?= =?UTF-8?q?=E9=80=92=202.=20=E8=A1=A8=E6=A0=BC=E7=95=8C=E9=9D=A2=E9=9B=B6?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=AE=9E=E7=8E=B0=E2=80=9C=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E5=88=97=E8=BF=87=E6=BB=A4=E6=98=BE=E7=A4=BA=E2=80=9D=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E5=BC=83=E7=94=A8v-if=E6=96=B9=E5=BC=8F=20(#?= =?UTF-8?q?59)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit :zap: CRUD优化 为CRUD.operation注入curd,免去属性传递 表格界面零配置实现“表格列过滤显示”功能,弃用v-if方式 --- src/components/Crud/CRUD.operation.vue | 34 ++++++++++++++++++++----- src/components/Crud/RR.operation.vue | 6 ++--- src/components/Crud/crud.js | 23 +++++++---------- src/views/generator/index.vue | 12 ++++----- src/views/mnt/app/index.vue | 14 +++++----- src/views/mnt/database/index.vue | 10 ++++---- src/views/mnt/deploy/index.vue | 8 +++--- src/views/mnt/deployHistory/index.vue | 10 ++++---- src/views/mnt/server/index.vue | 12 ++++----- src/views/monitor/log/errorLog.vue | 14 +++++----- src/views/monitor/log/index.vue | 14 +++++----- src/views/monitor/log/search.vue | 4 +-- src/views/monitor/online/index.vue | 16 ++++++------ src/views/monitor/server/index.vue | 22 ++++++++-------- src/views/system/dept/index.vue | 8 +++--- src/views/system/job/index.vue | 10 ++++---- src/views/system/job/module/header.vue | 4 +-- src/views/system/menu/index.vue | 22 ++++++++-------- src/views/system/role/index.vue | 14 +++++----- src/views/system/timing/index.vue | 18 ++++++------- src/views/system/user/index.vue | 18 ++++++------- src/views/tools/picture/index.vue | 16 ++++++------ src/views/tools/storage/local/index.vue | 16 ++++++------ src/views/tools/storage/qiniu/index.vue | 14 +++++----- 24 files changed, 174 insertions(+), 165 deletions(-) diff --git a/src/components/Crud/CRUD.operation.vue b/src/components/Crud/CRUD.operation.vue index de052b7..fd96c56 100644 --- a/src/components/Crud/CRUD.operation.vue +++ b/src/components/Crud/CRUD.operation.vue @@ -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 diff --git a/src/components/Crud/RR.operation.vue b/src/components/Crud/RR.operation.vue index 71453d5..18a8b09 100644 --- a/src/components/Crud/RR.operation.vue +++ b/src/components/Crud/RR.operation.vue @@ -6,12 +6,10 @@