dealSeoFooter.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. export default class DealSeoData {
  2. constructor({
  3. $axios,
  4. req,
  5. app,
  6. redirect,
  7. store,
  8. }, recruitData) {
  9. this.$axios = $axios
  10. this.req = req
  11. this.app = app
  12. this.redirect = redirect
  13. this.store = store
  14. this.selected = {
  15. city: 0,
  16. direction: 0, //职业角色 大
  17. directionSmall: 0,
  18. workType: 0,
  19. }
  20. this.recruitData = recruitData
  21. }
  22. async dealData() {
  23. let {
  24. name,
  25. path,
  26. params,
  27. fullPath
  28. } = this.app.context.route
  29. let typeList = await this.getTypeList()
  30. this.typeList = typeList
  31. let list = [],
  32. keys = [];
  33. switch (name) {
  34. case "JobListSeoIndex":
  35. case "job_$":
  36. case "job":
  37. case "JobListSeoIndex_$":
  38. let match = params.pathMatch || ''
  39. list = match.split('/').map(item => item.toLocaleLowerCase())
  40. list.length = Math.min(list.length, 3) //防止url超出
  41. keys = Object.keys(typeList)
  42. break
  43. case "JobListSeoDetail":
  44. break
  45. }
  46. //3 * 3 * n的循环 n < 100
  47. list.forEach(item => {
  48. keys.forEach(key => {
  49. typeList[key].list.forEach(typeItem => {
  50. if (typeItem.slug === item) {
  51. this.selected[key] = typeItem.id
  52. this.selected[key + 'Name'] = typeItem.name
  53. this.selected[key + 'Slug'] = typeItem.slug
  54. if (key === 'city') {
  55. this.selected["provice"] = typeItem.prov_id
  56. }
  57. if (key === "direction" && typeItem.children && typeItem.children.length > 1) {
  58. typeList[key].smallList = typeItem.children
  59. this.selected['directionSmall'] = 0
  60. this.selected['directionSmallName'] = "全部"
  61. }
  62. }
  63. if (key === "direction" && Array.isArray(typeItem.children)) { //查询是否在子分类
  64. typeItem.children.forEach(child => {
  65. if (child.slug === item) {
  66. this.selected['direction'] = typeItem.id
  67. this.selected['directionName'] = typeItem.name
  68. this.selected['directionSlug'] = typeItem.slug
  69. this.selected['directionSmall'] = child.id
  70. this.selected['directionSmallName'] = child.name
  71. this.selected['directionSmallSlug'] = child.slug
  72. typeList[key].smallList = typeItem.children
  73. }
  74. })
  75. }
  76. })
  77. })
  78. })
  79. return {
  80. selected: this.selected,
  81. footer: await this.getFooterData(),
  82. }
  83. }
  84. async getTypeList() {
  85. let res = await this.$axios.get('/api/recruit/get_options')
  86. let typeList = {
  87. direction: {
  88. title: '职业角色',
  89. list: [],
  90. smallList: []
  91. },
  92. city: {
  93. title: '国内地区',
  94. list: []
  95. },
  96. workType: {
  97. title: '工作方式',
  98. list: [{
  99. id: 0,
  100. name: "全部"
  101. }, {
  102. id: 1,
  103. name: "兼职",
  104. slug: "yuancheng"
  105. }, {
  106. id: 2,
  107. name: "全职",
  108. slug: "zhuchang"
  109. }]
  110. }
  111. }
  112. if (Number(res.data.status) === 1) {
  113. // res.data.data.direction.unshift({ id: 0, name: "全部" })
  114. // res.data.data.cities.unshift({ id: 0, name: "全部" })
  115. Object.keys(res.data.data).forEach(key => {
  116. let item = res.data.data[key]
  117. if (Array.isArray(item)) {
  118. item.forEach(ii => {
  119. ii.name = ii.name || ii.occupation_name || ""
  120. ii.id = Number(ii.id || ii.occupation_id || 0)
  121. if (Array.isArray(ii.children)) {
  122. ii.children.forEach(jj => {
  123. jj.name = jj.name || jj.direction_name || ""
  124. jj.id = Number(jj.id || jj.direction_id || 0)
  125. })
  126. }
  127. })
  128. }
  129. })
  130. typeList.direction.list = [...res.data.data.direction]
  131. typeList.city.list = [...res.data.data.cities]
  132. }
  133. return typeList
  134. }
  135. async getFooterData() {
  136. console.log('footer*** start',)
  137. //设置底部link列表
  138. const typeList = this.typeList
  139. const {
  140. city,
  141. citySlug,
  142. cityName = "",
  143. direction,
  144. directionName = "",
  145. directionSlug,
  146. directionSmall,
  147. directionSmallName = "",
  148. directionSmallSlug
  149. } = this.selected
  150. let job = directionSmall || direction
  151. let jobName = directionSmallName === "全部" ? directionName : (directionSmallName || directionName)
  152. let jobSlug = directionSmallSlug || directionSlug
  153. let baseUrl = this.store.state.domainConfig.siteUrl;
  154. let jishuBaseUrl = this.store.state.domainConfig.jishuinUrl;
  155. let kaifainUrl = this.store.state.domainConfig.kaifainUrl;
  156. let jobUrl = this.store.state.domainConfig.jobUrl;
  157. let footer = {
  158. baseLink: baseUrl,
  159. link: [{
  160. name: "",
  161. data: []
  162. }, {
  163. name: "",
  164. data: []
  165. },],
  166. }
  167. if (city && job) {
  168. //兼职城市&岗位页 ${jobName}兼职招聘>${cityName}${jobName}兼职招聘,并赋予对应的url
  169. footer.link[0].name = `热门城市${jobName}兼职招聘`
  170. footer.link[0].data = typeList.city.list.map((item) => {
  171. return {
  172. name: `${item.name}${jobName}兼职招聘`,
  173. url: `${jobUrl}/${jobSlug}/${item.slug}/`
  174. }
  175. })
  176. footer.link[1].name = `${cityName}热门岗位兼职招聘`
  177. footer.link[1].data = []
  178. typeList.direction.list.forEach((item) => {
  179. footer.link[1].data.push({
  180. name: `${cityName}${item.name}兼职招聘`,
  181. url: `${jobUrl}/${citySlug}/${item.slug}/`
  182. })
  183. if (Array.isArray(item.children)) {
  184. item.children.forEach(item1 => {
  185. footer.link[1].data.push({
  186. name: `${cityName}${item1.name}兼职招聘`,
  187. url: `${jobUrl}/${citySlug}/${item1.slug}/`
  188. })
  189. })
  190. }
  191. })
  192. } else if (city && !job) {
  193. //兼职城市
  194. footer.link[0].name = "热门城市兼职招聘"
  195. footer.link[0].data = typeList.city.list.map((item) => {
  196. return {
  197. name: `${item.name}兼职招聘`,
  198. url: `${jobUrl}/${item.slug}/`
  199. }
  200. })
  201. footer.link[1].name = `${cityName}热门岗位兼职招聘`
  202. footer.link[1].data = []
  203. typeList.direction.list.forEach((item) => {
  204. footer.link[1].data.push({
  205. name: `${cityName}${item.name}兼职招聘`,
  206. url: `${jobUrl}/${citySlug}/${item.slug}/`
  207. })
  208. if (Array.isArray(item.children)) {
  209. item.children.forEach(item1 => {
  210. footer.link[1].data.push({
  211. name: `${cityName}${item1.name}兼职招聘`,
  212. url: `${jobUrl}/${citySlug}/${item1.slug}/`
  213. })
  214. })
  215. }
  216. })
  217. } else if (!city && job) {
  218. //岗位页
  219. footer.link[0].name = "热门岗位兼职招聘"
  220. footer.link[0].data = []
  221. typeList.direction.list.forEach((item) => {
  222. footer.link[0].data.push({
  223. name: `${item.name}兼职招聘`,
  224. url: `${jobUrl}/${item.slug}/`
  225. })
  226. if (Array.isArray(item.children)) {
  227. item.children.forEach(item1 => {
  228. footer.link[0].data.push({
  229. name: `${item1.name}兼职招聘`,
  230. url: `${jobUrl}/${item1.slug}/`
  231. })
  232. })
  233. }
  234. })
  235. footer.link[1].name = `热门城市${jobName}兼职招聘`
  236. footer.link[1].data = typeList.city.list.map((item) => {
  237. return {
  238. name: `${item.name}${jobName}兼职招聘`,
  239. url: `${jobUrl}/${jobSlug}/${item.slug}/`
  240. }
  241. })
  242. } else {
  243. //非特定的url
  244. footer.link[0].name = "热门城市兼职招聘"
  245. footer.link[0].data = typeList.city.list.map((item) => {
  246. return {
  247. name: `${item.name}兼职招聘`,
  248. url: `${jobUrl}/${item.slug}/`
  249. }
  250. })
  251. footer.link[1].name = "热门岗位兼职招聘"
  252. footer.link[1].data = []
  253. typeList.direction.list.forEach((item) => {
  254. footer.link[1].data.push({
  255. name: `${item.name}兼职招聘`,
  256. url: `${jobUrl}/${item.slug}/`
  257. })
  258. if (Array.isArray(item.children)) {
  259. item.children.forEach(item1 => {
  260. footer.link[1].data.push({
  261. name: `${item1.name}兼职招聘`,
  262. url: `${jobUrl}/${item1.slug}/`
  263. })
  264. })
  265. }
  266. })
  267. }
  268. console.log('footer***', footer)
  269. return footer
  270. }
  271. }