dealSeoFooter.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. export default class DealSeoData {
  2. constructor({ $axios, req, app, redirect }, recruitData) {
  3. this.$axios = $axios
  4. this.req = req
  5. this.app = app
  6. this.redirect = redirect
  7. this.selected = {
  8. city: 0,
  9. direction: 0, //职业角色 大
  10. directionSmall: 0,
  11. workType: 0,
  12. }
  13. this.recruitData = recruitData
  14. }
  15. async dealData() {
  16. let { name, path, params, fullPath } = this.app.context.route
  17. let typeList = await this.getTypeList()
  18. this.typeList = typeList
  19. let list = [], keys = []
  20. switch (name) {
  21. case "JobListSeoIndex":
  22. let match = params.pathMatch || ''
  23. list = match.split('/').map(item => item.toLocaleLowerCase())
  24. list.length = Math.min(list.length, 3) //防止url超出
  25. keys = Object.keys(typeList)
  26. break
  27. case "JobListSeoDetail":
  28. break
  29. }
  30. //3 * 3 * n的循环 n < 100
  31. list.forEach(item => {
  32. keys.forEach(keys => {
  33. typeList[ keys ].list.forEach(typeItem => {
  34. if (typeItem.slug === item) {
  35. this.selected[ keys ] = typeItem.id
  36. this.selected[ keys + 'Name' ] = typeItem.name
  37. this.selected[ keys + 'Slug' ] = typeItem.slug
  38. if (keys === 'city') {
  39. this.selected[ "provice" ] = typeItem.prov_id
  40. }
  41. if (keys === "direction" && typeItem.children && typeItem.children.length > 1) {
  42. typeList[ keys ].smallList = typeItem.children
  43. this.selected[ 'directionSmall' ] = 0
  44. this.selected[ 'directionSmallName' ] = "全部"
  45. }
  46. }
  47. if (keys === "direction" && Array.isArray(typeItem.children)) { //查询是否在子分类
  48. typeItem.children.forEach(child => {
  49. if (child.slug === item) {
  50. this.selected[ 'direction' ] = typeItem.id
  51. this.selected[ 'directionName' ] = typeItem.name
  52. this.selected[ 'directionSlug' ] = typeItem.slug
  53. this.selected[ 'directionSmall' ] = child.id
  54. this.selected[ 'directionSmallName' ] = child.name
  55. this.selected[ 'directionSmallSlug' ] = child.slug
  56. typeList[ keys ].smallList = typeItem.children
  57. }
  58. })
  59. }
  60. })
  61. })
  62. })
  63. return {
  64. footer: await this.getFooterData(),
  65. }
  66. }
  67. async getTypeList() {
  68. let res = await this.$axios.get('/api/recruit/get_options')
  69. let typeList = {
  70. direction: {
  71. title: '职业角色',
  72. list: [],
  73. smallList: []
  74. },
  75. city: {
  76. title: '国内地区',
  77. list: []
  78. },
  79. workType: {
  80. title: '工作方式',
  81. list: [ { id: 0, name: "全部" }, { id: 1, name: "远程", slug: "yuancheng" }, {
  82. id: 2,
  83. name: "驻场",
  84. slug: "zhuchang"
  85. } ]
  86. }
  87. }
  88. if (Number(res.data.status) === 1) {
  89. // res.data.data.direction.unshift({ id: 0, name: "全部" })
  90. // res.data.data.cities.unshift({ id: 0, name: "全部" })
  91. Object.keys(res.data.data).forEach(key => {
  92. let item = res.data.data[ key ]
  93. if (Array.isArray(item)) {
  94. item.forEach(ii => {
  95. ii.name = ii.name || ii.occupation_name || ""
  96. ii.id = Number(ii.id || ii.occupation_id || 0)
  97. if (Array.isArray(ii.children)) {
  98. ii.children.forEach(jj => {
  99. jj.name = jj.name || jj.direction_name || ""
  100. jj.id = Number(jj.id || jj.direction_id || 0)
  101. })
  102. }
  103. })
  104. }
  105. })
  106. typeList.direction.list = [ ...res.data.data.direction ]
  107. typeList.city.list = [ ...res.data.data.cities ]
  108. }
  109. return typeList
  110. }
  111. async getFooterData() {
  112. //设置底部link列表
  113. const typeList = this.typeList
  114. const { city, citySlug, cityName = "", direction, directionName = "", directionSlug, directionSmall, directionSmallName = "", directionSmallSlug } = this.selected
  115. let job = directionSmall || direction
  116. let jobName = directionSmallName === "全部" ? directionName : (directionSmallName || directionName)
  117. let jobSlug = directionSmallSlug || directionSlug
  118. const { headers: { host } } = this.req
  119. let footer = {
  120. baseLink: "", link: [
  121. { name: "", data: [] }, { name: "", data: [] },
  122. ],
  123. }
  124. //设置baseLink
  125. if (host.indexOf('local') !== -1) {
  126. footer.baseLink = 'http://' + host
  127. } else {
  128. footer.baseLink = 'https://' + host
  129. }
  130. if (city && job) {
  131. //兼职城市&岗位页 ${jobName}兼职招聘>${cityName}${jobName}兼职招聘,并赋予对应的url
  132. footer.link[ 0 ].name = `热门城市${jobName}兼职招聘`
  133. footer.link[ 0 ].data = typeList.city.list.map((item) => {
  134. return { name: `${item.name}${jobName}兼职招聘`, url: `/job/${jobSlug}/${item.slug}/` }
  135. })
  136. footer.link[ 1 ].name = `${cityName}热门岗位兼职招聘`
  137. footer.link[ 1 ].data = []
  138. typeList.direction.list.forEach((item) => {
  139. footer.link[ 1 ].data.push({ name: `${cityName}${item.name}兼职招聘`, url: `/job/${citySlug}/${item.slug}/` })
  140. if (Array.isArray(item.children)) {
  141. item.children.forEach(item1 => {
  142. footer.link[ 1 ].data.push({ name: `${cityName}${item1.name}兼职招聘`, url: `/job/${citySlug}/${item1.slug}/` })
  143. })
  144. }
  145. })
  146. } else if (city && !job) {
  147. //兼职城市
  148. footer.link[ 0 ].name = "热门城市兼职招聘"
  149. footer.link[ 0 ].data = typeList.city.list.map((item) => {
  150. return { name: `${item.name}兼职招聘`, url: `/job/${item.slug}/` }
  151. })
  152. footer.link[ 1 ].name = `${cityName}热门岗位兼职招聘`
  153. footer.link[ 1 ].data = []
  154. typeList.direction.list.forEach((item) => {
  155. footer.link[ 1 ].data.push({ name: `${cityName}${item.name}兼职招聘`, url: `/job/${citySlug}/${item.slug}/` })
  156. if (Array.isArray(item.children)) {
  157. item.children.forEach(item1 => {
  158. footer.link[ 1 ].data.push({ name: `${cityName}${item1.name}兼职招聘`, url: `/job/${citySlug}/${item1.slug}/` })
  159. })
  160. }
  161. })
  162. }
  163. else if (!city && job) {
  164. //岗位页
  165. footer.link[ 0 ].name = "热门岗位兼职招聘"
  166. footer.link[ 0 ].data = []
  167. typeList.direction.list.forEach((item) => {
  168. footer.link[ 0 ].data.push({ name: `${item.name}兼职招聘`, url: `/job/${item.slug}/` })
  169. if (Array.isArray(item.children)) {
  170. item.children.forEach(item1 => {
  171. footer.link[ 0 ].data.push({ name: `${item1.name}兼职招聘`, url: `/job/${item1.slug}/` })
  172. })
  173. }
  174. })
  175. footer.link[ 1 ].name = `热门城市${jobName}兼职招聘`
  176. footer.link[ 1 ].data = typeList.city.list.map((item) => {
  177. return { name: `${item.name}${jobName}兼职招聘`, url: `/job/${jobSlug}/${item.slug}/` }
  178. })
  179. } else {
  180. //非特定的url
  181. footer.link[ 0 ].name = "热门城市兼职招聘"
  182. footer.link[ 0 ].data = typeList.city.list.map((item) => {
  183. return { name: `${item.name}兼职招聘`, url: `/job/${item.slug}/` }
  184. })
  185. footer.link[ 1 ].name = "热门岗位兼职招聘"
  186. footer.link[ 1 ].data = []
  187. typeList.direction.list.forEach((item) => {
  188. footer.link[ 1 ].data.push({ name: `${item.name}兼职招聘`, url: `/job/${item.slug}/` })
  189. if (Array.isArray(item.children)) {
  190. item.children.forEach(item1 => {
  191. footer.link[ 1 ].data.push({ name: `${item1.name}兼职招聘`, url: `/job/${item1.slug}/` })
  192. })
  193. }
  194. })
  195. }
  196. return footer
  197. }
  198. }