Files
ks-app-employment-service/stores/useSkillDevelopmentStore.js

294 lines
8.1 KiB
JavaScript
Raw Normal View History

2026-01-21 14:26:34 +08:00
import { computed, ref, watch } from 'vue';
import { defineStore } from 'pinia';
2026-01-22 01:15:41 +08:00
import { getCurrentPosition, getPath } from '@/apiRc/service/careerPath';
2026-01-23 15:43:53 +08:00
import { getCareerPath, getSkillResult } from '@/apiRc/service/skillDevelopment';
2026-01-22 01:15:41 +08:00
2026-01-21 14:26:34 +08:00
export const useSkillDevelopmentStore = defineStore('skill-development', () => {
2026-01-22 01:15:41 +08:00
const userInfo = ref({
userName: '',
professions: [],
skills: []
});
2026-01-21 14:26:34 +08:00
2026-01-22 01:15:41 +08:00
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 professionIndex = ref(0);
2026-01-21 14:26:34 +08:00
const profession = ref('');
2026-01-22 01:15:41 +08:00
const professionLabel = ref('');
2026-01-21 14:26:34 +08:00
const professions = ref([]);
const professionsRef = computed(() => {
2026-01-22 01:15:41 +08:00
if (!userInfo.value || !userInfo.value.professions || userInfo.value.professions.length === 0) {
2026-01-21 14:26:34 +08:00
return professions.value;
}
2026-01-22 01:15:41 +08:00
const userProfessionsLabels = userInfo.value.professions.map((d) => d.label);
2026-01-21 14:26:34 +08:00
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) {
2026-01-22 01:15:41 +08:00
professionsA = userInfo.value.professions;
2026-01-21 14:26:34 +08:00
professionsB = professions.value;
}
2026-01-22 01:15:41 +08:00
return [ ...professionsA, ...professionsB ];
2026-01-21 14:26:34 +08:00
});
2026-01-22 01:15:41 +08:00
const targetCareerIndex = ref(0);
2026-01-21 14:26:34 +08:00
const targetCareer = ref('');
2026-01-22 01:15:41 +08:00
const targetCareerLabel = ref('');
2026-01-21 14:26:34 +08:00
const paths = ref([]);
const pathsRef = computed(() => {
return paths.value.filter((d) => {
2026-01-23 18:38:13 +08:00
const [startJobId] = d.value.split('-');
return startJobId === profession.value;
2026-01-21 14:26:34 +08:00
});
});
2026-01-23 15:43:53 +08:00
const careerPaths = ref([]);
const currentCareer = ref(null);
2026-01-23 18:38:13 +08:00
const currentCareerIndex = ref(0);
2026-01-23 15:43:53 +08:00
const currentCareerLabel = computed(() => {
if (!currentCareer.value) {
return '';
}
return currentCareer.value.label;
});
2026-01-21 14:26:34 +08:00
const result = ref([]);
const fetchData = async () => {
try {
const { code, msg, data } = await getCurrentPosition();
if (code !== 0) {
2026-01-22 16:46:45 +08:00
uni.showToast({
title: msg,
icon: 'none'
});
2026-01-21 14:26:34 +08:00
return;
}
if (!data) {
return;
}
professions.value = data.map((d) => {
return {
label: d.name,
2026-01-22 01:15:41 +08:00
value: `${ d.jobId }`
2026-01-21 14:26:34 +08:00
};
});
} catch (e) {
console.warn(e);
}
};
const fetchDataPath = async () => {
try {
const { code, msg, data } = await getPath();
if (code !== 0) {
2026-01-22 16:46:45 +08:00
uni.showToast({
title: msg,
icon: 'none'
});
2026-01-21 14:26:34 +08:00
return;
}
if (!data) {
return;
}
paths.value = data.map((d) => {
return {
label: d.endJob,
2026-01-23 18:38:13 +08:00
value: `${d.startJobId}-${d.endJobId}`
2026-01-21 14:26:34 +08:00
};
});
} catch (e) {
console.warn(e);
}
};
2026-01-23 15:43:53 +08:00
const fetchCareerPaths = async () => {
2026-01-22 01:15:41 +08:00
if (!targetCareer.value) {
return;
}
2026-01-23 15:43:53 +08:00
const [startJobId, endJobId] = targetCareer.value.split('-');
const params = {
startJobId,
endJobId
};
try {
const { code, msg, data } = await getCareerPath(params);
if (code !== 0) {
uni.showToast({
title: msg,
icon: 'none'
});
return;
}
if (!data) {
return;
}
2026-01-23 18:38:13 +08:00
careerPaths.value = data.map((d, i) => {
let index = `${i}`;
let fontSize = 26;
if (i === 0) {
index = '起点';
fontSize = 18;
}
if (i === data.length - 1) {
index = '终点';
fontSize = 18;
}
2026-01-23 15:43:53 +08:00
return {
2026-01-23 18:38:13 +08:00
index,
2026-01-23 15:43:53 +08:00
label: d.name,
2026-01-23 18:38:13 +08:00
value: d.jobId,
fontSize
2026-01-23 15:43:53 +08:00
};
});
if (careerPaths.value[0]) {
2026-01-23 18:38:13 +08:00
void eventResult(0);
2026-01-23 15:43:53 +08:00
}
} catch (e) {
console.warn(e);
careerPaths.value = [];
2026-01-21 14:26:34 +08:00
}
2026-01-23 15:43:53 +08:00
};
2026-01-23 18:38:13 +08:00
const eventResult = async (index) => {
currentCareerIndex.value = index;
currentCareer.value = careerPaths.value[index] ?? null;
2026-01-21 14:26:34 +08:00
const params = {
2026-01-23 18:38:13 +08:00
jobId: currentCareer.value?.value
2026-01-21 14:26:34 +08:00
};
try {
2026-01-23 18:38:13 +08:00
const { code, msg, data } = await getSkillResult(params);
2026-01-21 14:26:34 +08:00
if (code !== 0) {
2026-01-22 16:46:45 +08:00
uni.showToast({
title: msg,
icon: 'none'
});
2026-01-21 14:26:34 +08:00
return;
}
2026-01-23 15:43:53 +08:00
if (!data) {
return;
}
result.value = data.map((d) => {
return {
label: d.secDimName,
value: d.secDimId,
children: d.skillDetList.map((d) => {
2026-01-21 14:26:34 +08:00
return {
2026-01-23 15:43:53 +08:00
label: d.skillName,
value: d.skillScore,
weight: d.skillWeight
2026-01-21 14:26:34 +08:00
};
2026-01-23 15:43:53 +08:00
})
};
});
2026-01-21 14:26:34 +08:00
} catch (e) {
console.warn(e);
}
};
const eventSearch = () => {
if (pathsRef.value.length === 0) {
2026-01-22 16:46:45 +08:00
uni.showToast({
title: '当前职业暂无发展路径,敬请期待!',
icon: 'none'
2026-01-21 14:26:34 +08:00
});
return;
}
if (!profession.value) {
2026-01-22 16:46:45 +08:00
uni.showToast({
title: '请选择当前职位!',
icon: 'none'
2026-01-21 14:26:34 +08:00
});
return;
}
if (!targetCareer.value) {
2026-01-22 16:46:45 +08:00
uni.showToast({
title: '请选择目标职业!',
icon: 'none'
2026-01-21 14:26:34 +08:00
});
return;
}
2026-01-23 15:43:53 +08:00
void fetchCareerPaths();
2026-01-21 14:26:34 +08:00
};
2026-01-22 01:15:41 +08:00
const eventProfession = (e) => {
professionIndex.value = Number(e.detail.value);
const item = professionsRef.value[ e.detail.value ];
profession.value = item.value;
professionLabel.value = item.label;
targetCareer.value = '';
targetCareerLabel.value = '';
2026-01-23 15:43:53 +08:00
careerPaths.value = [];
2026-01-22 01:15:41 +08:00
result.value = [];
};
2026-01-21 14:26:34 +08:00
2026-01-22 01:15:41 +08:00
const eventTargetCareer = (e) => {
targetCareerIndex.value = Number(e.detail.value);
const item = pathsRef.value[ e.detail.value ];
targetCareer.value = item.value;
targetCareerLabel.value = item.label;
2026-01-23 15:43:53 +08:00
careerPaths.value = [];
2026-01-22 01:15:41 +08:00
result.value = [];
};
void fetchData();
void fetchDataPath();
2026-01-21 14:26:34 +08:00
watch(
2026-01-22 01:15:41 +08:00
() => professionsRef.value,
2026-01-21 14:26:34 +08:00
() => {
2026-01-22 01:15:41 +08:00
if (professionsRef.value[ 0 ]) {
profession.value = professionsRef.value[ 0 ].value;
professionLabel.value = professionsRef.value[ 0 ].label;
2026-01-21 14:26:34 +08:00
}
}
);
return {
2026-01-22 01:15:41 +08:00
professionIndex,
professionLabel,
2026-01-21 14:26:34 +08:00
profession,
professionsRef,
2026-01-22 01:15:41 +08:00
targetCareerIndex,
2026-01-21 14:26:34 +08:00
targetCareer,
2026-01-22 01:15:41 +08:00
targetCareerLabel,
2026-01-21 14:26:34 +08:00
pathsRef,
2026-01-23 15:43:53 +08:00
careerPaths,
currentCareer,
currentCareerLabel,
2026-01-23 18:38:13 +08:00
currentCareerIndex,
2026-01-21 14:26:34 +08:00
result,
2026-01-22 01:15:41 +08:00
eventProfession,
eventTargetCareer,
2026-01-23 15:43:53 +08:00
eventSearch,
eventResult
2026-01-21 14:26:34 +08:00
};
});