Skip to content

Commit

Permalink
feat: IDC自动判断安装通道,更新直连区域机器的安装通道id
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 17725
  • Loading branch information
hyunfa authored and wyyalt committed Sep 10, 2024
1 parent 3335ce9 commit ec9f19c
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 9 deletions.
4 changes: 3 additions & 1 deletion frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/store/modules/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion frontend/src/store/modules/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 是否显示
Expand Down Expand Up @@ -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;
}

/**
* 获取用户信息
Expand Down Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions frontend/src/types/cloud/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
21 changes: 21 additions & 0 deletions frontend/src/views/agent/agent-setup/agent-import.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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';
}
}
});
}
}
/**
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/views/agent/agent-setup/agent-setup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/views/agent/components/create-excel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('密码'),
Expand All @@ -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: '',
Expand All @@ -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('密码'),
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/views/agent/config/editTableConfig.ts
Original file line number Diff line number Diff line change
@@ -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[] = [
Expand Down Expand Up @@ -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;
},
},
Expand Down

0 comments on commit ec9f19c

Please sign in to comment.