import * as settingServices from '@12333/services/api/Setting';
|
import * as userServices from '@12333/services/api/User';
|
import { useQuery, useQueryClient } from '@tanstack/vue-query';
|
import { CategoryUtils } from '@12333/utils';
|
import { IndustryCategoryType, TagType } from '@12333/constants';
|
|
export type UseTagMenuOptions = {
|
type: TagType;
|
};
|
|
export function useTagMenu({ type }: UseTagMenuOptions) {
|
const { data } = useQuery({
|
queryKey: ['settingServices/getTagMenu', { type }],
|
queryFn: async () => {
|
return await settingServices.getTagMenu(
|
{
|
type: type,
|
},
|
{ showLoading: false }
|
);
|
},
|
initialData: () => [] as API.CategoryMenu[],
|
});
|
|
const tagMenuListForMenuOptions = computed(() =>
|
data.value.map((x) => ({
|
text: x.name,
|
value: x.id,
|
}))
|
);
|
|
return {
|
tagMenuList: data,
|
tagMenuListForMenuOptions,
|
};
|
}
|
|
export function useTags({ type }: UseTagMenuOptions) {
|
const { data } = useQuery({
|
queryKey: ['settingServices/getTags', { type }],
|
queryFn: async () => {
|
return await settingServices.getTags(
|
{
|
type: type,
|
},
|
{ showLoading: false }
|
);
|
},
|
initialData: () => [] as API.TagDto[],
|
});
|
|
const tagList = computed(() => {
|
return data.value
|
.filter((x) => x.isVisable)
|
.map((x) => ({
|
text: x.name,
|
value: x.id,
|
}));
|
});
|
|
return {
|
tagList: tagList,
|
};
|
}
|
|
type UseCategoryMenuOptions = {
|
onSuccess?: (data: API.CategoryMenu[]) => void;
|
type: number;
|
};
|
|
export function useCategoryMenu(options: UseCategoryMenuOptions) {
|
const { onSuccess, type } = options;
|
const {
|
data: categoryMenuList,
|
isLoading,
|
refetch,
|
} = useQuery({
|
queryKey: ['logout/refresh', 'settingServices/getCategoryMenu', { catotryType: type }],
|
queryFn: async () => {
|
return await settingServices.getCategoryMenu({ catotryType: type }, { showLoading: false });
|
},
|
placeholderData: () => [] as API.CategoryMenu[],
|
onSuccess: (data) => {
|
onSuccess?.(data);
|
},
|
staleTime: 1000 * 60 * 30,
|
});
|
|
const queryClient = useQueryClient();
|
|
async function ensureCategoryMenu() {
|
return await queryClient.ensureQueryData({
|
queryKey: ['logout/refresh', 'settingServices/getCategoryMenu', { catotryType: type }],
|
});
|
}
|
|
const iHasParkCategory = computed(() =>
|
categoryMenuList.value.find((x) => CategoryUtils.isIHasPark(x.name))
|
);
|
|
return {
|
categoryMenuList,
|
ensureCategoryMenu,
|
iHasParkCategory,
|
isLoading,
|
categoryMenuRefetch: refetch,
|
};
|
}
|
|
export function useInformationCategoryMenu() {
|
const { categoryMenuList: informationCategoryList, ensureCategoryMenu } = useCategoryMenu({
|
type: IndustryCategoryType.IndustryInformation,
|
});
|
|
/**
|
* 是否是人博会或招聘会
|
*/
|
function isZPOrRB(categoryId: string) {
|
const category = informationCategoryList.value.find((x) => x.id === categoryId);
|
return CategoryUtils.isZPOrRBByName(category?.name);
|
}
|
|
/**
|
* 行业新闻/行业动态
|
*/
|
function isNewsOrTrends(categoryId: string) {
|
const category = informationCategoryList.value.find((x) => x.id === categoryId);
|
return CategoryUtils.isNewsOrTrendsByName(category?.name);
|
}
|
/**
|
* 是否是人博会或招聘会 行业新闻/行业动态
|
*/
|
function isZPOrRBOrNewsOrTrends(categoryId: string) {
|
const category = informationCategoryList.value.find((x) => x.id === categoryId);
|
return CategoryUtils.isZPOrRBOrNewsOrTrendsByName(category?.name);
|
}
|
|
const InformationCategoryRecommendId = 'recommend';
|
|
const informationCategoryListWithRecommend = computed(() => [
|
{
|
name: '推荐',
|
id: InformationCategoryRecommendId,
|
} as API.CategoryMenu,
|
...informationCategoryList.value,
|
]);
|
|
return {
|
informationCategoryList,
|
informationCategoryListWithRecommend,
|
ensureCategoryMenu,
|
isZPOrRB,
|
isNewsOrTrends,
|
isZPOrRBOrNewsOrTrends,
|
InformationCategoryRecommendId,
|
};
|
}
|
|
type UseCategoryListOptions = {
|
onSuccess?: (data: API.CategoryMenu[]) => void;
|
};
|
|
export function useParkOrHRCategoryList(options: UseCategoryListOptions = {}) {
|
const { onSuccess } = options;
|
const { categoryMenuList: parkOrHRCategoryList, ensureCategoryMenu } = useCategoryMenu({
|
type: IndustryCategoryType.IndustryServices,
|
onSuccess,
|
});
|
|
const orderCategory = computed(() =>
|
parkOrHRCategoryList.value.find((x) => CategoryUtils.isIHasOrder(x.name))
|
);
|
|
const resourceCategory = computed(() =>
|
parkOrHRCategoryList.value.find((x) => CategoryUtils.isIHasResource(x.name))
|
);
|
|
const iHasParkCategory = computed(() =>
|
parkOrHRCategoryList.value.find((x) => CategoryUtils.isIHasPark(x.name))
|
);
|
|
const isSocialSecurityAgency = computed(() =>
|
parkOrHRCategoryList.value.find((x) => CategoryUtils.isSocialSecurityAgency(x.name))
|
);
|
|
const hrCompanyCategory = computed(() =>
|
parkOrHRCategoryList.value.find((x) => CategoryUtils.isHumanResource(x.name))
|
);
|
|
const humanResourceCategory = computed(() =>
|
parkOrHRCategoryList.value.find((x) => CategoryUtils.isHumanResourceByName(x.name))
|
);
|
|
return {
|
parkOrHRCategoryList,
|
orderCategory,
|
resourceCategory,
|
iHasParkCategory,
|
isSocialSecurityAgency,
|
hrCompanyCategory,
|
humanResourceCategory,
|
ensureCategoryMenu,
|
};
|
}
|