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;
}
$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 = () => {

View File

@@ -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);
}
</script>

View File

@@ -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 = '') {

View File

@@ -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);
}
</script>

View File

@@ -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,8 +152,12 @@ function getCompanyList(type = 'add') {
current: pageState.current,
pageSize: pageState.pageSize,
};
$api.createRequest(`/app/internal/companyThirdPart/?zphID=${jobFairId}&zphmc=${jobFairName}`, params).then(
(resData) => {
$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);
@@ -165,8 +169,7 @@ function getCompanyList(type = 'add') {
}
pageState.total = resData.total;
pageState.maxPage = Math.ceil(pageState.total / pageState.pageSize);
}
);
});
}
const hasAppointment = () => {

View File

@@ -83,12 +83,7 @@
<view class="content-card">
<view class="card-title">
<text class="title">公司信息</text>
<text
class="btntext button-click"
@click="handleCompanyDetail"
>
单位详情
</text>
<text class="btntext button-click" @click="handleCompanyDetail">单位详情</text>
</view>
<view class="company-info">
<view class="companyinfo-left">
@@ -162,7 +157,12 @@
<template #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>
</view>
@@ -232,7 +232,7 @@ 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);
@@ -245,7 +245,7 @@ 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);
@@ -316,8 +316,8 @@ function jobApply() {
// 第三方数据申请逻辑
const params = {
jobid: jobInfo.value.id,
jobname:jobInfo.value.gwmc
}
jobname: jobInfo.value.gwmc,
};
if (jobInfo.value.isApply) {
$api.msg('已经投递过该岗位了~');
return;
@@ -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}`);
}

View File

@@ -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);
}
</script>

View File

@@ -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);

View File

@@ -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() {

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
},
])
}])
// 计算总未读数量,基于 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
}
} else {
badges.value[index] = {
count: countVal
// 处理显示文本超过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,
text: countVal
index: TABBAR_INDEX,
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() {
try {
$api.createRequest('/app/notice/info', {
const res = await $api.createRequest('/app/notice/info', {
isRead: 1
}, "GET").then((res) => {
}, "GET")
msgList.value = res.data || []
updateTabBarBadge()
})
} 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, // 开启持久化
})

View File

@@ -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);
}
// ------------------------------------------------------------------
// 检查当前请求是否需要加密