| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- export default class DealSeoData {
- constructor({
- $axios,
- req,
- app,
- redirect,
- store,
- }, recruitData) {
- this.$axios = $axios
- this.req = req
- this.app = app
- this.redirect = redirect
- this.store = store
- 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":
- case "job_$":
- case "job":
- 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(key => {
- typeList[key].list.forEach(typeItem => {
- if (typeItem.slug === item) {
- this.selected[key] = typeItem.id
- this.selected[key + 'Name'] = typeItem.name
- this.selected[key + 'Slug'] = typeItem.slug
- if (key === 'city') {
- this.selected["provice"] = typeItem.prov_id
- }
- if (key === "direction" && typeItem.children && typeItem.children.length > 1) {
- typeList[key].smallList = typeItem.children
- this.selected['directionSmall'] = 0
- this.selected['directionSmallName'] = "全部"
- }
- }
- if (key === "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[key].smallList = typeItem.children
- }
- })
- }
- })
- })
- })
- return {
- selected: this.selected,
- 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() {
- console.log('footer*** start',)
- //设置底部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
- let baseUrl = this.store.state.domainConfig.siteUrl;
- let jishuBaseUrl = this.store.state.domainConfig.jishuinUrl;
- let kaifainUrl = this.store.state.domainConfig.kaifainUrl;
- let jobUrl = this.store.state.domainConfig.jobUrl;
- let footer = {
- baseLink: baseUrl,
- link: [{
- name: "",
- data: []
- }, {
- name: "",
- data: []
- },],
- }
- 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: `${jobUrl}/${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: `${jobUrl}/${citySlug}/${item.slug}/`
- })
- if (Array.isArray(item.children)) {
- item.children.forEach(item1 => {
- footer.link[1].data.push({
- name: `${cityName}${item1.name}兼职招聘`,
- url: `${jobUrl}/${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: `${jobUrl}/${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: `${jobUrl}/${citySlug}/${item.slug}/`
- })
- if (Array.isArray(item.children)) {
- item.children.forEach(item1 => {
- footer.link[1].data.push({
- name: `${cityName}${item1.name}兼职招聘`,
- url: `${jobUrl}/${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: `${jobUrl}/${item.slug}/`
- })
- if (Array.isArray(item.children)) {
- item.children.forEach(item1 => {
- footer.link[0].data.push({
- name: `${item1.name}兼职招聘`,
- url: `${jobUrl}/${item1.slug}/`
- })
- })
- }
- })
- footer.link[1].name = `热门城市${jobName}兼职招聘`
- footer.link[1].data = typeList.city.list.map((item) => {
- return {
- name: `${item.name}${jobName}兼职招聘`,
- url: `${jobUrl}/${jobSlug}/${item.slug}/`
- }
- })
- } else {
- //非特定的url
- footer.link[0].name = "热门城市兼职招聘"
- footer.link[0].data = typeList.city.list.map((item) => {
- return {
- name: `${item.name}兼职招聘`,
- url: `${jobUrl}/${item.slug}/`
- }
- })
- footer.link[1].name = "热门岗位兼职招聘"
- footer.link[1].data = []
- typeList.direction.list.forEach((item) => {
- footer.link[1].data.push({
- name: `${item.name}兼职招聘`,
- url: `${jobUrl}/${item.slug}/`
- })
- if (Array.isArray(item.children)) {
- item.children.forEach(item1 => {
- footer.link[1].data.push({
- name: `${item1.name}兼职招聘`,
- url: `${jobUrl}/${item1.slug}/`
- })
- })
- }
- })
- }
- console.log('footer***', footer)
- return footer
- }
- }
|