Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat rule audit #546

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
import { useI18n } from 'vue-i18n';

import linkDataManageService from '@service/link-data-manage';
import StrategyManageService from '@service/strategy-manage';

import LinkDataDetailModel from '@model/link-data/link-data-detail';

Expand Down Expand Up @@ -242,12 +241,12 @@
// 获取标签列表
const {
loading: tagLoading,
} = useRequest(StrategyManageService.fetchStrategyTags, {
} = useRequest(linkDataManageService.fetchLinkTableTags, {
defaultValue: [],
manual: true,
onSuccess(data) {
tagData.value = data.reduce((res, item) => {
if (item.tag_id !== '-1') {
if (item.tag_id !== '-2') {
res.push({
id: item.tag_id,
name: item.tag_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<!-- 搜索框 -->
<div class="field-pop-select-search">
<bk-input
v-model="searchKey"
behavior="simplicity"
class="mb8">
<template #prefix>
Expand All @@ -32,7 +33,7 @@
<div class="field-pop-select-list">
<scroll-faker>
<div
v-for="(item, index) in tableFields"
v-for="(item, index) in renderFieldList"
:key="item.raw_name"
class="field-pop-select-item"
:class="[selectIndex === index ? 'select-item-active' : '']"
Expand All @@ -58,6 +59,10 @@
<bk-radio
v-for="item in localAggregateList"
:key="item.value"
v-bk-tooltips="{
disabled: !item.disabled,
content: t('已添加')
}"
:disabled="item.disabled"
:label="item.value">
{{ item.label }}
Expand Down Expand Up @@ -86,11 +91,16 @@
</bk-popover>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue';
import { computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';

import DatabaseTableFieldModel from '@model/strategy/database-table-field';

import useDebouncedRef from '@hooks/use-debounced-ref';

import { encodeRegexp } from '@utils/assist';


interface Emits {
(e: 'addExpectedResult', item: DatabaseTableFieldModel): void;
}
Expand All @@ -110,6 +120,16 @@
const localAggregateList = ref<Array<Record<string, any>>>([]);
const formData = ref<DatabaseTableFieldModel>(new DatabaseTableFieldModel());

const searchKey = useDebouncedRef('');

const renderFieldList = computed(() => props.tableFields.reduce((result, item) => {
const reg = new RegExp(encodeRegexp(searchKey.value), 'i');
if (reg.test(item.raw_name) || reg.test(item.display_name)) {
result.push(item);
}
return result;
}, [] as Array<DatabaseTableFieldModel>));

const fieldAggregateMap = {
string: ['COUNT', 'DISCOUNT'],
double: ['SUM', 'AVG', 'MIN', 'MAX', 'COUNT'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<div class="detail-wrapper">
<div style="display: flex; justify-content: space-between;">
<div>
<span>{{ t('连表预览') }}</span>
<span>{{ t('联表预览') }}</span>
<audit-icon
v-bk-tooltips="t('联表中,将自动生成各个原始表的字母别名,用于后续选择字段的简略标识')"
style=" margin-left: 9px; font-size: 14px;color: #c4c6cc; cursor: pointer;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
:key="dataSheetIndex"
:label="dataSheet.name"
:value="dataSheet.uid" />
<template #extension>
<div
class="refresh"
@click="fetchLinkTableAll">
<audit-icon
type="refresh" />
{{ t('刷新联表') }}
</div>
</template>
</bk-select>
</span>
</bk-form-item>
Expand Down Expand Up @@ -121,6 +130,7 @@
const {
loading,
data,
run: fetchLinkTableAll,
} = useRequest(LinkDataManageService.fetchLinkTableAll, {
defaultValue: [],
manual: true,
Expand Down Expand Up @@ -170,3 +180,11 @@
},
});
</script>
<style lang="postcss" scoped>
.refresh {
padding: 0 12px;
margin: auto;
color: #979ba5;
cursor: pointer;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@
});

const setTableData = (key: 'event_basic_field_configs' | 'event_data_field_configs' | 'event_evidence_field_configs') => {
if (isEditMode || isCloneMode) {
if (!props.data[key].length || !tableData.value[key].length) return;
if ((isEditMode || isCloneMode) && props.data[key].length && tableData.value[key].length) {
// 编辑填充参数
tableData.value[key] = tableData.value[key].map((item) => {
const editItem = props.data[key].find(edItem => edItem.field_name === item.field_name);
Expand All @@ -137,7 +136,10 @@
field_name: item.field_name,
display_name: item.display_name,
is_priority: editItem.is_priority,
map_config: editItem.map_config,
map_config: {
target_value: editItem.map_config?.target_value,
source_field: editItem.map_config?.source_field || editItem.map_config?.target_value, // 固定值赋值,用于反显
},
description: editItem.description,
example: item.example,
prefix: '',
Expand All @@ -151,15 +153,16 @@
switch (key) {
case 'event_basic_field_configs':
// 根据select填充event_basic_field_configs参数
if (!tableData.value[key].length || !props.select.length) return;
props.select.forEach((item) => {
if (fieldMap[item.raw_name]) {
const field = tableData.value[key].find(fieldItem => fieldItem.field_name === fieldMap[item.raw_name]);
if (field && field.map_config) {
field.map_config.source_field = item.display_name;
if (tableData.value[key].length && props.select.length) {
props.select.forEach((item) => {
if (fieldMap[item.raw_name]) {
const field = tableData.value[key].find(fieldItem => fieldItem.field_name === fieldMap[item.raw_name]);
if (field && field.map_config) {
field.map_config.source_field = item.display_name;
}
}
}
});
});
}
break;
case 'event_data_field_configs':
if (!props.select.length) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,44 @@
:default-value="config.map_config.source_field"
style="width: 100%;"
theme="background">
<bk-select v-model="config.map_config.source_field">
<bk-select
v-model="config.map_config.source_field"
@select="(value: string) => handlerSelect(value, config)">
<bk-option
v-for="(selectItem, index) in select"
v-for="(selectItem, index) in localSelect"
:key="index"
:label="selectItem.display_name"
:value="selectItem.display_name" />
<template #extension>
<div
v-if="!showAddCount"
style=" color: #63656e;text-align: center;flex: 1; cursor: pointer;"
@click="() => showAddCount = true">
<audit-icon
style=" margin-right: 5px;font-size: 14px;color: #979ba5;"
type="plus-circle" />
<span>{{ t('自定义常量') }}</span>
</div>
<div
v-else
style="
display: flex;
width: 100%;
padding: 0 5px;
align-items: center;
">
<bk-input
v-model="countValue"
:placeholder="t('请输入')" />
<audit-icon
style=" padding: 0 5px;font-size: 15px; color: #2caf5e;cursor: pointer;"
type="check-line"
@click="confirmAddCount" />
<audit-icon
style="font-size: 15px; color: #c4c6cc; cursor: pointer;"
type="close"
@click="() => showAddCount = false" />
</div>
</template>
</bk-select>
</select-verify>
Expand All @@ -49,19 +72,40 @@
v-model="config.map_config.source_field"
style="width: 100%;">
<bk-option
v-for="(selectItem, index) in select"
v-for="(selectItem, index) in localSelect"
:key="index"
:label="selectItem.display_name"
:value="selectItem.display_name" />
<template #extension>
<div
v-if="!showAddCount"
style=" color: #63656e;text-align: center;flex: 1; cursor: pointer;"
@click="() => showAddCount = true">
<audit-icon
style=" margin-right: 5px;font-size: 14px;color: #979ba5;"
type="plus-circle" />
<span>{{ t('自定义常量') }}</span>
</div>
<div
v-else
style="
display: flex;
width: 100%;
padding: 0 5px;
align-items: center;
">
<bk-input
v-model="countValue"
:placeholder="t('请输入')" />
<audit-icon
style=" padding: 0 5px;font-size: 15px; color: #2caf5e;cursor: pointer;"
type="check-line"
@click="confirmAddCount" />
<audit-icon
style="font-size: 15px; color: #c4c6cc; cursor: pointer;"
type="close"
@click="() => showAddCount = false" />
</div>
</template>
</bk-select>
<!-- 无需配置 -->
Expand Down Expand Up @@ -99,7 +143,8 @@
</template>

<script setup lang='ts'>
import { computed, ref } from 'vue';
import _ from 'lodash';
import { computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';

import DatabaseTableFieldModel from '@model/strategy/database-table-field';
Expand All @@ -121,6 +166,8 @@
const { t } = useI18n();
const selectVerifyRef = ref();
const showAddCount = ref(false);
const countValue = ref('');
const localSelect = ref<Array<DatabaseTableFieldModel>>([]);

const requiredField = ['raw_event_id', 'event_time', 'event_source', 'operator'];
const optionalField = ['event_content', 'event_type'];
Expand All @@ -133,6 +180,35 @@
return initKey;
});

const handlerSelect = (value: string, config: StrategyFieldEvent['event_basic_field_configs'][0]) => {
// 如果是固定值 给target_value赋值
const selectItem = localSelect.value.find(item => item.raw_name === value);
if (selectItem && !selectItem.table && config.map_config) {
// eslint-disable-next-line no-param-reassign
config.map_config.target_value = value;
}
};

const confirmAddCount = () => {
if (_.trim(countValue.value)) {
localSelect.value.push({
table: '',
raw_name: countValue.value,
display_name: countValue.value,
field_type: '',
aggregate: null,
remark: '', // 备注s
});
}
showAddCount.value = false;
};

watch(() => props.select, (data) => {
localSelect.value = _.cloneDeep(data);
}, {
immediate: true,
});

defineExpose<Exposes>({
getValue() {
if (!selectVerifyRef.value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,6 @@
const handleNext = () => {
Promise.all([formRef.value.validate(), eventRef.value.getValue()]).then(() => {
const params: IFormData = Object.assign({}, formData.value, eventRef.value.getData());
params.event_basic_field_configs = params.event_basic_field_configs.map((item) => {
if (item.map_config && !item.map_config.source_field && !item.map_config.target_value) {
// eslint-disable-next-line no-param-reassign
delete item.map_config;
}
return item;
});
emits('nextStep', 3, params);
});
};
Expand Down
16 changes: 15 additions & 1 deletion src/frontend/src/views/strategy-manage/strategy-create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

<script setup lang='ts'>
import { InfoBox } from 'bkui-vue';
import _ from 'lodash';
import {
computed,
onMounted,
Expand Down Expand Up @@ -231,7 +232,20 @@

// 提交
const handleSubmit = () => {
const params = { ...formData.value };
const params = _.cloneDeep(formData.value);
// 处理event_basic_field_configs
params.event_basic_field_configs = params.event_basic_field_configs.map((item) => {
if (item.map_config) {
if (!item.map_config.source_field && !item.map_config.target_value) {
// eslint-disable-next-line no-param-reassign
delete item.map_config;
} else if (item.map_config.source_field && item.map_config.target_value) {
// eslint-disable-next-line no-param-reassign
item.map_config.source_field = undefined;
}
}
return item;
});
// ai策略
if (controlTypeId.value !== 'BKM') {
InfoBox({
Expand Down
Loading