Skip to content

Commit

Permalink
feat(frontend): mysql和tendbcluster 备份单据优化 TencentBlueKing#6731
Browse files Browse the repository at this point in the history
  • Loading branch information
3octaves authored and jinquantianxia committed Dec 4, 2024
1 parent 335d530 commit d794cbe
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import type { MySQLTableBackupDetails } from '@services/model/ticket/details/mysql';
import TicketModel from '@services/model/ticket/ticket';

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

import { random } from '@utils';

// Mysql 库表备份
Expand All @@ -24,7 +26,7 @@ export function generateMysqlDbTableBackupCloneData(ticketData: TicketModel<MySQ
id: item.cluster_id,
domain: clusters[item.cluster_id].immute_domain,
},
backupLocal: 'Slave',
backupLocal: item.backup_on || clusters[item.cluster_id].cluster_type === ClusterTypes.TENDBHA ? 'Slave' : 'Master',
dbPatterns: item.db_patterns,
tablePatterns: item.table_patterns,
ignoreDbs: item.ignore_dbs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
:removeable="tableData.length < 2"
@add="(payload: Array<IDataRow>) => handleAppend(index, payload)"
@clone="(payload: IDataRow) => handleClone(index, payload)"
@id-change="(clusterId: number) => handleChangeCluster(index, clusterId)"
@remove="handleRemove(index)" />
</RenderData>
<TicketRemark v-model="remark" />
Expand Down Expand Up @@ -76,6 +77,7 @@

import TendbhaModel from '@services/model/mysql/tendbha';
import TendbsingleModel from '@services/model/mysql/tendbsingle';
import { filterClusters } from '@services/source/dbbase';
import { createTicket } from '@services/source/ticket';

import { useTicketCloneInfo } from '@hooks';
Expand Down Expand Up @@ -167,6 +169,7 @@
id: clusterData.id,
domain: clusterData.master_domain,
},
backupLocal: clusterData.cluster_type === ClusterTypes.TENDBHA ? 'Slave' : 'Master',
});
results.push(row);
domainMemo[domain] = true;
Expand All @@ -184,6 +187,33 @@
window.changeConfirm = true;
};

// 输入集群后查询集群信息并填充到table
const handleChangeCluster = async (index: number, clusterId: number) => {
if (tableData.value[index].clusterData?.id === clusterId) {
return;
}

const resultList = await filterClusters<TendbhaModel | TendbsingleModel>({
bk_biz_id: window.PROJECT_CONFIG.BIZ_ID,
cluster_ids: String(clusterId),
});
if (resultList.length < 1) {
return;
}
const item = resultList[0];
const domain = item.master_domain;
const row = createRowData({
clusterData: {
id: item.id,
domain,
},
backupLocal: item.cluster_type === ClusterTypes.TENDBHA ? 'Slave' : 'Master',
});
tableData.value[index] = row;
domainMemo[domain] = true;
selectedClusters.value[item.cluster_type].push(item);
};

const handleBatchEditColumn = (value: string | string[], filed: IDataRowBatchKey) => {
if (!value || checkListEmpty(tableData.value)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
ref="editRef"
v-model="localDomain"
:placeholder="t('请输入集群域名或从表头批量选择')"
:rules="rules" />
:rules="rules"
@focus="handleFocus" />
</div>
</template>
<!-- <script lang="ts">
Expand Down Expand Up @@ -57,6 +58,8 @@

const { currentBizId } = useGlobalBizs();

let isSkipInputFinish = false;

const editRef = ref();

const localClusterId = ref(0);
Expand Down Expand Up @@ -86,7 +89,9 @@
}).then((data) => {
if (data.length > 0) {
localClusterId.value = data[0].id;
emits('idChange', localClusterId.value);
if (!isSkipInputFinish) {
emits('idChange', data[0].id);
}
return true;
}
return false;
Expand Down Expand Up @@ -152,12 +157,17 @@
// },
// );

const handleFocus = () => {
isSkipInputFinish = false;
};

// onBeforeUnmount(() => {
// delete clusterIdMemo[instanceKey];
// });

defineExpose<Exposes>({
getValue() {
getValue(isSubmit = false) {
isSkipInputFinish = isSubmit;
return editRef.value
.getValue()
.then(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
domain: string;
};
// backupOn: string,
backupLocal: string;
backupLocal?: string;
dbPatterns?: string[];
tablePatterns?: string[];
ignoreDbs?: string[];
Expand All @@ -94,7 +94,7 @@
rowKey: random(),
clusterData: data.clusterData,
// backupOn: data.backupOn || '',
backupLocal: data.backupLocal || 'Slave',
backupLocal: data.backupLocal,
dbPatterns: data.dbPatterns,
tablePatterns: data.tablePatterns,
ignoreDbs: data.ignoreDbs,
Expand All @@ -116,6 +116,7 @@
(e: 'add', params: Array<IDataRow>): void;
(e: 'remove'): void;
(e: 'clone', value: IDataRow): void;
(e: 'idChange', value: number): void;
}

interface Exposes {
Expand Down Expand Up @@ -150,7 +151,7 @@
);

const handleClusterIdChange = (clusterId: number) => {
localClusterId.value = clusterId;
emits('idChange', clusterId);
};

const handleAppend = () => {
Expand All @@ -165,7 +166,7 @@
};

const getRowData = () => [
clusterRef.value.getValue(),
clusterRef.value.getValue(true),
// backupSourceRef.value.getValue('backup_on'),
dbPatternsRef.value.getValue('db_patterns'),
tablePatternsRef.value.getValue('table_patterns'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import type { MySQLTableBackupDetails } from '@services/model/ticket/details/mysql';
import TicketModel from '@services/model/ticket/ticket';

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

interface Props {
ticketDetails: TicketModel<MySQLTableBackupDetails>
}
Expand Down Expand Up @@ -131,7 +133,7 @@
const clusterData = clusterIds[item.cluster_id];
list.push(Object.assign({
cluster_id: item.cluster_id,
backup_on: item.backup_on || 'Slave',
backup_on: item.backup_on || clusterData.cluster_type === ClusterTypes.TENDBHA ? 'Slave' : 'Master',
db_patterns: item.db_patterns,
ignore_dbs: item.ignore_dbs,
ignore_tables: item.ignore_tables,
Expand Down

0 comments on commit d794cbe

Please sign in to comment.