Skip to content

feat(frontend): 统一业务选择框 #9905 #10086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 70 additions & 5 deletions dbm-ui/frontend/src/components/db-app-select/Index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<AppSelect
v-bind="{ ...attrs, ...props }"
:data="withFavorBizList"
:data="dataList"
:generate-key="(item: IAppItem) => item.bk_biz_id"
:generate-name="(item: IAppItem) => item.display_name"
:search-extension-method="searchExtensionMethod"
Expand All @@ -25,6 +25,21 @@
<span style="color: #979ba5">
(#{{ data.bk_biz_id }}{{ data.english_name ? `, ${data.english_name}` : '' }})
</span>
<template
v-if="data.bk_biz_id !== publicBiz.bk_biz_id"
#append>
<DbIcon
v-if="favorBizIdMap[data.bk_biz_id]"
class="unfavor-btn ml-4"
style="color: #ffb848"
type="star-fill"
@click.stop="handleUnfavor(data.bk_biz_id)" />
<DbIcon
v-else
class="favor-btn ml-4"
type="star"
@click.stop="handleFavor(data.bk_biz_id)" />
</template>
</TextOverflowLayout>
</template>
</AppSelect>
Expand All @@ -38,7 +53,7 @@

import { getBizs } from '@services/source/cmdb';

import { useUserProfile } from '@stores';
import { useGlobalBizs, useUserProfile } from '@stores';

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

Expand All @@ -52,11 +67,14 @@

interface Props {
list: IAppItem[];
showPublicBiz?: boolean;
}

type Emits = (e: 'change', value?: IAppItem) => void;

const props = defineProps<Props>();
const props = withDefaults(defineProps<Props>(), {
showPublicBiz: true,
});

const emits = defineEmits<Emits>();

Expand All @@ -68,10 +86,18 @@

const attrs = useAttrs();
const userProfile = useUserProfile();
const { publicBiz } = useGlobalBizs();

const favorBizIdMap = makeMap(userProfile.profile[UserPersonalSettings.APP_FAVOR] || []);
const favorBizIdMap = shallowRef(makeMap(userProfile.profile[UserPersonalSettings.APP_FAVOR] || []));

const withFavorBizList = computed(() => _.sortBy(props.list, (item) => favorBizIdMap[item.bk_biz_id]));
const dataList = computed(() => {
const sortedList = _.sortBy(props.list, (item) => favorBizIdMap.value[item.bk_biz_id]);

if (props.showPublicBiz) {
sortedList.unshift(publicBiz);
}
return sortedList;
});

const searchExtensionMethod = (data: IAppItem, keyword: string) => {
const rule = new RegExp(encodeRegexp(keyword), 'i');
Expand All @@ -83,6 +109,28 @@
modelValue.value = appInfo;
emits('change', appInfo);
};

const handleUnfavor = (bizId: number) => {
const lastFavorBizIdMap = { ...favorBizIdMap.value };
delete lastFavorBizIdMap[bizId];
favorBizIdMap.value = lastFavorBizIdMap;

userProfile.updateProfile({
label: UserPersonalSettings.APP_FAVOR,
values: Object.keys(lastFavorBizIdMap),
});
};

const handleFavor = (bizId: number) => {
favorBizIdMap.value = {
...favorBizIdMap.value,
[bizId]: true,
};
userProfile.updateProfile({
label: UserPersonalSettings.APP_FAVOR,
values: Object.keys(favorBizIdMap.value),
});
};
</script>

<style lang="less">
Expand All @@ -98,9 +146,26 @@

.tippy-box[data-theme='bk-app-select-menu'] {
.db-select-no-permission-item {
width: 100%;

.layout-content {
width: 100%;
}

& span {
display: inline !important;
}

&:hover {
.favor-btn {
opacity: 100%;
}
}

.favor-btn {
opacity: 0%;
transition: all 0.1s;
}
}
}
</style>
1 change: 1 addition & 0 deletions dbm-ui/frontend/src/stores/globalBizs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const useGlobalBizs = defineStore('GlobalBizs', {
return [PUBLIC_BIZ_INFO].concat(state.bizs);
},
currentBizInfo: (state): BizItem | undefined => state.bizs.find((item) => item.bk_biz_id === state.currentBizId),
publicBiz: () => PUBLIC_BIZ_INFO,
},
actions: {
changeBizId(id: number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
required>
<DbAppSelect
:disabled="isBusiness"
:list="globalBizsStore.bizListWithPublic"
:list="globalBizsStore.bizs"
:model-value="currentApp"
:show-public-biz="!isBusiness"
@change="handleAppChange">
</DbAppSelect>
</BkFormItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@
required>
<DbAppSelect
:disabled="isBusiness"
:list="globalBizsStore.bizListWithPublic"
:list="globalBizsStore.bizs"
:model-value="currentApp"
:show-public-biz="!isBusiness"
@change="handleAppChange">
</DbAppSelect>
</BkFormItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<template>
<DbAppSelect
clearable
:list="globalBizsStore.bizListWithPublic"
:list="globalBizsStore.bizs"
:model-value="currentApp"
@change="handleChange">
</DbAppSelect>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:label="t('所属业务')"
required>
<DbAppSelect
:list="globalBizsStore.bizListWithPublic"
:list="globalBizsStore.bizs"
:model-value="currentApp"
@change="handleAppChange">
</DbAppSelect>
Expand Down
4 changes: 2 additions & 2 deletions dbm-ui/frontend/src/views/tag-manage/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</BkTag>
<span class="title-divider">|</span>
<DbAppSelect
:list="bizListWithPublic"
:list="bizs"
:model-value="curBiz"
type="text"
@change="handleBizChange">
Expand Down Expand Up @@ -109,7 +109,7 @@
type IAppItem = ServiceReturnType<typeof getBizs>[number];

const { t } = useI18n();
const { bizListWithPublic, currentBizInfo } = useGlobalBizs();
const { bizs, currentBizInfo } = useGlobalBizs();
const route = useRoute();
const router = useRouter();

Expand Down
Loading