dealSeoIndex.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. export default class DealSeoData {
  2. constructor({ $axios, req, app, redirect, error }) {
  3. this.$axios = $axios
  4. this.req = req
  5. this.app = app
  6. this.redirect = redirect
  7. this.error = error
  8. this.selected = {
  9. city: 0,
  10. direction: 0, //职业角色 大
  11. directionIndex: 0, //移动端索引
  12. directionSmall: 0,
  13. workType: 0,
  14. }
  15. this.page = {
  16. page: 1,
  17. pageSize: 10,
  18. total: 0,
  19. keyword: ''
  20. }
  21. this.finished = false
  22. this.dataList = []
  23. this.provinces = []
  24. }
  25. async dealData() {
  26. let { name, query: { page = 1, c_d = [], keyword='' }, path, params, fullPath } = this.app.context.route
  27. this.page.page = page
  28. this.page.keyword = keyword
  29. //兼容APP 如果是带有 ${id}.html的,跳转到详情页
  30. let endStr = path.split('/').pop()
  31. if (/([0-9]*\.html)/.test(endStr)) {
  32. this.redirect(301, "/job/detail/"+endStr)
  33. return
  34. }
  35. if (path && path[ path.length - 1 ] !== '/') {
  36. let reditUrl = fullPath
  37. reditUrl = reditUrl.replace(path, path + '/')
  38. }
  39. let isSeoList = false
  40. let typeList = await this.getTypeList()
  41. switch (name) {
  42. case "job":
  43. case "JobListSeoIndex":
  44. //kaifain路由匹配进入
  45. try {
  46. let match = params.pathMatch || ''
  47. let list = match.split('/').map(item => item.toLocaleLowerCase())
  48. list = list.filter(item => !!item)
  49. let urlCheck = ""
  50. // 驻场招聘不参与URL里
  51. let keys = ["city", "direction"]
  52. //适配小程序直接传参
  53. console.log("query* list***", this.app.context.route)
  54. // list = (list.length ? list : c_d)
  55. list.length = Math.min(list.length, 3) //防止url超出
  56. //3 * 3 * n的循环 n < 100
  57. list.forEach(item => {
  58. keys.forEach(keys => {
  59. typeList[ keys ].list.forEach(typeItem => {
  60. if (typeItem.slug === item) {
  61. urlCheck += item
  62. this.selected[ keys ] = typeItem.id
  63. this.selected[ keys + 'Name' ] = typeItem.name
  64. this.selected[ keys + 'Slug' ] = typeItem.slug
  65. if (keys === 'city') {
  66. this.selected[ "provice" ] = typeItem.prov_id
  67. }
  68. if (keys === "direction" && typeItem.children && typeItem.children.length > 1) {
  69. typeList[ keys ].smallList = typeItem.children
  70. this.selected[ 'directionSmall' ] = 0
  71. this.selected[ 'directionSmallName' ] = "全部"
  72. }
  73. }
  74. if (keys === "direction" && Array.isArray(typeItem.children)) { //查询是否在子分类
  75. typeItem.children.forEach(child => {
  76. if (child.slug === item) {
  77. urlCheck += item
  78. this.selected[ 'direction' ] = typeItem.id
  79. this.selected[ 'directionName' ] = typeItem.name
  80. this.selected[ 'directionSlug' ] = typeItem.slug
  81. this.selected[ 'directionSmall' ] = child.id
  82. this.selected[ 'directionSmallName' ] = child.name
  83. this.selected[ 'directionSmallSlug' ] = child.slug
  84. typeList[ keys ].smallList = typeItem.children
  85. }
  86. })
  87. }
  88. })
  89. })
  90. })
  91. if (urlCheck !== list.join("")) {
  92. this.error({ statusCode: 404, message: "您要访问的页面不存在" })
  93. return
  94. }
  95. if (this.selected[ "provice" ]) {
  96. let item = this.provinces.filter(item => item.id === this.selected[ "provice" ])[ 0 ]
  97. this.selected[ "proviceName" ] = item && item.name
  98. }
  99. } catch ( e ) {
  100. console.log("解决方案列表", e)
  101. }
  102. break
  103. default:
  104. //其他
  105. page = 1
  106. }
  107. await this.getList()
  108. return {
  109. typeList,
  110. isSeoList, //是否是 /kaifain/s/页面进入
  111. dataList: this.dataList, //首次获取的数据
  112. mobile: this.app.$deviceType.isMobile(),
  113. selected: this.selected,
  114. page: this.page,
  115. finished: this.finished,
  116. head: this.dealThisMeta(isSeoList),
  117. breadcrumbList: this.dealBreadcrumbList()
  118. }
  119. }
  120. async getTypeList() {
  121. let res = await this.$axios.get('/api/recruit/get_options')
  122. let typeList = {
  123. direction: {
  124. title: '职业角色',
  125. list: [],
  126. smallList: []
  127. },
  128. city: {
  129. title: '国内地区',
  130. list: []
  131. },
  132. workType: {
  133. title: '工作方式',
  134. list: [ { id: 0, name: "全部", value: 0, text: "全部方式", },
  135. { id: 1, name: "远程", value: 1, text: "远程", slug: "yuancheng" }, {
  136. id: 2, name: "驻场", value: 2, text: "驻场", slug: "zhuchang"
  137. } ]
  138. }
  139. }
  140. if (Number(res.data.status) === 1) {
  141. res.data.data.direction.unshift({ id: 0, name: "全部", children:[] })
  142. res.data.data.cities.unshift({ id: 0, name: "全部" })
  143. Object.keys(res.data.data).forEach(key => {
  144. let item = res.data.data[ key ]
  145. if (Array.isArray(item)) {
  146. item.forEach(ii => {
  147. ii.name = ii.name || ii.occupation_name || ""
  148. ii.id = Number(ii.id || ii.occupation_id || 0)
  149. ii.text = ii.name
  150. ii.value = ii.id
  151. if (Array.isArray(ii.children)) {
  152. ii.children.forEach(jj => {
  153. jj.name = jj.name || jj.direction_name || ""
  154. jj.id = Number(jj.id || jj.direction_id || 0)
  155. jj.text = jj.name
  156. jj.value = jj.id
  157. })
  158. if (ii.children) {
  159. ii.children.unshift({ id: 0, name: "全部", value: 0, text: "全部", })
  160. }
  161. }
  162. })
  163. }
  164. })
  165. //单独设置百度app 选择器文案
  166. res.data.data.direction[0] = {...res.data.data.direction[0], text: "全部职业", value: 0, }
  167. res.data.data.cities[0] = {...res.data.data.cities[0], text: "全部地区", value: 0}
  168. typeList.direction.list = [ ...res.data.data.direction ]
  169. typeList.city.list = [ ...res.data.data.cities ]
  170. }
  171. return typeList
  172. }
  173. async getList() {
  174. const { page, selected: {city, direction, directionSmall, workType} } = this
  175. let p = {
  176. city: city,
  177. ...page
  178. }
  179. direction && (p.occupationId = direction) //一级
  180. workType && (p.workType = workType)
  181. directionSmall && (p.directionId = directionSmall) //耳二级
  182. console.log("获取 /api/recruit/search", p)
  183. let res = await this.$axios.post('/api/recruit/search', p)
  184. if (Number(res.data.status) === 1) {
  185. let data = res.data.data
  186. this.page.total = data.total
  187. let dataList = data.list || []
  188. this.dataList = [ ...dataList ]
  189. this.page.page += 1
  190. this.page.current = Number(data.page)
  191. if (this.page.total <= this.dataList.length) {
  192. this.finished = true
  193. }
  194. }
  195. }
  196. dealThisMeta() {
  197. const {
  198. city, cityName = "",
  199. direction, directionName = "",
  200. directionSmall, directionSmallName,
  201. workType, workTypeName, proviceName,
  202. } = this.selected
  203. const { headers: { host }, url } = this.req
  204. let job = directionSmall || direction
  205. let jobName = directionSmallName === "全部" ? directionName : (directionSmallName || directionName)
  206. let head = {
  207. title: "", keyword: "", descrption: "", h1: "", canonical: "", metaLocation: ""
  208. }
  209. //拼接canonical
  210. if (host.indexOf('local') !== -1) {
  211. head.canonical = 'http://' + host + url
  212. } else {
  213. head.canonical = 'https://' + host + url
  214. }
  215. if (city && !job) {
  216. //只有城市的
  217. head.title = `${cityName}程序员兼职工作招聘,2020年${cityName}程序员最新兼职工作招聘信息-程序员客栈`
  218. head.keyword = `${cityName}程序员兼职招聘,${cityName}程序员兼职工作招聘,2020年最新${cityName}程序员兼职招聘信息`
  219. head.descrption = `程序员客栈提供${cityName}程序员兼职工作最新招聘信息,核实${cityName}发布程序员招聘信息的企业资质,让有前往${cityName}工作意向的程序员能得到一份满意的${jobName}兼职工作;对${jobName}程序员从业者能力进行严格把关,保障${cityName}企业能在兼职招聘平台找到靠谱的${jobName}程序员,确保项目正常进行。找工作、招聘合格的程序员,就上程序员客栈兼职招聘平台!`
  220. head.h1 = `${cityName}程序员兼职工作招聘`
  221. head.metaLocation = `province=${proviceName};city=${cityName}`
  222. } else if (!city && job) {
  223. //只有岗位的
  224. head.title = `${jobName}兼职工作招聘,2020年${jobName}最新兼职工作招聘信息-程序员客栈`
  225. head.keyword = `${jobName}兼职招聘,${jobName}兼职工作招聘,2019年最新${jobName}兼职招聘信息`
  226. head.descrption = `程序员客栈提供${jobName}IT兼职工作最新招聘信息,核实${jobName}兼职招聘信息发布企业资质,让有${jobName}工作意向的程序员能得到一份满意的兼职工作;对${jobName}程序员从业者能力进行严格把关,保障企业能在兼职招聘平台找到靠谱的${jobName}程序员,确保项目正常进行。找工作、招聘合格的程序员,就上程序员客栈兼职招聘平台!`
  227. head.h1 = `${jobName}兼职工作招聘`
  228. } else if (city && job) {
  229. //兼职城市&岗位页
  230. head.title = `${cityName}${jobName}兼职工作招聘,2020年${cityName}${jobName}最新兼职工作招聘信息-程序员客栈`
  231. head.keyword = `${cityName}${jobName}兼职招聘,${cityName}${jobName}兼职工作招聘,2020年最新${cityName}${jobName}兼职招聘信息`
  232. head.descrption = `程序员客栈提供${cityName}${jobName}兼职工作最新招聘信息,核实${cityName}发布${jobName}招聘信息的企业资质,让有前往${cityName}工作意向的程序员能得到一份满意的${jobName}兼职工作;对${jobName}程序员从业者能力进行严格把关,保障${cityName}企业能在兼职招聘平台找到靠谱的${jobName}程序员,确保项目正常进行。找工作、招聘合格的程序员,就上程序员客栈兼职招聘平台!`
  233. head.h1 = `${cityName}${jobName}兼职工作招聘`
  234. } else {
  235. head.title = "兼职工作招聘,2020年最新兼职工作招聘信息-程序员客栈"
  236. head.keyword = "兼职招聘,兼职工作招聘,2020年最新兼职招聘信息"
  237. head.descrption = "程序员客栈提供全国各地城市IT兼职工作最新招聘信息,核实企业资质,让有工作需求的程序员能得到一份满意的兼职工作;对程序员从业者能力进行严格把关,保障企业能在兼职招聘平台找到靠谱的程序员,确保项目正常进行。找工作、招聘合格的程序员,就上程序员客栈兼职招聘平台!"
  238. }
  239. return head
  240. }
  241. /** 处理面包屑导航 **/
  242. dealBreadcrumbList() {
  243. let list = [
  244. { name: '首页', url: "/" },
  245. { name: '兼职招聘', url: "/job/" },
  246. ]
  247. const { city, citySlug, cityName = "", direction, directionName = "", directionSlug, directionSmall, directionSmallName = "", directionSmallSlug } = this.selected
  248. let job = directionSmall || direction
  249. let jobName = directionSmallName === "全部" ? directionName : (directionSmallName || directionName)
  250. let jobSlug = directionSmallSlug || directionSlug
  251. if (city && job) {
  252. //兼职城市&岗位页 ${jobName}兼职招聘>${cityName}${jobName}兼职招聘,并赋予对应的url
  253. list.push({ name: `${jobName}兼职招聘`, url: `/job/${jobSlug}/` })
  254. list.push({
  255. name: `${cityName}${jobName}兼职招聘`,
  256. url: `/job/${jobSlug}/${citySlug}/`
  257. })
  258. } else if (city && !job) {
  259. //兼职城市
  260. list.push({ name: `${cityName}兼职招聘`, url: `/job/${citySlug}/` })
  261. } else if (!city && job) {
  262. //岗位页
  263. list.push({ name: `${jobName}兼职招聘`, url: `/job/${jobSlug}/` })
  264. }
  265. return list
  266. }
  267. }