Skip to content

Commit

Permalink
perf(frontend): redis工具箱重构 TencentBlueKing#8840
Browse files Browse the repository at this point in the history
  • Loading branch information
3octaves committed Jan 24, 2025
1 parent d4dc666 commit f12751f
Show file tree
Hide file tree
Showing 10 changed files with 1,713 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@
<EditableColumn
:label="t('当前规格')"
:width="200">
<template
v-if="labelTip"
#head>
<BkPopover
:content="labelTip"
placement="top"
theme="dark">
<span class="spec-block-column-label-tip">{{ t('当前规格') }}</span>
</BkPopover>
</template>
<EditableBlock :placeholder="placeholder">
{{ data?.name ? `${data.name} ${showCounts ? t('((n))台', { n: data?.count }) : ''}` : '' }}
<SpecPanel
v-if="data"
v-if="data.id"
:data="data"
:show-qps="showQps">
<DbIcon
Expand All @@ -39,19 +49,25 @@
placeholder?: string;
showCounts?: boolean;
showQps?: boolean;
labelTip?: string;
}

withDefaults(defineProps<Props>(), {
data: undefined,
placeholder: undefined,
showCounts: true,
showQps: false,
labelTip: '',
});

const { t } = useI18n();
</script>

<style lang="less" scoped>
.spec-block-column-label-tip {
border-bottom: 1px dashed #979ba5;
}

.visible-icon {
font-size: 16px;
color: #3a84ff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
:value="item.value">
<div class="spec-select-column-spec-item">
<span class="text-overflow">
{{ item.label }}
<slot
:label="item.label"
name="label"
:value="item.value">
{{ item.label }}
</slot>
<BkTag
v-if="currentSpecIds?.includes(item.value)"
size="small"
Expand Down Expand Up @@ -79,6 +84,7 @@
const slots = defineSlots<{
head?: (value: { label: string }) => VNode;
label?: (value: { value: number; label: string }) => VNode;
}>();
const { t } = useI18n();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<template>
<EditableColumn
ref="editableTableColumn"
:append-rules="rules"
:field="field"
fixed="left"
:label="label || t('目标集群')"
:loading="isLoading"
:min-width="300"
required>
<template #headAppend>
<BkButton
text
theme="primary"
@click="handleShowClusterSelector">
<DbIcon type="batch-host-select" />
</BkButton>
</template>
<EditableInput
v-model="modelValue.master_domain"
:placeholder="t('请输入或选择集群')" />
<ClusterSelector
v-model:is-show="isShowClusterSelector"
:cluster-types="[ClusterTypes.REDIS]"
:selected="selected as MappedProps"
:tab-list-config="tabListConfig"
@change="handelClusterChange" />
</EditableColumn>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import RedisModel from '@services/model/redis/redis';
import { filterClusters } from '@services/source/dbbase';
import { ClusterTypes } from '@common/const';
import { domainRegex } from '@common/regex';
import ClusterSelector, { type TabConfig } from '@components/cluster-selector/Index.vue';
type MappedProps = {
[K in keyof Props['selected']]: RedisModel[];
};
interface Props {
selected: Record<
string,
{
id: number;
master_domain: string;
}[]
>;
label?: string;
field?: string;
tabListConfig?: Record<string, TabConfig>;
}
interface Emits {
(e: 'batch-edit', value: RedisModel[]): void;
}
withDefaults(defineProps<Props>(), {
label: '',
field: 'cluster.master_domain',
tabListConfig: undefined,
});
const emits = defineEmits<Emits>();
const modelValue = defineModel<Partial<ServiceReturnType<typeof filterClusters>[number]>>({
required: true,
});
const { t } = useI18n();
const rules = [
{
validator: (value: string) => domainRegex.test(value),
trigger: 'change',
message: t('目标集群输入格式有误'),
},
{
validator: () => Boolean(modelValue.value.id),
trigger: 'blur',
message: t('目标集群不存在'),
},
];
const editableTableColumnRef = useTemplateRef('editableTableColumn');
const isShowClusterSelector = ref(false);
const isLoading = ref(false);
watch(
() => modelValue.value.master_domain,
() => {
if (!modelValue.value.id && modelValue.value.master_domain) {
isLoading.value = true;
modelValue.value.id = undefined;
filterClusters<RedisModel>({
bk_biz_id: window.PROJECT_CONFIG.BIZ_ID,
exact_domain: modelValue.value.master_domain,
})
.then((data) => {
if (data.length > 0) {
[modelValue.value] = data;
}
})
.finally(() => {
isLoading.value = false;
editableTableColumnRef.value!.validate();
});
}
if (!modelValue.value.master_domain) {
modelValue.value.id = undefined;
}
},
{
immediate: true,
},
);
const handleShowClusterSelector = () => {
isShowClusterSelector.value = true;
};
const handelClusterChange = (selected: Record<string, RedisModel[]>) => {
const clusterList = Object.values(selected).flatMap((selectedList) => selectedList);
emits('batch-edit', clusterList);
};
</script>
Loading

0 comments on commit f12751f

Please sign in to comment.