Skip to content

Commit bba548c

Browse files
feat(frontend): 支持集群标签功能 #10056 (#10421)
2 parents 45492ba + c08465a commit bba548c

File tree

10 files changed

+160
-82
lines changed

10 files changed

+160
-82
lines changed

dbm-ui/frontend/src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,5 +1871,6 @@
18711871
"编辑集群别名": "",
18721872
"执行常用管理命令": "",
18731873
"多个标签值以空格、逗号、分号、竖线分割": "",
1874+
"标签值不能重复": "",
18741875
"这行勿动!新增翻译请在上一行添加!": ""
18751876
}

dbm-ui/frontend/src/locales/zh-cn.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4509,5 +4509,6 @@
45094509
"n项已修改": "{0} 项已修改",
45104510
"清空表格已有数据": "清空表格已有数据",
45114511
"多个标签值以空格、逗号、分号、竖线分割": "多个标签值以空格、逗号、分号、竖线分割",
4512+
"标签值不能重复": "标签值不能重复",
45124513
"这行勿动!新增翻译请在上一行添加!": ""
45134514
}

dbm-ui/frontend/src/views/db-manage/common/cluster-batch-add-tag/components/tag-operation/components/key-value-mode/Index.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@
9191
};
9292
9393
const handleDelete = (index: number) => {
94-
if (pairList.value.length === 1) {
95-
return;
96-
}
97-
9894
pairList.value.splice(index, 1);
9995
nextTick(() => {
10096
handleSelectKey();

dbm-ui/frontend/src/views/db-manage/common/cluster-table-column/ClusterTagColumn.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<template #default="{ data }: { data: IRowData }">
77
<ClusterTagCell
88
:data="data"
9+
mode="vertical"
910
@success="handleOperateSuccess" />
1011
</template>
1112
</BkTableColumn>

dbm-ui/frontend/src/views/db-manage/common/cluster-table-column/components/cluster-tag-cell/Index.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<template>
22
<div class="cluster-tag-list-box">
3-
<div class="list-display-main">
3+
<div
4+
v-if="isVertical"
5+
class="list-display-main">
46
<TextOverflowLayout
57
v-for="(item, index) in renderList"
68
:key="index">
@@ -16,6 +18,13 @@
1618
</BkButton>
1719
</template>
1820
</div>
21+
<div
22+
v-else
23+
class="list-display-main">
24+
<TextOverflowLayout>
25+
{{ renderList.map((item) => `${item.key} : ${item.value.join(' , ')}`).join(' , ') }}
26+
</TextOverflowLayout>
27+
</div>
1928
<AuthButton
2029
:action-id="actionId"
2130
class="edit-main"
@@ -45,11 +54,14 @@
4554
4655
interface Props {
4756
data: { permission: Record<string, boolean> } & ClusterCommonInfo;
57+
mode?: 'horizontal' | 'vertical';
4858
}
4959
5060
type Emits = (e: 'success') => void;
5161
52-
const props = defineProps<Props>();
62+
const props = withDefaults(defineProps<Props>(), {
63+
mode: 'horizontal',
64+
});
5365
const emits = defineEmits<Emits>();
5466
5567
const { t } = useI18n();
@@ -58,6 +70,8 @@
5870
5971
const isShowAddTag = ref(false);
6072
73+
const isVertical = computed(() => props.mode === 'vertical');
74+
6175
const totalList = computed(() =>
6276
props.data.sortedTags.map((item) => ({
6377
key: item.key,

dbm-ui/frontend/src/views/tag-manage/cluster/Index.vue

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@
7777
<template #content>
7878
<div class="append-tag-main">
7979
<div class="title-main">{{ t('标签值') }}</div>
80-
<BkInput
81-
v-model="appendTagValue"
82-
class="mt-6"
83-
:placeholder="t('请输入标签值(多个标签值以逗号、分号、竖线分割,回车完成输入)')" />
80+
<TagValueInput
81+
v-model="appendTagValues"
82+
class="mt-6" />
8483
</div>
8584
</template>
8685
<BkButton
@@ -245,10 +244,13 @@
245244

246245
import { batchCreateTags, deleteTag, listClusterTag, updateTag } from '@services/source/tag';
247246

247+
import { tagValueRegex } from '@common/regex';
248+
248249
import RenderTagOverflow from '@components/render-tag-overflow/Index.vue';
249250

250-
import { execCopy, getSearchSelectorParams, messageSuccess } from '@utils';
251+
import { execCopy, getSearchSelectorParams, messageError, messageSuccess } from '@utils';
251252

253+
import TagValueInput from './components/add-tag/components/key-value-mode/components/key-value-pair/components/TagValueInput.vue';
252254
import CreateTag from './components/add-tag/Index.vue';
253255
import EditableCell from './components/EditableCell.vue';
254256

@@ -261,7 +263,7 @@
261263
const isCreateTagDialogShow = ref(false);
262264
const searchValue = ref([]);
263265
const selectedMap = ref<Record<string, boolean>>({});
264-
const appendTagValue = ref('');
266+
const appendTagValues = ref<string[]>([]);
265267
const toggleInfoMap = ref<Record<string, boolean>>({});
266268
const existedKeyList = ref<Set<string>>(new Set());
267269
const appendTagVisableMap = ref<Record<number, boolean>>({});
@@ -385,22 +387,28 @@
385387
};
386388

387389
const handleConfirmAppendTagValue = () => {
388-
if (appendTagValue.value) {
389-
const tagList = appendTagValue.value.split(/[\s,,;;||]/).filter((item) => !!item);
390-
runBatchCreate({
391-
bk_biz_id: window.PROJECT_CONFIG.BIZ_ID,
392-
tags: tagList.map((value) => ({
393-
key: currentKey,
394-
value,
395-
})),
396-
type: 'cluster',
397-
});
398-
appendTagValue.value = '';
390+
if (!appendTagValues.value.length) {
391+
return;
392+
}
393+
394+
if (appendTagValues.value.some((item) => !tagValueRegex.test(item))) {
395+
messageError(t('标签值为1-100个字符,支持英文字母、数字或汉字,中划线(-),下划线(_),点(.)'));
396+
return;
399397
}
398+
399+
runBatchCreate({
400+
bk_biz_id: window.PROJECT_CONFIG.BIZ_ID,
401+
tags: appendTagValues.value.map((value) => ({
402+
key: currentKey,
403+
value,
404+
})),
405+
type: 'cluster',
406+
});
407+
appendTagValues.value = [];
400408
};
401409

402410
const handlecancelAppendTagValue = () => {
403-
appendTagValue.value = '';
411+
appendTagValues.value = [];
404412
appendTagVisableMap.value = {};
405413
};
406414

dbm-ui/frontend/src/views/tag-manage/cluster/components/add-tag/components/TextMode.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
return null;
8888
}
8989
const [key, value] = pairStr.split(validPairRegex);
90-
const valueList = value.trim().split(/[\s,,;;||]/);
90+
const valueList = value.trim().split(/[,,;;||]/);
9191
if (!key) {
9292
verifyTip.value = t('键必填');
9393
return null;

dbm-ui/frontend/src/views/tag-manage/cluster/components/add-tag/components/key-value-mode/Index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
import type { TagsPairType } from '../../Index.vue';
1717
18-
import KeyValuePair from './components/KeyValuePair.vue';
18+
import KeyValuePair from './components/key-value-pair/Index.vue';
1919
2020
interface Props {
2121
data?: TagsPairType;
Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,10 @@
1212
class="error-icon"
1313
type="exclamation-fill" />
1414
</div>
15-
<div class="value-input-wraper">
16-
<BkTagInput
17-
allow-auto-match
18-
allow-create
19-
class="value-input"
20-
:class="{ 'is-not-valid': !isValueVerifyPass }"
21-
collapse-tags
22-
has-delete-icon
23-
:model-value="pairInfo.value"
24-
:placeholder="t('请输入标签值(多个标签值以逗号、分号、竖线分割,回车完成输入)')"
25-
@change="checkInputValue" />
26-
<DbIcon
27-
v-if="!isValueVerifyPass"
28-
v-bk-tooltips="valueVerifyTip"
29-
class="error-icon"
30-
style="right: 18px"
31-
type="exclamation-fill" />
32-
</div>
15+
<TagValueInput
16+
ref="valueInputRef"
17+
v-model="pairInfo.value"
18+
class="value-input-wraper" />
3319
<div class="operation-main">
3420
<DbIcon
3521
type="plus-fill"
@@ -42,10 +28,11 @@
4228
</div>
4329
</template>
4430
<script setup lang="ts">
45-
import _ from 'lodash';
4631
import { useI18n } from 'vue-i18n';
4732
48-
import { tagKeyRegex, tagValueRegex } from '@common/regex';
33+
import { tagKeyRegex } from '@common/regex';
34+
35+
import TagValueInput from './components/TagValueInput.vue';
4936
5037
interface Props {
5138
data: typeof pairInfo.value;
@@ -66,14 +53,13 @@
6653
6754
const { t } = useI18n();
6855
56+
const valueInputRef = ref<InstanceType<typeof TagValueInput>>();
6957
const pairInfo = ref({
7058
key: '',
7159
value: [] as string[],
7260
});
7361
const isKeyVerifyPass = ref(true);
74-
const isValueVerifyPass = ref(true);
7562
const keyVerifyTip = ref(t('必填'));
76-
const valueVerifyTip = ref(t('必填'));
7763
7864
watch(
7965
() => props.data,
@@ -82,7 +68,6 @@
8268
pairInfo.value.key = props.data.key;
8369
pairInfo.value.value = props.data.value;
8470
keyVerifyTip.value = '';
85-
valueVerifyTip.value = '';
8671
}
8772
},
8873
{ immediate: true },
@@ -92,10 +77,6 @@
9277
isKeyVerifyPass.value = !keyVerifyTip.value;
9378
});
9479
95-
watch(valueVerifyTip, () => {
96-
isValueVerifyPass.value = !valueVerifyTip.value;
97-
});
98-
9980
const checkInputKey = (key: string) => {
10081
if (!key) {
10182
keyVerifyTip.value = t('必填');
@@ -115,22 +96,6 @@
11596
keyVerifyTip.value = '';
11697
};
11798
118-
const checkInputValue = (value: string[]) => {
119-
const inputList = _.flatMap(value.map((item) => item.split(/[\s,,;;||]/)));
120-
pairInfo.value.value = inputList;
121-
if (!value.length) {
122-
valueVerifyTip.value = t('必填');
123-
return;
124-
}
125-
126-
if (inputList.some((item) => !tagValueRegex.test(item))) {
127-
valueVerifyTip.value = t('标签值为1-100个字符,支持英文字母、数字或汉字,中划线(-),下划线(_),点(.)');
128-
return;
129-
}
130-
131-
valueVerifyTip.value = '';
132-
};
133-
13499
const handleAdd = () => {
135100
emits('add');
136101
};
@@ -142,8 +107,7 @@
142107
defineExpose<Exposes>({
143108
getValue() {
144109
isKeyVerifyPass.value = !!pairInfo.value.key && !keyVerifyTip.value;
145-
isValueVerifyPass.value = !!pairInfo.value.value.length && !valueVerifyTip.value;
146-
if (!isKeyVerifyPass.value || !isValueVerifyPass.value) {
110+
if (!isKeyVerifyPass.value || !valueInputRef.value!.getValue()) {
147111
return null;
148112
}
149113
@@ -167,9 +131,7 @@
167131
}
168132
169133
.value-input-wraper {
170-
position: relative;
171-
172-
.value-input {
134+
:deep(.value-input) {
173135
width: 340px;
174136
margin-right: 8px;
175137
margin-left: 14px;
@@ -195,14 +157,6 @@
195157
:deep(.bk-input--text) {
196158
background-color: #fff0f1;
197159
}
198-
199-
:deep(.bk-tag-input-trigger) {
200-
background-color: #fff0f1;
201-
202-
.clear-icon {
203-
display: none !important;
204-
}
205-
}
206160
}
207161
}
208162
</style>

0 commit comments

Comments
 (0)