首页卡片开发
This commit is contained in:
@@ -154,6 +154,79 @@ watch(() => userInfo.value, (newUserInfo, oldUserInfo) => {
|
||||
|
||||
// 切换tab
|
||||
const switchTab = (item, index) => {
|
||||
// 检查是否为"发布岗位"页面,需要判断企业信息是否完整
|
||||
if (item.path === '/pages/job/publishJob') {
|
||||
// 检查用户是否已登录
|
||||
const token = uni.getStorageSync('token') || '';
|
||||
const hasLogin = userStore.hasLogin;
|
||||
|
||||
if (!token || !hasLogin) {
|
||||
// 未登录,发送事件显示登录弹窗
|
||||
uni.$emit('showLoginModal');
|
||||
return; // 不进行页面跳转
|
||||
}
|
||||
|
||||
// 已登录,检查企业信息是否完整
|
||||
const cachedUserInfo = uni.getStorageSync('userInfo') || {};
|
||||
const storeUserInfo = userInfo.value || {};
|
||||
const currentUserInfo = storeUserInfo.id ? storeUserInfo : cachedUserInfo;
|
||||
|
||||
// 判断企业信息字段company是否为null或undefined
|
||||
if (!currentUserInfo.company || currentUserInfo.company === null) {
|
||||
// 企业信息为空,跳转到企业信息补全页面
|
||||
uni.navigateTo({
|
||||
url: '/pages/complete-info/company-info',
|
||||
});
|
||||
} else {
|
||||
// 企业信息完整,跳转到发布岗位页面
|
||||
uni.navigateTo({
|
||||
url: '/pages/job/publishJob',
|
||||
});
|
||||
}
|
||||
|
||||
currentItem.value = item.id;
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否为"我的"页面,需要登录验证和用户类型判断
|
||||
if (item.path === '/pages/mine/mine') {
|
||||
// 检查用户是否已登录
|
||||
const token = uni.getStorageSync('token') || '';
|
||||
const hasLogin = userStore.hasLogin;
|
||||
|
||||
if (!token || !hasLogin) {
|
||||
// 未登录,发送事件显示登录弹窗
|
||||
uni.$emit('showLoginModal');
|
||||
return; // 不进行页面跳转
|
||||
}
|
||||
|
||||
// 已登录,根据用户类型跳转到不同的"我的"页面
|
||||
const cachedUserInfo = uni.getStorageSync('userInfo') || {};
|
||||
const storeIsCompanyUser = userInfo.value?.isCompanyUser;
|
||||
const cachedIsCompanyUser = cachedUserInfo.isCompanyUser;
|
||||
|
||||
// 获取用户类型
|
||||
const userType = Number(storeIsCompanyUser !== undefined ? storeIsCompanyUser : (cachedIsCompanyUser !== undefined ? cachedIsCompanyUser : 1));
|
||||
|
||||
let targetPath = '/pages/mine/mine'; // 默认求职者页面
|
||||
|
||||
if (userType === 0) {
|
||||
// 企业用户,跳转到企业我的页面
|
||||
targetPath = '/pages/mine/company-mine';
|
||||
} else {
|
||||
// 求职者或其他用户类型,跳转到普通我的页面
|
||||
targetPath = '/pages/mine/mine';
|
||||
}
|
||||
|
||||
// 跳转到对应的页面
|
||||
uni.navigateTo({
|
||||
url: targetPath,
|
||||
});
|
||||
|
||||
currentItem.value = item.id;
|
||||
return;
|
||||
}
|
||||
|
||||
// 判断是否为 tabBar 页面
|
||||
const tabBarPages = [
|
||||
'/pages/index/index',
|
||||
@@ -164,12 +237,12 @@ const switchTab = (item, index) => {
|
||||
];
|
||||
|
||||
if (tabBarPages.includes(item.path)) {
|
||||
// tabBar 页面使用 switchTab
|
||||
uni.navigateTo({
|
||||
// TabBar 页面使用 redirectTo 避免页面栈溢出
|
||||
uni.redirectTo({
|
||||
url: item.path,
|
||||
});
|
||||
} else {
|
||||
// 非 tabBar 页面使用 navigateTo
|
||||
// 非 TabBar 页面使用 navigateTo
|
||||
uni.navigateTo({
|
||||
url: item.path,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user