From ec9f19cbbbfd6baa9393e1e5e0769ad9c98872f4 Mon Sep 17 00:00:00 2001 From: hyunfa <1598047833@qq.com> Date: Fri, 26 Jul 2024 15:40:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20IDC=E8=87=AA=E5=8A=A8=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E9=80=9A=E9=81=93,=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9B=B4=E8=BF=9E=E5=8C=BA=E5=9F=9F=E6=9C=BA=E5=99=A8=E7=9A=84?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E9=80=9A=E9=81=93id=20#=20Reviewed,=20transa?= =?UTF-8?q?ction=20id:=2017725?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/App.vue | 4 +++- frontend/src/store/modules/cloud.ts | 18 ++++++++++++++-- frontend/src/store/modules/main.ts | 17 ++++++++++++++- frontend/src/types/cloud/cloud.ts | 5 +++++ .../views/agent/agent-setup/agent-import.vue | 21 +++++++++++++++++++ .../views/agent/agent-setup/agent-setup.vue | 3 ++- .../views/agent/components/create-excel.ts | 6 +++--- .../src/views/agent/config/editTableConfig.ts | 4 +++- 8 files changed, 69 insertions(+), 9 deletions(-) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 6fa31934b..0076a0318 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -87,7 +87,9 @@ export default class App extends Vue { setDocumentTitle(PlatformConfigStore.defaults.i18n); // 设置favicon setShortcutIcon(PlatformConfigStore.defaults.favicon); - this.setFavicon() + this.setFavicon(); + // 获取自动判断安装通道参数 + await MainStore.getAutoJudgeInstallChannel(); const platform = window.navigator.platform.toLowerCase(); if (platform.indexOf('win') === 0) { this.systemCls = 'win'; diff --git a/frontend/src/store/modules/cloud.ts b/frontend/src/store/modules/cloud.ts index 6d7505a97..5676c1823 100644 --- a/frontend/src/store/modules/cloud.ts +++ b/frontend/src/store/modules/cloud.ts @@ -9,9 +9,10 @@ import { listInstallChannel, updateInstallChannel, } from '@/api/modules/installchannel'; import { transformDataKey } from '@/common/util'; -import { ICloud, ICloudAuth, ICloudForm, ICloudSource, IProxyDetail, IChannel } from '@/types/cloud/cloud'; +import { ICloud, ICloudAuth, ICloudForm, ICloudSource, IProxyDetail, IChannel, IChannelAuto } from '@/types/cloud/cloud'; import { IAp } from '@/types/config/config'; import axios from 'axios'; +import { MainStore } from '@/store/index'; export const SET_CLOUD_AP = 'SET_CLOUD_AP'; export const SET_CLOUD_LIST = 'SET_CLOUD_LIST'; @@ -253,8 +254,21 @@ export default class CloudStore extends VuexModule { @Action public async getChannelList(params?: { 'bk_cloud_id': number }) { const list = await listInstallChannel(params).catch(() => []); + const autoChannel: IChannelAuto = { id: -1, name: window.i18n.t('自动选择') }; const defaultChannel = { id: 'default', name: window.i18n.t('默认通道') }; - this.store.commit('agent/setChannelList', [defaultChannel, ...list]); + const index = list.findIndex((data :any) => data.id === -1); + let listData; + if (index === -1) { + listData = [autoChannel, defaultChannel, ...list]; + } else { + listData = [...list.slice(0, index + 1), defaultChannel, ...list.slice(index + 1)]; + } + if (MainStore.AUTO_SELECT_INSTALL_CHANNEL === -1) { + listData = listData.filter((data :any) => data.id !== -1); + } else if (MainStore.AUTO_SELECT_INSTALL_CHANNEL === 1) { + listData[0].bk_cloud_id = window.PROJECT_CONFIG.DEFAULT_CLOUD; + } + this.store.commit('agent/setChannelList', listData); return list; } @Action diff --git a/frontend/src/store/modules/main.ts b/frontend/src/store/modules/main.ts index 616dedd51..3f7848fd7 100644 --- a/frontend/src/store/modules/main.ts +++ b/frontend/src/store/modules/main.ts @@ -70,6 +70,7 @@ export default class Main extends VuexModule { public osMap: Dictionary = {}; public installDefaultValues: Dictionary = {}; public noticeShow = false; + public AUTO_SELECT_INSTALL_CHANNEL = -1; /** * 设置全局可视区域的 loading 是否显示 @@ -290,7 +291,10 @@ export default class Main extends VuexModule { public updateNoticeShow(isShow: boolean) { this.noticeShow = isShow; } - + @Mutation + public setAutoJudge(val: number) { + this.AUTO_SELECT_INSTALL_CHANNEL = val; + } /** * 获取用户信息 @@ -424,4 +428,15 @@ export default class Main extends VuexModule { }); this.updateInstallDefaultValues(config); } + + /** + * 获取判断是否获取直连安装通道下拉选择数据的布尔字段AUTO_SELECT_INSTALL_CHANNEL_ONLY_DIRECT_AREA + * @param {*} param + */ + @Action + public async getAutoJudgeInstallChannel() { + const data = await retrieveGlobalSettings({ key: 'AUTO_SELECT_INSTALL_CHANNEL_ONLY_DIRECT_AREA' }).catch(() => ({})); + const dataValue = data.AUTO_SELECT_INSTALL_CHANNEL_ONLY_DIRECT_AREA === undefined ? -1 : Number(data.AUTO_SELECT_INSTALL_CHANNEL_ONLY_DIRECT_AREA); + this.setAutoJudge(dataValue); + } } diff --git a/frontend/src/types/cloud/cloud.ts b/frontend/src/types/cloud/cloud.ts index 873195cb6..8bc291b67 100644 --- a/frontend/src/types/cloud/cloud.ts +++ b/frontend/src/types/cloud/cloud.ts @@ -99,3 +99,8 @@ export interface IChannel { jump_servers: string[] upstream_servers: { [key: string]: string[] } } +export interface IChannelAuto { + id: number | string + name: string + bk_cloud_id?: number +} diff --git a/frontend/src/views/agent/agent-setup/agent-import.vue b/frontend/src/views/agent/agent-setup/agent-import.vue index 9a69332b7..29846c982 100644 --- a/frontend/src/views/agent/agent-setup/agent-import.vue +++ b/frontend/src/views/agent/agent-setup/agent-import.vue @@ -366,6 +366,15 @@ export default class AgentImport extends Mixins(mixin) { }); data = JSON.parse(JSON.stringify(formatData)); } + const channelFlag = MainStore.AUTO_SELECT_INSTALL_CHANNEL; + channelFlag !== -1 && data.forEach((item: ISetupRow) => { + if (channelFlag === 1) { + item.install_channel_id = item.bk_cloud_id === 0 ? -1 : 'default'; + } else if (channelFlag === 0) { + item.install_channel_id = -1; + } + }); + const filterData = data.filter(item => item.bk_cloud_id === 0); // 将原始的数据备份;切换安装方式时,接入点的数据变更后的回退操作时需要用到 this.tableDataBackup = data; this.setupInfo.data = deepClone(data); @@ -499,6 +508,18 @@ export default class AgentImport extends Mixins(mixin) { if (!this.isUploading && v && v.length) { this.tableDataBackup = v; this.setupInfo.data = deepClone(v); + const channelFlag = MainStore.AUTO_SELECT_INSTALL_CHANNEL; + this.setupInfo.data.forEach((item: ISetupRow) => { + if (!item.install_channel_id) { + if (channelFlag === 1) { + item.install_channel_id = item.bk_cloud_id === 0 ? -1 : 'default'; + } else if (channelFlag === 0) { + item.install_channel_id = -1; + } else { + item.install_channel_id = 'default'; + } + } + }); } } /** diff --git a/frontend/src/views/agent/agent-setup/agent-setup.vue b/frontend/src/views/agent/agent-setup/agent-setup.vue index ccf0f16e1..ab3423e37 100644 --- a/frontend/src/views/agent/agent-setup/agent-setup.vue +++ b/frontend/src/views/agent/agent-setup/agent-setup.vue @@ -290,7 +290,8 @@ export default class AgentSetup extends Mixins(mixin, formLabelMixin) { return isEmpty(this.formData.bk_cloud_id); } private get filterChannelList() { - return AgentStore.channelList.filter(item => item.id === 'default' || item.bk_cloud_id === this.formData.bk_cloud_id); + return AgentStore.channelList.filter(item => item.id === 'default' || item.bk_cloud_id === this.formData.bk_cloud_id + || (MainStore.AUTO_SELECT_INSTALL_CHANNEL === 0 && item.id === -1)); } @Watch('formData.ap_id') diff --git a/frontend/src/views/agent/components/create-excel.ts b/frontend/src/views/agent/components/create-excel.ts index a2fa72937..8ed8f9f8f 100644 --- a/frontend/src/views/agent/components/create-excel.ts +++ b/frontend/src/views/agent/components/create-excel.ts @@ -37,7 +37,7 @@ export const demoData = [ { inner_ip: '1.1.1.1', os_type: 'LINUX', - install_channel_id: 'default', + install_channel_id: '', port: '22', account: 'root', auth_type: window.i18n.t('密码'), @@ -54,7 +54,7 @@ export const demoData = [ { inner_ip: '1.1.1.2', os_type: 'WINDOWS', - install_channel_id: 'default', + install_channel_id: '', port: '445', account: 'test', auth_type: '', @@ -71,7 +71,7 @@ export const demoData = [ { inner_ip: '1.1.1.3', os_type: 'LINUX', - install_channel_id: 'default', + install_channel_id: '', port: '8080', account: 'root2', auth_type: window.i18n.t('密码'), diff --git a/frontend/src/views/agent/config/editTableConfig.ts b/frontend/src/views/agent/config/editTableConfig.ts index 5e8ca866e..f605c715d 100644 --- a/frontend/src/views/agent/config/editTableConfig.ts +++ b/frontend/src/views/agent/config/editTableConfig.ts @@ -1,6 +1,7 @@ import { ISetupHead, ISetupRow } from '@/types'; import { authentication, defaultPort, sysOptions, defaultOsType, getDefaultConfig, addressingMode, DHCP_FILTER_KEYS } from '@/config/config'; import { ICloudSource } from '@/types/cloud/cloud'; +import { MainStore } from '@/store/index'; import { reguFnMinInteger, reguPort, reguIPMixins, reguIp, reguIPv6 } from '@/common/form-check'; export const config: ISetupHead[] = [ @@ -55,7 +56,8 @@ export const config: ISetupHead[] = [ }, getOptions(row) { return row.bk_cloud_id || row.bk_cloud_id === 0 - ? this.channelList.filter(item => item.bk_cloud_id === row.bk_cloud_id || item.id === 'default') + ? this.channelList.filter(item => item.bk_cloud_id === row.bk_cloud_id || item.id === 'default' + || (MainStore.AUTO_SELECT_INSTALL_CHANNEL === 0 && item.id === -1)) : this.channelList; }, },