mirror of
https://github.com/jumpserver/lina.git
synced 2025-09-25 14:25:23 +00:00
revert: 回滚表格自定义列功能 (#594)
* revert: 回滚表格自定义列功能 * fix: 优化写法 Co-authored-by: Orange <orangemtony@gmail.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div :class="grouped ? 'el-button-group' : ''">
|
<div :class="grouped ? 'el-button-group' : ''">
|
||||||
<el-button v-for="item in iActions" :key="item.name" :size="size" v-bind="item" @click="handleClick(item.name)">
|
<el-button v-for="item in iActions" :key="item.name" :size="size" v-bind="item" @click="handleClick(item.name)">
|
||||||
<el-tooltip v-if="['actionExport', 'actionImport', 'actionRefresh','actionColumnSetting'].indexOf(item.name) !== -1" effect="dark" :content="item.tip" placement="top">
|
<el-tooltip v-if="item.tip" effect="dark" :content="item.tip" placement="top">
|
||||||
<i v-if="item.fa" :class="'fa ' + item.fa" />{{ item.title }}
|
<i v-if="item.fa" :class="'fa ' + item.fa" />{{ item.title }}
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
<span v-else>
|
<span v-else>
|
||||||
|
@@ -178,7 +178,6 @@ export default {
|
|||||||
}
|
}
|
||||||
config.columns = columns
|
config.columns = columns
|
||||||
this.iConfig = config
|
this.iConfig = config
|
||||||
this.$eventBus.$emit('columnsChange', config)
|
|
||||||
},
|
},
|
||||||
filterChange(filters) {
|
filterChange(filters) {
|
||||||
const key = Object.keys(filters)[0]
|
const key = Object.keys(filters)[0]
|
||||||
|
@@ -1,94 +0,0 @@
|
|||||||
<template>
|
|
||||||
<Dialog
|
|
||||||
v-if="showColumnSettingPopover"
|
|
||||||
:title="$t('common.CustomCol')"
|
|
||||||
:visible.sync="showColumnSettingPopover"
|
|
||||||
:destroy-on-close="true"
|
|
||||||
:show-cancel="false"
|
|
||||||
width="35%"
|
|
||||||
top="10%"
|
|
||||||
@confirm="handleColumnConfirm()"
|
|
||||||
>
|
|
||||||
<el-alert type="success">
|
|
||||||
{{ this.$t('common.TableColSettingInfo') }}
|
|
||||||
</el-alert>
|
|
||||||
<el-checkbox-group
|
|
||||||
v-model="columnList"
|
|
||||||
>
|
|
||||||
<el-row>
|
|
||||||
<el-col
|
|
||||||
v-for="item in totalColumns"
|
|
||||||
:key="item.prop"
|
|
||||||
:span="8"
|
|
||||||
style="margin-top:5px;"
|
|
||||||
>
|
|
||||||
<el-checkbox
|
|
||||||
:label="item.prop"
|
|
||||||
:disabled="item.prop==='id' ||item.prop==='actions' "
|
|
||||||
>
|
|
||||||
{{ item.label }}
|
|
||||||
</el-checkbox>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
|
|
||||||
</el-checkbox-group>
|
|
||||||
</Dialog>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
import { mapGetters } from 'vuex'
|
|
||||||
import Dialog from '@/components/Dialog/index'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'ColumnSettingPopover',
|
|
||||||
components: {
|
|
||||||
Dialog
|
|
||||||
|
|
||||||
},
|
|
||||||
props: {
|
|
||||||
totalColumns: {
|
|
||||||
type: Array,
|
|
||||||
default: () => []
|
|
||||||
},
|
|
||||||
defaultColumn: {
|
|
||||||
type: Array,
|
|
||||||
default: () => []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
showColumnSettingPopover: false,
|
|
||||||
columnList: []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
...mapGetters([
|
|
||||||
'tableConfig'
|
|
||||||
])
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.$eventBus.$on('showColumnSettingPopover', () => {
|
|
||||||
this.showColumnSettingPopover = true
|
|
||||||
})
|
|
||||||
this.columnList = _.get(this.tableConfig, this.$route.name, this.defaultColumn || [])
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
handleColumnConfirm() {
|
|
||||||
const ACTIVE_COLUMN_KEY = this.$route.name
|
|
||||||
this.$store.commit('table/SET_TABLE_CONFIG',
|
|
||||||
{
|
|
||||||
key: ACTIVE_COLUMN_KEY,
|
|
||||||
value: this.columnList
|
|
||||||
}
|
|
||||||
)
|
|
||||||
this.showColumnSettingPopover = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang='less' scoped>
|
|
||||||
|
|
||||||
</style>
|
|
@@ -2,25 +2,21 @@
|
|||||||
<div>
|
<div>
|
||||||
<ActionsGroup :is-fa="true" :actions="rightSideActions" class="right-side-actions right-side-item" />
|
<ActionsGroup :is-fa="true" :actions="rightSideActions" class="right-side-actions right-side-item" />
|
||||||
<ImExportDialog :selected-rows="selectedRows" :url="tableUrl" v-bind="$attrs" />
|
<ImExportDialog :selected-rows="selectedRows" :url="tableUrl" v-bind="$attrs" />
|
||||||
<ColumnSettingPopover v-bind="$attrs" />
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import ActionsGroup from '@/components/ActionsGroup'
|
import ActionsGroup from '@/components/ActionsGroup'
|
||||||
import ImExportDialog from './ImExportDialog'
|
import ImExportDialog from './ImExportDialog'
|
||||||
import ColumnSettingPopover from './ColumnSettingPopover'
|
|
||||||
import { cleanActions } from './utils'
|
import { cleanActions } from './utils'
|
||||||
|
|
||||||
const defaultTrue = { type: Boolean, default: true }
|
const defaultTrue = { type: Boolean, default: true }
|
||||||
const defaultFalse = { type: Boolean, default: false }
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'RightSide',
|
name: 'RightSide',
|
||||||
components: {
|
components: {
|
||||||
ActionsGroup,
|
ActionsGroup,
|
||||||
ImExportDialog,
|
ImExportDialog
|
||||||
ColumnSettingPopover
|
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
tableUrl: {
|
tableUrl: {
|
||||||
@@ -41,13 +37,6 @@ export default {
|
|||||||
this.$eventBus.$emit('showImportDialog', { selectedRows })
|
this.$eventBus.$emit('showImportDialog', { selectedRows })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
hasColumnSetting: defaultFalse,
|
|
||||||
handleColumnConfig: {
|
|
||||||
type: Function,
|
|
||||||
default: function({ selectedRows }) {
|
|
||||||
this.$eventBus.$emit('showColumnSettingPopover')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
hasRefresh: defaultTrue,
|
hasRefresh: defaultTrue,
|
||||||
selectedRows: {
|
selectedRows: {
|
||||||
type: Array,
|
type: Array,
|
||||||
@@ -65,7 +54,6 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
defaultRightSideActions: [
|
defaultRightSideActions: [
|
||||||
{ name: 'actionColumnSetting', fa: 'fa-cog', tip: this.$t('common.CustomCol'), has: this.hasColumnSetting, callback: this.handleColumnConfig.bind(this) },
|
|
||||||
{ name: 'actionExport', fa: 'fa-download', tip: this.$t('common.Export'), has: this.hasExport, callback: this.handleExport.bind(this) },
|
{ name: 'actionExport', fa: 'fa-download', tip: this.$t('common.Export'), has: this.hasExport, callback: this.handleExport.bind(this) },
|
||||||
{ name: 'actionImport', fa: 'fa-upload', tip: this.$t('common.Import'), has: this.hasImport, callback: this.handleImport.bind(this) },
|
{ name: 'actionImport', fa: 'fa-upload', tip: this.$t('common.Import'), has: this.hasImport, callback: this.handleImport.bind(this) },
|
||||||
{ name: 'actionRefresh', fa: 'fa-refresh', tip: this.$t('common.Refresh'), has: this.hasRefresh, callback: this.handleRefresh }
|
{ name: 'actionRefresh', fa: 'fa-refresh', tip: this.$t('common.Refresh'), has: this.hasRefresh, callback: this.handleRefresh }
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<TableAction :table-url="iTableConfig.url" :search-table="search" :date-pick="handleDateChange" v-bind="iHeaderActions" :selected-rows="selectedRows" :reload-table="reloadTable" />
|
<TableAction :table-url="iTableConfig.url" :search-table="search" :date-pick="handleDateChange" v-bind="headerActions" :selected-rows="selectedRows" :reload-table="reloadTable" />
|
||||||
<IBox class="table-content">
|
<IBox class="table-content">
|
||||||
<AutoDataTable ref="dataTable" :filter-table="filter" :config="iTableConfig" @selection-change="handleSelectionChange" v-on="$listeners" />
|
<AutoDataTable ref="dataTable" :filter-table="filter" :config="iTableConfig" @selection-change="handleSelectionChange" v-on="$listeners" />
|
||||||
</IBox>
|
</IBox>
|
||||||
@@ -13,7 +13,7 @@ import IBox from '../IBox'
|
|||||||
import TableAction from './TableAction'
|
import TableAction from './TableAction'
|
||||||
import Emitter from '@/mixins/emitter'
|
import Emitter from '@/mixins/emitter'
|
||||||
import deepmerge from 'deepmerge'
|
import deepmerge from 'deepmerge'
|
||||||
import { mapGetters } from 'vuex'
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ListTable',
|
name: 'ListTable',
|
||||||
components: {
|
components: {
|
||||||
@@ -57,40 +57,12 @@ export default {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
hasCloneAction() {
|
|
||||||
const hasClone = _.get(this.tableConfig, 'columnsMeta.actions.formatterArgs.hasClone', null)
|
|
||||||
if (hasClone) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if (this.hasCreateAction && hasClone == null) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
iHeaderActions() {
|
|
||||||
const config = this.headerActions
|
|
||||||
const hasColumnSetting = _.get(this.headerActions, 'hasColumnSetting', false)
|
|
||||||
if (hasColumnSetting) {
|
|
||||||
config.totalColumns = this.tableConfig.columns
|
|
||||||
}
|
|
||||||
return config
|
|
||||||
},
|
|
||||||
iTableConfig() {
|
iTableConfig() {
|
||||||
const config = deepmerge(this.tableConfig, { extraQuery: this.extraQuery })
|
const config = deepmerge(this.tableConfig, { extraQuery: this.extraQuery })
|
||||||
this.$log.debug('Header actions', this.headerActions)
|
this.$log.debug('Header actions', this.headerActions)
|
||||||
_.set(config, 'columnsMeta.actions.formatterArgs.hasClone', this.hasCloneAction)
|
|
||||||
this.$log.debug('ListTable: iTableConfig change', config)
|
this.$log.debug('ListTable: iTableConfig change', config)
|
||||||
return this.getActiveColumns(config)
|
return config
|
||||||
},
|
}
|
||||||
defaultColumn() {
|
|
||||||
return _.get(this.headerActions, 'defaultColumn', [])
|
|
||||||
},
|
|
||||||
currentColumnSetting() {
|
|
||||||
return _.get(this.tableColConfig, this.$route.name, this.defaultColumn || [])
|
|
||||||
},
|
|
||||||
...mapGetters({
|
|
||||||
tableColConfig: 'tableConfig'
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
extraQuery: {
|
extraQuery: {
|
||||||
@@ -107,20 +79,6 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getActiveColumns(config) {
|
|
||||||
const hasColumnSetting = _.get(this.headerActions, 'hasColumnSetting', false)
|
|
||||||
if (hasColumnSetting) {
|
|
||||||
const currentColumnSetting = this.currentColumnSetting
|
|
||||||
const currentColumn = []
|
|
||||||
config.columns.forEach((v, k) => {
|
|
||||||
if (currentColumnSetting.indexOf(v.prop) !== -1 || v.prop === 'id') {
|
|
||||||
currentColumn.push(config.columns[k])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
config.columns = currentColumn
|
|
||||||
}
|
|
||||||
return config
|
|
||||||
},
|
|
||||||
handleSelectionChange(val) {
|
handleSelectionChange(val) {
|
||||||
this.selectedRows = val
|
this.selectedRows = val
|
||||||
},
|
},
|
||||||
|
@@ -151,9 +151,7 @@ export default {
|
|||||||
hasExport: false,
|
hasExport: false,
|
||||||
hasImport: false,
|
hasImport: false,
|
||||||
hasLeftActions: false,
|
hasLeftActions: false,
|
||||||
hasSearch: true,
|
hasSearch: true
|
||||||
hasColumnSetting: true,
|
|
||||||
defaultColumn: ['hostname', 'ip', 'SystemUsers', 'comment', 'id']
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@@ -98,40 +98,24 @@ export default {
|
|||||||
url: '/api/v1/assets/assets/',
|
url: '/api/v1/assets/assets/',
|
||||||
hasTree: true,
|
hasTree: true,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
'hostname', 'ip', 'hardware_info', 'connectivity', 'actions'
|
||||||
prop: 'hostname',
|
],
|
||||||
|
columnsMeta: {
|
||||||
|
hostname: {
|
||||||
formatter: DetailFormatter,
|
formatter: DetailFormatter,
|
||||||
label: this.$t('assets.Hostname'),
|
|
||||||
formatterArgs: {
|
formatterArgs: {
|
||||||
route: 'AssetDetail'
|
route: 'AssetDetail'
|
||||||
},
|
},
|
||||||
showOverflowTooltip: true
|
showOverflowTooltip: true
|
||||||
},
|
},
|
||||||
{
|
ip: {
|
||||||
prop: 'ip',
|
|
||||||
sortable: 'custom',
|
sortable: 'custom',
|
||||||
label: `IP`,
|
|
||||||
width: '140px'
|
width: '140px'
|
||||||
},
|
},
|
||||||
{
|
hardware_info: {
|
||||||
prop: 'domain_display',
|
|
||||||
label: this.$t('assets.Domain')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prop: 'hardware_info',
|
|
||||||
label: this.$t('assets.HardwareInfo'),
|
|
||||||
showOverflowTooltip: true
|
showOverflowTooltip: true
|
||||||
},
|
},
|
||||||
{
|
connectivity: {
|
||||||
prop: 'public_ip',
|
|
||||||
label: this.$t('assets.PublicIp')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prop: 'platform',
|
|
||||||
label: this.$t('assets.Platform')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prop: 'connectivity',
|
|
||||||
label: this.$t('assets.Reachable'),
|
label: this.$t('assets.Reachable'),
|
||||||
formatter: BooleanFormatter,
|
formatter: BooleanFormatter,
|
||||||
formatterArgs: {
|
formatterArgs: {
|
||||||
@@ -148,11 +132,8 @@ export default {
|
|||||||
width: '90px',
|
width: '90px',
|
||||||
align: 'center'
|
align: 'center'
|
||||||
},
|
},
|
||||||
{
|
actions: {
|
||||||
prop: 'actions',
|
|
||||||
formatter: ActionsFormatter,
|
formatter: ActionsFormatter,
|
||||||
label: this.$t('common.Actions'),
|
|
||||||
width: '140px',
|
|
||||||
formatterArgs: {
|
formatterArgs: {
|
||||||
hasClone: true,
|
hasClone: true,
|
||||||
performDelete: ({ row, col }) => {
|
performDelete: ({ row, col }) => {
|
||||||
@@ -172,11 +153,9 @@ export default {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
},
|
},
|
||||||
headerActions: {
|
headerActions: {
|
||||||
hasColumnSetting: true,
|
|
||||||
defaultColumn: ['hostname', 'ip', 'hardware_info', 'connectivity', 'actions'],
|
|
||||||
createRoute: {
|
createRoute: {
|
||||||
name: 'AssetCreate',
|
name: 'AssetCreate',
|
||||||
query: this.$route.query
|
query: this.$route.query
|
||||||
|
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { GenericListPage } from '@/layout/components'
|
import { GenericListPage } from '@/layout/components'
|
||||||
import { ActionsFormatter, DetailFormatter } from '@/components/ListTable/formatters'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -14,84 +13,29 @@ export default {
|
|||||||
return {
|
return {
|
||||||
tableConfig: {
|
tableConfig: {
|
||||||
url: '/api/v1/assets/system-users/',
|
url: '/api/v1/assets/system-users/',
|
||||||
columns: [
|
columns: ['name', 'username', 'protocol', 'login_mode', 'assets_amount', 'comment', 'actions'],
|
||||||
{
|
columnsMeta: {
|
||||||
prop: 'name',
|
username: {
|
||||||
label: this.$t('assets.Name'),
|
|
||||||
sortable: 'custom',
|
|
||||||
formatter: DetailFormatter,
|
|
||||||
showOverflowTooltip: true
|
showOverflowTooltip: true
|
||||||
},
|
},
|
||||||
{
|
protocol: {
|
||||||
prop: 'username',
|
width: '100px'
|
||||||
label: this.$t('assets.Username')
|
|
||||||
},
|
},
|
||||||
{
|
login_mode: {
|
||||||
prop: 'protocol',
|
|
||||||
label: this.$t('assets.Protocol'),
|
|
||||||
width: '100px',
|
|
||||||
'column-key': `protocol`,
|
|
||||||
filters: [
|
|
||||||
{
|
|
||||||
'value': 'ssh',
|
|
||||||
'text': 'ssh'
|
|
||||||
}, {
|
|
||||||
'value': 'rdp',
|
|
||||||
'text': 'rdp'
|
|
||||||
}, {
|
|
||||||
'value': 'telnet',
|
|
||||||
'text': 'telnet'
|
|
||||||
}, {
|
|
||||||
'value': 'vnc',
|
|
||||||
'text': 'vnc'
|
|
||||||
}, {
|
|
||||||
'value': 'mysql',
|
|
||||||
'text': 'mysql'
|
|
||||||
}, {
|
|
||||||
'value': 'oracle',
|
|
||||||
'text': 'oracle'
|
|
||||||
}, {
|
|
||||||
'value': 'mariadb',
|
|
||||||
'text': 'mariadb'
|
|
||||||
}, {
|
|
||||||
'value': 'postgresql',
|
|
||||||
'text': 'postgresql'
|
|
||||||
}, {
|
|
||||||
'value': 'k8s',
|
|
||||||
'text': 'k8s'
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prop: 'login_mode',
|
|
||||||
label: this.$t('assets.LoginModel'),
|
|
||||||
sortable: 'custom',
|
|
||||||
width: '120px'
|
width: '120px'
|
||||||
},
|
},
|
||||||
{
|
assets_amount: {
|
||||||
prop: 'assets_amount',
|
|
||||||
label: this.$t('setting.AssetCount'),
|
|
||||||
width: '80px'
|
width: '80px'
|
||||||
},
|
},
|
||||||
{
|
actions: {
|
||||||
prop: 'comment',
|
|
||||||
label: this.$t('assets.Comment')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
prop: 'actions',
|
|
||||||
label: this.$t('common.Actions'),
|
|
||||||
align: 'center',
|
|
||||||
width: '150px',
|
|
||||||
formatter: ActionsFormatter,
|
|
||||||
formatterArgs: {
|
formatterArgs: {
|
||||||
hasClone: true
|
hasClone: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
},
|
},
|
||||||
headerActions: {
|
headerActions: {
|
||||||
hasMoreActions: false,
|
hasMoreActions: false,
|
||||||
hasColumnSetting: true,
|
|
||||||
defaultColumn: ['name', 'username', 'protocol', 'assets_amount', 'comment', 'actions'],
|
|
||||||
createRoute: 'SystemUserCreate'
|
createRoute: 'SystemUserCreate'
|
||||||
},
|
},
|
||||||
helpMessage: this.$t('assets.SystemUserListHelpMessage')
|
helpMessage: this.$t('assets.SystemUserListHelpMessage')
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
:create-success-next-route="successUrl"
|
:create-success-next-route="successUrl"
|
||||||
:clean-form-value="cleanFormValue"
|
:clean-form-value="cleanFormValue"
|
||||||
:object="formData"
|
:object="formData"
|
||||||
|
:has-detail-in-msg="false"
|
||||||
:fields-meta="fieldsMeta"
|
:fields-meta="fieldsMeta"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
:create-success-next-route="successUrl"
|
:create-success-next-route="successUrl"
|
||||||
:clean-form-value="cleanFormValue"
|
:clean-form-value="cleanFormValue"
|
||||||
:object="formData"
|
:object="formData"
|
||||||
|
:has-detail-in-msg="false"
|
||||||
:initial="initial"
|
:initial="initial"
|
||||||
:fields-meta="fieldsMetas"
|
:fields-meta="fieldsMetas"
|
||||||
/>
|
/>
|
||||||
|
Reference in New Issue
Block a user