mirror of
https://github.com/jumpserver/lina.git
synced 2025-09-19 01:11:07 +00:00
perf: 解决 form group 不隐藏的问题
This commit is contained in:
@@ -1,20 +1,24 @@
|
|||||||
<template>
|
<template>
|
||||||
<DataForm
|
<DataForm
|
||||||
|
v-if="!loading"
|
||||||
ref="dataForm"
|
ref="dataForm"
|
||||||
v-loading="loading"
|
|
||||||
:fields="totalFields"
|
:fields="totalFields"
|
||||||
:form="iForm"
|
:form="iForm"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
v-on="$listeners"
|
v-on="$listeners"
|
||||||
>
|
>
|
||||||
<FormGroupHeader
|
<span
|
||||||
v-for="(group, i) in groups"
|
v-for="(group, i) in groups"
|
||||||
:slot="'id:'+group.name"
|
:slot="'id:'+group.name"
|
||||||
:key="'group-'+group.name"
|
:key="'group-'+group.name"
|
||||||
|
>
|
||||||
|
<FormGroupHeader
|
||||||
|
v-if="!groupHidden(group, i)"
|
||||||
:group="group"
|
:group="group"
|
||||||
:index="i"
|
:index="i"
|
||||||
:line="i !== 0"
|
:line="i !== 0"
|
||||||
/>
|
/>
|
||||||
|
</span>
|
||||||
</DataForm>
|
</DataForm>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -66,16 +70,16 @@ export default {
|
|||||||
this.optionUrlMetaAndGenerateColumns()
|
this.optionUrlMetaAndGenerateColumns()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
optionUrlMetaAndGenerateColumns() {
|
async optionUrlMetaAndGenerateColumns() {
|
||||||
this.$store.dispatch('common/getUrlMeta', { url: this.url }).then(data => {
|
let data = { actions: {}}
|
||||||
|
if (this.url) {
|
||||||
|
data = await this.$store.dispatch('common/getUrlMeta', { url: this.url })
|
||||||
|
}
|
||||||
this.remoteMeta = data.actions[this.method.toUpperCase()] || {}
|
this.remoteMeta = data.actions[this.method.toUpperCase()] || {}
|
||||||
this.generateColumns()
|
this.generateColumns()
|
||||||
this.cleanFormValue()
|
this.cleanFormValue()
|
||||||
}).catch(err => {
|
|
||||||
this.$log.error(err)
|
|
||||||
}).finally(() => {
|
|
||||||
this.loading = false
|
this.loading = false
|
||||||
})
|
console.log('Loading: ', this.groups)
|
||||||
},
|
},
|
||||||
generateColumns() {
|
generateColumns() {
|
||||||
const generator = new FormFieldGenerator()
|
const generator = new FormFieldGenerator()
|
||||||
@@ -114,6 +118,18 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
field.attrs.error = error
|
field.attrs.error = error
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
groupHidden(group, i) {
|
||||||
|
for (const field of group.fields) {
|
||||||
|
let hidden = field.hidden
|
||||||
|
if (typeof hidden === 'function') {
|
||||||
|
hidden = hidden(this.iForm)
|
||||||
|
}
|
||||||
|
if (!hidden) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -148,13 +148,15 @@ export class FormFieldGenerator {
|
|||||||
}
|
}
|
||||||
generateFieldGroup(field, fieldsMeta, remoteFieldsMeta) {
|
generateFieldGroup(field, fieldsMeta, remoteFieldsMeta) {
|
||||||
const [groupTitle, fields] = field
|
const [groupTitle, fields] = field
|
||||||
this.groups.push({
|
const _fields = this.generateFields(fields, fieldsMeta, remoteFieldsMeta)
|
||||||
|
const group = {
|
||||||
id: groupTitle,
|
id: groupTitle,
|
||||||
title: groupTitle,
|
title: groupTitle,
|
||||||
name: fields[0],
|
fields: _fields,
|
||||||
fields: fields
|
name: _fields[0].id
|
||||||
})
|
}
|
||||||
return this.generateFields(fields, fieldsMeta, remoteFieldsMeta)
|
this.groups.push(group)
|
||||||
|
return _fields
|
||||||
}
|
}
|
||||||
generateFields(_fields, fieldsMeta, remoteFieldsMeta) {
|
generateFields(_fields, fieldsMeta, remoteFieldsMeta) {
|
||||||
let fields = []
|
let fields = []
|
||||||
|
@@ -3,19 +3,21 @@
|
|||||||
<el-table :data="accounts" style="width: 100%">
|
<el-table :data="accounts" style="width: 100%">
|
||||||
<el-table-column prop="username" label="用户名" width="180" />
|
<el-table-column prop="username" label="用户名" width="180" />
|
||||||
<el-table-column prop="privileged" label="特权账号">
|
<el-table-column prop="privileged" label="特权账号">
|
||||||
<template slot-scope="scope">
|
<template v-slot="scope">
|
||||||
<i class="fa text-primary" :class="scope.row['privileged'] ? 'fa-check' : ''" />
|
<i class="fa text-primary" :class="scope.row['privileged'] ? 'fa-check' : ''" />
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column fixed="right" align="right" label="操作" width="135" class-name="buttons">
|
<el-table-column fixed="right" align="right" label="操作" width="135" class-name="buttons">
|
||||||
<template slot-scope="scope">
|
<template v-slot="scope">
|
||||||
<el-button type="danger" icon="el-icon-minus" size="mini" @click="removeAccount(scope.row)" />
|
<el-button type="danger" icon="el-icon-minus" size="mini" @click="removeAccount(scope.row)" />
|
||||||
<el-button type="primary" icon="el-icon-edit" size="mini" @click="onEditClick(scope.row)" />
|
<el-button type="primary" icon="el-icon-edit" size="mini" @click="onEditClick(scope.row)" />
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
|
<div class="actions">
|
||||||
<el-button size="mini" type="primary" @click="onAddClick">添加</el-button>
|
<el-button size="mini" type="primary" @click="onAddClick">添加</el-button>
|
||||||
<el-button size="mini" type="success" @click="onAddClick">模版添加</el-button>
|
<el-button size="mini" type="success" @click="onAddClick">模版添加</el-button>
|
||||||
|
</div>
|
||||||
<Dialog
|
<Dialog
|
||||||
v-if="visible"
|
v-if="visible"
|
||||||
:title="this.$tc('assets.AddAccount')"
|
:title="this.$tc('assets.AddAccount')"
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
<el-link :href="platformDetail" class="link-more" target="_blank">查看</el-link>
|
<el-link :href="platformDetail" class="link-more" target="_blank">查看</el-link>
|
||||||
<i class="fa fa-external-link" />
|
<i class="fa fa-external-link" />
|
||||||
</el-alert>
|
</el-alert>
|
||||||
<DataForm
|
<AutoDataForm
|
||||||
class="data-form"
|
class="data-form"
|
||||||
:form="form"
|
:form="form"
|
||||||
:disabled="iDisabled"
|
:disabled="iDisabled"
|
||||||
@@ -27,12 +27,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { Dialog, DataForm } from '@/components'
|
import { Dialog, AutoDataForm } from '@/components'
|
||||||
export default {
|
export default {
|
||||||
name: 'ProtocolSetting',
|
name: 'ProtocolSetting',
|
||||||
components: {
|
components: {
|
||||||
Dialog,
|
Dialog,
|
||||||
DataForm
|
AutoDataForm
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
item: {
|
item: {
|
||||||
@@ -46,19 +46,38 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
form: this.item.setting || {},
|
defaultSetting: {
|
||||||
|
required: false,
|
||||||
|
default: true,
|
||||||
|
is_active: true
|
||||||
|
},
|
||||||
|
loading: true,
|
||||||
|
form: {},
|
||||||
iDisabled: this.disabled,
|
iDisabled: this.disabled,
|
||||||
platformDetail: '#/console/assets/platforms/' + this.$route.query['platform'],
|
platformDetail: '#/console/assets/platforms/' + this.$route.query['platform'],
|
||||||
config: {
|
config: {
|
||||||
hasSaveContinue: false,
|
hasSaveContinue: false,
|
||||||
hasButtons: !this.disabled,
|
hasButtons: !this.disabled,
|
||||||
|
url: '',
|
||||||
fields: [
|
fields: [
|
||||||
|
[
|
||||||
|
'Hello', [
|
||||||
{
|
{
|
||||||
id: 'required',
|
id: 'required',
|
||||||
label: '必须配置',
|
label: '必须配置',
|
||||||
helpText: '资产上必须开启该协议',
|
helpText: '新建资产时,必须开启该协议',
|
||||||
type: 'switch'
|
type: 'switch'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'as_default',
|
||||||
|
label: '默认配置',
|
||||||
|
helpText: '新建资产时,默认配置',
|
||||||
|
type: 'switch'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Protocol', [
|
||||||
{
|
{
|
||||||
id: 'console',
|
id: 'console',
|
||||||
label: 'Console',
|
label: 'Console',
|
||||||
@@ -85,6 +104,8 @@ export default {
|
|||||||
hidden: () => this.item.name !== 'sftp'
|
hidden: () => this.item.name !== 'sftp'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -94,7 +115,8 @@ export default {
|
|||||||
this.$emit('update:visible', false)
|
this.$emit('update:visible', false)
|
||||||
},
|
},
|
||||||
onOpen() {
|
onOpen() {
|
||||||
this.form = this.item.setting
|
this.form = this.item.setting || this.defaultSetting
|
||||||
|
console.log('Item: ', this.item, this.form)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div v-for="(item, index) in items" :key="item.name" style="display: flex;margin-top: 8px;">
|
<div v-for="(item, index) in items" :key="item.name" style="display: flex;margin-top: 8px;">
|
||||||
<el-input v-model="item.port" class="input-with-select" v-bind="$attrs">
|
<el-input v-model="item.port" :placeholder="portPlaceholder" class="input-with-select" v-bind="$attrs">
|
||||||
<el-select
|
<el-select
|
||||||
slot="prepend"
|
slot="prepend"
|
||||||
v-model="item.name"
|
v-model="item.name"
|
||||||
@@ -89,6 +89,13 @@ export default {
|
|||||||
return this.choices.filter(proto => {
|
return this.choices.filter(proto => {
|
||||||
return this.selectedProtocolNames.indexOf(proto.name) === -1
|
return this.selectedProtocolNames.indexOf(proto.name) === -1
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
portPlaceholder() {
|
||||||
|
if (this.settingReadonly) {
|
||||||
|
return '端口'
|
||||||
|
} else {
|
||||||
|
return '默认端口'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="form-group-header">
|
<div class="form-group-header">
|
||||||
<div v-if="line" class="hr-line-dashed" />
|
<div v-if="line" class="hr-line-dashed" />
|
||||||
<h3>{{ group.title }}</h3>
|
<h3>{{ group['title'] }} </h3>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@@ -85,6 +85,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
protocols: {
|
protocols: {
|
||||||
|
label: '支持的协议',
|
||||||
...assetMeta.protocols,
|
...assetMeta.protocols,
|
||||||
el: {
|
el: {
|
||||||
choices: []
|
choices: []
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
<el-badge
|
<el-badge
|
||||||
v-if="props.tab === 'AssignedTicketList'"
|
v-if="props.tab === 'AssignedTicketList'"
|
||||||
slot="badge"
|
slot="badge"
|
||||||
slot-scope="props"
|
v-slot="props"
|
||||||
:value="getBadgeValue(props)"
|
:value="getBadgeValue(props)"
|
||||||
size="mini"
|
size="mini"
|
||||||
type="primary"
|
type="primary"
|
||||||
|
Reference in New Issue
Block a user