diff --git a/src/components/Apps/GatewayDialog/index.vue b/src/components/Apps/GatewayTestDialog/index.vue similarity index 100% rename from src/components/Apps/GatewayDialog/index.vue rename to src/components/Apps/GatewayTestDialog/index.vue diff --git a/src/components/Table/DataTable/compenents/el-data-table/el-data-table.vue b/src/components/Table/DataTable/compenents/el-data-table/el-data-table.vue index e1613c0c0..c76fa0cf8 100644 --- a/src/components/Table/DataTable/compenents/el-data-table/el-data-table.vue +++ b/src/components/Table/DataTable/compenents/el-data-table/el-data-table.vue @@ -1133,7 +1133,7 @@ export default { * @public */ clearSelection() { - return this.selectStrategy.clearSelection() + return this.selectStrategy?.clearSelection() }, // 弹窗相关 // 除非树形结构在操作列点击新增, 否则 row 是 MouseEvent diff --git a/src/components/Table/DataTable/compenents/el-data-table/utils/select-strategy.js b/src/components/Table/DataTable/compenents/el-data-table/utils/select-strategy.js index cfb6bafaa..fec8cd0f0 100644 --- a/src/components/Table/DataTable/compenents/el-data-table/utils/select-strategy.js +++ b/src/components/Table/DataTable/compenents/el-data-table/utils/select-strategy.js @@ -13,15 +13,28 @@ class StrategyAbstract { this.onSelect = this.onSelect.bind(this) this.onSelectAll = this.onSelectAll.bind(this) } + get elTable() { return this.elDataTable.$refs.table } - onSelectionChange() {} - onSelect() {} - onSelectAll() {} - toggleRowSelection() {} - clearSelection() {} - updateElTableSelection() {} + + onSelectionChange() { + } + + onSelect() { + } + + onSelectAll() { + } + + toggleRowSelection() { + } + + clearSelection() { + } + + updateElTableSelection() { + } } /** @@ -34,14 +47,16 @@ class StrategyNormal extends StrategyAbstract { onSelectionChange(val) { this.elDataTable.selected = val } + /** * toggleRowSelection和clearSelection的表现与el-table一致 */ toggleRowSelection(...args) { return this.elTable.toggleRowSelection(...args) } + clearSelection() { - return this.elTable.clearSelection() + return this.elTable?.clearSelection() } } @@ -65,6 +80,7 @@ class StrategyPersistSelection extends StrategyAbstract { const isChosen = selection.indexOf(row) > -1 this.toggleRowSelection(row, isChosen) } + /** * 用户切换当前页的多选 */ @@ -85,7 +101,7 @@ class StrategyPersistSelection extends StrategyAbstract { // 判断是全选还是取消全选 const shouldSelectAll = currentPageSelectedCount < selectableRows.length - this.elTable.clearSelection() + this.elTable?.clearSelection() if (shouldSelectAll) { selectableRows.forEach(row => { @@ -112,6 +128,7 @@ class StrategyPersistSelection extends StrategyAbstract { this.elDataTable.$emit('selection-change', this.elDataTable.selected) } + /** * toggleRowSelection和clearSelection管理elDataTable的selected数组 * 记得最后要将状态同步到el-table中 @@ -133,10 +150,12 @@ class StrategyPersistSelection extends StrategyAbstract { this.elDataTable.$emit('toggle-row-selection', isSelected, row) this.updateElTableSelection() } + clearSelection() { this.elDataTable.selected = [] this.updateElTableSelection() } + /** * 将selected状态同步到el-table中 */ @@ -144,7 +163,7 @@ class StrategyPersistSelection extends StrategyAbstract { const { data, id, selected } = this.elDataTable const selectedIds = new Set(selected.map(r => r[id])) - this.elTable.clearSelection() + this.elTable?.clearSelection() data.forEach(row => { const shouldBeSelected = selectedIds.has(row[id]) diff --git a/src/components/Table/DataTable/index.vue b/src/components/Table/DataTable/index.vue index 57a30cb90..60aa4c636 100644 --- a/src/components/Table/DataTable/index.vue +++ b/src/components/Table/DataTable/index.vue @@ -129,7 +129,7 @@ export default { watch: {}, methods: { getList() { - this.$refs.table.clearSelection() + this.$refs.table?.clearSelection() return this.$refs.table.getList() }, getData() { diff --git a/src/components/Table/TableFormatters/ActionsFormatter.vue b/src/components/Table/TableFormatters/ActionsFormatter.vue index d529fd5ae..65a546b07 100644 --- a/src/components/Table/TableFormatters/ActionsFormatter.vue +++ b/src/components/Table/TableFormatters/ActionsFormatter.vue @@ -37,6 +37,22 @@ const defaultUpdateCallback = function({ row, col }) { this.$router.push(route) } +const defaultViewCallback = function({ row, col }) { + const id = row.id + let route = { params: { id: id }} + const viewRoute = this.colActions.viewRoute + + if (typeof updateRoute === 'object') { + route = Object.assign(route, viewRoute) + } else if (typeof updateRoute === 'function') { + route = viewRoute({ row, col }) + } else { + route.name = viewRoute + } + + this.$router.push(route) +} + const defaultCloneCallback = function({ row, col }) { const id = row.id let route = { query: { clone_from: id }} @@ -105,6 +121,7 @@ export default { cloneRoute: this.$route.name.replace('List', 'Create'), performDelete: defaultPerformDelete, onUpdate: defaultUpdateCallback, + onView: defaultViewCallback, onDelete: defaultDeleteCallback, onClone: defaultCloneCallback, extraActions: [] diff --git a/src/layout/components/GenericCreateUpdateForm/index.vue b/src/layout/components/GenericCreateUpdateForm/index.vue index 9d6529660..50ea43f63 100644 --- a/src/layout/components/GenericCreateUpdateForm/index.vue +++ b/src/layout/components/GenericCreateUpdateForm/index.vue @@ -134,14 +134,7 @@ export default { // 获取提交的方法 submitMethod: { type: [Function, String], - default: function() { - const params = this.$route.params - if (params.id) { - return 'put' - } else { - return 'post' - } - } + default: null }, // 获取创建和更新的url function getUrl: { @@ -333,7 +326,10 @@ export default { } else { this.method = this.submitMethod } - // console.log('Drawer: ', this.drawer, this.submitMethod) + // console.log('Drawer: ', this.drawer, this.submitMethod, this.action) + if (!this.drawer && !this.method) { + this.method = this.$route.params['id'] ? 'put' : 'post' + } if (this.drawer && !this.submitMethod) { if (this.action === 'clone' || this.action === 'create') { this.method = 'post' @@ -424,6 +420,7 @@ export default { if (needGetObjectDetail === null) { needGetObjectDetail = this.isUpdateMethod() || this.action === 'clone' } + // console.log('Get form value: ', needGetObjectDetail, this.needGetObjectDetail, this.isUpdateMethod(), this.action) if (!needGetObjectDetail) { return Object.assign(this.form, this.initial) } diff --git a/src/views/assets/Asset/AssetList/HostList.vue b/src/views/assets/Asset/AssetList/HostList.vue index 655990a9e..4f8d17fa4 100644 --- a/src/views/assets/Asset/AssetList/HostList.vue +++ b/src/views/assets/Asset/AssetList/HostList.vue @@ -12,7 +12,7 @@