首页岗位列表接口调用两次的问题修改

This commit is contained in:
冯辉
2025-10-24 17:53:53 +08:00
parent 5a31d56c9a
commit d80baf6f0b

View File

@@ -559,10 +559,17 @@ const rangeOptions = ref([
{ value: 3, text: '疆外' },
]);
const isLoaded = ref(false);
const isInitialized = ref(false); // 添加初始化标志
const { columnCount, columnSpace } = useColumnCount(() => {
pageState.pageSize = 10 * (columnCount.value - 1);
getJobRecommend('refresh');
// 只在首次初始化时调用,避免重复调用
if (!isInitialized.value) {
isInitialized.value = true;
getJobRecommend('refresh');
}
nextTick(() => {
waterfallsFlowRef.value?.refresh?.();
useLocationStore().getLocation();
@@ -575,6 +582,13 @@ const getCompanyInfo = () => {
const cachedUserInfo = uni.getStorageSync('userInfo') || {};
console.log('缓存中的userInfo:', cachedUserInfo);
// 重置企业信息
companyInfo.name = '';
companyInfo.avatar = '';
companyInfo.industry = '';
companyInfo.scale = '';
companyInfo.isVerified = false;
// 检查是否有company字段
if (cachedUserInfo.company) {
const company = cachedUserInfo.company;
@@ -588,19 +602,23 @@ const getCompanyInfo = () => {
// 判断是否实名legalIdCard字段有值则表示已实名
companyInfo.isVerified = !!(company.legalIdCard && company.legalIdCard.trim());
console.log('企业信息:', {
console.log('企业信息已更新:', {
name: companyInfo.name,
industry: companyInfo.industry,
size: companyInfo.scale,
isVerified: companyInfo.isVerified
});
} else {
console.log('缓存中没有company字段');
// 保持默认值
console.log('缓存中没有company字段,企业信息已重置');
}
} catch (error) {
console.error('获取企业信息失败:', error);
// 保持默认值
// 重置为默认值
companyInfo.name = '';
companyInfo.avatar = '';
companyInfo.industry = '';
companyInfo.scale = '';
companyInfo.isVerified = false;
}
};
@@ -611,8 +629,6 @@ const goToCompanyInfo = () => {
// 组件初始化时加载数据
onMounted(() => {
getJobRecommend('refresh');
// 获取企业信息
getCompanyInfo();
@@ -631,6 +647,13 @@ onShow(() => {
getCompanyInfo();
});
// 监听用户信息变化,当登录状态改变时重新获取企业信息
watch([hasLogin, userInfo], () => {
if (hasLogin.value) {
getCompanyInfo();
}
}, { deep: true });
// 登录检查函数
const checkLogin = () => {
const tokenValue = uni.getStorageSync('token') || '';
@@ -646,6 +669,9 @@ const checkLogin = () => {
const handleLoginSuccess = () => {
// 登录成功后刷新数据
getJobRecommend('refresh');
// 重新获取企业信息
getCompanyInfo();
};
// 处理附近工作点击