From 93d8d0f5bf8aedea8ed0ced6b37574ba4a0aaee3 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 20 Sep 2022 17:32:58 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/asset.js | 2 +- src/store/modules/assets.js | 12 +++---- .../assets/Platform/PlatformCreateUpdate.vue | 32 ++++--------------- src/views/assets/Platform/PlatformList.vue | 4 +-- 4 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/api/asset.js b/src/api/asset.js index 0a30522a5..f541815ee 100644 --- a/src/api/asset.js +++ b/src/api/asset.js @@ -42,7 +42,7 @@ export function getCommandFilterList(data) { export function getCategoryTypes() { return request({ - url: '/api/v1/assets/platforms/categories/', + url: '/api/v1/assets/categories/', method: 'get' }) } diff --git a/src/store/modules/assets.js b/src/store/modules/assets.js index 67d884c08..31895ce95 100644 --- a/src/store/modules/assets.js +++ b/src/store/modules/assets.js @@ -11,8 +11,8 @@ const mutations = { state.assetCategories = categories const toOption = (choice) => { return { - label: choice['display_name'], - value: choice['value'] + label: choice['name'], + value: choice['id'] } } state.assetCategoriesCascader = categories.map((item) => { @@ -27,14 +27,14 @@ const mutations = { for (const category of categories) { category.children.forEach((type, index) => { const option = { - name: type.value, - title: type.display_name, + name: type.id, + title: type.name, type: 'primary', - category: category.value, + category: category.id, has: true } if (index === 0) { - option.group = category.display_name + option.group = category.name } dropdown.push(option) }) diff --git a/src/views/assets/Platform/PlatformCreateUpdate.vue b/src/views/assets/Platform/PlatformCreateUpdate.vue index 03c479460..ea48391ef 100644 --- a/src/views/assets/Platform/PlatformCreateUpdate.vue +++ b/src/views/assets/Platform/PlatformCreateUpdate.vue @@ -41,7 +41,6 @@ export default { [this.$t('common.Basic'), [ 'name', 'category_type', 'charset', 'domain_enabled' ]], - ['网络设备', ['brand']], ['配置', [ 'protocols_enabled', 'protocols', 'su_enabled', 'su_method' @@ -145,7 +144,7 @@ export default { async setConstraints() { const category = this.$route.query.category const type = this.$route.query.type - const url = `/api/v1/assets/platforms/type-constraints/?category=${category}&type=${type}` + const url = `/api/v1/assets/categories/constraints/?category=${category}&type=${type}` const constraints = await this.$axios.get(url) const fieldsCheck = ['protocols_enabled', 'domain_enabled', 'su_enabled'] @@ -157,15 +156,10 @@ export default { } _.set(this.fieldsMeta, `${field}.el.disabled`, disabled) } - this.fieldsMeta.protocols.el.choices = constraints['protocols'] || [] - this.fieldsMeta.brand.hidden = () => constraints['brand_enabled'] !== true - await this.setAutomationMethods(constraints) + await this.setAutomations(constraints['automation']) }, - async setAutomationMethods(constraints) { - const category = this.$route.query.category - const type = this.$route.query.type - const allMethods = await this.$axios.get('/api/v1/assets/platforms/ops-methods/') || [] + async setAutomations(automation) { const autoFieldsMeta = this.fieldsMeta.automation.fieldsMeta const autoFields = this.fieldsMeta.automation.fields .filter(item => item.endsWith('_method')) @@ -175,36 +169,24 @@ export default { for (const item of autoFields) { const itemEnabled = item + '_enabled' const itemMethod = item + '_method' - const itemConstraint = constraints[itemEnabled] + const itemConstraint = automation[itemEnabled] // 设置隐藏和disabled if (itemConstraint === false) { _.set(autoFieldsMeta, `${itemEnabled}.el.disabled`, true) } if (!autoFieldsMeta[itemMethod]?.hidden) { - _.set(autoFieldsMeta, `${itemMethod}.hidden`, (formValue) => !formValue[itemEnabled]) - } - // 设置默认值 - if (initial[itemEnabled] === undefined) { initial[itemEnabled] = false + _.set(autoFieldsMeta, `${itemMethod}.hidden`, (formValue) => !formValue[itemEnabled]) } // 设置 method 类型和 options if (_.get(autoFieldsMeta, `${itemMethod}.type`) === undefined) { _.set(autoFieldsMeta, `${itemMethod}.type`, 'select') } - const methods = allMethods.filter(method => { - const ok = method['method'] === item && method['category'] === category - const tpOk = method['type'].indexOf(type) > -1 || - method['type'].indexOf('all') > -1 - return ok & tpOk - }).map(method => { + const methods = automation[itemMethod + 's'] || [] + autoFieldsMeta[itemMethod].options = methods.map(method => { return { value: method['id'], label: method['name'] } }) - if (methods.length > 0) { - const itemMethod = itemEnabled.replace('_enabled', '_method') - autoFieldsMeta[itemMethod].options = methods - } } - console.log('Automation fields meta: ', this.fieldsMeta.automation) } } } diff --git a/src/views/assets/Platform/PlatformList.vue b/src/views/assets/Platform/PlatformList.vue index 6b0a75f3f..5b8b90fc3 100644 --- a/src/views/assets/Platform/PlatformList.vue +++ b/src/views/assets/Platform/PlatformList.vue @@ -121,8 +121,8 @@ export default { const state = await this.$store.dispatch('assets/getAssetCategories') this.tab.submenu = state.assetCategories.map(item => { return { - title: item.display_name, - name: item.value + title: item.name, + name: item.id } }) }