| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- export default class DealSeoData {
- constructor({ $axios, req, app, redirect }, recruitData) {
- this.$axios = $axios
- this.req = req
- this.app = app
- this.redirect = redirect
- this.selected = {
- city: 0,
- direction: 0, //职业角色 大
- directionSmall: 0,
- workType: 0,
- }
- this.recruitData = recruitData
- }
-
- async dealData() {
- let { name, path, params, fullPath } = this.app.context.route
- let typeList = await this.getTypeList()
- this.typeList = typeList
-
- let list = [], keys = []
- switch (name) {
- case "JobListSeoIndex":
- let match = params.pathMatch || ''
- list = match.split('/').map(item => item.toLocaleLowerCase())
- list.length = Math.min(list.length, 3) //防止url超出
- keys = Object.keys(typeList)
- break
- case "JobListSeoDetail":
- break
- }
- //3 * 3 * n的循环 n < 100
- list.forEach(item => {
- keys.forEach(keys => {
- typeList[ keys ].list.forEach(typeItem => {
- if (typeItem.slug === 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) {
- 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
- }
- })
- }
- })
- })
- })
-
- return {
- footer: await this.getFooterData(),
- }
- }
-
-
- 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: "全部" }, { id: 1, name: "远程", slug: "yuancheng" }, {
- id: 2,
- name: "驻场",
- slug: "zhuchang"
- } ]
- }
- }
-
- if (Number(res.data.status) === 1) {
- // res.data.data.direction.unshift({ id: 0, name: "全部" })
- // 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)
- 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)
- })
- }
- })
- }
- })
- typeList.direction.list = [ ...res.data.data.direction ]
- typeList.city.list = [ ...res.data.data.cities ]
- }
- return typeList
- }
-
- async getFooterData() {
- //设置底部link列表
- const typeList = this.typeList
- 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
- const { headers: { host } } = this.req
- let footer = {
- baseLink: "", link: [
- { name: "", data: [] }, { name: "", data: [] },
- ],
- }
- //设置baseLink
- if (host.indexOf('local') !== -1) {
- footer.baseLink = 'http://' + host
- } else {
- footer.baseLink = 'https://' + host
- }
- if (city && job) {
- //兼职城市&岗位页 ${jobName}兼职招聘>${cityName}${jobName}兼职招聘,并赋予对应的url
- footer.link[ 0 ].name = `热门城市${jobName}兼职招聘`
- footer.link[ 0 ].data = typeList.city.list.map((item) => {
- return { name: `${item.name}${jobName}兼职招聘`, url: `/job/${jobSlug}/${item.slug}/` }
- })
- footer.link[ 1 ].name = `${cityName}热门岗位兼职招聘`
- footer.link[ 1 ].data = []
- typeList.direction.list.forEach((item) => {
- footer.link[ 1 ].data.push({ name: `${cityName}${item.name}兼职招聘`, url: `/job/${citySlug}/${item.slug}/` })
- if (Array.isArray(item.children)) {
- item.children.forEach(item1 => {
- footer.link[ 1 ].data.push({ name: `${cityName}${item1.name}兼职招聘`, url: `/job/${citySlug}/${item1.slug}/` })
- })
- }
- })
- } else if (city && !job) {
- //兼职城市
- footer.link[ 0 ].name = "热门城市兼职招聘"
- footer.link[ 0 ].data = typeList.city.list.map((item) => {
- return { name: `${item.name}兼职招聘`, url: `/job/${item.slug}/` }
- })
- footer.link[ 1 ].name = `${cityName}热门岗位兼职招聘`
- footer.link[ 1 ].data = []
- typeList.direction.list.forEach((item) => {
- footer.link[ 1 ].data.push({ name: `${cityName}${item.name}兼职招聘`, url: `/job/${citySlug}/${item.slug}/` })
- if (Array.isArray(item.children)) {
- item.children.forEach(item1 => {
- footer.link[ 1 ].data.push({ name: `${cityName}${item1.name}兼职招聘`, url: `/job/${citySlug}/${item1.slug}/` })
- })
- }
- })
- }
- else if (!city && job) {
- //岗位页
- footer.link[ 0 ].name = "热门岗位兼职招聘"
- footer.link[ 0 ].data = []
- typeList.direction.list.forEach((item) => {
- footer.link[ 0 ].data.push({ name: `${item.name}兼职招聘`, url: `/job/${item.slug}/` })
- if (Array.isArray(item.children)) {
- item.children.forEach(item1 => {
- footer.link[ 0 ].data.push({ name: `${item1.name}兼职招聘`, url: `/job/${item1.slug}/` })
- })
- }
- })
- footer.link[ 1 ].name = `热门城市${jobName}兼职招聘`
- footer.link[ 1 ].data = typeList.city.list.map((item) => {
- return { name: `${item.name}${jobName}兼职招聘`, url: `/job/${jobSlug}/${item.slug}/` }
- })
- } else {
- //非特定的url
- footer.link[ 0 ].name = "热门城市兼职招聘"
- footer.link[ 0 ].data = typeList.city.list.map((item) => {
- return { name: `${item.name}兼职招聘`, url: `/job/${item.slug}/` }
- })
- footer.link[ 1 ].name = "热门岗位兼职招聘"
- footer.link[ 1 ].data = []
- typeList.direction.list.forEach((item) => {
- footer.link[ 1 ].data.push({ name: `${item.name}兼职招聘`, url: `/job/${item.slug}/` })
- if (Array.isArray(item.children)) {
- item.children.forEach(item1 => {
- footer.link[ 1 ].data.push({ name: `${item1.name}兼职招聘`, url: `/job/${item1.slug}/` })
- })
- }
- })
- }
- return footer
- }
- }
|