个人资料和岗位列表联调,简历优化部分页面

This commit is contained in:
2026-04-01 11:41:51 +08:00
parent 0468339d23
commit 821a950df2
42 changed files with 5935 additions and 748 deletions
+79 -10
View File
@@ -5,6 +5,8 @@ import type { MenuItemRaw } from '@/api/menu'
import { buildDynamicRoutes } from '@/router/dynamicRoutes'
import { fetchIndustryTree, fetchJobCategoryTree, fetchRegionTree } from '@/api/common'
import type { IndustryItem, JobCategoryItem, RegionItem } from '@/api/common'
import { fetchJobIntention, saveJobIntention } from '@/api/jobs'
import type { JobIntention } from '@/api/jobs'
/** 职位列表页缓存数据(从详情页返回时恢复用) */
export interface JobListCache {
@@ -71,6 +73,12 @@ export interface RootState {
* 为 null 表示没有缓存,需要重新请求
*/
jobListCache: JobListCache | null
/**
* 求职意向数据 — JobGoalDialog 和 Jobs 页面共享
* 由 loadJobIntention action 从接口加载,saveJobIntention action 保存后更新
*/
jobIntention: JobIntention
}
export default createStore<RootState>({
@@ -86,6 +94,12 @@ export default createStore<RootState>({
jobCategories: [],
regions: [],
jobListCache: null,
jobIntention: {
categoryIds: [],
regionCodes: [],
industryIds: [],
employmentType: 0,
},
},
getters: {
getAppName: (state) => state.appName,
@@ -129,6 +143,14 @@ export default createStore<RootState>({
SET_JOB_LIST_CACHE(state, cache: JobListCache | null) {
state.jobListCache = cache
},
SET_JOB_INTENTION(state, data: JobIntention) {
state.jobIntention = {
categoryIds: data.categoryIds ?? [],
regionCodes: data.regionCodes ?? [],
industryIds: data.industryIds ?? [],
employmentType: data.employmentType ?? 0,
}
},
},
actions: {
updateAppName({ commit }, name: string) {
@@ -179,32 +201,79 @@ export default createStore<RootState>({
commit('SET_AUTHENTICATED', false)
commit('SET_SHOW_LOGIN', false)
commit('SET_LOGIN_REDIRECT', '')
// 清除 Jobs 页面缓存数据
commit('SET_JOB_LIST_CACHE', null)
commit('SET_JOB_INTENTION', {
categoryIds: [],
regionCodes: [],
industryIds: [],
employmentType: 0,
})
},
/**
* 加载工具类公共数据(行业分类、岗位分类等)
* 进首页和 Jobs 页时调用,刷新全局数据
* 进首页和 Jobs 页时调用
* 如果 store 中已有数据则跳过请求,避免重复加载
* 传入 force = true 可强制刷新
*/
async loadCommonData({ commit }) {
async loadCommonData({ commit, state }, { force = false } = {}) {
const needIndustry = force || state.industries.length === 0
const needJobCategory = force || state.jobCategories.length === 0
const needRegion = force || state.regions.length === 0
// 三个都已缓存,直接返回
if (!needIndustry && !needJobCategory && !needRegion) return
try {
const [industryRes, jobCategoryRes, regionRes] = await Promise.all([
fetchIndustryTree(),
fetchJobCategoryTree(),
fetchRegionTree(),
])
if (industryRes.code === '0' && industryRes.data) {
const promises: Promise<any>[] = []
// 按需发起请求,保持顺序以便后续取值
promises.push(needIndustry ? fetchIndustryTree() : Promise.resolve(null))
promises.push(needJobCategory ? fetchJobCategoryTree() : Promise.resolve(null))
promises.push(needRegion ? fetchRegionTree() : Promise.resolve(null))
const [industryRes, jobCategoryRes, regionRes] = await Promise.all(promises)
if (industryRes && industryRes.code === '0' && industryRes.data) {
commit('SET_INDUSTRIES', industryRes.data)
}
if (jobCategoryRes.code === '0' && jobCategoryRes.data) {
if (jobCategoryRes && jobCategoryRes.code === '0' && jobCategoryRes.data) {
commit('SET_JOB_CATEGORIES', jobCategoryRes.data)
}
if (regionRes.code === '0' && regionRes.data) {
if (regionRes && regionRes.code === '0' && regionRes.data) {
commit('SET_REGIONS', regionRes.data)
}
} catch (err) {
console.error('[store] 加载公共分类数据失败', err)
}
},
/**
* 从接口加载求职意向数据到 store
* JobGoalDialog 和 Jobs 页面都可调用
*/
async loadJobIntention({ commit }) {
try {
const res = await fetchJobIntention()
if (res.code === '0' && res.data) {
commit('SET_JOB_INTENTION', res.data)
}
} catch (err) {
console.error('[store] 加载求职意向失败', err)
}
},
/**
* 保存求职意向到后端,成功后同步更新 store
* @param data 求职意向数据
*/
async saveJobIntention({ commit }, data: JobIntention) {
const res = await saveJobIntention(data)
if (res.code === '0') {
commit('SET_JOB_INTENTION', data)
}
return res
},
},
modules: {},
})