Skip to content

Commit

Permalink
perf(frontend): redis工具箱重构_安装module TencentBlueKing#8840
Browse files Browse the repository at this point in the history
  • Loading branch information
3octaves committed Jan 21, 2025
1 parent 96dfaa5 commit b6c9f88
Show file tree
Hide file tree
Showing 5 changed files with 494 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './dataStructure';
export * from './dataStructureTaskDelete';
export * from './destroy';
export * from './insApply';
export * from './installModule';
export * from './instanceDestroy';
export * from './instanceProxyClose';
export * from './instanceProxyOpen';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { DetailBase, DetailClusters } from '../common';

export interface InstallModule extends DetailBase {
clusters: DetailClusters;
bk_cloud_id: number;
infos: {
cluster_id: number;
db_version: string;
load_modules: string[];
}[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
*
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License athttps://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
* the specific language governing permissions and limitations under the License.
-->

<template>
<Component :is="components[page]" />
</template>
<script setup lang="ts">
import { useRoute } from 'vue-router';

import Page2 from '@views/db-manage/common/create-ticket-success/Index.vue';

import Page1 from './create/Index.vue';

const route = useRoute();

const components = {
create: Page1,
success: Page2,
};

const page = computed(() => (route.params.page as keyof typeof components) || 'create');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,307 @@
<!--
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
*
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License athttps://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
* the specific language governing permissions and limitations under the License.
-->

<template>
<SmartAction>
<div class="install-module">
<BkAlert
closable
theme="info"
:title="t('为集群安装扩展 Module,仅 RedisCluster、Redis 主从 支持安装 Module。')" />
<DbForm
ref="form"
class="toolbox-form"
form-type="vertical"
:model="formData"
style="margin-top: 16px">
<EditableTable
ref="editableTable"
class="mt16 mb16"
:model="tableData"
:rules="rules">
<EditableTableRow
v-for="(item, index) in tableData"
:key="index">
<EditClusterColumn
v-model="item.cluster"
:cluster-types="[ClusterTypes.REDIS]"
field="cluster.master_domain"
:label="t('目标集群')"
:selected="selected"
:tab-list-config="tabListConfig"
@batch-edit="handleClusterBatchEdit" />
<EditableTableColumn
:label="t('架构版本')"
:width="200">
<EditBlock :placeholder="t('选择集群后自动生成')">
{{ item.cluster.cluster_type_name }}
</EditBlock>
</EditableTableColumn>
<EditableTableColumn
:label="t('版本')"
:width="200">
<EditBlock :placeholder="t('选择集群后自动生成')">
{{ item.cluster.major_version }}
</EditBlock>
</EditableTableColumn>
<ModuleSelectColumn
v-model="item.load_modules"
:params="{
clusterId: item.cluster.id,
version: item.cluster.major_version,
}">
</ModuleSelectColumn>
<OperationColumn
:create-row-method="createRowData"
:table-data="tableData" />
</EditableTableRow>
</EditableTable>
<TicketRemark v-model="formData.remark" />
</DbForm>
</div>
<template #action>
<BkButton
class="w-88"
:loading="isSubmitting"
theme="primary"
@click="handleSubmit">
{{ t('提交') }}
</BkButton>
<DbPopconfirm
:confirm-handler="handleReset"
:content="t('重置将会清空当前填写的所有内容_请谨慎操作')"
:title="t('确认重置页面')">
<BkButton
class="ml-8 w-88"
:disabled="isSubmitting">
{{ t('重置') }}
</BkButton>
</DbPopconfirm>
</template>
</SmartAction>
</template>

<script setup lang="ts">
import type { ComponentProps } from 'vue-component-type-helpers';
import { useI18n } from 'vue-i18n';

import RedisModel from '@services/model/redis/redis';
import { RepairAndVerifyFrequencyModes, RepairAndVerifyModes } from '@services/model/redis/redis-dst-history-job';
import { type Redis } from '@services/model/ticket/ticket';
import { getRedisList } from '@services/source/redis';

import { useCreateTicket, useTicketDetail } from '@hooks';

import { ClusterTypes, TicketTypes } from '@common/const';

import { type TabItem } from '@components/cluster-selector/Index.vue';
import EditableTable, {
Block as EditBlock,
Column as EditableTableColumn,
Row as EditableTableRow,
} from '@components/editable-table/Index.vue';

import OperationColumn from '@views/db-manage/common/toolbox-field/column/operation-column/Index.vue';
import TicketRemark from '@views/db-manage/common/toolbox-field/form-item/ticket-remark/Index.vue';
import EditClusterColumn from '@views/db-manage/redis/common/toolbox-field/edit-cluster-column/Index.vue';

import { messageError } from '@utils';

import ModuleSelectColumn from './components/ModuleSelectColumn.vue';

interface IDataRow {
cluster: {
id?: number;
master_domain?: string;
bk_cloud_id?: number;
cluster_type?: string;
cluster_type_name?: string;
major_version?: string;
};
load_modules: string[];
}

const createRowData = (values?: Partial<IDataRow>) => ({
cluster: values?.cluster ? values.cluster : ({} as IDataRow['cluster']),
load_modules: values?.load_modules || [],
});

const createDefaultFormData = () => ({
data_check_repair_setting_type: RepairAndVerifyModes.DATA_CHECK_AND_REPAIR,
data_check_repair_setting_execution_frequency: RepairAndVerifyFrequencyModes.ONCE_AFTER_REPLICATION,
remark: '',
});

const { t } = useI18n();

// 单据克隆
useTicketDetail<Redis.InstallModule>(TicketTypes.REDIS_CLUSTER_LOAD_MODULES, {
onSuccess(ticketDetail) {
const { details, remark } = ticketDetail;
const { infos, clusters } = details;
tableData.value = infos.map((infoItem) =>
createRowData({
cluster: {
master_domain: clusters[infoItem.cluster_id].immute_domain,
},
load_modules: infoItem.load_modules,
}),
);
Object.assign(formData, {
remark,
});
},
});

const { run: createTicketRun, loading: isSubmitting } = useCreateTicket<{
bk_cloud_id: number;
infos: {
cluster_id: number;
db_version: string;
load_modules: string[];
}[];
}>(TicketTypes.REDIS_CLUSTER_LOAD_MODULES);

const editableTableRef = useTemplateRef('editableTable');

const tableData = ref<IDataRow[]>([createRowData()]);

const formData = reactive(createDefaultFormData());

const rules = {
'cluster.master_domain': [
{
validator: (value: string) => {
if (value) {
const nonEmptyIdList = tableData.value.filter((row) => row.cluster.master_domain === value);
return nonEmptyIdList.length === 1;
}
return true;
},
trigger: 'change',
message: t('目标集群重复'),
},
],
};

const tabListConfig = {
[ClusterTypes.REDIS]: {
getResourceList: (params: ServiceParameters<typeof getRedisList>) =>
getRedisList({
cluster_type: [ClusterTypes.PREDIXY_REDIS_CLUSTER, ClusterTypes.REDIS_INSTANCE].join(','),
...params,
}),
},
} as unknown as Record<string, TabItem>;

const selected = computed(() => {
const selectedClusters: ComponentProps<typeof EditClusterColumn>['selected'] = {
[ClusterTypes.REDIS]: [],
};
tableData.value.forEach((tableRow) => {
const { id, master_domain: masterDomain } = tableRow.cluster;
if (id && masterDomain) {
selectedClusters[ClusterTypes.REDIS].push({
id,
master_domain: masterDomain,
});
}
});
return selectedClusters;
});

const clusterMemo = computed(() =>
Object.fromEntries(
Object.values(selected.value).flatMap((clusters) =>
clusters.filter((cluster) => cluster.master_domain).map((cluster) => [cluster.master_domain, true]),
),
),
);

const handleClusterBatchEdit = (clusterList: RedisModel[]) => {
const newList: IDataRow[] = [];
clusterList.forEach((item) => {
if (!clusterMemo.value[item.master_domain]) {
const domain = item.master_domain;
if (!clusterMemo.value[domain]) {
newList.push(
createRowData({
cluster: {
id: item.id,
master_domain: item.master_domain,
bk_cloud_id: item.bk_cloud_id,
cluster_type: item.cluster_type,
cluster_type_name: item.cluster_type_name,
major_version: item.major_version,
},
}),
);
}
}
});
tableData.value = [...(tableData.value[0].cluster.id ? tableData.value : []), ...newList];
window.changeConfirm = true;
};

const handleSubmit = async () => {
const validateResult = await editableTableRef.value!.validate();
if (validateResult) {
const isSameCloud = tableData.value.every(
(item) => item.cluster.bk_cloud_id === tableData.value[0].cluster.bk_cloud_id,
);
if (!isSameCloud) {
messageError(t('仅允许同一管控区域的集群一起安装module'));
return;
}
createTicketRun({
details: {
bk_cloud_id: tableData.value[0].cluster.bk_cloud_id!,
infos: tableData.value.map((tableItem) => ({
cluster_id: tableItem.cluster.id!,
db_version: tableItem.cluster.major_version!,
load_modules: tableItem.load_modules,
})),
},
remark: formData.remark,
});
}
};

// 重置
const handleReset = () => {
Object.assign(formData, createDefaultFormData());
tableData.value = [createRowData()];
window.changeConfirm = false;
};
</script>

<style lang="less" scoped>
.install-module {
padding-bottom: 20px;

.page-action-box {
display: flex;
align-items: center;
margin-top: 16px;

.safe-action {
margin-left: auto;

.safe-action-text {
padding-bottom: 2px;
border-bottom: 1px dashed #979ba5;
}
}
}
}
</style>
Loading

0 comments on commit b6c9f88

Please sign in to comment.