微信小程序兼容修改

This commit is contained in:
冯辉
2025-11-04 21:12:12 +08:00
parent 81aae7a9ad
commit 349d17b5c4
10 changed files with 528 additions and 186 deletions

View File

@@ -208,7 +208,20 @@ const jobInfo = ref({});
const state = reactive({});
const mapCovers = ref([]);
const jobIdRef = ref();
const raderData = ref({});
// 竞争力分析数据,初始化为包含默认值的完整结构,确保雷达图能正常渲染
const raderData = ref({
matchScore: 0,
rank: 0,
percentile: 0,
radarChart: {
skill: 0,
experience: 0,
education: 0,
salary: 0,
age: 0,
location: 0
}
});
const videoPalyerRef = ref(null);
const explainUrlRef = ref('');
@@ -246,10 +259,17 @@ onLoad((option) => {
});
onShow(() => {
const option = parseQueryParams(); // 兼容微信内置浏览器
if (option.jobId) {
initLoad(option);
// 仅在 H5 环境中从 URL 获取参数(小程序环境中 onShow 不会传递 URL 参数)
// #ifdef H5
try {
const option = parseQueryParams(); // 兼容微信内置浏览器
if (option.jobId) {
initLoad(option);
}
} catch (e) {
console.warn('onShow 中解析 URL 参数失败:', e);
}
// #endif
});
function initLoad(option) {
@@ -317,8 +337,59 @@ function getTextWidth(text, size = 12) {
function getCompetivetuveness(jobId) {
$api.createRequest(`/app/job/competitiveness/${jobId}`, {}, 'GET').then((resData) => {
raderData.value = resData.data;
currentStep.value = resData.data.matchScore * 0.04;
// 如果接口返回的数据为 null 或空使用默认值0
if (resData && resData.data) {
// 确保 radarChart 字段存在,如果不存在则使用默认值
const radarChart = resData.data.radarChart || {
skill: 0,
experience: 0,
education: 0,
salary: 0,
age: 0,
location: 0
};
raderData.value = {
matchScore: resData.data.matchScore || 0,
rank: resData.data.rank || 0,
percentile: resData.data.percentile || 0,
radarChart: radarChart
};
currentStep.value = (resData.data.matchScore || 0) * 0.04;
} else {
// 接口返回 null 或空数据时使用默认值0
raderData.value = {
matchScore: 0,
rank: 0,
percentile: 0,
radarChart: {
skill: 0,
experience: 0,
education: 0,
salary: 0,
age: 0,
location: 0
}
};
currentStep.value = 0;
}
}).catch((error) => {
// 接口请求失败时使用默认值0
console.error('获取竞争力分析失败:', error);
raderData.value = {
matchScore: 0,
rank: 0,
percentile: 0,
radarChart: {
skill: 0,
experience: 0,
education: 0,
salary: 0,
age: 0,
location: 0
}
};
currentStep.value = 0;
});
}