岗位发布开发

This commit is contained in:
冯辉
2025-10-23 17:16:16 +08:00
parent 20f2038f8c
commit b72b7dd7d6
25 changed files with 3402 additions and 327 deletions

View File

@@ -0,0 +1,281 @@
<template>
<view class="custom-tabbar">
<view
class="tabbar-item"
v-for="(item, index) in tabbarList"
:key="index"
@click="switchTab(item, index)"
>
<view class="tabbar-icon">
<image
:src="currentItem === item.id ? item.selectedIconPath : item.iconPath"
mode="aspectFit"
/>
</view>
<view class="badge" v-if="item.badge && item.badge > 0">{{ item.badge }}</view>
<view class="tabbar-text" :class="{ 'active': currentItem === item.id }">
{{ item.text }}
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed, watch, onMounted } from 'vue';
import { storeToRefs } from 'pinia';
import useUserStore from '@/stores/useUserStore';
import { useReadMsg } from '@/stores/useReadMsg';
const props = defineProps({
currentPage: {
type: Number,
default: 0
}
});
const userStore = useUserStore();
const { userInfo } = storeToRefs(userStore);
const readMsg = useReadMsg();
const currentItem = ref(props.currentPage);
// 监听props变化
watch(() => props.currentPage, (newPage) => {
currentItem.value = newPage;
});
// 生成tabbar配置的函数
const generateTabbarList = () => {
const baseItems = [
{
id: 0,
text: '职位',
path: '/pages/index/index',
iconPath: '/static/tabbar/calendar.png',
selectedIconPath: '/static/tabbar/calendared.png',
centerItem: false,
badge: readMsg.badges[0]?.count || 0,
},
{
id: 2,
text: 'AI+',
path: '/pages/chat/chat',
iconPath: '/static/tabbar/logo3.png',
selectedIconPath: '/static/tabbar/logo3.png',
centerItem: true,
badge: readMsg.badges[2]?.count || 0,
},
{
id: 3,
text: '消息',
path: '/pages/msglog/msglog',
iconPath: '/static/tabbar/chat4.png',
selectedIconPath: '/static/tabbar/chat4ed.png',
centerItem: false,
badge: readMsg.badges[3]?.count || 0,
},
{
id: 4,
text: '我的',
path: '/pages/mine/mine',
iconPath: '/static/tabbar/mine.png',
selectedIconPath: '/static/tabbar/mined.png',
centerItem: false,
badge: readMsg.badges[4]?.count || 0,
},
];
// 获取用户类型统一使用isCompanyUser字段0=企业用户1=求职者, 3=网格员)
// 优先从store获取如果为空则直接从缓存获取
const cachedUserInfo = uni.getStorageSync('userInfo') || {};
console.log('完整userInfo对象:', userInfo.value);
console.log('缓存中的userInfo:', cachedUserInfo);
// 获取isCompanyUser字段
const storeIsCompanyUser = userInfo.value?.isCompanyUser;
const cachedIsCompanyUser = cachedUserInfo.isCompanyUser;
console.log('store中的isCompanyUser:', storeIsCompanyUser);
console.log('缓存中的isCompanyUser:', cachedIsCompanyUser);
// 获取用户类型的逻辑:
// 1. 优先使用store中的isCompanyUser
// 2. 如果store中没有使用缓存中的isCompanyUser
// 3. 最后默认为1求职者
const userType = Number(storeIsCompanyUser !== undefined ? storeIsCompanyUser : (cachedIsCompanyUser !== undefined ? cachedIsCompanyUser : 1));
if (userType === 0 || userType === 2) {
// 企业用户:显示发布岗位
baseItems.splice(1, 0, {
id: 1,
text: '发布岗位',
path: '/pages/job/publishJob',
iconPath: '/static/tabbar/post.png',
selectedIconPath: '/static/tabbar/posted.png',
centerItem: false,
badge: 0,
});
} else {
// 求职者用户(包括未登录状态):显示招聘会
baseItems.splice(1, 0, {
id: 1,
text: '招聘会',
path: '/pages/careerfair/careerfair',
iconPath: '/static/tabbar/post.png',
selectedIconPath: '/static/tabbar/posted.png',
centerItem: false,
badge: readMsg.badges[1]?.count || 0,
});
}
return baseItems;
};
// 根据用户类型生成不同的导航栏配置
const tabbarList = computed(() => {
return generateTabbarList();
});
// 强制刷新tabbar的方法
const forceRefresh = () => {
// 触发响应式更新
const cachedUserInfo = uni.getStorageSync('userInfo') || {};
const currentUserType = userInfo.value?.isCompanyUser !== undefined ? userInfo.value.isCompanyUser : (cachedUserInfo.isCompanyUser !== undefined ? cachedUserInfo.isCompanyUser : 1);
console.log('强制刷新tabbar当前用户类型:', currentUserType);
};
// 监听用户类型变化只监听isCompanyUser字段
watch(() => userInfo.value?.isCompanyUser, (newIsCompanyUser, oldIsCompanyUser) => {
console.log('用户类型变化监听:', {
newIsCompanyUser,
oldIsCompanyUser,
userInfo: userInfo.value
});
if (newIsCompanyUser !== oldIsCompanyUser) {
console.log('用户类型发生变化重新生成tabbar:', newIsCompanyUser);
// 强制触发computed重新计算
forceRefresh();
}
}, { immediate: true });
// 监听用户信息变化(包括登录状态)
watch(() => userInfo.value, (newUserInfo, oldUserInfo) => {
console.log('用户信息变化监听:', { newUserInfo, oldUserInfo });
if (newUserInfo !== oldUserInfo) {
console.log('用户信息发生变化重新生成tabbar');
// 强制触发computed重新计算
forceRefresh();
}
}, { immediate: true, deep: true });
// 切换tab
const switchTab = (item, index) => {
// 判断是否为 tabBar 页面
const tabBarPages = [
'/pages/index/index',
'/pages/careerfair/careerfair',
'/pages/chat/chat',
'/pages/msglog/msglog',
'/pages/mine/mine'
];
if (tabBarPages.includes(item.path)) {
// tabBar 页面使用 switchTab
uni.navigateTo({
url: item.path,
});
} else {
// 非 tabBar 页面使用 navigateTo
uni.navigateTo({
url: item.path,
});
}
currentItem.value = item.id;
};
onMounted(() => {
currentItem.value = props.currentPage;
// 调试信息显示当前用户状态和tabbar配置
console.log('CustomTabBar mounted, 用户信息:', userInfo.value);
console.log('当前tabbar配置:', tabbarList.value);
forceRefresh();
});
</script>
<style lang="scss" scoped>
.custom-tabbar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 88rpx;
background-color: #ffffff;
border-top: 1rpx solid #e5e5e5;
display: flex;
align-items: center;
padding-bottom: env(safe-area-inset-bottom);
z-index: 999;
box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1);
}
.tabbar-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
color: #5E5F60;
font-size: 22rpx;
position: relative;
cursor: pointer;
}
.tabbar-icon {
width: 44rpx;
height: 44rpx;
margin-bottom: 4rpx;
position: relative;
}
.tabbar-icon image {
width: 100%;
height: 100%;
}
.tabbar-text {
font-size: 20rpx;
line-height: 1;
transition: color 0.3s ease;
}
.tabbar-text.active {
color: #256BFA;
font-weight: 500;
}
.badge {
position: absolute;
top: 4rpx;
right: 20rpx;
min-width: 30rpx;
height: 30rpx;
background-color: #ff4444;
color: #fff;
font-size: 18rpx;
border-radius: 15rpx;
text-align: center;
line-height: 30rpx;
padding: 0 10rpx;
transform: scale(0.8);
}
/* 中间按钮特殊样式 */
.tabbar-item:has(.center-item) {
.tabbar-icon {
width: 60rpx;
height: 60rpx;
margin-bottom: 0;
}
}
</style>

View File

@@ -31,13 +31,13 @@ const userTypes = [
{ value: 3, label: '政府人员' }
];
const currentUserType = computed(() => userInfo.value?.userType || 0);
const currentUserType = computed(() => userInfo.value?.isCompanyUser !== undefined ? userInfo.value.isCompanyUser : 0);
const switchUserType = (userType) => {
console.log('切换用户类型:', userType);
console.log('切换前 userInfo:', userInfo.value);
userInfo.value.userType = userType;
userInfo.value.isCompanyUser = userType;
console.log('切换后 userInfo:', userInfo.value);

View File

@@ -13,7 +13,30 @@
<view class="btn-confirm" @click="confirm">确认</view>
</view>
<view class="popup-list">
<!-- 多选模式 -->
<view v-if="multiSelect" class="multi-select-list">
<view v-if="!processedListData[0] || processedListData[0].length === 0" class="empty-tip">
暂无数据
</view>
<view
v-else
class="skill-tags-container"
>
<view
v-for="(item, index) in processedListData[0]"
:key="index"
class="skill-tag"
:class="{ 'skill-tag-active': selectedValues.includes(item[this.rowKey]) }"
@click.stop="toggleSelect(item)"
@touchstart.stop="toggleSelect(item)"
>
<text class="skill-tag-text">{{ getLabel(item) }}</text>
</view>
</view>
</view>
<!-- 单选模式 -->
<picker-view
v-else
indicator-style="height: 84rpx;"
:value="selectedIndex"
@change="bindChange"
@@ -54,6 +77,8 @@ export default {
rowKey: 'value',
selectedItems: [],
unit: '',
multiSelect: false,
selectedValues: [],
};
},
computed: {
@@ -66,6 +91,13 @@ export default {
});
});
},
// 计算选中的项目
computedSelectedItems() {
if (!this.multiSelect) return this.selectedItems;
return this.processedListData[0] ? this.processedListData[0].filter(item =>
this.selectedValues.includes(item[this.rowKey])
) : [];
},
},
methods: {
open(newConfig = {}) {
@@ -80,7 +112,10 @@ export default {
rowKey = 'value',
maskClick = false,
defaultIndex = [],
multiSelect = false,
defaultValues = [],
} = newConfig;
this.reset();
if (title) this.title = title;
if (typeof success === 'function') this.confirmCallback = success;
@@ -92,10 +127,16 @@ export default {
this.rowKey = rowKey;
this.maskClick = maskClick;
this.unit = unit;
this.multiSelect = multiSelect;
this.selectedIndex =
defaultIndex.length === this.listData.length ? defaultIndex : new Array(this.listData.length).fill(0);
this.selectedItems = this.selectedIndex.map((val, index) => this.processedListData[index][val]);
if (multiSelect) {
this.selectedValues = defaultValues || [];
} else {
this.selectedIndex =
defaultIndex.length === this.listData.length ? defaultIndex : new Array(this.listData.length).fill(0);
this.selectedItems = this.selectedIndex.map((val, index) => this.processedListData[index][val]);
}
this.$nextTick(() => {
this.$refs.popup.open();
});
@@ -117,6 +158,22 @@ export default {
getLabel(item) {
return item?.[this.rowLabel] ?? '';
},
toggleSelect(item) {
if (!item || !this.rowKey || !item[this.rowKey]) {
return;
}
const value = item[this.rowKey];
const index = this.selectedValues.indexOf(value);
if (index > -1) {
// 取消选中
this.selectedValues.splice(index, 1);
} else {
// 选中
this.selectedValues.push(value);
}
},
setColunm(index, list) {
if (index > this.listData.length) {
return console.warn('最长' + this.listData.length);
@@ -135,7 +192,14 @@ export default {
}
try {
const result = await callback(this.selectedIndex, this.selectedItems); // 无论是 async 还是返回 Promise 的函数都可以 await
let result;
if (this.multiSelect) {
// 多选模式:传递 selectedValues 和 selectedItems
result = await callback(this.selectedValues, this.computedSelectedItems);
} else {
// 单选模式:传递 selectedIndex 和 selectedItems
result = await callback(this.selectedIndex, this.selectedItems);
}
if (result !== false) {
this.$refs.popup.close();
}
@@ -154,6 +218,8 @@ export default {
this.rowKey = 'value';
this.selectedItems = [];
this.unit = '';
this.multiSelect = false;
this.selectedValues = [];
},
},
};
@@ -224,10 +290,83 @@ export default {
color: #666d7f;
line-height: 38rpx;
}
.btn-confirm {
.btn-confirm {
font-weight: 400;
font-size: 32rpx;
color: #256bfa;
}
}
.multi-select-list {
padding: 20rpx 30rpx;
max-height: calc(60vh - 120rpx);
overflow-y: auto;
}
.empty-tip {
text-align: center;
padding: 60rpx 0;
color: #999999;
font-size: 28rpx;
}
.skill-tags-container {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
align-items: flex-start;
}
.skill-tag {
display: inline-flex;
align-items: center;
padding: 12rpx 20rpx;
border-radius: 20rpx;
background-color: #f8f9fa;
border: 2rpx solid #e8eaee;
cursor: pointer;
transition: all 0.3s ease;
font-size: 24rpx;
color: #333333;
white-space: nowrap;
user-select: none;
&:hover {
background-color: #e9ecef;
border-color: #d0d0d0;
transform: translateY(-1rpx);
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
}
&:active {
transform: translateY(0);
background-color: #dee2e6;
}
.skill-tag-text {
font-size: 24rpx;
color: inherit;
line-height: 1.2;
font-weight: 400;
font-size: 32rpx;
color: #256bfa;
}
&.skill-tag-active {
background-color: #256bfa;
border-color: #256bfa;
color: #ffffff;
box-shadow: 0 2rpx 8rpx rgba(37, 107, 250, 0.3);
.skill-tag-text {
color: #ffffff;
font-weight: 500;
}
&:hover {
background-color: #1e5ce6;
border-color: #1e5ce6;
transform: translateY(-1rpx);
box-shadow: 0 4rpx 12rpx rgba(37, 107, 250, 0.4);
}
}
}
</style>

View File

@@ -10,7 +10,7 @@
>
<image :src="currentItem == item.id ? item.selectedIconPath : item.iconPath"></image>
</view>
<view class="badge" v-if="item.badge">{{ item.badge }}</view>
<view class="badge" v-if="item.badge && item.badge > 0">{{ item.badge }}</view>
<view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']">
<text>{{ item.text }}</text>
</view>
@@ -19,7 +19,7 @@
</template>
<script setup>
import { ref, onMounted, computed } from 'vue';
import { ref, onMounted, computed, watch, nextTick } from 'vue';
import { useReadMsg } from '@/stores/useReadMsg';
import { storeToRefs } from 'pinia';
import useUserStore from '@/stores/useUserStore';
@@ -36,35 +36,60 @@ const readMsg = useReadMsg();
const { userInfo } = storeToRefs(useUserStore());
const currentItem = ref(0);
// 根据用户类型生成不同的导航栏配置
const tabbarList = computed(() => {
// 监听用户类型变化重新生成tabbar配置
watch(() => userInfo.value?.isCompanyUser, (newIsCompanyUser, oldIsCompanyUser) => {
console.log('midell-box用户类型变化监听:', { newIsCompanyUser, oldIsCompanyUser, userInfo: userInfo.value });
if (newIsCompanyUser !== oldIsCompanyUser) {
console.log('用户类型发生变化重新生成tabbar:', newIsCompanyUser);
// tabbarList是computed会自动重新计算
// 强制触发响应式更新
nextTick(() => {
console.log('tabbar配置已更新:', tabbarList.value);
});
}
}, { immediate: true });
// 监听用户信息变化(包括登录状态)
watch(() => userInfo.value, (newUserInfo, oldUserInfo) => {
console.log('midell-box用户信息变化监听:', { newUserInfo, oldUserInfo });
if (newUserInfo !== oldUserInfo) {
console.log('用户信息发生变化重新生成tabbar');
// 强制触发响应式更新
nextTick(() => {
console.log('tabbar配置已更新:', tabbarList.value);
});
}
}, { immediate: true, deep: true });
// 生成tabbar配置的函数
const generateTabbarList = () => {
const baseItems = [
{
id: 0,
text: '首页',
text: '职位2',
path: '/pages/index/index',
iconPath: '../../static/tabbar/calendar.png',
selectedIconPath: '../../static/tabbar/calendared.png',
centerItem: false,
badge: readMsg.badges[0].count,
badge: readMsg.badges[0]?.count || 0,
},
{
id: 2,
text: '',
text: 'AI+',
path: '/pages/chat/chat',
iconPath: '../../static/tabbar/logo3.png',
selectedIconPath: '../../static/tabbar/logo3.png',
centerItem: true,
badge: readMsg.badges[2].count,
badge: readMsg.badges[2]?.count || 0,
},
{
id: 3,
text: '消息',
text: '消息2',
path: '/pages/msglog/msglog',
iconPath: '../../static/tabbar/chat4.png',
selectedIconPath: '../../static/tabbar/chat4ed.png',
centerItem: false,
badge: readMsg.badges[3].count,
badge: readMsg.badges[3]?.count || 0,
},
{
id: 4,
@@ -73,12 +98,12 @@ const tabbarList = computed(() => {
iconPath: '../../static/tabbar/mine.png',
selectedIconPath: '../../static/tabbar/mined.png',
centerItem: false,
badge: readMsg.badges[4].count,
badge: readMsg.badges[4]?.count || 0,
},
];
// 根据用户类型添加不同的导航项
const userType = userInfo.value?.userType || 0;
// 根据用户类型添加不同的导航项,未登录时默认为求职者
const userType = userInfo.value?.isCompanyUser !== undefined ? userInfo.value.isCompanyUser : 1;
if (userType === 0) {
// 企业用户:显示发布岗位,隐藏招聘会
@@ -86,13 +111,13 @@ const tabbarList = computed(() => {
id: 1,
text: '发布岗位',
path: '/pages/job/publishJob',
iconPath: '../../static/tabbar/publish-job.svg',
selectedIconPath: '../../static/tabbar/publish-job-selected.svg',
iconPath: '../../static/tabbar/post.png',
selectedIconPath: '../../static/tabbar/posted.png',
centerItem: false,
badge: 0,
});
} else {
// 普通用户、网格员、政府人员:显示招聘会
// 求职者用户(包括未登录状态):显示招聘会
baseItems.splice(1, 0, {
id: 1,
text: '招聘会',
@@ -100,11 +125,16 @@ const tabbarList = computed(() => {
iconPath: '../../static/tabbar/post.png',
selectedIconPath: '../../static/tabbar/posted.png',
centerItem: false,
badge: readMsg.badges[1].count,
badge: readMsg.badges[1]?.count || 0,
});
}
return baseItems;
};
// 根据用户类型生成不同的导航栏配置
const tabbarList = computed(() => {
return generateTabbarList();
});
onMounted(() => {

View File

@@ -102,6 +102,7 @@
<script setup>
import { ref, inject } from 'vue';
import useUserStore from '@/stores/useUserStore';
import { tabbarManager } from '@/utils/tabbarManager';
const { $api } = inject('globalFunction');
const { loginSetToken } = useUserStore();
@@ -162,22 +163,33 @@ const getPhoneNumber = (e) => {
userType: userType.value
}, 'post').then((resData) => {
uni.hideLoading();
console.log(resData, 'resume.idCard');
if (resData.token) {
// 登录成功存储token
loginSetToken(resData.token).then((resume) => {
// 更新用户类型到缓存
if (resData.isCompanyUser !== undefined) {
console.log(resData.isCompanyUser, 'resData.isCompanyUser');
const userInfo = uni.getStorageSync('userInfo') || {};
userInfo.isCompanyUser = Number(resData.isCompanyUser); // 0-企业用户1-求职者
uni.setStorageSync('userInfo', userInfo);
}
$api.msg('登录成功');
// 刷新tabbar以显示正确的用户类型
tabbarManager.refreshTabBar();
close();
emit('success');
// 根据用户类型跳转到不同的信息补全页面
if (!resume.data.jobTitleId) {
if (userType.value === 1) {
if (!resume.jobTitleId) {
console.log(resume, 'resume.idCard');
if (userType.value === 1 && !resData.idCard) {
// 求职者跳转到个人信息补全页面
uni.navigateTo({
url: '/pages/complete-info/complete-info?step=1'
});
} else if (userType.value === 0) {
} else if (userType.value === 0 && !resData.idCard) {
// 招聘者跳转到企业信息补全页面
uni.navigateTo({
url: '/pages/complete-info/company-info'
@@ -233,6 +245,15 @@ const wxLogin = () => {
if (resData.token) {
loginSetToken(resData.token).then((resume) => {
console.log(resData, 'resData.isCompanyUser');
// 更新用户类型到缓存
if (resData.isCompanyUser) {
console.log(resData.isCompanyUser, 'resData.isCompanyUser');
const userInfo = uni.getStorageSync('userInfo') || {};
userInfo.isCompanyUser = Number(resData.isCompanyUser); // 0-企业用户1-求职者
uni.setStorageSync('userInfo', userInfo);
}
$api.msg('登录成功');
close();
emit('success');
@@ -285,7 +306,16 @@ const wxLogin = () => {
}, 'post').then((resData) => {
if (resData.token) {
loginSetToken(resData.token).then((resume) => {
// 更新用户类型到缓存
if (resData.isCompanyUser !== undefined) {
const userInfo = uni.getStorageSync('userInfo') || {};
userInfo.isCompanyUser = resData.isCompanyUser ? 0 : 1; // 0-企业用户1-求职者
uni.setStorageSync('userInfo', userInfo);
}
$api.msg('登录成功');
// 刷新tabbar以显示正确的用户类型
tabbarManager.refreshTabBar();
close();
emit('success');
@@ -330,7 +360,16 @@ const testLogin = () => {
uni.hideLoading();
loginSetToken(resData.token).then((resume) => {
// 更新用户类型到缓存
if (resData.isCompanyUser !== undefined) {
const userInfo = uni.getStorageSync('userInfo') || {};
userInfo.isCompanyUser = resData.isCompanyUser ? 0 : 1; // 0-企业用户1-求职者
uni.setStorageSync('userInfo', userInfo);
}
$api.msg('测试登录成功');
// 刷新tabbar以显示正确的用户类型
tabbarManager.refreshTabBar();
close();
emit('success');