Skip to content

Commit

Permalink
feat(frontend): 添加全局及业务下的资源标签管理功能 TencentBlueKing#7285
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 22658
  • Loading branch information
royalpioneer committed Nov 3, 2024
1 parent 2ef1f79 commit 944f627
Show file tree
Hide file tree
Showing 30 changed files with 3,931 additions and 3,885 deletions.
4 changes: 1 addition & 3 deletions dbm-ui/frontend/src/layout/components/ResourceManage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
key="resourceTagsManagement"
v-db-console="'resourceManage.resourceTagsManagement'">
<template #icon>
<DbIcon
svg
type="tag-3" />
<DbIcon type="tag-3" />
</template>
<span
v-overflow-tips.right
Expand Down
7,201 changes: 3,601 additions & 3,600 deletions dbm-ui/frontend/src/locales/zh-cn.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions dbm-ui/frontend/src/services/model/db-resource/DbResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export default class DbResource {
bk_biz_name: string;
};
ip: string;
label: string;
labels: {
name: string;
id: number;
}[];
net_device_id: string;
os_bit: string;
os_type: string;
Expand Down Expand Up @@ -81,7 +84,7 @@ export default class DbResource {
this.device_class = payload.device_class;
this.for_biz = payload.for_biz;
this.ip = payload.ip;
this.label = payload.label;
this.labels = payload.labels;
this.net_device_id = payload.net_device_id;
this.os_bit = payload.os_bit;
this.os_type = payload.os_type;
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/frontend/src/services/source/dbresourceResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function getSpecResourceCount(params: {
*/
export function updateResource(params: {
bk_host_ids: number[];
labels?: string[];
labels?: number[];
for_biz: number;
rack_id: string;
resource_type: string;
Expand Down
5 changes: 1 addition & 4 deletions dbm-ui/frontend/src/services/source/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ export function getTagRelatedResource(params: { bk_biz_id: number; ids: number[]
return http.post<
{
id: number;
related_resources: {
resource_type: string;
count: number;
}[];
ip_count: number;
}[]
>(`${path}related_resources/`, params);
}
10 changes: 5 additions & 5 deletions dbm-ui/frontend/src/stores/globalBizs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export const useGlobalBizs = defineStore('GlobalBizs', {
}),
getters: {
currentBizInfo: (state): BizItem | undefined => state.bizs.find((item) => item.bk_biz_id === state.currentBizId),
bizIdMap: (state): Map<number, BizItem> => {
const map = new Map<number, BizItem>();
state.bizs.forEach((biz) => map.set(biz.bk_biz_id, biz));
return map;
},
bizIdMap: (state): Map<number, BizItem> =>
state.bizs.reduce((map, biz) => {
map.set(biz.bk_biz_id, biz);
return map;
}, new Map<number, BizItem>()),
},
actions: {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@

<template>
<div class="resource-pool-list-page">
<SearchBox
ref="searchBoxRef"
class="mb-25"
@change="handleSearch" />
<div class="action-box mb-16">
<template v-if="props.type === ResourcePool.public">
<template v-if="type === ResourcePool.public">
<BkButton
:disabled="selectionHostIdList.length < 1"
theme="primary"
@click="handleShowBatchConvertToBusiness">
{{ t('转入业务资源池') }}</BkButton
>
{{ t('转入业务资源池') }}
</BkButton>
</template>
<template v-else>
<ImportHostBtn
Expand Down Expand Up @@ -77,18 +81,13 @@
</BkDropdownMenu>
</template>
</BkDropdown>
<ResourceSearchSelector v-model="searchValue" />
<TagResearchSelector v-model="researchTags" />
<AuthButton
action-id="resource_operation_view"
class="quick-search-btn"
@click="handleGoOperationRecord">
<DbIcon type="history-2" />
</AuthButton>
</div>
<TagResearchPanel
v-if="researchTags.length"
v-model="researchTags" />
<RenderTable
ref="tableRef"
:columns="tableColumn"
Expand All @@ -111,32 +110,32 @@
<BatchCovertToPublic
v-model:is-show="isShowBatchCovertToPublic"
:selected="selectionListWholeDataMemo"
@refresh="fetchData" />
@refresh="handleRefresh" />
<BatchMoveToRecyclePool
v-model:is-show="isShowBatchMoveToRecyclePool"
:selected="selectionListWholeDataMemo"
@refresh="fetchData" />
@refresh="handleRefresh" />
<BatchMoveToFaultPool
v-model:is-show="isShowBatchMoveToFaultPool"
:selected="selectionListWholeDataMemo"
@refresh="fetchData" />
@refresh="handleRefresh" />
<BatchUndoImport
v-model:is-show="isShowBatchUndoImport"
:selected="selectionListWholeDataMemo"
@refresh="fetchData" />
@refresh="handleRefresh" />
<BatchConvertToBusiness
v-model:is-show="isShowBatchConvertToBusiness"
:biz-id="(currentBizId as number)"
:selected="selectionListWholeDataMemo"
@refresh="fetchData" />
@refresh="handleRefresh" />
<BatchAssign
v-model:is-show="isShowBatchAssign"
:selected="selectionListWholeDataMemo"
@refresh="fetchData" />
@refresh="handleRefresh" />
<UpdateAssign
v-model:is-show="isShowUpdateAssign"
:edit-data="(curEditData as DbResourceModel)"
@refresh="fetchData" />
@refresh="handleRefresh" />
</div>
</template>
<script setup lang="tsx">
Expand All @@ -147,7 +146,6 @@
import { useRouter } from 'vue-router';
import DbResourceModel from '@services/model/db-resource/DbResource';
import type ResourceTagModel from '@services/model/db-resource/ResourceTag';
import { fetchList } from '@services/source/dbresourceResource';
import { useGlobalBizs } from '@stores';
Expand All @@ -156,7 +154,7 @@
import DiskPopInfo from '@components/disk-pop-info/DiskPopInfo.vue';
import HostAgentStatus from '@components/host-agent-status/Index.vue';
import { execCopy, getSearchSelectorParams } from '@utils';
import { execCopy } from '@utils';
import { ResourcePool } from '../../type';
Expand All @@ -171,9 +169,7 @@
import ImportHost from './components/import-host/Index.vue';
import ImportHostBtn from './components/ImportHostBtn.vue';
import RenderTable from './components/RenderTable.vue';
import ResourceSearchSelector from './components/resource-search-selector/Index.vue';
import TagResearchPanel from './components/tag-research/panel/Index.vue';
import TagResearchSelector from './components/tag-research/selector/Index.vue';
import SearchBox from './components/search-box/Index.vue';
import UpdateAssign from './components/update-assign/Index.vue';
import useTableSetting from './hooks/useTableSetting';
Expand All @@ -196,7 +192,6 @@
const searchBoxRef = ref();
const tableRef = ref();
const searchValue = ref([]);
const selectionHostIdList = ref<number[]>([]);
const isShowBatchSetting = ref(false);
const isShowImportHost = ref(false);
Expand All @@ -208,19 +203,9 @@
const isShowBatchAssign = ref(false);
const isShowUpdateAssign = ref(false);
const curEditData = ref<DbResourceModel>();
const researchTags = ref<ResourceTagModel[]>([]);
const isSelectedSameBiz = ref(false);
const isBatchOperationShow = ref(false);
watch(researchTags, () => {
if (researchTags.value.length) {
searchParams.labels = researchTags.value.map((item) => item.id).join(',');
} else {
delete searchParams.labels;
}
fetchData();
});
const curBizId = computed(() => {
let bizId = undefined;
switch (props.type) {
Expand All @@ -234,6 +219,11 @@
return bizId;
});
const dataSource = (params: ServiceParameters<typeof fetchList>) => fetchList({
for_biz: curBizId.value,
...params,
});
const searchParams: Record<string, any> = {};
let selectionListWholeDataMemo: DbResourceModel[] = [];
const tableColumn = [
Expand Down Expand Up @@ -267,10 +257,10 @@
theme={(!data.resource_type || data.resource_type === 'PUBLIC') ? 'success' : undefined}>{t('所属DB')} : {data.resource_type_display}
</Tag>
{
data.label && Array.isArray(data.label) && (
data.label.map(item => (
data.labels && Array.isArray(data.labels) && (
data.labels.map(item => (
<Tag>
{item}
{item.name}
</Tag>
))
)}
Expand Down Expand Up @@ -396,20 +386,15 @@
},
];
watch(
searchValue,
() => {
fetchData();
}
);
const fetchData = () => {
tableRef.value.fetchData({
...searchParams,
...getSearchSelectorParams(searchValue.value)
});
tableRef.value.fetchData(searchParams);
};
const handleSearch = (params: Record<string, any>) => {
tableRef.value.fetchData(params);
};
// 导入主机
const handleImportHost = () => {
isShowImportHost.value = true;
Expand Down Expand Up @@ -511,7 +496,9 @@
}
const handleShowBatchAssign = () => {
if (isSelectedSameBiz.value) isShowBatchAssign.value = true;
if (isSelectedSameBiz.value) {
isShowBatchAssign.value = true;
}
handleBatchOperationShow(false);
}
Expand All @@ -520,15 +507,18 @@
curEditData.value = data;
}
const handleRefresh = () => {
fetchData();
Object.values(selectionHostIdList.value).forEach((hostId) => {
tableRef.value.removeSelectByKey(hostId);
});
selectionHostIdList.value = [];
}
const handleBatchOperationShow = (val: boolean) => {
isBatchOperationShow.value = val;
}
const dataSource = async (params: ServiceParameters<typeof fetchList>) => await fetchList({
for_biz: curBizId.value,
...params,
})
onMounted(() => {
fetchData();
});
Expand All @@ -541,7 +531,7 @@
.quick-search-btn {
width: 32px;
margin-left: 8px;
margin-left: auto;
}
.search-selector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@
const { run: runRemove } = useRequest(removeResource, {
manual: true,
onSuccess: () => {
onSuccess() {
messageSuccess(t('操作成功'));
emits('refresh');
},
});
const { run: convertToPublic } = useRequest(updateResource, {
manual: true,
onSuccess: () => {
onSuccess() {
messageSuccess(t('操作成功'));
emits('refresh');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
<div>
<span
v-bk-tooltips="{
disabled: hostList.length > 0,
disabled: !!hostList.length,
content: t('请选择主机'),
}">
<BkButton
:disabled="hostList.length < 1"
:disabled="!hostList.length"
:loading="isUpdating"
theme="primary"
@click="handleSubmit">
Expand All @@ -58,6 +58,8 @@
import DbResourceModel from '@services/model/db-resource/DbResource';
import { updateResource } from '@services/source/dbresourceResource';
import { messageSuccess } from '@utils';
import FormPanel from './components/FormPanel.vue';
import ListPanel from './components/ListPanel.vue';
Expand Down Expand Up @@ -93,9 +95,9 @@
const { loading: isUpdating, run: runUpdate } = useRequest(updateResource, {
manual: true,
onSuccess: () => {
emits('refresh');
isShow.value = false;
onSuccess() {
handleCancel();
messageSuccess('设置成功');
},
});
Expand All @@ -111,18 +113,19 @@
};
const handleSubmit = async () => {
const data = await formPanelRef.value?.getValue();
const data = await formPanelRef.value!.getValue();
runUpdate({
bk_host_ids: hostList.value.map((item) => item.bk_host_id),
for_biz: data?.for_biz as number,
resource_type: data?.resource_type as string,
labels: data?.labels,
for_biz: data.for_biz as number,
resource_type: data.resource_type as string,
labels: data.labels,
rack_id: '',
storage_device: {},
});
};
const handleCancel = () => {
emits('refresh');
isShow.value = false;
};
</script>
Expand Down
Loading

0 comments on commit 944f627

Please sign in to comment.