| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- 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()
- 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超出
- //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
- }
- 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
- const { headers: { host }, url } = this.req
- let job = directionSmall || direction
- let jobName = directionSmallName === "全部" ? directionName : (directionSmallName || directionName)
- let head = {
- title: "", keyword: "", descrption: "", h1: "", canonical: "", metaLocation: ""
- }
- //拼接canonical
- if (host.indexOf('local') !== -1) {
- head.canonical = 'http://' + host + url
- } else {
- head.canonical = 'https://' + host + url
- }
- if (city && !job) {
- //只有城市的
- head.title = `${cityName}程序员兼职工作招聘,2020年${cityName}程序员最新兼职工作招聘信息-程序员客栈`
- head.keyword = `${cityName}程序员兼职招聘,${cityName}程序员兼职工作招聘,2020年最新${cityName}程序员兼职招聘信息`
- head.descrption = `程序员客栈提供${cityName}程序员兼职工作最新招聘信息,核实${cityName}发布程序员招聘信息的企业资质,让有前往${cityName}工作意向的程序员能得到一份满意的${jobName}兼职工作;对${jobName}程序员从业者能力进行严格把关,保障${cityName}企业能在兼职招聘平台找到靠谱的${jobName}程序员,确保项目正常进行。找工作、招聘合格的程序员,就上程序员客栈兼职招聘平台!`
- head.h1 = `${cityName}程序员兼职工作招聘`
- head.metaLocation = `province=${proviceName};city=${cityName}`
- } else if (!city && job) {
- //只有岗位的
- head.title = `${jobName}兼职工作招聘,2020年${jobName}最新兼职工作招聘信息-程序员客栈`
- head.keyword = `${jobName}兼职招聘,${jobName}兼职工作招聘,2019年最新${jobName}兼职招聘信息`
- head.descrption = `程序员客栈提供${jobName}IT兼职工作最新招聘信息,核实${jobName}兼职招聘信息发布企业资质,让有${jobName}工作意向的程序员能得到一份满意的兼职工作;对${jobName}程序员从业者能力进行严格把关,保障企业能在兼职招聘平台找到靠谱的${jobName}程序员,确保项目正常进行。找工作、招聘合格的程序员,就上程序员客栈兼职招聘平台!`
- head.h1 = `${jobName}兼职工作招聘`
- } else if (city && job) {
- //兼职城市&岗位页
- head.title = `${cityName}${jobName}兼职工作招聘,2020年${cityName}${jobName}最新兼职工作招聘信息-程序员客栈`
- head.keyword = `${cityName}${jobName}兼职招聘,${cityName}${jobName}兼职工作招聘,2020年最新${cityName}${jobName}兼职招聘信息`
- head.descrption = `程序员客栈提供${cityName}${jobName}兼职工作最新招聘信息,核实${cityName}发布${jobName}招聘信息的企业资质,让有前往${cityName}工作意向的程序员能得到一份满意的${jobName}兼职工作;对${jobName}程序员从业者能力进行严格把关,保障${cityName}企业能在兼职招聘平台找到靠谱的${jobName}程序员,确保项目正常进行。找工作、招聘合格的程序员,就上程序员客栈兼职招聘平台!`
- head.h1 = `${cityName}${jobName}兼职工作招聘`
- } else {
- head.title = "兼职工作招聘,2020年最新兼职工作招聘信息-程序员客栈"
- head.keyword = "兼职招聘,兼职工作招聘,2020年最新兼职招聘信息"
- head.descrption = "程序员客栈提供全国各地城市IT兼职工作最新招聘信息,核实企业资质,让有工作需求的程序员能得到一份满意的兼职工作;对程序员从业者能力进行严格把关,保障企业能在兼职招聘平台找到靠谱的程序员,确保项目正常进行。找工作、招聘合格的程序员,就上程序员客栈兼职招聘平台!"
- }
- 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
- }
- }
|