export default class DealSeoData { constructor({$axios, req, app, redirect, error}) { this.$axios = $axios this.req = req; this.app = app; this.redirect = redirect; this.error = error; this.selected = { city: 0, direction: 0, //职业角色 大 directionIndex: 0, //移动端索引 directionSmall: 0, workType: 0, } this.page = { page: 1, pageSize: 10, total: 0, keyword: '' } this.finished = false this.dataList = [] this.provinces = [] } async dealData() { let { name, query: { page = 1, c_d = [], keyword = '' }, path, params, fullPath } = this.app.context.route this.page.page = page this.page.keyword = keyword //兼容APP 如果是带有 ${id}.html的,跳转到详情页 let endStr = path.split('/').pop() if (/([0-9]*\.html)/.test(endStr)) { this.redirect(301, "/job/detail/" + endStr) return } if (path && path[path.length - 1] !== '/') { let reditUrl = fullPath reditUrl = reditUrl.replace(path, path + '/') } let isSeoList = false let typeList = await this.getTypeList(); console.log("dealSeoIndex name:::::::::", name); switch (name) { case "job": case "JobListSeoIndex": //kaifain路由匹配进入 try { let match = params.pathMatch || '' let list = match.split('/').map(item => item.toLocaleLowerCase()) list = list.filter(item => !!item) let urlCheck = "" // 驻场招聘不参与URL里 let keys = ["city", "direction"]; //适配小程序直接传参 console.log("query* list***", this.app.context.route) // list = (list.length ? list : c_d) list.length = Math.min(list.length, 3) //防止url超出 console.log("&&&&&&&&&&&&&&", list); //3 * 3 * n的循环 n < 100 list.forEach(item => { keys.forEach(keys => { typeList[keys].list.forEach(typeItem => { if (typeItem.slug === item) { urlCheck += item this.selected[keys] = typeItem.id this.selected[keys + 'Name'] = typeItem.name this.selected[keys + 'Slug'] = typeItem.slug if (keys === 'city') { this.selected["provice"] = typeItem.prov_id } if (keys === "direction" && typeItem.children && typeItem.children.length > 1) { typeList[keys].smallList = typeItem.children this.selected['directionSmall'] = 0 this.selected['directionSmallName'] = "全部" } } if (keys === "direction" && Array.isArray(typeItem.children)) { //查询是否在子分类 typeItem.children.forEach(child => { if (child.slug === item) { urlCheck += item this.selected['direction'] = typeItem.id this.selected['directionName'] = typeItem.name this.selected['directionSlug'] = typeItem.slug this.selected['directionSmall'] = child.id this.selected['directionSmallName'] = child.name this.selected['directionSmallSlug'] = child.slug typeList[keys].smallList = typeItem.children } }) } }) }) }) if (urlCheck !== list.join("")) { this.error({ statusCode: 404, message: "您要访问的页面不存在" }) return } if (this.selected["provice"]) { let item = this.provinces.filter(item => item.id === this.selected["provice"])[0] this.selected["proviceName"] = item && item.name } } catch (e) { console.log("解决方案列表", e) } break default: //其他 page = 1 } // 通过 window.location.search 获取 workType let workType = this.app.context.route.query.workType || '' if (Number(workType) === 1 || Number(workType) === 2) { this.selected.workType = 2 } await this.getList() return { typeList, isSeoList, //是否是 /kaifain/s/页面进入 dataList: this.dataList, //首次获取的数据 mobile: this.app.$deviceType.isMobile(), selected: this.selected, page: this.page, finished: this.finished, head: this.dealThisMeta(isSeoList), breadcrumbList: this.dealBreadcrumbList() } } async getTypeList() { let res = await this.$axios.get('/api/recruit/get_options') let typeList = { direction: { title: '职业角色', list: [], smallList: [] }, city: { title: '国内地区', list: [] }, workType: { title: '工作方式', list: [{ id: 0, name: "全部", value: 0, text: "全部方式", }, { id: 1, name: "兼职", value: 1, text: "兼职", slug: "yuancheng" }, { id: 2, name: "驻场", value: 2, text: "驻场", slug: "zhuchang" } ] } } if (Number(res.data.status) === 1) { res.data.data.direction.unshift({ id: 0, name: "全部", children: [] }) res.data.data.cities.unshift({ id: 0, name: "全部" }) Object.keys(res.data.data).forEach(key => { let item = res.data.data[key] if (Array.isArray(item)) { item.forEach(ii => { ii.name = ii.name || ii.occupation_name || "" ii.id = Number(ii.id || ii.occupation_id || 0) ii.text = ii.name ii.value = ii.id if (Array.isArray(ii.children)) { ii.children.forEach(jj => { jj.name = jj.name || jj.direction_name || "" jj.id = Number(jj.id || jj.direction_id || 0) jj.text = jj.name jj.value = jj.id }) if (ii.children) { ii.children.unshift({ id: 0, name: "全部", value: 0, text: "全部", }) } } }) } }) //单独设置百度app 选择器文案 res.data.data.direction[0] = { ...res.data.data.direction[0], text: "全部职业", value: 0, } res.data.data.cities[0] = { ...res.data.data.cities[0], text: "全部地区", value: 0 } typeList.direction.list = [...res.data.data.direction] typeList.city.list = [...res.data.data.cities] } return typeList } async getList() { const { page, selected: { city, direction, directionSmall, workType } } = this; let p = { city: city, ...page }; direction && (p.occupationId = direction); //一级 workType && (p.workType = workType); directionSmall && (p.directionId = directionSmall);//耳二级 console.log("获取 /api/recruit/search", p) let res = await this.$axios.post('/api/recruit/search', p); if (Number(res.data.status) === 1) { let data = res.data.data; this.page.total = data.total; let dataList = data.list || []; this.dataList = [...dataList]; this.page.page += 1; this.page.current = Number(data.page); if (this.page.total <= this.dataList.length) { this.finished = true } } } dealThisMeta() { const { city, cityName = "", direction, directionName = "", directionSmall, directionSmallName, workType, workTypeName, proviceName, } = this.selected let job = directionSmall || direction let jobName = directionSmallName === "全部" ? directionName : (directionSmallName || directionName) let head = { title: "", keyword: "", description: "", h1: "", canonical: "", metaLocation: "" } if (this.req) { const { headers: { host }, url } = this.req //拼接canonical if (host.indexOf('local') !== -1) { head.canonical = 'http://' + host + url } else { head.canonical = 'https://' + host + url } } if (city && !job) { //只有城市的 head.title = `【${cityName}招聘】${cityName}程序员招聘-程序员客栈` head.keyword = `${cityName}程序员招聘,${cityName}人才网,${cityName}人才招聘` head.description = `程序员客栈为程序员提供2021年最新的${cityName}程序员招聘信息,${cityName}人才招聘信息。百万工作机会,直接开聊,在线面试,程序员找工作就上程序员客栈网站或APP,直接与招聘者开聊吧!` head.h1 = `` head.metaLocation = `province=${proviceName};city=${cityName}` } else if (!city && job) { //只有岗位的 head.title = `【全国${jobName}招聘】-程序员客栈` head.keyword = `全国${jobName}招聘,全国${jobName}人才网,全国${jobName}招聘网` head.description = `程序员客栈为程序员提供2021年最新的全国${jobName}招聘信息,百万工作机会,直接开聊,在线面试,程序员找工作就上程序员客栈网站或APP,直接与招聘者开聊吧!` head.h1 = `` } else if (city && job) { //兼职城市&岗位页 head.title = `【${cityName}${jobName}招聘】-2021年${cityName}${jobName}最新人才招聘信息-程序员客栈`; head.keyword = `${cityName}${jobName}招聘,${cityName}${jobName}人才网,${cityName}${jobName}招聘网`; head.description = `程序员客栈为程序员提供2021年最新的${cityName}${jobName}招聘信息,百万工作机会,直接开聊,在线面试,程序员找工作就上程序员客栈,直接与招聘者开聊吧!`; head.h1 = `` } else { // 没有任何参数 head.title = "程序员客栈-高端IT技术人才程序员招聘求职找工作!"; head.keyword = "程序员招聘,直聘网,招聘网,人才网,找工作,求职"; head.description = "程序员客栈是权威领先的技术人才招聘网,开启技术人才网招聘求职新时代,让求职者与招聘者直接开聊、加快面试、即时反馈,找工作、找技术人才就来程序员客栈吧!" } return head } /** 处理面包屑导航 **/ dealBreadcrumbList() { let list = [{ name: '首页', url: "/" }, { name: '兼职招聘', url: "/job/" }, ] const { city, citySlug, cityName = "", direction, directionName = "", directionSlug, directionSmall, directionSmallName = "", directionSmallSlug } = this.selected let job = directionSmall || direction let jobName = directionSmallName === "全部" ? directionName : (directionSmallName || directionName) let jobSlug = directionSmallSlug || directionSlug if (city && job) { //兼职城市&岗位页 ${jobName}兼职招聘>${cityName}${jobName}兼职招聘,并赋予对应的url list.push({ name: `${jobName}兼职招聘`, url: `/job/${jobSlug}/` }) list.push({ name: `${cityName}${jobName}兼职招聘`, url: `/job/${jobSlug}/${citySlug}/` }) } else if (city && !job) { //兼职城市 list.push({ name: `${cityName}兼职招聘`, url: `/job/${citySlug}/` }) } else if (!city && job) { //岗位页 list.push({ name: `${jobName}兼职招聘`, url: `/job/${jobSlug}/` }) } return list } }