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, getPathDetail } from '@/apiRc/service/careerPath';
|
|
|
|
|
|
2026-01-21 14:26:34 +08:00
|
|
|
|
|
|
|
|
export const useCareerPathStore = defineStore('career-path', () => {
|
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-22 01:15:41 +08:00
|
|
|
return `${ d.startJobId }` === profession.value;
|
2026-01-21 14:26:34 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = ref([]);
|
|
|
|
|
|
|
|
|
|
const fetchData = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const { code, msg, data } = await getCurrentPosition();
|
|
|
|
|
if (code !== 0) {
|
|
|
|
|
$emitter.emit('error-message', msg);
|
|
|
|
|
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) {
|
|
|
|
|
$emitter.emit('error-message', msg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!data) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
paths.value = data.map((d) => {
|
|
|
|
|
return {
|
|
|
|
|
label: d.endJob,
|
2026-01-22 01:15:41 +08:00
|
|
|
value: `${ d.startJobId }-${ d.endJobId }`,
|
2026-01-21 14:26:34 +08:00
|
|
|
startJobId: d.startJobId
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn(e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const fetchResult = async () => {
|
|
|
|
|
if (!targetCareer.value) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-01-22 01:15:41 +08:00
|
|
|
const [ startJobId, endJobId ] = targetCareer.value.split('-');
|
2026-01-21 14:26:34 +08:00
|
|
|
const params = {
|
|
|
|
|
startJobId: Number(startJobId),
|
|
|
|
|
endJobId: Number(endJobId)
|
|
|
|
|
};
|
|
|
|
|
try {
|
|
|
|
|
const { code, msg, data } = await getPathDetail(params);
|
|
|
|
|
if (code !== 0) {
|
|
|
|
|
$emitter.emit('error-message', msg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!data) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
result.value = data.map((d, i) => {
|
|
|
|
|
return {
|
2026-01-22 01:15:41 +08:00
|
|
|
type: i === 0 ? 'start' : i === data.length - 1 ? 'end' : 'step',
|
2026-01-21 14:26:34 +08:00
|
|
|
step: i,
|
|
|
|
|
title: d.name,
|
|
|
|
|
tags: d.skillNameList.split(',')
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.warn(e);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const eventSearch = () => {
|
|
|
|
|
if (pathsRef.value.length === 0) {
|
|
|
|
|
ElMessage.warning({
|
|
|
|
|
message: '当前职业暂无发展路径,敬请期待!',
|
|
|
|
|
duration: 5000
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!profession.value) {
|
|
|
|
|
ElMessage.warning({
|
|
|
|
|
message: '请选择当前职位!',
|
|
|
|
|
duration: 5000
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!targetCareer.value) {
|
|
|
|
|
ElMessage.warning({
|
|
|
|
|
message: '请选择目标职业!',
|
|
|
|
|
duration: 5000
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
void fetchResult();
|
|
|
|
|
};
|
|
|
|
|
|
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 = '';
|
|
|
|
|
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;
|
|
|
|
|
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,
|
|
|
|
|
result,
|
2026-01-22 01:15:41 +08:00
|
|
|
eventProfession,
|
|
|
|
|
eventTargetCareer,
|
2026-01-21 14:26:34 +08:00
|
|
|
eventSearch
|
|
|
|
|
};
|
|
|
|
|
});
|