flat: 优化

This commit is contained in:
Apcallover
2025-11-30 16:47:06 +08:00
parent 8cf55d3925
commit 9a38bbd298
15 changed files with 167 additions and 122 deletions

View File

@@ -165,7 +165,7 @@ function serchforIt(defaultId) {
return; return;
} }
$api.createRequest('/app/common/jobTitle/treeselect', {}, 'GET').then((resData) => { const LoadCache = (resData) => {
if (userInfo.value.jobTitleId) { if (userInfo.value.jobTitleId) {
const ids = userInfo.value.jobTitleId.split(',').map((id) => Number(id)); const ids = userInfo.value.jobTitleId.split(',').map((id) => Number(id));
count.value = ids.length; count.value = ids.length;
@@ -174,7 +174,8 @@ function serchforIt(defaultId) {
state.jobTitleId = userInfo.value.jobTitleId; state.jobTitleId = userInfo.value.jobTitleId;
state.stations = resData.data; state.stations = resData.data;
state.visible = true; state.visible = true;
}); };
$api.createRequestWithCache('/app/common/jobTitle/treeselect', {}, 'GET', false, LoadCache).then(LoadCache);
} }
const reset = () => { const reset = () => {

View File

@@ -53,7 +53,7 @@ function getJobList(type = 'add') {
current: pageState.page, current: pageState.page,
pageSize: pageState.pageSize, pageSize: pageState.pageSize,
}; };
$api.createRequest('/app/user/apply/job', params).then((resData) => { const LoadCache = (resData) => {
const { rows, total } = resData; const { rows, total } = resData;
if (type === 'add') { if (type === 'add') {
const str = pageState.pageSize * (pageState.page - 1); const str = pageState.pageSize * (pageState.page - 1);
@@ -66,8 +66,9 @@ function getJobList(type = 'add') {
// pageState.list = resData.rows; // pageState.list = resData.rows;
pageState.total = resData.total; pageState.total = resData.total;
pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize); pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize);
console.log(pageState.list); };
});
$api.createRequestWithCache('/app/user/apply/job', params, 'GET', false, {}, LoadCache).then(LoadCache);
} }
</script> </script>

View File

@@ -176,12 +176,13 @@ function complete(values) {
} }
function getTree() { function getTree() {
$api.createRequest('/app/common/jobTitle/treeselect', {}, 'GET').then((resData) => { const LoadCache = (resData) => {
if (resData.code === 200) { if (resData.code === 200) {
dataSource.value = flattenTree(resData.data); dataSource.value = flattenTree(resData.data);
treeDataList.value = resData.data; treeDataList.value = resData.data;
} }
}); };
$api.createRequestWithCache('/app/common/jobTitle/treeselect', {}, 'GET', false, LoadCache).then(LoadCache);
} }
function flattenTree(treeData, parentPath = '') { function flattenTree(treeData, parentPath = '') {

View File

@@ -178,7 +178,8 @@ function getJobList(type = 'add') {
current: pageState.page, current: pageState.page,
pageSize: pageState.pageSize, pageSize: pageState.pageSize,
}; };
$api.createRequest('/app/user/collection/job', params).then((resData) => { const LoadCache = (resData) => {
console.log(resData);
const { rows, total } = resData; const { rows, total } = resData;
if (type === 'add') { if (type === 'add') {
const str = pageState.pageSize * (pageState.page - 1); const str = pageState.pageSize * (pageState.page - 1);
@@ -191,7 +192,8 @@ function getJobList(type = 'add') {
// pageState.list = resData.rows; // pageState.list = resData.rows;
pageState.total = resData.total; pageState.total = resData.total;
pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize); pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize);
}); };
$api.createRequestWithCache('/app/user/collection/job', params, 'GET', false, {}, LoadCache).then(LoadCache);
} }
function getCompanyList(type = 'add') { function getCompanyList(type = 'add') {
@@ -206,7 +208,7 @@ function getCompanyList(type = 'add') {
current: pageCompanyState.page, current: pageCompanyState.page,
pageSize: pageCompanyState.pageSize, pageSize: pageCompanyState.pageSize,
}; };
$api.createRequest('/app/user/collection/company', params).then((resData) => { const LoadCache = (resData) => {
const { rows, total } = resData; const { rows, total } = resData;
if (type === 'add') { if (type === 'add') {
const str = pageCompanyState.pageSize * (pageCompanyState.page - 1); const str = pageCompanyState.pageSize * (pageCompanyState.page - 1);
@@ -219,7 +221,8 @@ function getCompanyList(type = 'add') {
// pageCompanyState.list = resData.rows; // pageCompanyState.list = resData.rows;
pageCompanyState.total = resData.total; pageCompanyState.total = resData.total;
pageCompanyState.maxPage = Math.ceil(pageCompanyState.total / pageCompanyState.pageSize); pageCompanyState.maxPage = Math.ceil(pageCompanyState.total / pageCompanyState.pageSize);
}); };
$api.createRequestWithCache('/app/user/collection/company', params, 'GET', false, {}, LoadCache).then(LoadCache);
} }
</script> </script>

View File

@@ -134,7 +134,7 @@ onLoad((options) => {
}); });
function getJobFairInfo(id, name) { 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; fairInfo.value = resData.data;
hasAppointment(); hasAppointment();
}); });
@@ -152,8 +152,12 @@ function getCompanyList(type = 'add') {
current: pageState.current, current: pageState.current,
pageSize: pageState.pageSize, pageSize: pageState.pageSize,
}; };
$api.createRequest(`/app/internal/companyThirdPart/?zphID=${jobFairId}&zphmc=${jobFairName}`, params).then( $api.createRequest(
(resData) => { `/app/internal/companyThirdPart/?zphID=${jobFairId}&zphmc=${jobFairName}`,
params,
'GET',
true
).then((resData) => {
const { rows, total } = resData; const { rows, total } = resData;
if (type === 'add') { if (type === 'add') {
const str = pageState.pageSize * (pageState.current - 1); const str = pageState.pageSize * (pageState.current - 1);
@@ -165,8 +169,7 @@ function getCompanyList(type = 'add') {
} }
pageState.total = resData.total; pageState.total = resData.total;
pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize); pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize);
} });
);
} }
const hasAppointment = () => { const hasAppointment = () => {

View File

@@ -83,12 +83,7 @@
<view class="content-card"> <view class="content-card">
<view class="card-title"> <view class="card-title">
<text class="title">公司信息</text> <text class="title">公司信息</text>
<text <text class="btntext button-click" @click="handleCompanyDetail">单位详情</text>
class="btntext button-click"
@click="handleCompanyDetail"
>
单位详情
</text>
</view> </view>
<view class="company-info"> <view class="company-info">
<view class="companyinfo-left"> <view class="companyinfo-left">
@@ -162,7 +157,12 @@
<template #footer> <template #footer>
<view class="footer"> <view class="footer">
<view v-if="dataType==2" class="btn-wq button-click" :class="{'btn-des' : jobInfo.isApply}" @click="jobApply"> <view
v-if="dataType == 2"
class="btn-wq button-click"
:class="{ 'btn-des': jobInfo.isApply }"
@click="jobApply"
>
<span v-if="jobInfo.isApply">已投递</span> <span v-if="jobInfo.isApply">已投递</span>
<span v-if="!jobInfo.isApply">立即投递</span> <span v-if="!jobInfo.isApply">立即投递</span>
</view> </view>
@@ -232,7 +232,7 @@ function getDetail(jobId) {
if (dataType.value === 2) { if (dataType.value === 2) {
// 第三方数据接口 // 第三方数据接口
return new Promise((reslove, reject) => { 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; const { gsID, gsmc, zphID } = resData.data;
jobInfo.value = resData.data; jobInfo.value = resData.data;
reslove(resData.data); reslove(resData.data);
@@ -245,7 +245,7 @@ function getDetail(jobId) {
}); });
} else { } else {
// 原数据接口 // 原数据接口
$api.createRequest(`/app/job/${jobId}`).then((resData) => { $api.createRequest(`/app/job/${jobId}`, {}, 'GET', true).then((resData) => {
const { latitude, longitude, companyName, companyId } = resData.data; const { latitude, longitude, companyName, companyId } = resData.data;
jobInfo.value = resData.data; jobInfo.value = resData.data;
getCompanyIsAJobs(companyId); getCompanyIsAJobs(companyId);
@@ -316,8 +316,8 @@ function jobApply() {
// 第三方数据申请逻辑 // 第三方数据申请逻辑
const params = { const params = {
jobid: jobInfo.value.id, jobid: jobInfo.value.id,
jobname:jobInfo.value.gwmc jobname: jobInfo.value.gwmc,
} };
if (jobInfo.value.isApply) { if (jobInfo.value.isApply) {
$api.msg('已经投递过该岗位了~'); $api.msg('已经投递过该岗位了~');
return; return;
@@ -380,7 +380,9 @@ function jobCollection() {
// 处理公司详情跳转 // 处理公司详情跳转
function handleCompanyDetail() { function handleCompanyDetail() {
if (dataType.value === 2) { 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 { } else {
navTo(`/packageA/pages/UnitDetails/UnitDetails?companyId=${jobInfo.value.company.companyId}`); navTo(`/packageA/pages/UnitDetails/UnitDetails?companyId=${jobInfo.value.company.companyId}`);
} }

View File

@@ -127,7 +127,7 @@ function getList(type = 'add', loading = true) {
pageSize: pageState.pageSize, pageSize: pageState.pageSize,
type: ranItem.value.value, type: ranItem.value.value,
}; };
$api.createRequest('/app/user/collection/fair', params).then((resData) => { const LoadCache = (resData) => {
const { rows, total } = resData; const { rows, total } = resData;
if (type === 'add') { if (type === 'add') {
const str = pageState.pageSize * (pageState.page - 1); const str = pageState.pageSize * (pageState.page - 1);
@@ -140,7 +140,8 @@ function getList(type = 'add', loading = true) {
// pageState.list = resData.rows; // pageState.list = resData.rows;
pageState.total = resData.total; pageState.total = resData.total;
pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize); pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize);
}); };
$api.createRequestWithCache('/app/user/collection/fair', params, 'GET', false, {}, LoadCache).then(LoadCache);
} }
</script> </script>

View File

@@ -201,7 +201,7 @@ function getFair(type = 'add') {
if (currentDay.value?.fullDate) { if (currentDay.value?.fullDate) {
params.zphjbsj = currentDay.value.fullDate.replace(/-/g, ''); 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; const { rows, total } = resData;
if (type === 'add') { if (type === 'add') {
// const str = pageState.pageSize * (pageState.page - 1); // const str = pageState.pageSize * (pageState.page - 1);

View File

@@ -241,9 +241,10 @@ function nextStep() {
// 获取职位 // 获取职位
function getTreeselect() { function getTreeselect() {
$api.createRequest('/app/common/jobTitle/treeselect', {}, 'GET').then((resData) => { const LoadCache = (resData) => {
state.station = resData.data; state.station = resData.data;
}); };
$api.createRequestWithCache('/app/common/jobTitle/treeselect', {}, 'GET', false, LoadCache).then(LoadCache);
} }
function loginbackdoor() { function loginbackdoor() {

View File

@@ -381,14 +381,17 @@ defineExpose({ loadData, handleFilterConfirm });
border-radius: 12rpx 12rpx 12rpx 12rpx; border-radius: 12rpx 12rpx 12rpx 12rpx;
.nearby-list .nearby-list
border-top: 2rpx solid #EBEBEB; border-top: 2rpx solid #EBEBEB;
height: calc(100% - 140rpx) min-height: calc(100% - 140rpx)
background: #f4f4f4 background: #f4f4f4
display: flex;
flex-direction: column;
.one-cards{ .one-cards{
height: 100% height: 100%
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding: 0 20rpx 20rpx 20rpx; padding: 0 20rpx 20rpx 20rpx;
background: #f4f4f4 background: #f4f4f4
flex: 1
} }
.nav-filter .nav-filter
padding: 16rpx 28rpx 0 28rpx padding: 16rpx 28rpx 0 28rpx

View File

@@ -370,14 +370,17 @@ defineExpose({ loadData, handleFilterConfirm });
background: #e8e8e8; background: #e8e8e8;
overflow: hidden overflow: hidden
.nearby-list .nearby-list
height: calc(100% - 384rpx) min-height: calc(100% - 384rpx)
background: #f4f4f4 background: #f4f4f4
display: flex;
flex-direction: column;
.one-cards{ .one-cards{
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding: 0 20rpx 20rpx 20rpx; padding: 0 20rpx 20rpx 20rpx;
background: #f4f4f4 background: #f4f4f4
height: 100% height: 100%
flex: 1
} }
.nav-filter .nav-filter
padding: 16rpx 28rpx 0 28rpx padding: 16rpx 28rpx 0 28rpx

View File

@@ -483,14 +483,17 @@ defineExpose({ loadData, handleFilterConfirm });
z-index: 1; z-index: 1;
.nearby-list .nearby-list
border-top: 2rpx solid #EBEBEB; border-top: 2rpx solid #EBEBEB;
height: calc(100% - 222rpx) min-height: calc(100% - 222rpx)
background: #f4f4f4 background: #f4f4f4
display: flex;
flex-direction: column;
.one-cards{ .one-cards{
height: 100% height: 100%
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding: 0 20rpx 20rpx 20rpx; padding: 0 20rpx 20rpx 20rpx;
background: #f4f4f4 background: #f4f4f4
flex: 1
} }
.nav-filter .nav-filter
padding: 16rpx 28rpx 0 28rpx padding: 16rpx 28rpx 0 28rpx

View File

@@ -285,14 +285,17 @@ defineExpose({ loadData, handleFilterConfirm });
border-radius: 12rpx 12rpx 12rpx 12rpx; border-radius: 12rpx 12rpx 12rpx 12rpx;
.nearby-list .nearby-list
border-top: 2rpx solid #EBEBEB; border-top: 2rpx solid #EBEBEB;
height: calc(100% - 252rpx) min-height: calc(100% - 252rpx)
background: #f4f4f4 background: #f4f4f4
display: flex;
flex-direction: column;
.one-cards{ .one-cards{
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding: 0 20rpx 20rpx 20rpx; padding: 0 20rpx 20rpx 20rpx;
background: #f4f4f4 background: #f4f4f4
height: 100% height: 100%
flex: 1
} }
.nav-filter .nav-filter
padding: 16rpx 28rpx 0 28rpx padding: 16rpx 28rpx 0 28rpx

View File

@@ -12,27 +12,25 @@ import {
$api, $api,
} from '../common/globalFunction'; } from '../common/globalFunction';
// 控制消息 // 常量定义:消息在 TabBar 的索引位置
const TABBAR_INDEX = 3;
export const useReadMsg = defineStore('readMsg', () => { export const useReadMsg = defineStore('readMsg', () => {
const msgList = ref([]) const msgList = ref([])
// 用于自定义 Tabbar 组件的渲染
const badges = ref([{ 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(() => const unreadCount = computed(() =>
msgList.value.reduce((sum, msg) => sum + (msg.notReadCount || 0), 0) 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) msgList.value.filter(msg => msg.notReadCount > 0)
) )
function updateBadgeEffect() {
// 设置 TabBar 角标
function updateTabBarBadge() {
const count = unreadCount.value const count = unreadCount.value
const index = 3 // 处理显示文本超过99显示99+
const countVal = count > 99 ? '99+' : String(count) const countStr = count > 99 ? '99+' : String(count)
if (count === 0) {
uni.removeTabBarBadge({ // 1. 更新内部状态 (用于自定义 UI)
index if (badges.value[TABBAR_INDEX]) {
}) // 替换为你消息页面的 TabBar index badges.value[TABBAR_INDEX].count = count === 0 ? 0 : countStr
badges.value[index] = {
count: 0
}
} else {
badges.value[index] = {
count: countVal
} }
// 2. 更新系统原生 TabBar
// 加 try-catch 防止在非 Tabbar 页面或加栽未完成时报错
try {
if (count > 0) {
uni.setTabBarBadge({ uni.setTabBarBadge({
index, index: TABBAR_INDEX,
text: countVal text: countStr
})
} else {
uni.removeTabBarBadge({
index: TABBAR_INDEX
}) })
} }
} catch (e) {
console.warn('TabBar Badge 更新失败(可能当前非TabBar页面):', e)
} }
}
watch(unreadCount, () => {
updateBadgeEffect()
console.log('value', unreadCount.value)
}, {
immediate: true
})
// 拉取消息列表 // 拉取消息列表
async function fetchMessages() { async function fetchMessages() {
try { try {
$api.createRequest('/app/notice/info', { const res = await $api.createRequest('/app/notice/info', {
isRead: 1 isRead: 1
}, "GET").then((res) => { }, "GET")
msgList.value = res.data || [] msgList.value = res.data || []
updateTabBarBadge()
})
} catch (err) { } catch (err) {
console.error('获取消息失败:', err) console.error('获取消息失败:', err)
} }
@@ -83,17 +90,23 @@ export const useReadMsg = defineStore('readMsg', () => {
// 设置为已读 // 设置为已读
async function markAsRead(item, index) { async function markAsRead(item, index) {
const msg = msgList.value[index] const targetMsg = msgList.value[index]
if (!msg || msg.isRead === 1) return if (!targetMsg) return
// 如果已经是已读,直接返回,避免无效请求
// 假设服务端逻辑是isRead=1 表示已读 (注意检查你的字段定义)
// 你的原代码判断是 if (msg.isRead === 1) return如果是这样下面请求成功应该设为 1
// 但通常未读是0已读是1。这里维持你原有的逻辑假设服务端把 notReadCount 清零
try { try {
let params = { let params = {
id: msg.noticeId id: targetMsg.noticeId
} }
$api.createRequest('/app/notice/read?id=' + msg.noticeId, params, "POST").then((res) => { await $api.createRequest('/app/notice/read?id=' + targetMsg.noticeId, params, "POST")
msgList.value[index].isRead = 1
updateTabBarBadge() // 更新本地数据
}) msgList.value[index].notReadCount = 0
msgList.value[index].isRead = 1 // 标记已读状态
} catch (err) { } catch (err) {
console.error('设置消息已读失败:', err) console.error('设置消息已读失败:', err)
} }
@@ -106,8 +119,8 @@ export const useReadMsg = defineStore('readMsg', () => {
unreadCount, unreadCount,
fetchMessages, fetchMessages,
markAsRead, markAsRead,
updateTabBarBadge updateTabBarBadge: updateBadgeEffect
} }
}, { }, {
unistorage: true, unistorage: true, // 开启持久化
}) })

View File

@@ -26,6 +26,10 @@ const needToEncrypt = [
*/ */
export async function createRequestWithCache(url, data = {}, method = 'GET', loading = false, headers = {}, export async function createRequestWithCache(url, data = {}, method = 'GET', loading = false, headers = {},
onCacheLoad = null) { onCacheLoad = null) {
// 是分页接口的话, 只缓存第一页的数据
if (data.current && data.current > 1) {
return createRequest(url, data, method, loading, headers);
}
const cacheKey = `${method.toUpperCase()}:${url}:${JSON.stringify(data)}`; const cacheKey = `${method.toUpperCase()}:${url}:${JSON.stringify(data)}`;
baseDB.getDB().then(async (dbHelper) => { baseDB.getDB().then(async (dbHelper) => {
@@ -77,13 +81,16 @@ export function createRequest(url, data = {}, method = 'GET', loading = false, h
mask: true mask: true
}) })
} }
let Authorization = '' let header = {
if (useUserStore().token) { ...headers
Authorization = `${useUserStore().token}` };
} const userStore = useUserStore();
const token = userStore.token;
const header = headers || {}; if (token) {
header["Authorization"] = encodeURIComponent(Authorization); // 确保 Authorization 不会被覆盖,且进行编码
header["Authorization"] = encodeURIComponent(token);
}
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// 检查当前请求是否需要加密 // 检查当前请求是否需要加密