diff --git a/src/components/AccountCreateUpdateForm/index.vue b/src/components/AccountCreateUpdateForm/index.vue index 2b968a9fb..9c316f29f 100644 --- a/src/components/AccountCreateUpdateForm/index.vue +++ b/src/components/AccountCreateUpdateForm/index.vue @@ -14,6 +14,7 @@ import Select2 from '@/components/FormFields/Select2' import AssetSelect from '@/components/AssetSelect' import { encryptPassword } from '@/utils/crypto' import { Required, RequiredChange } from '@/components/DataForm/rules' +import AutomationParamsForm from '@/views/assets/Platform/AutomationParamsSetting.vue' export default { name: 'AccountCreateForm', @@ -69,7 +70,7 @@ export default { 'secret_type', 'secret', 'ssh_key', 'token', 'access_key', 'passphrase' ]], - [this.$t('common.Other'), ['push_now', 'on_invalid', 'is_active', 'comment']] + [this.$t('common.Other'), ['push_now', 'params', 'on_invalid', 'is_active', 'comment']] ], fieldsMeta: { assets: { @@ -206,6 +207,21 @@ export default { return !automation.push_account_enabled || !automation.ansible_enabled || !this.$hasPerm('accounts.push_account') || this.addTemplate } }, + params: { + label: this.$t('assets.PushParams'), + component: AutomationParamsForm, + el: { + method: this.asset?.auto_config?.push_account_method + }, + hidden: (formValue) => { + const automation = this.iPlatform.automation || {} + return !formValue.push_now || + !automation.push_account_enabled || + !automation.ansible_enabled || + !this.$hasPerm('accounts.push_account') || + this.addTemplate + } + }, comment: { hidden: () => { return this.addTemplate diff --git a/src/components/FormFields/DynamicInput.vue b/src/components/FormFields/DynamicInput.vue new file mode 100644 index 000000000..3248f3214 --- /dev/null +++ b/src/components/FormFields/DynamicInput.vue @@ -0,0 +1,83 @@ + + + + + diff --git a/src/components/FormFields/index.js b/src/components/FormFields/index.js index 0f4d0fabf..eb69b3167 100644 --- a/src/components/FormFields/index.js +++ b/src/components/FormFields/index.js @@ -9,6 +9,7 @@ import PhoneInput from './PhoneInput' import UploadField from './UploadField' import UpdateToken from './UpdateToken' import UserPassword from './UserPassword' +import DynamicInput from './DynamicInput' import PasswordInput from './PasswordInput' import UploadSecret from './UploadSecret' import WeekCronSelect from './WeekCronSelect' @@ -27,6 +28,7 @@ export default { PhoneInput, UploadField, UserPassword, + DynamicInput, PasswordInput, UploadSecret, WeekCronSelect, @@ -46,6 +48,7 @@ export { PhoneInput, UploadField, UserPassword, + DynamicInput, PasswordInput, UploadSecret, WeekCronSelect, diff --git a/src/i18n/langs/en.json b/src/i18n/langs/en.json index 45b0b4dc8..f830583cb 100644 --- a/src/i18n/langs/en.json +++ b/src/i18n/langs/en.json @@ -86,7 +86,7 @@ "AccountPushExecutionList": "Execution list", "AccountPushCreate": "Account push create", "AccountPushUpdate": "Account push update", - "AutoPushHelpText": "Please select an asset or node before setting it up", + "AutoPushHelpText": "The push parameter settings are currently only effective for assets with a platform type of host.", "AccountPushList": "Account push list" }, "AccountBackup": { @@ -359,7 +359,8 @@ "Protocols": "Protocols", "PublicIp": "Public ip", "Push": "Push", - "PushSetting": "Push setting", + "PushParams": "Push params", + "ChangeSecretParams": "Change secret params", "PushSystemUserNow": "Push system user now", "PushAllSystemUsersToAsset": "Push all system users to asset", "QuickUpdate": "Quick update", diff --git a/src/i18n/langs/ja.json b/src/i18n/langs/ja.json index 2aef75aaf..fc9890b59 100644 --- a/src/i18n/langs/ja.json +++ b/src/i18n/langs/ja.json @@ -86,7 +86,7 @@ "AccountPushExecutionList": "実行リスト", "AccountPushCreate": "アカウントのプッシュ作成", "AccountPushUpdate": "アカウントプッシュ更新", - "AutoPushHelpText": "まず資産またはノードを選択して設定してください", + "AutoPushHelpText": "Pushパラメータの設定は、プラットフォームの種類がホストである資産に対してのみ有効です。", "AccountPushList": "アカウントプッシュ" }, "AccountBackup": { @@ -353,7 +353,8 @@ "LoginOption": "ログインオプション", "PublicIp": "パブリックネットワークIP", "Push": "プッシュ", - "PushSetting": "プッシュ設定", + "PushParams": "プッシュパラメータ", + "ChangeSecretParams": "改密パラメータです", "PushSystemUserNow": "プッシュシステムユーザー", "PushAllSystemUsersToAsset": "すべてのシステムユーザーをアセットにプッシュ", "QuickUpdate": "クイックアップデート", diff --git a/src/i18n/langs/zh.json b/src/i18n/langs/zh.json index 869bd45f7..28183aaed 100644 --- a/src/i18n/langs/zh.json +++ b/src/i18n/langs/zh.json @@ -21,7 +21,7 @@ "AccountPushList": "账号推送", "AccountPushCreate": "账号推送创建", "AccountPushUpdate": "账号推送更新", - "AutoPushHelpText": "请先选择资产或者节点在进行设置", + "AutoPushHelpText": "推送参数设置,目前仅对平台种类为主机的资产生效。", "AccountPushExecutionList": "执行列表" }, "AccountBackup": { @@ -371,7 +371,8 @@ "LoginOption": "登录选项", "PublicIp": "公网IP", "Push": "推送", - "PushSetting": "推送设置", + "PushParams": "推送参数", + "ChangeSecretParams": "改密参数", "PushSystemUserNow": "推送系统用户", "PushAllSystemUsersToAsset": "推送所有系统用户到资产", "QuickUpdate": "快速更新", diff --git a/src/views/accounts/Account/AccountDetail/Detail.vue b/src/views/accounts/Account/AccountDetail/Detail.vue index 88c3719c7..be5021e1d 100644 --- a/src/views/accounts/Account/AccountDetail/Detail.vue +++ b/src/views/accounts/Account/AccountDetail/Detail.vue @@ -11,6 +11,13 @@ :url="secretUrl" :visible.sync="showViewSecretDialog" /> + @@ -20,12 +27,14 @@ import AutoDetailCard from '@/components/DetailCard/auto' import QuickActions from '@/components/QuickActions' import ViewSecret from '@/components/AccountListTable/ViewSecret' import { openTaskPage } from '@/utils/jms' +import AutomationParamsForm from '@/views/assets/Platform/AutomationParamsSetting.vue' export default { name: 'Detail', components: { AutoDetailCard, QuickActions, + AutomationParamsForm, ViewSecret }, props: { @@ -39,6 +48,8 @@ export default { const filterSuFrom = ['database', 'device', 'cloud', 'web', 'windows'] return { + needSetAutoPushParams: false, + autoPushVisible: false, secretUrl: `/api/v1/accounts/account-secrets/${this.object.id}/`, showViewSecretDialog: false, quickActions: [ @@ -117,12 +128,16 @@ export default { }, callbacks: Object.freeze({ click: () => { - this.$axios.post( - `/api/v1/accounts/accounts/tasks/`, - { action: 'push', accounts: [this.object.id] } - ).then(res => { - openTaskPage(res['task']) - }) + if (this.needSetAutoPushParams) { + this.autoPushVisible = true + } else { + this.$axios.post( + `/api/v1/accounts/accounts/tasks/`, + { action: 'push', accounts: [this.object.id] } + ).then(res => { + openTaskPage(res['task']) + }) + } } }) }, @@ -205,6 +220,26 @@ export default { } }, computed: { + pushAccountMethod() { + return this.object.asset?.auto_config?.push_account_method || '' + } + }, + methods: { + onCanSetting(item) { + this.needSetAutoPushParams = item + }, + onSubmit(form) { + this.$axios.post( + `/api/v1/accounts/accounts/tasks/`, + { + action: 'push', + accounts: [this.object.id], + params: form + } + ).then(res => { + openTaskPage(res['task']) + }) + } } } diff --git a/src/views/accounts/AccountPush/AccountAutoPush.vue b/src/views/accounts/AccountPush/AccountAutoPush.vue index ad1302238..615b52469 100644 --- a/src/views/accounts/AccountPush/AccountAutoPush.vue +++ b/src/views/accounts/AccountPush/AccountAutoPush.vue @@ -12,7 +12,7 @@ v-if="visible" width="60%" :visible.sync="visible" - :title="$tc('assets.AutoPush')" + :title="title" :show-cancel="false" :show-confirm="false" :destroy-on-close="true" @@ -43,6 +43,12 @@ export default { type: Object, default: () => ({}) }, + title: { + type: String, + default: function() { + return this.$t('assets.PushParams') + } + }, assets: { type: Array, default: () => [] @@ -117,9 +123,10 @@ export default { const platforms = await this.getFilterPlatforms() let pushAccountMethods = platforms.map(i => i.automation?.push_account_method) pushAccountMethods = _.uniq(pushAccountMethods) - this.setFormConfig(pushAccountMethods) - - if (pushAccountMethods.length > 0) { + // 检测是否有可设置的推送方式 + const hasCanSettingPushMethods = _.intersection(pushAccountMethods, Object.keys(this.remoteMeta)) + this.setFormConfig(hasCanSettingPushMethods) + if (hasCanSettingPushMethods.length > 0) { this.isDisabled = false this.$emit('input', this.form) } else { @@ -134,27 +141,25 @@ export default { this.config.fields = [] for (const method of methods) { - const filterField = this.remoteMeta[method] - if (filterField) { - // 修改资产、节点时不点击设置按钮也需要获取form表单值暴露出去 - if (this.form.hasOwnProperty(method)) { - newForm[method] = this.form[method] - } - fields.push([method, [method]]) - fieldsMeta[method] = { - fields: [], - fieldsMeta: {} - } - if (Object.keys(filterField?.children || {}).length > 0) { - for (const [k, v] of Object.entries(filterField.children)) { - const item = { - ...v, - type: 'input' - } - delete item.default - fieldsMeta[method].fields.push(k) - fieldsMeta[method].fieldsMeta[k] = item + const filterField = this.remoteMeta[method] || {} + // 修改资产、节点时不点击设置按钮也需要获取form表单值暴露出去 + if (this.form.hasOwnProperty(method)) { + newForm[method] = this.form[method] + } + fields.push([filterField.label, [method]]) + fieldsMeta[method] = { + fields: [], + fieldsMeta: {} + } + if (Object.keys(filterField?.children || {}).length > 0) { + for (const [k, v] of Object.entries(filterField.children)) { + const item = { + ...v, + type: 'input' } + delete item.default + fieldsMeta[method].fields.push(k) + fieldsMeta[method].fieldsMeta[k] = item } } } diff --git a/src/views/accounts/AccountPush/AccountPushCreateUpdate.vue b/src/views/accounts/AccountPush/AccountPushCreateUpdate.vue index ba84d311a..66d168151 100644 --- a/src/views/accounts/AccountPush/AccountPushCreateUpdate.vue +++ b/src/views/accounts/AccountPush/AccountPushCreateUpdate.vue @@ -97,7 +97,7 @@ export default { }, params: { component: AccountAutoPush, - label: this.$t('assets.AutoPush'), + label: this.$t('assets.PushParams'), el: { assets: this.asset_ids, nodes: this.node_ids diff --git a/src/views/assets/Platform/AutomationParamsSetting.vue b/src/views/assets/Platform/AutomationParamsSetting.vue index 31d7f695b..333cb9347 100644 --- a/src/views/assets/Platform/AutomationParamsSetting.vue +++ b/src/views/assets/Platform/AutomationParamsSetting.vue @@ -1,18 +1,20 @@