Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/hf2/feat/merge-ap-and-agen…
Browse files Browse the repository at this point in the history
…t' into _V2.4.X/dev_issue#1683_2.4.5_2_2_42
  • Loading branch information
ping15 committed Dec 16, 2024
2 parents 49adcc4 + 1bad054 commit e48ace7
Show file tree
Hide file tree
Showing 79 changed files with 6,145 additions and 847 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,8 @@ build.yml
## Helm
support-files/**/private_values.yaml
support-files/**/*.tgz
.codecc
.codecc
.idea
.vscode

pre-*-bkcodeai
1 change: 1 addition & 0 deletions frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ module.exports = {
rules: {
'@typescript-eslint/member-ordering': 'off',
'no-param-reassign': 'off',
'vue/camelcase': 'off',
},
};
33 changes: 33 additions & 0 deletions frontend/src/api/modules/pkg_manage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { request } from '../base';

export const listPackage = request('GET', 'api/agent/package/');
export const listPackageNew = request('POST', 'api/agent/package/search/{{pk}}');
export const updatePackage = request('PUT', 'api/agent/package/{{pk}}/');
export const deletePackage = request('DELETE', 'api/agent/package/{{pk}}/');
export const quickSearchCondition = request('GET', 'api/agent/package/quick_search_condition/');
export const uploadPackage = request('POST', 'api/agent/package/upload/');
export const parsePackage = request('POST', 'api/agent/package/parse/');
export const createAgentRegisterTask = request('POST', 'api/agent/package/create_register_task/');
export const queryAgentRegisterTask = request('GET', 'api/agent/package/query_register_task/');
export const getTags = request('GET', 'api/agent/package/tags/');
export const getVersion = request('POST', 'api/agent/package/version/');
export const getDeployedHostsCount = request('POST', 'api/agent/package/deployed_hosts_count/');
export const createAgentTags = request('POST', 'api/agent/package/create_agent_tags/');
export const versionCompare = request('POST', 'api/agent/package/version_compare/');

export default {
listPackage,
updatePackage,
listPackageNew,
deletePackage,
quickSearchCondition,
uploadPackage,
parsePackage,
createAgentRegisterTask,
queryAgentRegisterTask,
getTags,
getVersion,
getDeployedHostsCount,
createAgentTags,
versionCompare,
};
4 changes: 3 additions & 1 deletion frontend/src/common/demand-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Vue from 'vue';

import {
bkBadge, bkButton, bkCheckbox, bkCheckboxGroup, bkCol, bkCollapse, bkCollapseItem, bkContainer, bkDatePicker,
bkDialog, bkDropdownMenu, bkException, bkForm, bkFormItem, bkInfoBox, bkInput, bkLoading, bkMessage,
bkDialog, bkDropdownMenu, bkException, bkForm, bkFormItem, bkComposeFormItem,
bkInfoBox, bkInput, bkLoading, bkMessage,
bkNavigation, bkNavigationMenu, bkNavigationMenuItem, bkNotify, bkOption, bkOptionGroup, bkPagination,
bkPopover, bkProcess, bkProgress, bkRadio, bkRadioGroup, bkRoundProgress, bkRow, bkSearchSelect, bkSelect,
bkSideslider, bkSlider, bkSteps, bkSwitcher, bkTab, bkTabPanel, bkTable, bkTableColumn, bkTagInput, bkTimePicker,
Expand All @@ -31,6 +32,7 @@ Vue.use(bkDropdownMenu);
Vue.use(bkException);
Vue.use(bkForm);
Vue.use(bkFormItem);
Vue.use(bkComposeFormItem);
Vue.use(bkInput);
Vue.use(bkNavigation);
Vue.use(bkNavigationMenu);
Expand Down
29 changes: 16 additions & 13 deletions frontend/src/common/form-check.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import i18n from '@/setup';
import { isEmpty } from './util';
import {
splitCodeArr,
Expand Down Expand Up @@ -34,7 +35,7 @@ export function createIpRegu(type: 'IPv4' | 'IPv6' | 'mixins' = 'IPv4', isBatch
: (val: string) => !val || regex.test(val);
return {
trigger: 'blur',
message: window.i18n.t('IP格式不正确'),
message: i18n.t('IP格式不正确'),
// regex,
validator,
};
Expand All @@ -45,7 +46,7 @@ export function createIpRegu(type: 'IPv4' | 'IPv6' | 'mixins' = 'IPv4', isBatch
*/
export const reguRequired = {
required: true,
message: window.i18n.t('必填项'),
message: i18n.t('必填项'),
trigger: 'blur',
};
export const reguIp = createIpRegu();
Expand All @@ -57,39 +58,41 @@ export const reguIpMixinsBatch = createIpRegu('mixins', true);
export const reguUrl = {
regex: regUrl,
validator: (val: string) => regUrl.test(val),
message: window.i18n.t('URL格式不正确'),
message: i18n.t('URL格式不正确'),
trigger: 'blur',
};
export const reguUrlMixinIp = {
regex: regUrlMixinIp,
message: window.i18n.t('URL格式不正确'),
message: i18n.t('URL格式不正确'),
trigger: 'blur',
validator: (val: string) => regUrlMixinIp.test(val),
};
export const reguPort = {
// validator: (val: string) => regNaturalNumber.test(val) && parseInt(val, 10) <= 65535, // 端口范围不应该包括
validator: (val: string) => regNaturalNumber.test(val) && val && parseInt(val, 10) && parseInt(val, 10) <= 65535,
message: window.i18n.t('端口范围', { range: '1-65535' }),
validator: (val: string): boolean => regNaturalNumber.test(val)
&& val && parseInt(val, 10)
&& parseInt(val, 10) <= 65535,
message: i18n.t('端口范围', { range: '1-65535' }),
trigger: 'blur',
};
export const reguNaturalNumber = {
regex: regNaturalNumber,
validator: (val: string) => regNaturalNumber.test(val),
message: window.i18n.t('不小于零的整数'),
message: i18n.t('不小于零的整数'),
trigger: 'blur',
};
export function reguFnName(params?: { max: number } = {}) {
const { max = 32 } = params;
return {
validator: (val: string) => regNormalText.test(val) && regrLengthCheck(val, max),
message: window.i18n.t('正常输入内容校验', [max]),
message: i18n.t('正常输入内容校验', [max]),
trigger: 'blur',
};
}
export function reguFnStrLength(max = 40) {
return {
validator: (val: string) => regrLengthCheck(val, max),
message: window.i18n.t('字符串长度校验', [Math.floor(max / 2), max]),
message: i18n.t('字符串长度校验', [Math.floor(max / 2), max]),
trigger: 'blur',
};
}
Expand All @@ -98,29 +101,29 @@ export function reguFnSysPath(params?: { [key: string]: number | string } = {})
const reg = regFnSysPath({ minText, maxText, minLevel, type });
return {
type,
message: window.i18n.t(i18nMap[type], { minLevel, maxText }),
message: i18n.t(i18nMap[type], { minLevel, maxText }),
trigger: 'blur',
validator: (val: string) => reg.test(val),
};
}
export function reguFnMinInteger(min = 0) {
return {
message: window.i18n.t('整数最小值校验提示', { min }),
message: i18n.t('整数最小值校验提示', { min }),
validator: (val: string) => isEmpty(val) || (regInteger.test(val) && parseInt(val, 10) >= min),
trigger: 'blur',
};
}
export function reguFnRangeInteger(min: number, max: number) {
return {
validator: (val: string) => regInteger.test(val) && Number(val) <= max && Number(val) >= min,
message: window.i18n.t('整数范围校验提示', { max, min }),
message: i18n.t('整数范围校验提示', { max, min }),
trigger: 'blur',
};
}
// 一行内不能重复
export const reguIpInLineRepeat = {
trigger: 'blur',
message: window.i18n.t('冲突校验', { prop: 'IP' }),
message: i18n.t('冲突校验', { prop: 'IP' }),
validator(val: string) {
if (!val) return true;
const splitCode = splitCodeArr.find(split => val.indexOf(split) > 0);
Expand Down
34 changes: 34 additions & 0 deletions frontend/src/common/form-label-hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ref } from 'vue';

export default function useFormLabelWidth() {
const minWidth = ref(0);

const initLabelWidth = (form: Vue) => {
const el = form ? form.$el : null;
if (!el) return;
let max = 0;
const leftPadding = 28;
const safePadding = 8;
const $labelEleList = el.querySelectorAll('.bk-label');
$labelEleList.forEach((item) => {
const spanEle = item.querySelector('span');
if (spanEle) {
const { width } = spanEle.getBoundingClientRect();
max = Math.max(minWidth.value, max, width);
}
});
const width = Math.ceil(max + leftPadding + safePadding);
$labelEleList.forEach((item) => {
(item as HTMLElement).style.width = `${width}px`;
});
el.querySelectorAll('.bk-form-content').forEach((item) => {
(item as HTMLElement).style.marginLeft = `${width}px`;
});
return width;
};

return {
minWidth,
initLabelWidth,
};
}
2 changes: 1 addition & 1 deletion frontend/src/common/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const regIp = new RegExp(`^${IpStr}$`);
export const regFilterIp = new RegExp(`^(?:\\d+:)?(${IpStr})$`);
export const regExclusiveFilterIp = new RegExp(`^\\d+:${IpStr}$`);
export const regIPv6 = new RegExp(`^${IPv6Str}$`);
export const regIpMixin = window.$DHCP ? new RegExp(`^${IpStr}|${IPv6Str}$`) : regIp; // 区分环境可用的IP类型
export const regIpMixin = window.$DHCP ? new RegExp(`^${IpStr}$|^${IPv6Str}$`) : regIp; // 区分环境可用的IP类型
export const regFilterIpMixin = window.$DHCP ? new RegExp(`^(?:\\d+:)?(${IpStr}|${IPv6Str})$`) : regFilterIp;
export const regExclusiveFilterIpMixin = window.$DHCP ? new RegExp(`^\\d+:(${IpStr}|${IPv6Str})$`) : regExclusiveFilterIp; // 用于区分IP还是按管控区域筛选ip
export const regUrl = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'*+,;=.]+$/;
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,28 @@ export const sort = (arr: any[], key: string) => {
return (`${pre}`).toString().localeCompare((`${next}`));
});
};
/**
* 单个函数用于解析和比较版本号
* 排序规则:1. 数字
*/
export const compareVersions = (a: string, b: string) => {
if (a === b) return 0;
if (!a || !b) return a ? 1 : -1;
// 解析版本号字符串,返回数字数组
const parseVersion = (version: string) => version?.match(/\d+/g)?.map(Number);

// 获取版本号的数字数组
const versionA = parseVersion(a) || [];
const versionB = parseVersion(b) || [];

// 比较主版本号、次版本号、补丁号和附加编号
for (let i = 0; i < versionA.length; i++) {
const diff = versionA[i] - versionB[i];
if (diff !== 0) return diff;
}

return 0; // 全部相同
}
/**
* 对象深拷贝
* @param {*} obj
Expand Down
20 changes: 16 additions & 4 deletions frontend/src/components/RussianDolls/DollForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@ import { deepClone } from '@/common/util';
export default defineComponent({
name: 'RussianDollsForm',
props: {
data: () => [],
layout: () => [],
rules: () => ({}),
value: () => ({}),
data: {
type: Array,
default: () => [],
},
layout: {
type: Array,
default: () => [],
},
rules: {
type: Object,
default: () => ({}),
},
value: {
type: Object,
default: () => ({}),
},
labelWidth: {
type: Number,
default: 150,
Expand Down
20 changes: 16 additions & 4 deletions frontend/src/components/RussianDolls/item/DollArray.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,22 @@ import bus from '@/common/bus';
export default defineComponent({
props: {
item: () => ({}),
schema: () => ({}),
value: () => [],
valueProp: '',
item: {
type: Object,
default: () => ({}),
},
schema: {
type: Object,
default: () => ({}),
},
value: {
type: Array,
default: () => [],
},
valueProp: {
type: String,
default: '',
},
labelWidth: {
type: Number,
default: 110,
Expand Down
30 changes: 24 additions & 6 deletions frontend/src/components/RussianDolls/item/DollBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,30 @@ import { defineComponent, inject, toRefs } from 'vue';
export default defineComponent({
props: {
item: () => ({}),
schema: () => ({}),
itemIndex: -1,
value: '',
valueProp: '',
labelWidth: 110,
item: {
type: Object,
default: () => ({}),
},
schema: {
type: Object,
default: () => ({}),
},
itemIndex: {
type: Number,
default: -1,
},
value: {
type: String,
default: '',
},
valueProp: {
type: String,
default: '',
},
labelWidth: {
type: Number,
default: 110,
},
},
setup(props) {
const updateFormData = inject('updateFormData');
Expand Down
25 changes: 20 additions & 5 deletions frontend/src/components/RussianDolls/item/DollIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,26 @@ import { defineComponent, toRefs } from 'vue';
export default defineComponent({
props: {
item: () => ({}),
itemIndex: -1,
value: () => ({}),
valueProp: '',
labelWidth: 110,
item: {
type: Object,
default: () => ({}),
},
itemIndex: {
type: Number,
default: -1,
},
value: {
type: Object,
default: () => ({}),
},
valueProp: {
type: String,
default: '',
},
labelWidth: {
type: Number,
default: 110,
},
},
setup(props) {
return {
Expand Down
Loading

0 comments on commit e48ace7

Please sign in to comment.