diff --git a/components/selectJobs/selectJobs.vue b/components/selectJobs/selectJobs.vue index 2ac6218..686683d 100644 --- a/components/selectJobs/selectJobs.vue +++ b/components/selectJobs/selectJobs.vue @@ -165,7 +165,7 @@ function serchforIt(defaultId) { return; } - $api.createRequest('/app/common/jobTitle/treeselect', {}, 'GET').then((resData) => { + const LoadCache = (resData) => { if (userInfo.value.jobTitleId) { const ids = userInfo.value.jobTitleId.split(',').map((id) => Number(id)); count.value = ids.length; @@ -174,7 +174,8 @@ function serchforIt(defaultId) { state.jobTitleId = userInfo.value.jobTitleId; state.stations = resData.data; state.visible = true; - }); + }; + $api.createRequestWithCache('/app/common/jobTitle/treeselect', {}, 'GET', false, LoadCache).then(LoadCache); } const reset = () => { diff --git a/packageA/pages/Intendedposition/Intendedposition.vue b/packageA/pages/Intendedposition/Intendedposition.vue index 61a7234..08e4e78 100644 --- a/packageA/pages/Intendedposition/Intendedposition.vue +++ b/packageA/pages/Intendedposition/Intendedposition.vue @@ -53,7 +53,7 @@ function getJobList(type = 'add') { current: pageState.page, pageSize: pageState.pageSize, }; - $api.createRequest('/app/user/apply/job', params).then((resData) => { + const LoadCache = (resData) => { const { rows, total } = resData; if (type === 'add') { const str = pageState.pageSize * (pageState.page - 1); @@ -66,8 +66,9 @@ function getJobList(type = 'add') { // pageState.list = resData.rows; pageState.total = resData.total; pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize); - console.log(pageState.list); - }); + }; + + $api.createRequestWithCache('/app/user/apply/job', params, 'GET', false, {}, LoadCache).then(LoadCache); } diff --git a/packageA/pages/addPosition/addPosition.vue b/packageA/pages/addPosition/addPosition.vue index 2eeef40..1545e26 100644 --- a/packageA/pages/addPosition/addPosition.vue +++ b/packageA/pages/addPosition/addPosition.vue @@ -176,12 +176,13 @@ function complete(values) { } function getTree() { - $api.createRequest('/app/common/jobTitle/treeselect', {}, 'GET').then((resData) => { + const LoadCache = (resData) => { if (resData.code === 200) { dataSource.value = flattenTree(resData.data); treeDataList.value = resData.data; } - }); + }; + $api.createRequestWithCache('/app/common/jobTitle/treeselect', {}, 'GET', false, LoadCache).then(LoadCache); } function flattenTree(treeData, parentPath = '') { diff --git a/packageA/pages/collection/collection.vue b/packageA/pages/collection/collection.vue index a627a04..5f1bc81 100644 --- a/packageA/pages/collection/collection.vue +++ b/packageA/pages/collection/collection.vue @@ -178,7 +178,8 @@ function getJobList(type = 'add') { current: pageState.page, pageSize: pageState.pageSize, }; - $api.createRequest('/app/user/collection/job', params).then((resData) => { + const LoadCache = (resData) => { + console.log(resData); const { rows, total } = resData; if (type === 'add') { const str = pageState.pageSize * (pageState.page - 1); @@ -191,7 +192,8 @@ function getJobList(type = 'add') { // pageState.list = resData.rows; pageState.total = resData.total; pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize); - }); + }; + $api.createRequestWithCache('/app/user/collection/job', params, 'GET', false, {}, LoadCache).then(LoadCache); } function getCompanyList(type = 'add') { @@ -206,7 +208,7 @@ function getCompanyList(type = 'add') { current: pageCompanyState.page, pageSize: pageCompanyState.pageSize, }; - $api.createRequest('/app/user/collection/company', params).then((resData) => { + const LoadCache = (resData) => { const { rows, total } = resData; if (type === 'add') { const str = pageCompanyState.pageSize * (pageCompanyState.page - 1); @@ -219,7 +221,8 @@ function getCompanyList(type = 'add') { // pageCompanyState.list = resData.rows; pageCompanyState.total = resData.total; pageCompanyState.maxPage = Math.ceil(pageCompanyState.total / pageCompanyState.pageSize); - }); + }; + $api.createRequestWithCache('/app/user/collection/company', params, 'GET', false, {}, LoadCache).then(LoadCache); } diff --git a/packageA/pages/exhibitors/exhibitors.vue b/packageA/pages/exhibitors/exhibitors.vue index ca3fac5..0a8659a 100644 --- a/packageA/pages/exhibitors/exhibitors.vue +++ b/packageA/pages/exhibitors/exhibitors.vue @@ -134,7 +134,7 @@ onLoad((options) => { }); function getJobFairInfo(id, name) { - $api.createRequest(`/app/internal/jobFairThirdPart/${id}`).then((resData) => { + $api.createRequest(`/app/internal/jobFairThirdPart/${id}`, {}, 'GET', true).then((resData) => { fairInfo.value = resData.data; hasAppointment(); }); @@ -152,21 +152,24 @@ function getCompanyList(type = 'add') { current: pageState.current, pageSize: pageState.pageSize, }; - $api.createRequest(`/app/internal/companyThirdPart/?zphID=${jobFairId}&zphmc=${jobFairName}`, params).then( - (resData) => { - const { rows, total } = resData; - if (type === 'add') { - const str = pageState.pageSize * (pageState.current - 1); - const end = pageState.list.length; - const reslist = rows; - pageState.list.splice(str, end, ...reslist); - } else { - pageState.list = rows; - } - pageState.total = resData.total; - pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize); + $api.createRequest( + `/app/internal/companyThirdPart/?zphID=${jobFairId}&zphmc=${jobFairName}`, + params, + 'GET', + true + ).then((resData) => { + const { rows, total } = resData; + if (type === 'add') { + const str = pageState.pageSize * (pageState.current - 1); + const end = pageState.list.length; + const reslist = rows; + pageState.list.splice(str, end, ...reslist); + } else { + pageState.list = rows; } - ); + pageState.total = resData.total; + pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize); + }); } const hasAppointment = () => { diff --git a/packageA/pages/post/post.vue b/packageA/pages/post/post.vue index f0d83ed..449ea0d 100644 --- a/packageA/pages/post/post.vue +++ b/packageA/pages/post/post.vue @@ -11,7 +11,7 @@ - + @@ -23,7 +23,7 @@ :is-month="true" > - + - {{jobInfo.xlyq == '不限' ? '学历不限' : jobInfo.xlyq}} + {{ jobInfo.xlyq == '不限' ? '学历不限' : jobInfo.xlyq }} - + - {{jobInfo.gwgzjy == '不限' ? '经验不限' : jobInfo.gwgzjy}} + {{ jobInfo.gwgzjy == '不限' ? '经验不限' : jobInfo.gwgzjy }} @@ -83,12 +83,7 @@ 公司信息 - - 单位详情 - + 单位详情 @@ -103,12 +98,12 @@ :value="jobInfo.company?.industry" >   - - {{jobInfo.qyxz}} + {{ jobInfo.qyxz }} 在招 @@ -156,19 +151,24 @@ - + @@ -232,12 +232,12 @@ function getDetail(jobId) { if (dataType.value === 2) { // 第三方数据接口 return new Promise((reslove, reject) => { - $api.createRequest(`/app/internal/jobThirdPart/${jobId}`).then((resData) => { + $api.createRequest(`/app/internal/jobThirdPart/${jobId}`, {}, 'GET', true).then((resData) => { const { gsID, gsmc, zphID } = resData.data; jobInfo.value = resData.data; reslove(resData.data); getCompanyIsAJobs(gsID, gsmc, zphID); - + if (resData.data.latitude && resData.data.longitude) { initMapCovers(resData.data.latitude, resData.data.longitude, resData.data.gsmc); } @@ -245,12 +245,12 @@ function getDetail(jobId) { }); } else { // 原数据接口 - $api.createRequest(`/app/job/${jobId}`).then((resData) => { + $api.createRequest(`/app/job/${jobId}`, {}, 'GET', true).then((resData) => { const { latitude, longitude, companyName, companyId } = resData.data; jobInfo.value = resData.data; getCompanyIsAJobs(companyId); getCompetivetuveness(jobId); - + if (latitude && longitude) { initMapCovers(latitude, longitude, companyName); } @@ -315,12 +315,12 @@ function jobApply() { if (dataType.value === 2) { // 第三方数据申请逻辑 const params = { - jobid:jobInfo.value.id, - jobname:jobInfo.value.gwmc - } + jobid: jobInfo.value.id, + jobname: jobInfo.value.gwmc, + }; if (jobInfo.value.isApply) { $api.msg('已经投递过该岗位了~'); - return ; + return; } else { $api.createRequest(`/app/internal/sendResume`, params, 'POST').then((resData) => { $api.msg('投递成功'); @@ -380,7 +380,9 @@ function jobCollection() { // 处理公司详情跳转 function handleCompanyDetail() { if (dataType.value === 2) { - navTo(`/packageA/pages/UnitDetails/UnitDetails?companyId=${jobInfo.value.gsID}&companyName=${jobInfo.value.gsmc}&zphId=${jobInfo.value.zphID}&dataType=2`); + navTo( + `/packageA/pages/UnitDetails/UnitDetails?companyId=${jobInfo.value.gsID}&companyName=${jobInfo.value.gsmc}&zphId=${jobInfo.value.zphID}&dataType=2` + ); } else { navTo(`/packageA/pages/UnitDetails/UnitDetails?companyId=${jobInfo.value.company.companyId}`); } @@ -660,4 +662,4 @@ for i in 0..100 box-shadow: 0rpx -4rpx 24rpx 0rpx rgba(11,44,112,0.12); } } - \ No newline at end of file + diff --git a/packageA/pages/reservation/reservation.vue b/packageA/pages/reservation/reservation.vue index bd2aa1d..31c8dd2 100644 --- a/packageA/pages/reservation/reservation.vue +++ b/packageA/pages/reservation/reservation.vue @@ -127,7 +127,7 @@ function getList(type = 'add', loading = true) { pageSize: pageState.pageSize, type: ranItem.value.value, }; - $api.createRequest('/app/user/collection/fair', params).then((resData) => { + const LoadCache = (resData) => { const { rows, total } = resData; if (type === 'add') { const str = pageState.pageSize * (pageState.page - 1); @@ -140,7 +140,8 @@ function getList(type = 'add', loading = true) { // pageState.list = resData.rows; pageState.total = resData.total; pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize); - }); + }; + $api.createRequestWithCache('/app/user/collection/fair', params, 'GET', false, {}, LoadCache).then(LoadCache); } diff --git a/pages/careerfair/careerfair.vue b/pages/careerfair/careerfair.vue index 5d5495b..c5023f1 100644 --- a/pages/careerfair/careerfair.vue +++ b/pages/careerfair/careerfair.vue @@ -201,7 +201,7 @@ function getFair(type = 'add') { if (currentDay.value?.fullDate) { params.zphjbsj = currentDay.value.fullDate.replace(/-/g, ''); } - $api.createRequest('/app/internal/jobFairThirdPart', params).then((resData) => { + $api.createRequest('/app/internal/jobFairThirdPart', params, 'GET', true).then((resData) => { const { rows, total } = resData; if (type === 'add') { // const str = pageState.pageSize * (pageState.page - 1); diff --git a/pages/login/login.vue b/pages/login/login.vue index 096b691..578c658 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -241,9 +241,10 @@ function nextStep() { // 获取职位 function getTreeselect() { - $api.createRequest('/app/common/jobTitle/treeselect', {}, 'GET').then((resData) => { + const LoadCache = (resData) => { state.station = resData.data; - }); + }; + $api.createRequestWithCache('/app/common/jobTitle/treeselect', {}, 'GET', false, LoadCache).then(LoadCache); } function loginbackdoor() { diff --git a/pages/nearby/components/four.vue b/pages/nearby/components/four.vue index cd84057..130fc65 100644 --- a/pages/nearby/components/four.vue +++ b/pages/nearby/components/four.vue @@ -381,14 +381,17 @@ defineExpose({ loadData, handleFilterConfirm }); border-radius: 12rpx 12rpx 12rpx 12rpx; .nearby-list border-top: 2rpx solid #EBEBEB; - height: calc(100% - 140rpx) + min-height: calc(100% - 140rpx) background: #f4f4f4 + display: flex; + flex-direction: column; .one-cards{ height: 100% display: flex; flex-direction: column; padding: 0 20rpx 20rpx 20rpx; background: #f4f4f4 + flex: 1 } .nav-filter padding: 16rpx 28rpx 0 28rpx diff --git a/pages/nearby/components/one.vue b/pages/nearby/components/one.vue index 33241ce..8641473 100644 --- a/pages/nearby/components/one.vue +++ b/pages/nearby/components/one.vue @@ -370,14 +370,17 @@ defineExpose({ loadData, handleFilterConfirm }); background: #e8e8e8; overflow: hidden .nearby-list - height: calc(100% - 384rpx) + min-height: calc(100% - 384rpx) background: #f4f4f4 + display: flex; + flex-direction: column; .one-cards{ display: flex; flex-direction: column; padding: 0 20rpx 20rpx 20rpx; background: #f4f4f4 height: 100% + flex: 1 } .nav-filter padding: 16rpx 28rpx 0 28rpx diff --git a/pages/nearby/components/three.vue b/pages/nearby/components/three.vue index 02fe209..5d2bc68 100644 --- a/pages/nearby/components/three.vue +++ b/pages/nearby/components/three.vue @@ -483,14 +483,17 @@ defineExpose({ loadData, handleFilterConfirm }); z-index: 1; .nearby-list border-top: 2rpx solid #EBEBEB; - height: calc(100% - 222rpx) + min-height: calc(100% - 222rpx) background: #f4f4f4 + display: flex; + flex-direction: column; .one-cards{ height: 100% display: flex; flex-direction: column; padding: 0 20rpx 20rpx 20rpx; background: #f4f4f4 + flex: 1 } .nav-filter padding: 16rpx 28rpx 0 28rpx diff --git a/pages/nearby/components/two.vue b/pages/nearby/components/two.vue index 4245977..e7b8642 100644 --- a/pages/nearby/components/two.vue +++ b/pages/nearby/components/two.vue @@ -285,14 +285,17 @@ defineExpose({ loadData, handleFilterConfirm }); border-radius: 12rpx 12rpx 12rpx 12rpx; .nearby-list border-top: 2rpx solid #EBEBEB; - height: calc(100% - 252rpx) + min-height: calc(100% - 252rpx) background: #f4f4f4 + display: flex; + flex-direction: column; .one-cards{ display: flex; flex-direction: column; padding: 0 20rpx 20rpx 20rpx; background: #f4f4f4 height: 100% + flex: 1 } .nav-filter padding: 16rpx 28rpx 0 28rpx diff --git a/stores/useReadMsg.js b/stores/useReadMsg.js index 7f0760d..f99f62a 100644 --- a/stores/useReadMsg.js +++ b/stores/useReadMsg.js @@ -12,27 +12,25 @@ import { $api, } from '../common/globalFunction'; -// 控制消息 +// 常量定义:消息在 TabBar 的索引位置 +const TABBAR_INDEX = 3; + export const useReadMsg = defineStore('readMsg', () => { const msgList = ref([]) + // 用于自定义 Tabbar 组件的渲染 const badges = ref([{ - count: 0 - }, - { - count: 0 - }, - { - count: 0 - }, - { - count: 0 - }, - { - count: 0 - }, - ]) + count: 0 + }, { + count: 0 + }, { + count: 0 + }, { + count: 0 + }, { + count: 0 + }]) - // 计算总未读数量,基于 notReadCount 字段 + // 计算总未读数量 const unreadCount = computed(() => msgList.value.reduce((sum, msg) => sum + (msg.notReadCount || 0), 0) ) @@ -42,40 +40,49 @@ export const useReadMsg = defineStore('readMsg', () => { msgList.value.filter(msg => msg.notReadCount > 0) ) - - // 设置 TabBar 角标 - function updateTabBarBadge() { + function updateBadgeEffect() { const count = unreadCount.value - const index = 3 - const countVal = count > 99 ? '99+' : String(count) - if (count === 0) { - uni.removeTabBarBadge({ - index - }) // 替换为你消息页面的 TabBar index - badges.value[index] = { - count: 0 + // 处理显示文本:超过99显示99+ + const countStr = count > 99 ? '99+' : String(count) + + // 1. 更新内部状态 (用于自定义 UI) + if (badges.value[TABBAR_INDEX]) { + badges.value[TABBAR_INDEX].count = count === 0 ? 0 : countStr + } + + // 2. 更新系统原生 TabBar + // 加 try-catch 防止在非 Tabbar 页面或加栽未完成时报错 + try { + if (count > 0) { + uni.setTabBarBadge({ + index: TABBAR_INDEX, + text: countStr + }) + } else { + uni.removeTabBarBadge({ + index: TABBAR_INDEX + }) } - } else { - badges.value[index] = { - count: countVal - } - uni.setTabBarBadge({ - index, - text: countVal - }) + } catch (e) { + console.warn('TabBar Badge 更新失败(可能当前非TabBar页面):', e) } } + watch(unreadCount, () => { + updateBadgeEffect() + console.log('value', unreadCount.value) + }, { + immediate: true + }) + // 拉取消息列表 async function fetchMessages() { try { - $api.createRequest('/app/notice/info', { + const res = await $api.createRequest('/app/notice/info', { isRead: 1 - }, "GET").then((res) => { - msgList.value = res.data || [] - updateTabBarBadge() - }) + }, "GET") + msgList.value = res.data || [] } catch (err) { console.error('获取消息失败:', err) } @@ -83,17 +90,23 @@ export const useReadMsg = defineStore('readMsg', () => { // 设置为已读 async function markAsRead(item, index) { - const msg = msgList.value[index] - if (!msg || msg.isRead === 1) return + const targetMsg = msgList.value[index] + if (!targetMsg) return + + // 如果已经是已读,直接返回,避免无效请求 + // 假设服务端逻辑是:isRead=1 表示已读 (注意检查你的字段定义) + // 你的原代码判断是 if (msg.isRead === 1) return,如果是这样,下面请求成功应该设为 1 + // 但通常未读是0,已读是1。这里维持你原有的逻辑,假设服务端把 notReadCount 清零 try { let params = { - id: msg.noticeId + id: targetMsg.noticeId } - $api.createRequest('/app/notice/read?id=' + msg.noticeId, params, "POST").then((res) => { - msgList.value[index].isRead = 1 - updateTabBarBadge() - }) + await $api.createRequest('/app/notice/read?id=' + targetMsg.noticeId, params, "POST") + + // 更新本地数据 + msgList.value[index].notReadCount = 0 + msgList.value[index].isRead = 1 // 标记已读状态 } catch (err) { console.error('设置消息已读失败:', err) } @@ -106,8 +119,8 @@ export const useReadMsg = defineStore('readMsg', () => { unreadCount, fetchMessages, markAsRead, - updateTabBarBadge + updateTabBarBadge: updateBadgeEffect } }, { - unistorage: true, + unistorage: true, // 开启持久化 }) \ No newline at end of file diff --git a/utils/request.js b/utils/request.js index b4eca8d..deb722a 100644 --- a/utils/request.js +++ b/utils/request.js @@ -26,6 +26,10 @@ const needToEncrypt = [ */ export async function createRequestWithCache(url, data = {}, method = 'GET', loading = false, headers = {}, onCacheLoad = null) { + // 是分页接口的话, 只缓存第一页的数据 + if (data.current && data.current > 1) { + return createRequest(url, data, method, loading, headers); + } const cacheKey = `${method.toUpperCase()}:${url}:${JSON.stringify(data)}`; baseDB.getDB().then(async (dbHelper) => { @@ -77,13 +81,16 @@ export function createRequest(url, data = {}, method = 'GET', loading = false, h mask: true }) } - let Authorization = '' - if (useUserStore().token) { - Authorization = `${useUserStore().token}` - } + let header = { + ...headers + }; + const userStore = useUserStore(); + const token = userStore.token; - const header = headers || {}; - header["Authorization"] = encodeURIComponent(Authorization); + if (token) { + // 确保 Authorization 不会被覆盖,且进行编码 + header["Authorization"] = encodeURIComponent(token); + } // ------------------------------------------------------------------ // 检查当前请求是否需要加密