From d80baf6f0be2cef4966da3921677f518264f28d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E8=BE=89?= <13935151924@163.com> Date: Fri, 24 Oct 2025 17:53:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=B2=97=E4=BD=8D=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8=E4=B8=A4=E6=AC=A1?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/components/index-one.vue | 40 +++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/pages/index/components/index-one.vue b/pages/index/components/index-one.vue index 8d6a2bb..bcd7b95 100644 --- a/pages/index/components/index-one.vue +++ b/pages/index/components/index-one.vue @@ -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(); }; // 处理附近工作点击