dealSeoIndex.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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 {
  27. name,
  28. query: {
  29. page = 1,
  30. c_d = [],
  31. keyword = ''
  32. },
  33. path,
  34. params,
  35. fullPath
  36. } = this.app.context.route
  37. this.page.page = page
  38. this.page.keyword = keyword
  39. //兼容APP 如果是带有 ${id}.html的,跳转到详情页
  40. let endStr = path.split('/').pop()
  41. if (/([0-9]*\.html)/.test(endStr)) {
  42. this.redirect(301, "/job/detail/" + endStr)
  43. return
  44. }
  45. if (path && path[path.length - 1] !== '/') {
  46. let reditUrl = fullPath
  47. reditUrl = reditUrl.replace(path, path + '/')
  48. }
  49. let isSeoList = false
  50. let typeList = await this.getTypeList();
  51. console.log("dealSeoIndex name:::::::::", name);
  52. switch (name) {
  53. case "job":
  54. case "JobListSeoIndex":
  55. //kaifain路由匹配进入
  56. try {
  57. let match = params.pathMatch || ''
  58. let list = match.split('/').map(item => item.toLocaleLowerCase())
  59. list = list.filter(item => !!item)
  60. let urlCheck = ""
  61. // 驻场招聘不参与URL里
  62. let keys = ["city", "direction"];
  63. //适配小程序直接传参
  64. console.log("query* list***", this.app.context.route)
  65. // list = (list.length ? list : c_d)
  66. list.length = Math.min(list.length, 3) //防止url超出
  67. console.log("&&&&&&&&&&&&&&", list);
  68. //3 * 3 * n的循环 n < 100
  69. list.forEach(item => {
  70. keys.forEach(keys => {
  71. typeList[keys].list.forEach(typeItem => {
  72. if (typeItem.slug === item) {
  73. urlCheck += item
  74. this.selected[keys] = typeItem.id
  75. this.selected[keys + 'Name'] = typeItem.name
  76. this.selected[keys + 'Slug'] = typeItem.slug
  77. if (keys === 'city') {
  78. this.selected["provice"] = typeItem.prov_id
  79. }
  80. if (keys === "direction" && typeItem.children && typeItem.children.length > 1) {
  81. typeList[keys].smallList = typeItem.children
  82. this.selected['directionSmall'] = 0
  83. this.selected['directionSmallName'] = "全部"
  84. }
  85. }
  86. if (keys === "direction" && Array.isArray(typeItem.children)) { //查询是否在子分类
  87. typeItem.children.forEach(child => {
  88. if (child.slug === item) {
  89. urlCheck += item
  90. this.selected['direction'] = typeItem.id
  91. this.selected['directionName'] = typeItem.name
  92. this.selected['directionSlug'] = typeItem.slug
  93. this.selected['directionSmall'] = child.id
  94. this.selected['directionSmallName'] = child.name
  95. this.selected['directionSmallSlug'] = child.slug
  96. typeList[keys].smallList = typeItem.children
  97. }
  98. })
  99. }
  100. })
  101. })
  102. })
  103. if (urlCheck !== list.join("")) {
  104. this.error({
  105. statusCode: 404,
  106. message: "您要访问的页面不存在"
  107. })
  108. return
  109. }
  110. if (this.selected["provice"]) {
  111. let item = this.provinces.filter(item => item.id === this.selected["provice"])[0]
  112. this.selected["proviceName"] = item && item.name
  113. }
  114. } catch (e) {
  115. console.log("解决方案列表", e)
  116. }
  117. break
  118. default:
  119. //其他
  120. page = 1
  121. }
  122. // 通过 window.location.search 获取 workType
  123. let workType = this.app.context.route.query.workType || ''
  124. if (Number(workType) === 1 || Number(workType) === 2) {
  125. this.selected.workType = 2
  126. }
  127. await this.getList()
  128. return {
  129. typeList,
  130. isSeoList, //是否是 /kaifain/s/页面进入
  131. dataList: this.dataList, //首次获取的数据
  132. mobile: this.app.$deviceType.isMobile(),
  133. selected: this.selected,
  134. page: this.page,
  135. finished: this.finished,
  136. head: this.dealThisMeta(isSeoList),
  137. breadcrumbList: this.dealBreadcrumbList()
  138. }
  139. }
  140. async getTypeList() {
  141. let res = await this.$axios.get('/api/recruit/get_options')
  142. let typeList = {
  143. direction: {
  144. title: '职业角色',
  145. list: [],
  146. smallList: []
  147. },
  148. city: {
  149. title: '国内地区',
  150. list: []
  151. },
  152. workType: {
  153. title: '工作方式',
  154. list: [{
  155. id: 0,
  156. name: "全部",
  157. value: 0,
  158. text: "全部方式",
  159. },
  160. {
  161. id: 1,
  162. name: "兼职",
  163. value: 1,
  164. text: "兼职",
  165. slug: "yuancheng"
  166. }, {
  167. id: 2,
  168. name: "驻场",
  169. value: 2,
  170. text: "驻场",
  171. slug: "zhuchang"
  172. }
  173. ]
  174. }
  175. }
  176. if (Number(res.data.status) === 1) {
  177. res.data.data.direction.unshift({
  178. id: 0,
  179. name: "全部",
  180. children: []
  181. })
  182. res.data.data.cities.unshift({
  183. id: 0,
  184. name: "全部"
  185. })
  186. Object.keys(res.data.data).forEach(key => {
  187. let item = res.data.data[key]
  188. if (Array.isArray(item)) {
  189. item.forEach(ii => {
  190. ii.name = ii.name || ii.occupation_name || ""
  191. ii.id = Number(ii.id || ii.occupation_id || 0)
  192. ii.text = ii.name
  193. ii.value = ii.id
  194. if (Array.isArray(ii.children)) {
  195. ii.children.forEach(jj => {
  196. jj.name = jj.name || jj.direction_name || ""
  197. jj.id = Number(jj.id || jj.direction_id || 0)
  198. jj.text = jj.name
  199. jj.value = jj.id
  200. })
  201. if (ii.children) {
  202. ii.children.unshift({
  203. id: 0,
  204. name: "全部",
  205. value: 0,
  206. text: "全部",
  207. })
  208. }
  209. }
  210. })
  211. }
  212. })
  213. //单独设置百度app 选择器文案
  214. res.data.data.direction[0] = {
  215. ...res.data.data.direction[0],
  216. text: "全部职业",
  217. value: 0,
  218. }
  219. res.data.data.cities[0] = {
  220. ...res.data.data.cities[0],
  221. text: "全部地区",
  222. value: 0
  223. }
  224. typeList.direction.list = [...res.data.data.direction]
  225. typeList.city.list = [...res.data.data.cities]
  226. }
  227. return typeList
  228. }
  229. async getList() {
  230. const {
  231. page,
  232. selected: {
  233. city,
  234. direction,
  235. directionSmall,
  236. workType
  237. }
  238. } = this;
  239. let p = {
  240. city: city,
  241. ...page
  242. };
  243. direction && (p.occupationId = direction); //一级
  244. workType && (p.workType = workType);
  245. directionSmall && (p.directionId = directionSmall);//耳二级
  246. console.log("获取 /api/recruit/search", p)
  247. let res = await this.$axios.post('/api/recruit/search', p);
  248. if (Number(res.data.status) === 1) {
  249. let data = res.data.data;
  250. this.page.total = data.total;
  251. let dataList = data.list || [];
  252. this.dataList = [...dataList];
  253. this.page.page += 1;
  254. this.page.current = Number(data.page);
  255. if (this.page.total <= this.dataList.length) {
  256. this.finished = true
  257. }
  258. }
  259. }
  260. dealThisMeta() {
  261. const {
  262. city,
  263. cityName = "",
  264. direction,
  265. directionName = "",
  266. directionSmall,
  267. directionSmallName,
  268. workType,
  269. workTypeName,
  270. proviceName,
  271. } = this.selected
  272. let job = directionSmall || direction
  273. let jobName = directionSmallName === "全部" ? directionName : (directionSmallName || directionName)
  274. let head = {
  275. title: "",
  276. keyword: "",
  277. description: "",
  278. h1: "",
  279. canonical: "",
  280. metaLocation: ""
  281. }
  282. if (this.req) {
  283. const {
  284. headers: {
  285. host
  286. },
  287. url
  288. } = this.req
  289. //拼接canonical
  290. if (host.indexOf('local') !== -1) {
  291. head.canonical = 'http://' + host + url
  292. } else {
  293. head.canonical = 'https://' + host + url
  294. }
  295. }
  296. if (city && !job) {
  297. //只有城市的
  298. head.title = `【${cityName}招聘】${cityName}程序员招聘-程序员客栈`
  299. head.keyword = `${cityName}程序员招聘,${cityName}人才网,${cityName}人才招聘`
  300. head.description = `程序员客栈为程序员提供2021年最新的${cityName}程序员招聘信息,${cityName}人才招聘信息。百万工作机会,直接开聊,在线面试,程序员找工作就上程序员客栈网站或APP,直接与招聘者开聊吧!`
  301. head.h1 = ``
  302. head.metaLocation = `province=${proviceName};city=${cityName}`
  303. } else if (!city && job) {
  304. //只有岗位的
  305. head.title = `【全国${jobName}招聘】-程序员客栈`
  306. head.keyword = `全国${jobName}招聘,全国${jobName}人才网,全国${jobName}招聘网`
  307. head.description = `程序员客栈为程序员提供2021年最新的全国${jobName}招聘信息,百万工作机会,直接开聊,在线面试,程序员找工作就上程序员客栈网站或APP,直接与招聘者开聊吧!`
  308. head.h1 = ``
  309. } else if (city && job) {
  310. //兼职城市&岗位页
  311. head.title = `【${cityName}${jobName}招聘】-2021年${cityName}${jobName}最新人才招聘信息-程序员客栈`;
  312. head.keyword = `${cityName}${jobName}招聘,${cityName}${jobName}人才网,${cityName}${jobName}招聘网`;
  313. head.description = `程序员客栈为程序员提供2021年最新的${cityName}${jobName}招聘信息,百万工作机会,直接开聊,在线面试,程序员找工作就上程序员客栈,直接与招聘者开聊吧!`;
  314. head.h1 = ``
  315. } else {
  316. // 没有任何参数
  317. head.title = "程序员客栈-高端IT技术人才程序员招聘求职找工作!";
  318. head.keyword = "程序员招聘,直聘网,招聘网,人才网,找工作,求职";
  319. head.description = "程序员客栈是权威领先的技术人才招聘网,开启技术人才网招聘求职新时代,让求职者与招聘者直接开聊、加快面试、即时反馈,找工作、找技术人才就来程序员客栈吧!"
  320. }
  321. return head
  322. }
  323. /** 处理面包屑导航 **/
  324. dealBreadcrumbList() {
  325. let list = [{
  326. name: '首页',
  327. url: "/"
  328. },
  329. {
  330. name: '兼职招聘',
  331. url: "/job/"
  332. },
  333. ]
  334. const {
  335. city,
  336. citySlug,
  337. cityName = "",
  338. direction,
  339. directionName = "",
  340. directionSlug,
  341. directionSmall,
  342. directionSmallName = "",
  343. directionSmallSlug
  344. } = this.selected
  345. let job = directionSmall || direction
  346. let jobName = directionSmallName === "全部" ? directionName : (directionSmallName || directionName)
  347. let jobSlug = directionSmallSlug || directionSlug
  348. if (city && job) {
  349. //兼职城市&岗位页 ${jobName}兼职招聘>${cityName}${jobName}兼职招聘,并赋予对应的url
  350. list.push({
  351. name: `${jobName}兼职招聘`,
  352. url: `/job/${jobSlug}/`
  353. })
  354. list.push({
  355. name: `${cityName}${jobName}兼职招聘`,
  356. url: `/job/${jobSlug}/${citySlug}/`
  357. })
  358. } else if (city && !job) {
  359. //兼职城市
  360. list.push({
  361. name: `${cityName}兼职招聘`,
  362. url: `/job/${citySlug}/`
  363. })
  364. } else if (!city && job) {
  365. //岗位页
  366. list.push({
  367. name: `${jobName}兼职招聘`,
  368. url: `/job/${jobSlug}/`
  369. })
  370. }
  371. return list
  372. }
  373. }