Skip to content

Commit

Permalink
Merge pull request #1 from GONGONGONG/feature/sys_api
Browse files Browse the repository at this point in the history
feature: 使用接口获取操作系统类型 (closed TencentBlueKing#230)
  • Loading branch information
iSecloud authored Nov 16, 2021
2 parents 8b540e6 + 9a4bbe6 commit 6fac268
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 39 deletions.
15 changes: 4 additions & 11 deletions frontend/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MainStore } from '@/store';

export interface IAuth {
id: string
name: string
Expand Down Expand Up @@ -34,17 +36,8 @@ const getAuthentication = () => {
}
return auths;
};
const getSysOptions = () => {
const options: {id: string, name: string }[] = [
{ id: 'WINDOWS', name: 'Windows' },
{ id: 'LINUX', name: 'Linux' },
];
if (window.PROJECT_CONFIG.BKAPP_RUN_ENV !== 'ce') {
options.push({ id: 'AIX', name: 'AIX' }, { id: 'SOLARIS', name: 'Solaris' });
}
return options;
};

export const authentication = getAuthentication();
export const defaultPort = window.PROJECT_CONFIG.DEFAULT_SSH_PORT ? Number(window.PROJECT_CONFIG.DEFAULT_SSH_PORT) : 22;
export const sysOptions = getSysOptions();
export const sysOptions = MainStore.osList;
export default authentication;
9 changes: 9 additions & 0 deletions frontend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const router = new VueRouter({
routes,
});

const loadOsRoute = ['agentSetup', 'agentImport', 'agentEdit'];
const cancelRequest = async () => {
const allRequest = http.queue.get() as any[];
const requestQueue = allRequest.filter(request => request.cancelWhenRouteChange);
Expand Down Expand Up @@ -72,6 +73,14 @@ const beforeRouterMethod = async (to: Route, next: any) => {
// 重置业务权限
MainStore.updateBizAction(authority ? authority.page : '');
await cancelRequest();
if (!MainStore.osList) {
if (loadOsRoute.includes(to.name)) {
const list = await MainStore.getOsList();
MainStore.updateOsList(list);
} else {
MainStore.getOsList().then(list => MainStore.updateOsList(list));
}
}
next();
};

Expand Down
6 changes: 2 additions & 4 deletions frontend/src/store/modules/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,8 @@ export default class AgentStore extends VuexModule {
* @param {*} params
*/
@Action
public async getFilterCondition() {
let data: ISearchItem[] = await getFilterCondition({
category: 'host',
}).catch(() => []);
public async getFilterCondition(category = 'host') {
let data: ISearchItem[] = await getFilterCondition({ category }).catch(() => []);
data = data.map((item) => {
if (item.children && item.children.length) {
item.multiable = true;
Expand Down
18 changes: 17 additions & 1 deletion frontend/src/store/modules/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Vue from 'vue';
import http from '@/api';
import navList from '@/router/navigation-config';
import { retrieveBiz, fetchTopo } from '@/api/modules/cmdb';
import { retrieveGlobalSettings } from '@/api/modules/meta';
import { retrieveGlobalSettings, getFilterCondition } from '@/api/modules/meta';
import { fetchPublicKeys } from '@/api/modules/rsa';
import {
fetchPermission,
Expand Down Expand Up @@ -65,6 +65,8 @@ export default class Main extends VuexModule {
// cache view
public cacheViews: string[] = [];
public routerBackName = '';
public osList: any = null;
public osMap: Dictionary = null;

// 公共 mutations
/**
Expand Down Expand Up @@ -274,6 +276,15 @@ export default class Main extends VuexModule {
public updateRouterBackName(name = '') {
this.routerBackName = name;
}
@Mutation
public updateOsList(list = []) {
this.osList = list;
this.osMap = list.reduce((map, item) => {
map[item.id] = item.name;
return map;
}, {});
}

/**
* 获取用户信息
*
Expand Down Expand Up @@ -379,4 +390,9 @@ export default class Main extends VuexModule {
const data: IKeyItem[] = await fetchPublicKeys(params).catch(() => []);
return data.find(item => item.name === 'DEFAULT') || {};
}
@Action
public async getOsList(category = 'os_type'): Promise<Dictionary> {
const res = await getFilterCondition({ category }).catch(() => []);
return res || [];
}
}
2 changes: 1 addition & 1 deletion frontend/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface IAuthApply {
}

export type RequestMethods = 'delete' | 'get' | 'head' | 'post' | 'put' | 'patch';
export type IOs = 'LINUX' | 'WINDOWS' | 'AIX';
export type IOs = 'LINUX' | 'WINDOWS' | 'AIX' | 'SOLARIS';

export interface IUserConfig {
// http 请求默认 id
Expand Down
9 changes: 3 additions & 6 deletions frontend/src/views/agent/agent-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -691,12 +691,6 @@ export default class AgentList extends Mixins(pollMixin, TableHeaderMixins, auth
terminated: this.$t('异常'),
unknown: this.$t('未知'),
};
private osMap = {
LINUX: 'Linux',
WINDOWS: 'Windows',
AIX: 'AIX',
SOLARIS: 'Solaris',
};
// 批量操作
private operate: IOperateItem[] = [
{
Expand Down Expand Up @@ -768,6 +762,9 @@ export default class AgentList extends Mixins(pollMixin, TableHeaderMixins, auth
private operateBiz: IBizValue[] =[]; // 有操作权限的业务
private cloudAgentNum = 0; // 从云区域点击跳转过来的主机数量,区分是否因为权限问题看不到主机
private get osMap() {
return MainStore.osMap;
}
private get fontSize() {
return MainStore.fontSize;
}
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/views/plugin/plugin-list/plugin-list-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,6 @@ export default class PluginRuleTable extends Mixins(FormLabelMixin, HeaderRender
private currentHostId = -1;
private currentHostStatus = '';
private showSlider = false;
private osMap = {
LINUX: 'Linux',
WINDOWS: 'Windows',
AIX: 'AIX',
};
// 本地存储Key
private localMark = 'plugin_list_table';
private filterField: ITabelFliter[] = [];
Expand All @@ -220,6 +215,9 @@ export default class PluginRuleTable extends Mixins(FormLabelMixin, HeaderRender
failed: this.$t('异常'), // 失败
};
private get osMap() {
return MainStore.osMap;
}
private get selectionCount() {
if (this.checkType === 'current') {
return this.selections.length;
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/views/plugin/plugin-list/plugin-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,6 @@ export default class PluginList extends Mixins(HeaderFilterMixins) {
private runningCount = 0;
private checkValue: CheckValueEnum = 0;
private hasOldRouteParams = false;
private osMap = {
LINUX: 'Linux',
WINDOWS: 'Windows',
AIX: 'AIX',
};
private strategyValue: Array<number | string> = []; // 插件id number, 策略名称 string
private sortData: ISortData = {
head: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,16 @@ export default class PerformPreview extends Mixins(HeaderRenderMixin, HeaderFilt
head: '',
sort_type: '',
};
private osMap: Dictionary = {
LINUX: 'Linux',
WINDOWS: 'Windows',
AIX: 'AIX',
};
private statusMap = {
running: window.i18n.t('正常'),
terminated: window.i18n.t('异常'),
not_installed: window.i18n.t('未安装'),
};
public filterData: ISearchItem[] = [];
private get osMap() {
return MainStore.osMap;
}
private get statisticsList() {
return [
{ id: 'running', count: this.runningNum, path: '正常agent个数' },
Expand Down

0 comments on commit 6fac268

Please sign in to comment.