= 职业规划推荐
This commit is contained in:
175
stores/useCareerRecommendationStore.js
Normal file
175
stores/useCareerRecommendationStore.js
Normal file
@@ -0,0 +1,175 @@
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { getProfessions, getSkillTags, getRecommend } from '@/apiRc/service/careerRecommendation';
|
||||
|
||||
|
||||
export const useCareerRecommendationStore = defineStore('career-recommendation', () => {
|
||||
const userInfo = ref({
|
||||
userName: '',
|
||||
professions: [],
|
||||
skills: []
|
||||
})
|
||||
|
||||
try {
|
||||
const data = uni.getStorageSync('userInfo');
|
||||
|
||||
userInfo.value.professions = data.jobTitle.map((d) => {
|
||||
return {
|
||||
label: d,
|
||||
value: d
|
||||
};
|
||||
});
|
||||
userInfo.value.skills = data.appSkillsList.map((d) => {
|
||||
return {
|
||||
label: d.name,
|
||||
value: d.name
|
||||
};
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
|
||||
const profession = ref('');
|
||||
const professionLabel = ref('');
|
||||
const professions = ref([]);
|
||||
const professionsRef = computed(() => {
|
||||
if (!userInfo.value || !userInfo.value.professions || userInfo.value.professions.length === 0) {
|
||||
return professions.value;
|
||||
}
|
||||
const userProfessionsLabels = userInfo.value.professions.map((d) => d.label);
|
||||
let professionsA = [];
|
||||
let professionsB = [];
|
||||
professions.value.filter((d) => userProfessionsLabels.includes(d.label));
|
||||
for (const d of professions.value) {
|
||||
if (userProfessionsLabels.includes(d.label)) {
|
||||
professionsA.push(d);
|
||||
} else {
|
||||
professionsB.push(d);
|
||||
}
|
||||
}
|
||||
if (professionsA.length === 0) {
|
||||
professionsA = userInfo.value.professions;
|
||||
professionsB = professions.value;
|
||||
}
|
||||
return [...professionsA, ...professionsB];
|
||||
});
|
||||
|
||||
const skills = ref([]);
|
||||
const skillTags = computed(() => {
|
||||
if (userInfo.value.professions[0] && professionLabel.value === userInfo.value.professions[0].value) {
|
||||
return userInfo.value.skills.map((d) => d.label);
|
||||
}
|
||||
return skills.value;
|
||||
});
|
||||
|
||||
const result = ref([]);
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const { code, msg, data } = await getProfessions();
|
||||
if (code !== 0) {
|
||||
$emitter.emit('error-message', msg);
|
||||
return;
|
||||
}
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
professions.value = data.map((d) => {
|
||||
return {
|
||||
label: d.name,
|
||||
value: `${d.jobId}`
|
||||
};
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchSkillTags = async () => {
|
||||
const params = {
|
||||
jobName: professionLabel.value
|
||||
};
|
||||
try {
|
||||
const { code, msg, data } = await getSkillTags(params);
|
||||
if (code !== 0) {
|
||||
$emitter.emit('error-message', msg);
|
||||
return;
|
||||
}
|
||||
if (typeof data !== 'undefined' && Array.isArray(data) && data.length > 0 && data[0]) {
|
||||
skills.value = data[0].skillDetList.map((d) => d.skillName);
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchRecommend = async () => {
|
||||
const params = {
|
||||
jobName: professionLabel.value
|
||||
};
|
||||
try {
|
||||
const { code, msg, data } = await getRecommend(params);
|
||||
if (code !== 0) {
|
||||
$emitter.emit('error-message', msg);
|
||||
return;
|
||||
}
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
result.value = data.map((d) => {
|
||||
return {
|
||||
title: d.jobName,
|
||||
tags: d.skillList.map((d) => d.skillName),
|
||||
percentage: d.similarityScore ?? 0
|
||||
};
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
};
|
||||
|
||||
const eventProfession = (item) => {
|
||||
profession.value = item.value;
|
||||
professionLabel.value = item.label;
|
||||
}
|
||||
|
||||
const eventSearch = () => {
|
||||
void fetchRecommend();
|
||||
};
|
||||
|
||||
void fetchData();
|
||||
|
||||
watch(
|
||||
() => profession.value,
|
||||
() => {
|
||||
if (profession.value) {
|
||||
void fetchSkillTags();
|
||||
eventSearch();
|
||||
}
|
||||
},
|
||||
{
|
||||
immediate: true
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => professionsRef.value,
|
||||
() => {
|
||||
if (professionsRef.value[0]) {
|
||||
profession.value = professionsRef.value[0].value;
|
||||
professionLabel.value = professionsRef.value[0].label;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
profession,
|
||||
professionLabel,
|
||||
professions,
|
||||
professionsRef,
|
||||
skillTags,
|
||||
result,
|
||||
eventSearch,
|
||||
eventProfession
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user