perf: 优化代码,搜索 (#1080)

* perf: 修改不再存储 .env.devlopement

* perf: 优化代码,搜索

Co-authored-by: ibuler <ibuler@qq.com>
This commit is contained in:
fit2bot 2021-09-27 14:29:37 +08:00 committed by GitHub
parent 731d01450f
commit a382c82732
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 149 additions and 91 deletions

View File

@ -1,3 +1,4 @@
lina lina
dist dist
node_modules node_modules
.git

View File

@ -1,5 +1,5 @@
import { ChoicesFormatter } from '@/components/TableFormatters'
import { toSafeLocalDateStr } from '@/utils/common' import { toSafeLocalDateStr } from '@/utils/common'
import ChoicesFormatter from '@/components/TableFormatters/ChoicesFormatter'
import i18n from '@/i18n/i18n' import i18n from '@/i18n/i18n'
export const connectivityMeta = { export const connectivityMeta = {
@ -7,9 +7,14 @@ export const connectivityMeta = {
formatter: ChoicesFormatter, formatter: ChoicesFormatter,
formatterArgs: { formatterArgs: {
iconChoices: { iconChoices: {
ok: 'fa-check text-primary', ok: 'fa-check',
failed: 'fa-times text-danger', failed: 'fa-times',
unknown: 'fa-circle text-warning' unknown: 'fa-circle-o'
},
classChoices: {
ok: 'text-primary',
failed: 'text-danger',
unknown: 'text-warning'
}, },
hasTips: true, hasTips: true,
getTips: ({ row, cellValue }) => { getTips: ({ row, cellValue }) => {

View File

@ -1,6 +1,14 @@
<template> <template>
<div> <div>
<DataTable v-if="!loading" ref="dataTable" v-loading="loading" :config="iConfig" v-bind="$attrs" v-on="$listeners" @filter-change="filterChange" /> <DataTable
v-if="!loading"
ref="dataTable"
v-loading="loading"
:config="iConfig"
v-bind="$attrs"
v-on="$listeners"
@filter-change="filterChange"
/>
<ColumnSettingPopover <ColumnSettingPopover
:current-columns="popoverColumns.currentCols" :current-columns="popoverColumns.currentCols"
:total-columns-list="popoverColumns.totalColumnsList" :total-columns-list="popoverColumns.totalColumnsList"
@ -13,7 +21,13 @@
<script type="text/jsx"> <script type="text/jsx">
import DataTable from '../DataTable' import DataTable from '../DataTable'
import { DateFormatter, DetailFormatter, DisplayFormatter, BooleanFormatter, ActionsFormatter } from '@/components/TableFormatters' import {
DateFormatter,
DetailFormatter,
DisplayFormatter,
ActionsFormatter,
ChoicesFormatter
} from '@/components/TableFormatters'
import i18n from '@/i18n/i18n' import i18n from '@/i18n/i18n'
import ColumnSettingPopover from './components/ColumnSettingPopover' import ColumnSettingPopover from './components/ColumnSettingPopover'
import { newURL } from '@/utils/common' import { newURL } from '@/utils/common'
@ -103,7 +117,7 @@ export default {
break break
case 'is_valid': case 'is_valid':
col.label = i18n.t('common.Validity') col.label = i18n.t('common.Validity')
col.formatter = BooleanFormatter col.formatter = ChoicesFormatter
col.align = 'center' col.align = 'center'
col.width = '80px' col.width = '80px'
break break
@ -123,7 +137,7 @@ export default {
col.formatter = DisplayFormatter col.formatter = DisplayFormatter
break break
case 'boolean': case 'boolean':
col.formatter = BooleanFormatter col.formatter = ChoicesFormatter
col.align = 'center' col.align = 'center'
col.width = '80px' col.width = '80px'
break break

View File

@ -5,7 +5,7 @@
<script> <script>
import BaseFormatter from './base' import BaseFormatter from './base'
export default { export default {
name: 'ChoicesFormatter', name: 'BooleanFormatter',
extends: BaseFormatter, extends: BaseFormatter,
props: { props: {
formatterArgsDefault: { formatterArgsDefault: {
@ -16,6 +16,7 @@ export default {
true: 'fa-check text-primary', true: 'fa-check text-primary',
false: 'fa-times text-danger' false: 'fa-times text-danger'
}, },
showFalse: true,
typeChange(val) { typeChange(val) {
return !!val return !!val
} }
@ -31,6 +32,9 @@ export default {
computed: { computed: {
iconClass() { iconClass() {
const key = this.formatterArgs.typeChange(this.cellValue) const key = this.formatterArgs.typeChange(this.cellValue)
if (!key && !this.formatterArgs.showFalse) {
return ''
}
return this.formatterArgs.iconChoices[key] return this.formatterArgs.iconChoices[key]
} }
} }

View File

@ -1,11 +1,11 @@
<template> <template>
<div> <el-tooltip v-if="shown" :disabled="!formatterArgs.hasTips" placement="bottom" effect="dark">
<el-tooltip v-if="formatterArgs.hasTips" placement="bottom" effect="dark">
<div slot="content" v-html="tips" /> <div slot="content" v-html="tips" />
<i :class="'fa ' + iconClass" /> <span :class="classes">
<i v-if="formatterArgs.useIcon" :class="'fa ' + icon" />
<span v-if="formatterArgs.useText">{{ text }}</span>
</span>
</el-tooltip> </el-tooltip>
<i v-else :class="'fa ' + iconClass" />
</div>
</template> </template>
<script> <script>
@ -19,13 +19,24 @@ export default {
default() { default() {
return { return {
iconChoices: { iconChoices: {
true: 'fa-check text-primary', true: 'fa-check',
false: 'fa-times text-danger' false: 'fa-times'
}, },
getIconKey({ row, cellValue }) { classChoices: {
true: 'text-primary',
false: 'text-danger'
},
textChoices: {
true: this.$t('common.Yes'),
false: this.$t('common.No')
},
getKey({ row, cellValue }) {
return cellValue return cellValue
}, },
hasTips: false, hasTips: false,
useIcon: true,
useText: false,
showFalse: true,
getTips: ({ row, cellValue }) => { getTips: ({ row, cellValue }) => {
return cellValue return cellValue
} }
@ -39,12 +50,28 @@ export default {
} }
}, },
computed: { computed: {
iconClass() { key() {
const key = this.formatterArgs.getIconKey({ row: this.row, cellValue: this.cellValue }) return this.formatterArgs.getKey(
return this.formatterArgs.iconChoices[key] { row: this.row, cellValue: this.cellValue }
)
},
icon() {
return this.formatterArgs.iconChoices[this.key]
},
classes() {
return this.formatterArgs.classChoices[this.key]
},
text() {
return this.formatterArgs.textChoices[this.key]
}, },
tips() { tips() {
return this.formatterArgs.getTips({ cellValue: this.cellValue, row: this.row }) return this.formatterArgs.getTips({ cellValue: this.cellValue, row: this.row })
},
shown() {
if (!this.formatterArgs.showFalse && !this.key) {
return false
}
return true
} }
} }
} }

View File

@ -1,5 +1,5 @@
<template> <template>
<span>{{ display }}</span> <span :class="cls"> {{ value }}</span>
</template> </template>
<script> <script>
@ -19,19 +19,27 @@ export default {
}, },
data() { data() {
return { return {
display: this.getValue() formatterArgs: Object.assign(this.formatterArgsDefault, this.col.formatterArgs)
} }
}, },
methods: { computed: {
getValue() { value() {
const formatterArgs = Object.assign(this.formatterArgsDefault, this.col.formatterArgs) const displayKey = this.formatterArgs.displayKey
const displayKey = formatterArgs.displayKey
let value = this.row[displayKey] let value = this.row[displayKey]
if (value === undefined) { if (value === undefined) {
value = this.row[this.col.prop] value = this.row[this.col.prop]
} }
return value return value
},
cls() {
const classChoices = this.formatterArgs?.classChoices
if (!classChoices) {
return ''
} }
return classChoices[this.cellValue]
}
},
methods: {
} }
} }
</script> </script>

View File

@ -1,7 +1,6 @@
import DetailFormatter from './DetailFormatter' import DetailFormatter from './DetailFormatter'
import ArrayFormatter from './ArrayFormatter' import ArrayFormatter from './ArrayFormatter'
import DisplayFormatter from './DisplayFormatter' import DisplayFormatter from './DisplayFormatter'
import BooleanFormatter from './BooleanFormatter'
import ChoicesFormatter from './ChoicesFormatter' import ChoicesFormatter from './ChoicesFormatter'
import ActionsFormatter from './ActionsFormatter' import ActionsFormatter from './ActionsFormatter'
import DeleteActionFormatter from './DeleteActionFormatter' import DeleteActionFormatter from './DeleteActionFormatter'
@ -15,7 +14,6 @@ import StatusFormatter from './StatusFormatter'
export default { export default {
DetailFormatter, DetailFormatter,
DisplayFormatter, DisplayFormatter,
BooleanFormatter,
ChoicesFormatter, ChoicesFormatter,
ActionsFormatter, ActionsFormatter,
DeleteActionFormatter, DeleteActionFormatter,
@ -31,7 +29,6 @@ export default {
export { export {
DetailFormatter, DetailFormatter,
DisplayFormatter, DisplayFormatter,
BooleanFormatter,
ChoicesFormatter, ChoicesFormatter,
ActionsFormatter, ActionsFormatter,
DeleteActionFormatter, DeleteActionFormatter,

View File

@ -4,7 +4,6 @@
<script> <script>
import GenericListTable from '@/layout/components/GenericListTable/index' import GenericListTable from '@/layout/components/GenericListTable/index'
import { BooleanFormatter, DateFormatter } from '@/components/TableFormatters'
export default { export default {
name: 'TaskExecutionList', name: 'TaskExecutionList',
@ -26,33 +25,24 @@ export default {
}, },
tableConfig: { tableConfig: {
url: `/api/v1/xpack/gathered-user/task-executions/?task=${this.object.id}`, url: `/api/v1/xpack/gathered-user/task-executions/?task=${this.object.id}`,
columns: [ columns: ['timedelta', 'date_start', 'success'],
{ columnsMeta: {
prop: 'timedelta', timedelta: {
label: this.$t('ops.timeDelta'), label: this.$t('ops.timeDelta'),
formatter: function(row) { formatter: function(row) {
return row.timedelta.toFixed(2) + 's' return row.timedelta.toFixed(2) + 's'
}
}, },
{ width: null
prop: 'date_start',
label: this.$t('common.DateStart'),
formatter: DateFormatter
}, },
{ date_start: {
prop: 'success', width: null
label: this.$t('common.Success'), },
width: '90px', success: {
align: 'center', width: null,
formatter: BooleanFormatter, label: this.$t('common.Success')
formatterArgs: {
iconChoices: {
false: 'fa-times text-danger',
true: 'fa-check text-primary'
} }
} }
}
]
} }
} }
} }

View File

@ -36,7 +36,10 @@ export default {
width: '100px' width: '100px'
}, },
username_same_with_user: { username_same_with_user: {
width: '150px' width: '150px',
formatterArgs: {
showFalse: false
}
}, },
login_mode: { login_mode: {
width: '120px' width: '120px'

View File

@ -17,7 +17,10 @@ export default {
return { return {
tableConfig: { tableConfig: {
url: '/api/v1/audits/login-logs/', url: '/api/v1/audits/login-logs/',
columns: ['username', 'type', 'backend', 'ip', 'city', 'user_agent', 'mfa', 'reason', 'status', 'datetime'], columns: [
'username', 'type', 'backend', 'ip', 'city',
'user_agent', 'mfa', 'reason', 'status', 'datetime'
],
columnsMeta: { columnsMeta: {
username: { username: {
showOverflowTooltip: true showOverflowTooltip: true
@ -33,7 +36,13 @@ export default {
width: '90px' width: '90px'
}, },
status: { status: {
width: '85px' width: '85px',
formatterArgs: {
classChoices: {
true: 'text-primary',
false: 'text-danger'
}
}
}, },
mfa: { mfa: {
label: 'MFA', label: 'MFA',

View File

@ -5,7 +5,6 @@
<script> <script>
import ListTable from '@/components/ListTable' import ListTable from '@/components/ListTable'
import { SetToDefaultCommandStorage, TestCommandStorage } from '@/api/sessions' import { SetToDefaultCommandStorage, TestCommandStorage } from '@/api/sessions'
import { BooleanFormatter } from '@/components/TableFormatters'
export default { export default {
name: 'CommandStorage', name: 'CommandStorage',
components: { components: {
@ -56,12 +55,8 @@ export default {
} }
}, },
is_default: { is_default: {
formatter: BooleanFormatter,
formatterArgs: { formatterArgs: {
iconChoices: { showFalse: false
true: 'fa-check text-primary',
false: ''
}
}, },
align: 'center', align: 'center',
width: '100px' width: '100px'

View File

@ -4,7 +4,6 @@
<script> <script>
import ListTable from '@/components/ListTable' import ListTable from '@/components/ListTable'
import { TestReplayStorage, SetToDefaultReplayStorage } from '@/api/sessions' import { TestReplayStorage, SetToDefaultReplayStorage } from '@/api/sessions'
import { BooleanFormatter } from '@/components/TableFormatters'
export default { export default {
name: 'ReplayStorage', name: 'ReplayStorage',
components: { components: {
@ -61,12 +60,8 @@ export default {
} }
}, },
is_default: { is_default: {
formatter: BooleanFormatter,
formatterArgs: { formatterArgs: {
iconChoices: { showFalse: false
true: 'fa-check text-primary',
false: ''
}
}, },
align: 'center', align: 'center',
width: '100px' width: '100px'

View File

@ -17,7 +17,6 @@
import { GenericListPage, GenericCreateUpdateForm } from '@/layout/components' import { GenericListPage, GenericCreateUpdateForm } from '@/layout/components'
import Dialog from '@/components/Dialog' import Dialog from '@/components/Dialog'
import Select2 from '@/components/FormFields/Select2' import Select2 from '@/components/FormFields/Select2'
import { BooleanFormatter } from '@/components/TableFormatters'
export default { export default {
components: { components: {
GenericListPage, GenericListPage,
@ -94,7 +93,7 @@ export default {
'name', 'remote_addr', 'session_online', 'name', 'remote_addr', 'session_online',
'stat.cpu_load', 'stat.cpu_load',
'stat.disk_used', 'stat.memory_used', 'stat.disk_used', 'stat.memory_used',
'status_display', 'status',
'is_active', 'is_alive', 'actions' 'is_active', 'is_alive', 'actions'
], ],
columnsMeta: { columnsMeta: {
@ -113,16 +112,25 @@ export default {
label: this.$t('sessions.systemMemoryUsedPercent'), label: this.$t('sessions.systemMemoryUsedPercent'),
width: '120px' width: '120px'
}, },
'status_display': { status: {
label: this.$t('xpack.LoadStatus'), label: this.$t('xpack.LoadStatus'),
width: '120px' width: '120px',
// formatter: DisplayFormatter,
filterable: 'custom',
formatterArgs: {
classChoices: {
offline: 'fa fa-chain-broken text-danger',
critical: 'fa fa-bolt text-warning',
high: 'fa fa-exclamation-triangle text-info',
normal: 'fa fa-check text-primary'
}
}
}, },
remote_addr: { remote_addr: {
sortable: 'custom' sortable: 'custom'
}, },
is_active: { is_active: {
label: this.$t('sessions.active'), label: this.$t('sessions.active'),
formatter: BooleanFormatter,
width: '80px', width: '80px',
align: 'center' align: 'center'
}, },

View File

@ -46,8 +46,8 @@ export default {
columns: [ columns: [
'name', 'username', 'email', 'phone', 'wechat', 'name', 'username', 'email', 'phone', 'wechat',
'groups_display', 'total_role_display', 'source', 'groups_display', 'total_role_display', 'source',
'is_valid', 'login_blocked', 'mfa_enabled', 'is_expired', 'is_valid', 'login_blocked', 'mfa_enabled',
'mfa_force_enabled', 'mfa_force_enabled', 'is_expired',
'last_login', 'date_joined', 'date_password_last_updated', 'last_login', 'date_joined', 'date_password_last_updated',
'comment', 'created_by', 'actions' 'comment', 'created_by', 'actions'
], ],
@ -72,6 +72,22 @@ export default {
label: this.$t('users.Role'), label: this.$t('users.Role'),
showOverflowTooltip: true showOverflowTooltip: true
}, },
mfa_enabled: {
label: 'MFA',
formatterArgs: {
showFalse: false
}
},
mfa_force_enabled: {
formatterArgs: {
showFalse: false
}
},
is_expired: {
formatterArgs: {
showFalse: false
}
},
groups_display: { groups_display: {
width: '200px', width: '200px',
showOverflowTooltip: true showOverflowTooltip: true
@ -81,10 +97,10 @@ export default {
canClone: true, canClone: true,
hasDelete: hasDelete, hasDelete: hasDelete,
canUpdate: function({ row }) { canUpdate: function({ row }) {
return row.can_update return row['can_update']
}, },
canDelete: function({ row }) { canDelete: function({ row }) {
return row.can_delete return row['can_delete']
}, },
extraActions: [ extraActions: [
{ {

View File

@ -5,7 +5,6 @@
<script type="text/jsx"> <script type="text/jsx">
import GenericListTable from '@/layout/components/GenericListTable' import GenericListTable from '@/layout/components/GenericListTable'
import { ACCOUNT_PROVIDER_ATTRS_MAP, aliyun, aws_china, aws_international, huaweicloud, qcloud, azure, azure_international, vmware, nutanix, qingcloud_private, huaweicloud_private, gcp } from '../const' import { ACCOUNT_PROVIDER_ATTRS_MAP, aliyun, aws_china, aws_international, huaweicloud, qcloud, azure, azure_international, vmware, nutanix, qingcloud_private, huaweicloud_private, gcp } from '../const'
import { BooleanFormatter, DetailFormatter } from '@/components/TableFormatters'
export default { export default {
components: { components: {
@ -21,10 +20,8 @@ export default {
], ],
columnsMeta: { columnsMeta: {
name: { name: {
prop: 'name',
sortable: true, sortable: true,
showOverflowTooltip: true, showOverflowTooltip: true,
formatter: DetailFormatter,
formatterArgs: { formatterArgs: {
route: 'AccountDetail' route: 'AccountDetail'
} }
@ -51,17 +48,6 @@ export default {
} }
] ]
} }
},
validity: {
width: '90px',
align: 'center',
formatter: BooleanFormatter,
formatterArgs: {
iconChoices: {
false: 'fa-times text-danger',
true: 'fa-check text-primary'
}
}
} }
} }
}, },