dealSeoList.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.pagination = {
  9. page: 1,
  10. pagesize: 9,
  11. total: 0,
  12. loading: false,
  13. selectedCateIdOne: '',
  14. selectedCateIdTwo: '',
  15. noMore: true
  16. }
  17. this.cateNameOne = ''
  18. this.cateNameTwo = ''
  19. this.mobile = this.app.$deviceType.isMobile()
  20. this.root_type = 0
  21. }
  22. async dealData() {
  23. const self = this
  24. let {
  25. name,
  26. query: { page = 1, root_type = 0 },
  27. path,
  28. params,
  29. fullPath
  30. } = this.app.context.route
  31. this.pagination.page = Number(page)
  32. this.root_type = root_type
  33. // 目前仅将二级 id 拼接到 url 上
  34. let match = params.pathMatch || ''
  35. let matchList = match.split('/')
  36. matchList.pop()
  37. let lastMatch = matchList.pop() || ''
  38. // console.log(`match: ${match}, matchList: ${matchList}, lastMatch: ${lastMatch}`)
  39. // 重定向
  40. if (path.indexOf('/frontend/learn/list') > -1) {
  41. this.redirect(301, '/learn/' + lastMatch)
  42. }
  43. // 无需分类信息
  44. // let learnCate = await this._getSkillCate()
  45. // let learnCateAll = []
  46. // learnCate.forEach(item => {
  47. // if (item.children && item.children.length) {
  48. // item.children.forEach(child => {
  49. // learnCateAll.push(child)
  50. // })
  51. // }
  52. // })
  53. // if (lastMatch) {
  54. // // 遍历分类数组,因为每个 children 都添加了“全部”,此处逻辑无需修改
  55. // let selectedCateIdOne = ''
  56. // learnCate.forEach(cateOne => {
  57. // cateOne.children.forEach(cateTwo => {
  58. // if (cateTwo.value === lastMatch) {
  59. // selectedCateIdOne = cateOne.value
  60. // self.cateNameOne = cateOne.label
  61. // if (cateTwo.label === '全部') {
  62. // self.cateNameTwo = cateOne.label
  63. // } else {
  64. // self.cateNameTwo = cateTwo.label
  65. // }
  66. // }
  67. // })
  68. // })
  69. // if (selectedCateIdOne) {
  70. // this.pagination.selectedCateIdOne = selectedCateIdOne
  71. // this.pagination.selectedCateIdTwo = lastMatch
  72. // }
  73. // }
  74. // 处理完分类信息,再获取数据
  75. let learnList = await this._getLearnList()
  76. return {
  77. root_type,
  78. // learnCate,
  79. // learnCateAll,
  80. learnList, //首次获取的数据
  81. mobile: this.mobile,
  82. pagination: this.pagination,
  83. head: this.dealThisMeta()
  84. }
  85. }
  86. /** 获取技能服务列表 */
  87. async _getLearnList () {
  88. // 接口参数释义:https://www.yesdev.cn/apidocs-detail-20.html
  89. const data = {
  90. type: 4,
  91. page: this.pagination.page,
  92. page_size: this.pagination.pagesize,
  93. cate_id: this.pagination.selectedCateIdTwo,
  94. status: 2,
  95. owner_type: 1,
  96. root_type: this.root_type
  97. }
  98. let res = await this.$axios.$post('/api/sale/saleList', data)
  99. let learnList = []
  100. if (Number(res.status) === 1) {
  101. learnList = res.data.list || []
  102. learnList.forEach((item) => {
  103. let imageList = item.image.split(',')
  104. item.coverImage = imageList[0] || ''
  105. imageList.splice(0, 1)
  106. item.imageList = imageList
  107. })
  108. this.pagination.total = Number(res.data.total)
  109. this.pagination.pagesize = Number(res.data.page_size) || 9
  110. if (this.pagination.page * this.pagination.pagesize >= this.pagination.total) {
  111. this.pagination.noMore = true
  112. } else {
  113. this.pagination.noMore = false
  114. }
  115. }
  116. return learnList
  117. }
  118. dealThisMeta() {
  119. let head = {
  120. title: "客栈学院",
  121. keyword: "客栈学院",
  122. description: "客栈学院",
  123. h1: "",
  124. canonical: "",
  125. metaLocation: ""
  126. }
  127. if (this.req) {
  128. const { headers: { host }, url } = this.req
  129. //拼接canonical
  130. if (host.indexOf('local') !== -1) {
  131. head.canonical = 'http://' + host + url
  132. } else {
  133. head.canonical = 'https://' + host + url
  134. }
  135. }
  136. // if (this.cateNameTwo) {
  137. // // 分类页
  138. // head.title = `${this.cateNameTwo}技能服务-程序员客栈技术服务`;
  139. // head.keyword = `${this.cateNameTwo}开发,${this.cateNameTwo}编程,自学${this.cateNameTwo},${this.cateNameTwo}教学`;
  140. // head.description = "技能服务是程序员客栈远程工作平台为企业和自由职业者提供的标准化数字服务,通过标准定价的模块化技能,帮助企业和自由职业者快速达成合作。";
  141. // } else {
  142. // // 列表页,无筛选参数
  143. // head.title = "程序员客栈技能商城-【程序员客栈技能服务】";
  144. // head.keyword = "程序员客栈技能商城,远程工作,Logo设计,网页设计,微信公众号运营,PPT设计,社群运营,文案编辑,视频剪辑,音频录制,翻译";
  145. // head.description = "技能服务是程序员客栈远程工作平台为企业和自由职业者提供的标准化数字服务,通过标准定价的模块化技能,帮助企业和自由职业者快速达成合作。";
  146. // }
  147. return head
  148. }
  149. }