Skip to content

Commit 80d85d1

Browse files
committed
feat(frontend): 集群标准化 #4654
# Reviewed, transaction id: 23991
1 parent fdd0af4 commit 80d85d1

File tree

16 files changed

+115
-78
lines changed

16 files changed

+115
-78
lines changed

dbm-ui/frontend/src/common/const/queryClusterTypes.ts renamed to dbm-ui/frontend/src/common/const/dbClusterTypes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DBTypes } from './dbTypes';
44
/**
55
* db类型关联集群类型集合映射关系
66
*/
7-
export const queryClusterTypes = {
7+
export const DBClusterTypes = {
88
[DBTypes.MYSQL]: [ClusterTypes.TENDBSINGLE, ClusterTypes.TENDBHA],
99
[DBTypes.TENDBCLUSTER]: [ClusterTypes.TENDBCLUSTER],
1010
[DBTypes.REDIS]: [

dbm-ui/frontend/src/common/const/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from './clusterInsStatus';
44
export * from './clusterTypeInfos';
55
export * from './clusterTypes';
66
export * from './confLevels';
7+
export * from './dbClusterTypes';
78
export * from './dbSysExclude';
89
export * from './dbTypeInfos';
910
export * from './dbTypes';
@@ -12,7 +13,6 @@ export * from './machineTypes';
1213
export * from './occupiedInnerHeight';
1314
export * from './osTypes';
1415
export * from './pipelineStatus';
15-
export * from './queryClusterTypes';
1616
export * from './ticketTypeInfos';
1717
export * from './ticketTypes';
1818
export * from './userPersonalSettings';

dbm-ui/frontend/src/services/source/dbbase.ts

+32-2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,28 @@ export function checkInstance<T extends InstanceInfos>(params: { instance_addres
106106

107107
// 查询全集群信息
108108
export function queryAllTypeCluster(params: {
109+
bk_biz_id: number;
110+
cluster_types?: string;
111+
immute_domain?: string;
112+
phase?: string;
113+
limit?: number;
114+
offset?: number;
115+
}) {
116+
return http.get<
117+
{
118+
bk_cloud_id: number;
119+
cluster_type: string;
120+
id: number;
121+
immute_domain: string;
122+
major_version: string;
123+
name: string;
124+
region: string;
125+
}[]
126+
>(`${path}/simple_query_cluster/`, params);
127+
}
128+
129+
// 全集群列表
130+
export function queryAllTypeClusterList(params: {
109131
bk_biz_id?: number; // 业务id
110132
cluster_types?: string; // 集群类型(逗号间隔)
111133
immute_domain?: string; // 集群域名
@@ -118,7 +140,7 @@ export function queryAllTypeCluster(params: {
118140
status?: string; // 集群状态
119141
bk_cloud_id?: number; // 集群所属云区域id
120142
region?: string; // 集群所属地域
121-
limit?: number;
143+
limit?: number; // limit: 10 表示分页,limit: -1表示分页结构的全量数据, limit: 不传limit参数或者值为空就返回旧数据结构的全量数据
122144
offset?: number;
123145
}) {
124146
return http.get<
@@ -140,5 +162,13 @@ export function queryAllTypeCluster(params: {
140162
status: string;
141163
}[]
142164
>
143-
>(`${path}/simple_query_cluster/`, params);
165+
>(`${path}/simple_query_cluster_v2/`, params);
166+
}
167+
export type ClusterInfo = ServiceReturnType<typeof queryAllTypeClusterList>['results'][number];
168+
169+
/**
170+
* 根据用户手动输入的域名列表查询
171+
*/
172+
export function checkDomains(params: { domains: string[] }) {
173+
return http.post<ClusterInfo[]>(`${path}/check_domains/`, params);
144174
}

dbm-ui/frontend/src/services/source/mysql.ts

-7
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,3 @@ export function getClusterList(params: {
3939
}) {
4040
return http.post<ListBase<TendbhaModel[]>>(`/apis/mysql/query_clusters/`, params);
4141
}
42-
43-
/**
44-
* 根据用户手动输入的域名列表查询
45-
*/
46-
export function checkDomains(params: { domains: Array<string> }) {
47-
return http.post<Array<TendbhaModel>>(`/apis/mysql/check_domains/`, params);
48-
}

dbm-ui/frontend/src/views/cluster-standardize/components/cluster-selector/Index.vue

+10-14
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,26 @@
6868
</template>
6969
</BkDialog>
7070
</template>
71+
<script setup lang="ts">
72+
import type { ClusterInfo } from '@services/source/dbbase';
7173

72-
<script lang="ts">
73-
import type { queryAllTypeCluster } from '@services/source/dbbase';
74+
import { ClusterTypes, DBTypes } from '@common/const';
7475

75-
export type ICluster = ServiceReturnType<typeof queryAllTypeCluster>['results'][number];
76+
import { t } from '@locales/index';
77+
78+
import ClusterSelect from './components/cluster-select/Index.vue';
79+
import PanelTab from './components/common/PanelTab.vue';
80+
import ManualInput from './components/manual-input/Index.vue';
81+
import PreviewResult from './components/preview-result/Index.vue';
7682

7783
interface Props {
7884
dbType: DBTypes;
79-
selected: Record<string, ICluster[]>;
85+
selected: Record<string, ClusterInfo[]>;
8086
}
8187

8288
interface Emits {
8389
(e: 'change', value: Props['selected']): void;
8490
}
85-
</script>
86-
<script setup lang="ts">
87-
import { ClusterTypes, DBTypes } from '@common/const';
88-
89-
import { t } from '@locales/index';
90-
91-
import ClusterSelect from './components/cluster-select/Index.vue';
92-
import PanelTab from './components/common/PanelTab.vue';
93-
import ManualInput from './components/manual-input/Index.vue';
94-
import PreviewResult from './components/preview-result/Index.vue';
9591

9692
const props = withDefaults(defineProps<Props>(), {
9793
selected: () => ({}),

dbm-ui/frontend/src/views/cluster-standardize/components/cluster-selector/components/cluster-select/Index.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@
7878
</div>
7979
</BkLoading>
8080
</template>
81-
<script setup lang="ts" generic="T extends ServiceReturnType<typeof queryAllTypeCluster>['results'][number]">
81+
<script setup lang="ts" generic="T extends ClusterInfo">
8282
import { useI18n } from 'vue-i18n';
8383

84-
import type { queryAllTypeCluster } from '@services/source/dbbase';
84+
import type { ClusterInfo } from '@services/source/dbbase';
8585

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

dbm-ui/frontend/src/views/cluster-standardize/components/cluster-selector/components/cluster-select/Table.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
</BkLoading>
3737
</div>
3838
</template>
39-
<script setup lang="tsx" generic="T extends ServiceReturnType<typeof queryAllTypeCluster>['results'][number]">
39+
<script setup lang="tsx" generic="T extends ClusterInfo">
4040
import { useI18n } from 'vue-i18n';
4141

42-
import type { queryAllTypeCluster } from '@services/source/dbbase';
42+
import type { ClusterInfo } from '@services/source/dbbase';
4343

4444
import { useLinkQueryColumnSerach } from '@hooks';
4545

@@ -112,7 +112,7 @@
112112
} = useLinkQueryColumnSerach({
113113
searchType: props.activePanelId,
114114
fetchDataFn: () => fetchResources(),
115-
isQueryAttrs: false
115+
isQueryAttrs: false,
116116
});
117117

118118
const checkedMap = shallowRef({} as Record<string, T>);

dbm-ui/frontend/src/views/cluster-standardize/components/cluster-selector/components/cluster-select/hooks/useTableData.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
*/
1313

1414
import type { ISearchValue } from 'bkui-vue/lib/search-select/utils';
15+
import _ from 'lodash';
1516
import { useRequest } from 'vue-request';
1617

17-
import { queryAllTypeCluster } from '@services/source/dbbase';
18+
import { type ClusterInfo, queryAllTypeClusterList } from '@services/source/dbbase';
1819

1920
import { getSearchSelectorParams } from '@utils';
2021

@@ -29,7 +30,7 @@ export function useTableData(
2930
db_module_id?: number;
3031
}>,
3132
) {
32-
const tableData = shallowRef<ServiceReturnType<typeof queryAllTypeCluster>['results']>([]);
33+
const tableData = shallowRef<ClusterInfo[]>([]);
3334
const pagination = reactive({
3435
count: 0,
3536
current: 1,
@@ -39,15 +40,21 @@ export function useTableData(
3940
layout: ['total', 'limit', 'list'],
4041
});
4142

42-
const searchParams = computed(() => ({
43-
limit: pagination.limit,
44-
offset: (pagination.current - 1) * pagination.limit,
45-
extra: 1,
46-
...getSearchSelectorParams(searchSelectValue.value),
47-
...params.value,
48-
}));
43+
const searchParams = computed(() => {
44+
const comParams = getSearchSelectorParams(searchSelectValue.value);
45+
const cloneParams = _.cloneDeep(comParams);
46+
delete cloneParams.domain;
47+
return {
48+
limit: pagination.limit,
49+
offset: (pagination.current - 1) * pagination.limit,
50+
extra: 1,
51+
immute_domain: comParams.domain,
52+
...cloneParams,
53+
...params.value,
54+
};
55+
});
4956

50-
const { run: fetchDataFn, loading: isLoading } = useRequest(queryAllTypeCluster, {
57+
const { run: fetchDataFn, loading: isLoading } = useRequest(queryAllTypeClusterList, {
5158
manual: true,
5259
onSuccess(data) {
5360
tableData.value = data.results;

dbm-ui/frontend/src/views/cluster-standardize/components/cluster-selector/components/manual-input/Index.vue

+27-17
Original file line numberDiff line numberDiff line change
@@ -79,40 +79,38 @@
7979
<template #main>
8080
<BkLoading :loading="inputState.isLoading">
8181
<Table
82-
:checked="checkedMap"
82+
:active-panel-id="activePanelId"
83+
:last-values="lastValues"
8384
:table-data="tableData"
8485
@change="handleChange" />
8586
</BkLoading>
8687
</template>
8788
</BkResizeLayout>
8889
</div>
8990
</template>
90-
<script setup lang="ts" generic="T extends TendbhaModel">
91+
<script setup lang="ts" generic="T extends ClusterInfo">
9192
import { useI18n } from 'vue-i18n';
9293

93-
import type TendbhaModel from '@services/model/mysql/tendbha';
94-
import { checkDomains } from '@services/source/mysql';
94+
import type { ClusterInfo } from '@services/source/dbbase';
95+
import { checkDomains } from '@services/source/dbbase';
9596

9697
import { domainRegex } from '@common/regex';
9798

9899
import Table from './Table.vue';
99100

100101
interface Props {
101-
checked: Record<string, T>;
102-
checkKey?: string;
102+
lastValues: Record<string, T[]>;
103+
activePanelId: string;
103104
}
104105

105106
interface Emits {
106-
(e: 'change', value: Props['checked']): void;
107+
(e: 'change', value: Props['lastValues']): void;
107108
}
108-
const props = withDefaults(defineProps<Props>(), {
109-
checkKey: 'master_domain',
110-
});
109+
const props = defineProps<Props>();
111110
const emits = defineEmits<Emits>();
112111

113112
const { t } = useI18n();
114113
const inputRef = ref();
115-
const checkedMap = computed(() => props.checked);
116114

117115
const inputState = reactive({
118116
values: '',
@@ -135,7 +133,7 @@
135133
},
136134
});
137135

138-
const handleChange = (checked: Props['checked']) => {
136+
const handleChange = (checked: Props['lastValues']) => {
139137
emits('change', checked);
140138
};
141139

@@ -198,7 +196,7 @@
198196
const item = lines[i];
199197
const infos = results[i];
200198
const remove = lines.splice(i, 1);
201-
const isExisted = results.find((existItem) => existItem[props.checkKey as keyof TendbhaModel] === item);
199+
const isExisted = results.find((existItem) => existItem.immute_domain === item);
202200
if (!isExisted) {
203201
legalLines.push(...remove);
204202
} else {
@@ -212,12 +210,24 @@
212210
errorState.domain.selectionEnd = legalLines.join('\n').length;
213211

214212
// 解析完成后选中
215-
const checked = { ...props.checked };
213+
const lastValues = { ...props.lastValues };
216214
for (const item of tableData.value) {
217-
const domain = item.master_domain;
218-
checked[domain] = item as T;
215+
const clusterType = props.activePanelId;
216+
if (!lastValues[clusterType]) {
217+
lastValues[clusterType] = [];
218+
}
219+
const list = lastValues[clusterType];
220+
const isExisted =
221+
list.length > 0 &&
222+
list.find((i) => `${i.immute_domain}_${i.bk_cloud_id}` === `${item.immute_domain}_${item.bk_cloud_id}`);
223+
if (!isExisted) {
224+
lastValues[clusterType].push(item);
225+
}
219226
}
220-
emits('change', checked);
227+
emits('change', {
228+
...props.lastValues,
229+
...lastValues,
230+
});
221231
} catch (_) {
222232
console.error(_);
223233
}

dbm-ui/frontend/src/views/cluster-standardize/components/cluster-selector/components/manual-input/Table.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
:settings="tableSettings" />
2828
</div>
2929
</template>
30-
<script setup lang="tsx" generic="T extends ServiceReturnType<typeof queryAllTypeCluster>['results'][number]">
30+
<script setup lang="tsx" generic="T extends ClusterInfo">
3131
import { useI18n } from 'vue-i18n';
3232

33-
import type { queryAllTypeCluster } from '@services/source/dbbase';
33+
import type { ClusterInfo } from '@services/source/dbbase';
3434

3535
import DbStatus from '@components/db-status/index.vue';
3636

dbm-ui/frontend/src/views/cluster-standardize/components/cluster-selector/components/preview-result/Index.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@
6363
</div>
6464
</div>
6565
</template>
66-
<script setup lang="ts" generic="T extends ServiceReturnType<typeof queryAllTypeCluster>['results'][number]">
66+
<script setup lang="ts" generic="T extends ClusterInfo">
6767
import { useI18n } from 'vue-i18n';
6868

69-
import type { queryAllTypeCluster } from '@services/source/dbbase';
69+
import type { ClusterInfo } from '@services/source/dbbase';
7070

7171
import { useCopy } from '@hooks';
7272

dbm-ui/frontend/src/views/cluster-standardize/components/mysql/Index.vue

+6-5
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@
6464
import { useI18n } from 'vue-i18n';
6565
import { useRequest } from 'vue-request';
6666

67+
import type { ClusterInfo } from '@services/source/dbbase';
6768
import { createTicket } from '@services/source/ticket';
6869

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

71-
import ClusterSelector, { type ICluster } from '../cluster-selector/Index.vue';
72+
import ClusterSelector from '../cluster-selector/Index.vue';
7273
import type { ClusterModel } from '../common/RenderCluster.vue';
7374

7475
import RenderData from './components/render-data/Index.vue';
@@ -82,9 +83,9 @@
8283

8384
const isShowBatchSelector = ref(false);
8485
const tableData = ref<IDataRow[]>([createRowData()]);
85-
const selected = shallowRef<Record<string, ICluster[]>>({
86-
[ClusterTypes.TENDBHA]: [] as ICluster[],
87-
[ClusterTypes.TENDBSINGLE]: [] as ICluster[],
86+
const selected = shallowRef<Record<string, ClusterInfo[]>>({
87+
[ClusterTypes.TENDBHA]: [] as ClusterInfo[],
88+
[ClusterTypes.TENDBSINGLE]: [] as ClusterInfo[],
8889
});
8990

9091
const totalNum = computed(() => tableData.value.filter((item) => Boolean(item.clusterType)).length);
@@ -121,7 +122,7 @@
121122
};
122123

123124
// 从集群选择器选择确认后
124-
const handelClusterChange = (data: Record<string, ICluster[]>) => {
125+
const handelClusterChange = (data: Record<string, ClusterInfo[]>) => {
125126
selected.value = data;
126127
const newList = Object.values(data)
127128
.flat()

dbm-ui/frontend/src/views/db-manage/common/webconsole/Index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
consolePanelRef.value!.export();
134134
};
135135
136-
const handleChangeCurrentCluster = (data: ClusterItem) => {
136+
const handleChangeCurrentCluster = (data: ClusterInfo) => {
137137
clusterInfo.value = data;
138138
};
139139

0 commit comments

Comments
 (0)