diff --git a/dbm-ui/frontend/src/components/db-app-select/Index.vue b/dbm-ui/frontend/src/components/db-app-select/Index.vue index c14a30dc14..f19373c4ff 100644 --- a/dbm-ui/frontend/src/components/db-app-select/Index.vue +++ b/dbm-ui/frontend/src/components/db-app-select/Index.vue @@ -1,7 +1,7 @@ @@ -38,7 +53,7 @@ import { getBizs } from '@services/source/cmdb'; - import { useUserProfile } from '@stores'; + import { useGlobalBizs, useUserProfile } from '@stores'; import { UserPersonalSettings } from '@common/const'; @@ -52,11 +67,14 @@ interface Props { list: IAppItem[]; + showPublicBiz?: boolean; } type Emits = (e: 'change', value?: IAppItem) => void; - const props = defineProps(); + const props = withDefaults(defineProps(), { + showPublicBiz: true, + }); const emits = defineEmits(); @@ -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'); @@ -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), + }); + }; diff --git a/dbm-ui/frontend/src/stores/globalBizs.ts b/dbm-ui/frontend/src/stores/globalBizs.ts index a19d50a851..5ed4a34c63 100644 --- a/dbm-ui/frontend/src/stores/globalBizs.ts +++ b/dbm-ui/frontend/src/stores/globalBizs.ts @@ -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) { diff --git a/dbm-ui/frontend/src/views/resource-manage/pool/components/host-list/components/batch-assign/components/FormPanel.vue b/dbm-ui/frontend/src/views/resource-manage/pool/components/host-list/components/batch-assign/components/FormPanel.vue index 97c90b9498..9f0c7842eb 100644 --- a/dbm-ui/frontend/src/views/resource-manage/pool/components/host-list/components/batch-assign/components/FormPanel.vue +++ b/dbm-ui/frontend/src/views/resource-manage/pool/components/host-list/components/batch-assign/components/FormPanel.vue @@ -37,8 +37,9 @@ required> diff --git a/dbm-ui/frontend/src/views/resource-manage/pool/components/host-list/components/import-host/components/FormPanel.vue b/dbm-ui/frontend/src/views/resource-manage/pool/components/host-list/components/import-host/components/FormPanel.vue index 058118a3ec..dc9fdb5a83 100644 --- a/dbm-ui/frontend/src/views/resource-manage/pool/components/host-list/components/import-host/components/FormPanel.vue +++ b/dbm-ui/frontend/src/views/resource-manage/pool/components/host-list/components/import-host/components/FormPanel.vue @@ -99,8 +99,9 @@ required> diff --git a/dbm-ui/frontend/src/views/resource-manage/pool/components/host-list/components/search-box/components/com-factory/components/ForBiz.vue b/dbm-ui/frontend/src/views/resource-manage/pool/components/host-list/components/search-box/components/com-factory/components/ForBiz.vue index c452da60ed..3f41a25e59 100644 --- a/dbm-ui/frontend/src/views/resource-manage/pool/components/host-list/components/search-box/components/com-factory/components/ForBiz.vue +++ b/dbm-ui/frontend/src/views/resource-manage/pool/components/host-list/components/search-box/components/com-factory/components/ForBiz.vue @@ -14,7 +14,7 @@