From 4c8f79555d0a61478a1846e12b5826319cfd1d0e Mon Sep 17 00:00:00 2001 From: Apcallover <1503963513@qq.com> Date: Thu, 23 Jul 2026 21:29:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AD=9B=E9=80=89=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E6=95=B0=E6=8D=AE=E5=8A=A0=E8=BD=BD=E7=AB=9E=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../new-filter-page/new-filter-page.vue | 40 ++++----- pages/index/components/index-one.vue | 43 ++++----- stores/useDictStore.js | 88 +++++++++++-------- 3 files changed, 91 insertions(+), 80 deletions(-) diff --git a/components/new-filter-page/new-filter-page.vue b/components/new-filter-page/new-filter-page.vue index c834b8c..a956c7c 100644 --- a/components/new-filter-page/new-filter-page.vue +++ b/components/new-filter-page/new-filter-page.vue @@ -26,6 +26,24 @@ + + + + + + + @@ -62,24 +80,6 @@ - - - - - - - @@ -169,16 +169,16 @@ const getJobTypeData = () => { // 标签页数据 const tabs = [ + { key: 'salary', label: '薪资' }, { key: 'education', label: '学历要求' }, { key: 'experience', label: '工作经验' }, - { key: 'salary', label: '薪资' }, { key: 'scale', label: '公司规模' }, { key: 'jobType', label: '岗位类型' }, { key: 'area', label: '地区' } ]; // 当前激活的标签 -const activeTab = ref('education'); +const activeTab = ref('salary'); // 存储已选中的值 const selectedValues = reactive({ diff --git a/pages/index/components/index-one.vue b/pages/index/components/index-one.vue index 0ab5ddc..a884acc 100644 --- a/pages/index/components/index-one.vue +++ b/pages/index/components/index-one.vue @@ -847,6 +847,28 @@ onUnmounted(() => { uni.$off('citySelected'); }); +const isFourLevelLinkagePurview = ref(false); +const getIsFourLevelLinkagePurview = () => { + let userInfo = uni.getStorageSync('userInfo'); + if (userInfo) { + $api.myRequest( + '/auth/login2/ks', + { userid: userInfo.dwUserid, idcardno: userInfo.idCard }, + 'POST', + 9100, + {} + ).then((res) => { + if (res.code == 200) { + uni.setStorageSync('fourLevelLinkage-token', res.data.access_token); + let roleIdList = ['103', '106', '107']; + if (res.data.roleIdList.some((item) => roleIdList.includes(item))) { + isFourLevelLinkagePurview.value = true; + } + } + }); + } +}; + onShow(() => { // 页面显示时获取最新的企业信息 getCompanyInfo(); @@ -1458,27 +1480,6 @@ const toggleJobStatus = (job) => { $api.msg(isCurrentlyUp ? '下架失败,请重试' : '上架失败,请重试'); }); }; -const isFourLevelLinkagePurview = ref(false); -const getIsFourLevelLinkagePurview = () => { - let userInfo = uni.getStorageSync('userInfo'); - if (userInfo) { - $api.myRequest( - '/auth/login2/ks', - { userid: userInfo.dwUserid, idcardno: userInfo.idCard }, - 'POST', - 9100, - {} - ).then((res) => { - if (res.code == 200) { - uni.setStorageSync('fourLevelLinkage-token', res.data.access_token); - let roleIdList = ['103', '106', '107']; - if (res.data.roleIdList.some((item) => roleIdList.includes(item))) { - isFourLevelLinkagePurview.value = true; - } - } - }); - } -}; function dataToImg(data) { const result = data.map((item) => ({ ...item, diff --git a/stores/useDictStore.js b/stores/useDictStore.js index cae10f5..5001eee 100644 --- a/stores/useDictStore.js +++ b/stores/useDictStore.js @@ -11,6 +11,8 @@ import { // 静态树 O(1) 超快查询!!!!! let IndustryMap = null +// 复用同一批字典请求,避免 App 启动和页面组件同时初始化时产生竞态。 +let dictDataPromise = null // 构建索引 function buildIndex(tree) { const map = new Map(); @@ -50,46 +52,54 @@ const useDictStore = defineStore("dict", () => { return data }) } - if (complete.value) return - if (dictLoading.value) return - dictLoading.value = true - try { - const [education, experience, area, scale, sex, affiliation, nature, noticeType] = - await Promise.all([ - getDictSelectOption('education'), - getDictSelectOption('experience'), - getDictSelectOption('area', true), - getDictSelectOption('scale'), - getDictSelectOption('app_sex'), - getDictSelectOption('political_affiliation'), - getDictSelectOption('company_nature'), - getDictSelectOption('sys_notice_type'), - ]); + if (complete.value) return Promise.resolve() + // App.vue 会在启动时加载字典,页面组件也可能同时加载。 + // 不能在请求进行中直接 return,否则调用方会把当时的空 state 复制下来。 + if (dictDataPromise) return dictDataPromise - state.education = education; - state.experience = experience; - state.area = area; - state.scale = scale; - state.sex = sex; - state.affiliation = affiliation; - state.nature = nature - state.noticeType = noticeType - complete.value = true - getIndustryDict() // 获取行业 - } catch (error) { - console.error('Error fetching dictionary data:', error); - // 确保即使出错也能返回空数组 - state.education = []; - state.experience = []; - state.area = []; - state.scale = []; - state.sex = []; - state.affiliation = []; - state.nature = []; - state.noticeType = []; - } finally { - dictLoading.value = false - } + dictLoading.value = true + dictDataPromise = (async () => { + try { + const [education, experience, area, scale, sex, affiliation, nature, noticeType] = + await Promise.all([ + getDictSelectOption('education'), + getDictSelectOption('experience'), + getDictSelectOption('area', true), + getDictSelectOption('scale'), + getDictSelectOption('app_sex'), + getDictSelectOption('political_affiliation'), + getDictSelectOption('company_nature'), + getDictSelectOption('sys_notice_type'), + ]); + + state.education = education; + state.experience = experience; + state.area = area; + state.scale = scale; + state.sex = sex; + state.affiliation = affiliation; + state.nature = nature + state.noticeType = noticeType + complete.value = true + getIndustryDict() // 获取行业 + } catch (error) { + console.error('Error fetching dictionary data:', error); + // 确保即使出错也能返回空数组 + state.education = []; + state.experience = []; + state.area = []; + state.scale = []; + state.sex = []; + state.affiliation = []; + state.nature = []; + state.noticeType = []; + } finally { + dictLoading.value = false + dictDataPromise = null + } + })() + + return dictDataPromise }; async function getIndustryDict() {