perf(settings): 优化配置页面

This commit is contained in:
ibuler
2021-01-22 19:01:30 +08:00
committed by Orange
parent d267cd1f5e
commit 48a7310739
10 changed files with 99 additions and 283 deletions

View File

@@ -87,6 +87,12 @@ export default {
field.el.type = 'textarea'
field.el.rows = 3
}
if (fieldMeta.write_only) {
field.el.type = 'password'
}
break
case 'boolean':
type = 'checkbox'
break
default:
type = 'input'
@@ -137,6 +143,7 @@ export default {
// const fieldMeta = this.meta[name] || this.meta['attrs']['children'][name] || {}
const fieldMeta = this.meta[name] || ((this.meta['attrs']) ? (this.meta['attrs']['children'][name]) : {})
field.label = fieldMeta.label
field.helpText = fieldMeta.help_text
field = this.generateFieldByType(fieldMeta.type, field, fieldMeta)
field = this.generateFieldByName(name, field)
field = this.generateFieldByOther(field, fieldMeta)

View File

@@ -711,6 +711,9 @@
"SecurityInsecureCommand": "危险命令告警",
"Insecure_Command_Alert": "危险命令告警",
"SecurityInsecureCommandEmailReceiver": "告警接收邮件",
"MailSend": "邮件发送",
"LDAPServerInfo": "LDAP 服务器",
"LDAPUser": "LDAP 用户",
"helpText": {
"ApiKeyList": "使用api key签名请求头每个请求的头部是不一样的, 请查阅使用文档",
"authLdapSearchFilter": "可能的选项是(cn或uid或sAMAccountName=%(user)s)",
@@ -720,7 +723,7 @@
"emailCustomUserCreatedHonorific": "提示: 创建用户时,发送设置密码邮件的敬语 (例如: 您好)",
"emailCustomUserCreatedSignature": "提示: 邮件的署名 (例如: jumpserver)",
"emailCustomUserCreatedSubject": "提示: 创建用户时,发送设置密码邮件的主题 (例如: 创建用户成功)",
"emailEmailFrom": "提示发送邮件账号默认使用SMTP账号作为发送账号",
"emailEmailFrom": "",
"emailHostPassword": "提示一些邮件提供商需要输入的是Token",
"emailRecipient": "提示:仅用来作为测试邮件收件人",
"emailSubjectPrefix": "提示: 一些关键字可能会被邮件提供商拦截,如 跳板机、JumpServer",

View File

@@ -701,6 +701,9 @@
"emailTest": "Test connection",
"emailUserSSL": "Use SSL",
"emailUserTLS": "Use TLS",
"MailSend": "Mail send",
"LDAPServerInfo": "LDAP Server",
"LDAPUser": "LDAP User",
"helpText": {
"ApiKeyList": "The API key is used to sign the request header. The header of each request is different. Please refer to the usage documentation",
"authLdapSearchFilter": "Choice may be (cn|uid|sAMAccountName)=%(user)s)",

View File

@@ -34,9 +34,12 @@ async function checkLogin({ to, from, next }) {
try {
return await store.dispatch('users/getProfile')
} catch (e) {
setTimeout(() => {
window.location = process.env.VUE_APP_LOGIN_PATH
}, 100)
const status = e.response.status
if (status === 401 || status === 403) {
setTimeout(() => {
window.location = process.env.VUE_APP_LOGIN_PATH
}, 100)
}
return reject('No profile get: ' + e)
}
}

View File

@@ -10,7 +10,6 @@ export default {
},
data() {
return {
fields: [
[this.$t('common.Basic'), ['name', 'type', 'domain']],
[this.$t('applications.DBInfo'), ['attrs']],

View File

@@ -1,14 +1,10 @@
<template>
<IBox>
<GenericCreateUpdateForm
:fields="selectFields"
:fields="fields"
:url="url"
:initial="object"
:update-success-next-route="successUrl"
:create-success-next-route="successUrl"
:clean-form-value="cleanFormValue"
:object="object"
:fields-meta="fieldsMeta"
:get-method="getMethod"
:has-detail-in-msg="false"
/>
@@ -18,48 +14,22 @@
<script>
import GenericCreateUpdateForm from '@/layout/components/GenericCreateUpdateForm'
import { IBox } from '@/components'
import { Required } from '@/components/DataForm/rules'
export default {
name: 'Basic',
components: {
GenericCreateUpdateForm,
IBox
},
props: {
object: {
type: Object,
default: null
}
},
data() {
return {
selectFields: [[this.$t('common.BasicInfo'), ['SITE_URL', 'USER_GUIDE_URL', 'EMAIL_SUBJECT_PREFIX']]],
fields: [
[this.$t('common.BasicInfo'), ['SITE_URL', 'USER_GUIDE_URL']]
],
successUrl: { name: 'Settings', params: { activeMenu: 'Basic' }},
fieldsMeta: {
SITE_URL: {
label: this.$t('setting.siteUrl'),
rules: [Required],
helpText: this.$t('setting.helpText.siteUrl')
},
USER_GUIDE_URL: {
label: this.$t('setting.userGuideUrl'),
helpText: this.$t('setting.helpText.userGuideUrl')
},
EMAIL_SUBJECT_PREFIX: {
label: this.$t('setting.emailSubjectPrefix'),
rules: [Required],
helpText: this.$t('setting.helpText.emailSubjectPrefix')
}
},
url: '/api/v1/settings/setting/'
url: '/api/v1/settings/setting/?category=basic'
}
},
methods: {
cleanFormValue(data) {
return {
basic: data
}
},
getMethod() {
return 'put'
}

View File

@@ -1,13 +1,8 @@
<template>
<IBox>
<GenericCreateUpdateForm
:fields="selectFields"
:fields="fields"
:url="url"
:initial="object"
:update-success-next-route="successUrl"
:clean-form-value="cleanFormValue"
:object.sync="object"
:fields-meta="fieldsMeta"
:get-method="getMethod"
:more-buttons="moreButtons"
:has-detail-in-msg="false"
@@ -19,7 +14,6 @@
import GenericCreateUpdateForm from '@/layout/components/GenericCreateUpdateForm'
import { testEmailSetting } from '@/api/settings'
import { IBox } from '@/components'
import { Required } from '@/components/DataForm/rules'
export default {
name: 'Email',
@@ -27,59 +21,37 @@ export default {
GenericCreateUpdateForm,
IBox
},
props: {
object: {
type: Object,
default: null
}
},
data() {
const vm = this
return {
selectFields: [[this.$t('common.BasicInfo'), ['EMAIL_HOST', 'EMAIL_PORT', 'EMAIL_HOST_USER', 'EMAIL_HOST_PASSWORD',
'EMAIL_FROM', 'EMAIL_RECIPIENT', 'EMAIL_USE_SSL', 'EMAIL_USE_TLS']]],
successUrl: { name: 'Settings', params: { activeMenu: 'Email' }},
fieldsMeta: {
EMAIL_HOST: {
label: this.$t('setting.emailHost'),
rules: [Required]
},
EMAIL_PORT: {
label: this.$t('setting.emailPort'),
rules: [Required]
},
EMAIL_HOST_USER: {
label: this.$t('setting.emailHostUser'),
rules: [Required]
},
EMAIL_HOST_PASSWORD: {
label: this.$t('setting.emailHostPassword'),
helpText: this.$t('setting.helpText.emailHostPassword'),
type: 'input',
el: {
type: 'password'
}
},
EMAIL_FROM: {
label: this.$t('setting.emailEmailFrom'),
helpText: this.$t('setting.helpText.emailEmailFrom')
},
EMAIL_RECIPIENT: {
label: this.$t('setting.emailRecipient'),
helpText: this.$t('setting.helpText.emailRecipient')
},
EMAIL_USE_SSL: {
label: this.$t('setting.emailUserSSL'),
type: 'checkbox',
helpTips: this.$t('setting.helpTip.emailUserSSL')
},
EMAIL_USE_TLS: {
label: this.$t('setting.emailUserTLS'),
type: 'checkbox',
helpTips: this.$t('setting.helpTip.emailUserTLS')
}
},
url: '/api/v1/settings/setting/',
fields: [
[
this.$t('common.BasicInfo'),
[
'EMAIL_HOST', 'EMAIL_PORT', 'EMAIL_HOST_USER',
'EMAIL_HOST_PASSWORD'
]
],
[
this.$t('setting.Security'),
[
'EMAIL_USE_SSL', 'EMAIL_USE_TLS'
]
],
[
this.$t('setting.MailSend'),
[
'EMAIL_FROM', 'EMAIL_SUBJECT_PREFIX'
]
],
[
this.$t('common.Other'),
[
'EMAIL_RECIPIENT'
]
]
],
url: '/api/v1/settings/setting/?category=email',
moreButtons: [
{
title: this.$t('setting.emailTest'),
@@ -98,14 +70,6 @@ export default {
}
},
methods: {
cleanFormValue(data) {
if (data['EMAIL_HOST_PASSWORD'] === '') {
delete data['EMAIL_HOST_PASSWORD']
}
return {
email: data
}
},
getMethod() {
return 'put'
}

View File

@@ -3,10 +3,6 @@
<GenericCreateUpdateForm
:fields="selectFields"
:url="url"
:initial="object"
:update-success-next-route="successUrl"
:clean-form-value="cleanFormValue"
:object="object"
:fields-meta="fieldsMeta"
:get-method="getMethod"
:has-detail-in-msg="false"
@@ -23,49 +19,30 @@ export default {
GenericCreateUpdateForm,
IBox
},
props: {
object: {
type: Object,
default: null
}
},
data() {
return {
selectFields: [
[this.$t('setting.createUserSetting'), ['EMAIL_CUSTOM_USER_CREATED_SUBJECT', 'EMAIL_CUSTOM_USER_CREATED_HONORIFIC',
'EMAIL_CUSTOM_USER_CREATED_BODY', 'EMAIL_CUSTOM_USER_CREATED_SIGNATURE']]
[
this.$t('setting.createUserSetting'),
[
'EMAIL_CUSTOM_USER_CREATED_SUBJECT', 'EMAIL_CUSTOM_USER_CREATED_HONORIFIC',
'EMAIL_CUSTOM_USER_CREATED_BODY', 'EMAIL_CUSTOM_USER_CREATED_SIGNATURE'
]
]
],
successUrl: { name: 'Settings', params: { activeMenu: 'EmailContent' }},
fieldsMeta: {
EMAIL_CUSTOM_USER_CREATED_SUBJECT: {
label: this.$t('setting.emailCustomUserCreatedSubject'),
helpText: this.$t('setting.helpText.emailCustomUserCreatedSubject')
},
EMAIL_CUSTOM_USER_CREATED_HONORIFIC: {
label: this.$t('setting.emailCustomUserCreatedHonorific'),
helpText: this.$t('setting.helpText.emailCustomUserCreatedHonorific')
},
EMAIL_CUSTOM_USER_CREATED_BODY: {
label: this.$t('setting.emailCustomUserCreatedBody'),
'EMAIL_CUSTOM_USER_CREATED_BODY': {
el: {
type: 'textarea'
},
helpText: this.$t('setting.helpText.emailCustomUserCreatedBody')
},
EMAIL_CUSTOM_USER_CREATED_SIGNATURE: {
label: this.$t('setting.emailCustomUserCreatedSignature'),
helpText: this.$t('setting.helpText.emailCustomUserCreatedSignature')
type: 'textarea',
rows: 3
}
}
},
url: '/api/v1/settings/setting/'
url: '/api/v1/settings/setting/?category=email_content'
}
},
methods: {
cleanFormValue(data) {
return {
email_content: data
}
},
getMethod() {
return 'put'
}

View File

@@ -1,13 +1,9 @@
<template>
<div v-if="!loading">
<div>
<IBox>
<GenericCreateUpdateForm
:fields="selectFields"
:url="url"
:initial="initialData"
:update-success-next-route="successUrl"
:clean-form-value="cleanFormValue"
:object="initialData"
:fields-meta="fieldsMeta"
:get-method="getMethod"
:more-buttons="moreButtons"
@@ -69,11 +65,12 @@
<script>
import Dialog from '@/components/Dialog'
import GenericCreateUpdateForm from '@/layout/components/GenericCreateUpdateForm'
import { testLdapSetting, testLdapUserLogin,
importLdapUser, refreshLdapUserCache, StartLdapUserCache } from '@/api/settings'
import {
testLdapSetting, testLdapUserLogin,
importLdapUser, refreshLdapUserCache, StartLdapUserCache
} from '@/api/settings'
import ListTable from '@/components/ListTable'
import { IBox } from '@/components'
import { Required } from '@/components/DataForm/rules'
export default {
name: 'Ldap',
@@ -83,12 +80,6 @@ export default {
IBox,
Dialog
},
props: {
object: {
type: Object,
default: null
}
},
data() {
return {
loading: true,
@@ -96,48 +87,34 @@ export default {
dialogVisible: false,
dialogLdapUserImport: false,
dialogLdapUserImportLoginStatus: false,
initialData: {},
selectFields: [[this.$t('common.BasicInfo'), ['AUTH_LDAP_SERVER_URI', 'AUTH_LDAP_BIND_DN', 'AUTH_LDAP_BIND_PASSWORD', 'AUTH_LDAP_SEARCH_OU',
'AUTH_LDAP_SEARCH_FILTER', 'AUTH_LDAP_USER_ATTR_MAP', 'AUTH_LDAP']]],
successUrl: { name: 'Settings', params: { activeMenu: 'Email' }},
selectFields: [
[
this.$t('setting.LDAPServerInfo'),
[
'AUTH_LDAP_SERVER_URI', 'AUTH_LDAP_BIND_DN', 'AUTH_LDAP_BIND_PASSWORD'
]
],
[
this.$t('setting.LDAPUser'),
[
'AUTH_LDAP_SEARCH_OU', 'AUTH_LDAP_SEARCH_FILTER', 'AUTH_LDAP_USER_ATTR_MAP'
]
],
[
this.$t('common.Other'),
[
'AUTH_LDAP'
]
]
],
fieldsMeta: {
AUTH_LDAP_SERVER_URI: {
label: this.$t('setting.authLdapServerUri'),
rules: [Required]
},
AUTH_LDAP_BIND_DN: {
label: this.$t('setting.authLdapBindDn')
},
AUTH_LDAP_BIND_PASSWORD: {
label: this.$t('setting.authLdapBindPassword'),
type: 'input',
el: {
type: 'password'
}
},
AUTH_LDAP_SEARCH_OU: {
label: this.$t('setting.authLdapSearchOu'),
helpText: this.$t('setting.helpText.authLdapSearchOu')
},
AUTH_LDAP_SEARCH_FILTER: {
label: this.$t('setting.authLdapSearchFilter'),
rules: [Required],
helpText: this.$t('setting.helpText.authLdapSearchFilter')
},
AUTH_LDAP_USER_ATTR_MAP: {
label: this.$t('setting.authLdapUserAttrMap'),
el: {
type: 'textarea'
},
rules: [Required],
helpText: this.$t('setting.helpText.authLdapUserAttrMap')
},
AUTH_LDAP: {
label: this.$t('setting.authLdap'),
type: 'checkbox'
}
}
},
url: '/api/v1/settings/setting/',
url: '/api/v1/settings/setting/?category=ldap',
moreButtons: [
{
title: this.$t('setting.ldapConnectTest'),

View File

@@ -1,5 +1,5 @@
<template>
<div v-if="!loading">
<div>
<TabPage :submenu="submenu" :active-menu.sync="activeMenu">
<keep-alive>
<component :is="activeMenu" :object="componentData" />
@@ -19,7 +19,6 @@ import Ldap from './Ldap'
import Terminal from './Terminal'
import Security from './Security'
import License from './License'
import { getSettings } from '@/api/settings'
export default {
components: {
IBox,
@@ -71,36 +70,14 @@ export default {
}
},
computed: {
Title() {
title() {
return this.$t('settings.setting')
},
componentData() {
switch (this.activeMenu) {
case 'Basic':
return this.basicData(this.settingsData)
case 'Email':
return this.emailData(this.settingsData)
case 'EmailContent':
return this.emailContentData(this.settingsData)
case 'Ldap':
return this.ldapData(this.settingsData)
case 'Terminal':
return this.terminalData(this.settingsData)
case 'Security':
return this.securityData(this.settingsData)
case 'License':
return {}
}
return this.basicData(this.settingsData)
return {}
}
},
mounted() {
getSettings().then(data => {
this.settingsData = data
this.initial()
this.loading = false
})
},
methods: {
initial() {
@@ -127,74 +104,10 @@ export default {
case 'License':
this.activeMenu = 'License'
break
default:
this.activeMenu = 'Basic'
break
}
},
basicData(data) {
const basic = data.basic
if (basic.SITE_URL === null) {
basic.SITE_URL = ''
}
if (basic.EMAIL_SUBJECT_PREFIX === null) {
basic.EMAIL_SUBJECT_PREFIX = ''
}
if (basic.USER_GUIDE_URL === null) {
basic.USER_GUIDE_URL = ''
}
return basic
},
emailData(data) {
const email = data.email
if (email.EMAIL_FROM === null) {
email.EMAIL_FROM = ''
}
if (email.EMAIL_RECIPIENT === null) {
email.EMAIL_RECIPIENT = ''
}
if (email.EMAIL_USE_TLS === null) {
email.EMAIL_USE_TLS = false
}
if (email.EMAIL_HOST === null) {
email.EMAIL_HOST = ''
}
if (email.EMAIL_HOST_USER === null) {
email.EMAIL_HOST_USER = ''
}
if (email.EMAIL_PORT === null) {
email.EMAIL_PORT = ''
}
if (email.EMAIL_USE_SSL === null) {
email.EMAIL_USE_SSL = false
}
return email
},
emailContentData(data) {
const email_content = data.email_content
if (email_content.EMAIL_CUSTOM_USER_CREATED_BODY === null) {
email_content.EMAIL_CUSTOM_USER_CREATED_BODY = ''
}
if (email_content.EMAIL_CUSTOM_USER_CREATED_HONORIFIC === null) {
email_content.EMAIL_CUSTOM_USER_CREATED_HONORIFIC = ''
}
if (email_content.EMAIL_CUSTOM_USER_CREATED_SIGNATURE === null) {
email_content.EMAIL_CUSTOM_USER_CREATED_SIGNATURE = ''
}
if (email_content.EMAIL_CUSTOM_USER_CREATED_SUBJECT === null) {
email_content.EMAIL_CUSTOM_USER_CREATED_SUBJECT = ''
}
return email_content
},
ldapData(data) {
return data.ldap
},
terminalData(data) {
return data.terminal
},
securityData(data) {
const security = data.security
if (security.SECURITY_COMMAND_EXECUTION === null) {
security.SECURITY_COMMAND_EXECUTION = false
}
return security
}
}
}