dealSeoList.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. pageCount: 1,
  13. loading: false,
  14. selectedCateIdOne: '',
  15. selectedCateIdTwo: '',
  16. noMore: true
  17. }
  18. this.cateNameOne = ''
  19. this.cateNameTwo = ''
  20. this.mobile = this.app.$deviceType.isMobile()
  21. this.root_type = 0
  22. }
  23. async dealData() {
  24. const self = this
  25. let {
  26. name,
  27. query: { page = 1, root_type = 0 },
  28. path,
  29. params,
  30. fullPath
  31. } = this.app.context.route
  32. this.pagination.page = Number(page)
  33. this.root_type = root_type
  34. // 目前仅将二级 id 拼接到 url 上
  35. let match = params.pathMatch || ''
  36. let matchList = match.split('/')
  37. matchList.pop();
  38. let lastMatch = matchList.pop() || '';
  39. // console.log(`match: ${match}, matchList: ${matchList}, lastMatch: ${lastMatch}`)
  40. // 重定向
  41. if (path.indexOf('/frontend/consult/list') > -1) {
  42. this.redirect(301, '/consult/' + lastMatch)
  43. }
  44. let consultCate = await this._getConsultCate()
  45. let consultCateAll = []
  46. consultCate.forEach(item => {
  47. if (item.children && item.children.length) {
  48. item.children.forEach(child => {
  49. consultCateAll.push(child)
  50. })
  51. }
  52. })
  53. if (lastMatch) {
  54. // 遍历分类数组
  55. let selectedCateIdOne = ''
  56. consultCate.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 consultList = await this._getConsultList()
  76. // 获取最新交易数据
  77. let newestTradeList = await this._getNewestTradeList()
  78. return {
  79. root_type,
  80. consultCate,
  81. consultCateAll,
  82. consultList, //首次获取的数据
  83. newestTradeList,
  84. mobile: this.mobile,
  85. pagination: this.pagination,
  86. head: this.dealThisMeta()
  87. }
  88. }
  89. /** 获取技能分类 */
  90. async _getConsultCate () {
  91. let res = await this.$axios.$post('/api/sale/cateListYes', { type: 3, root_type: this.root_type })
  92. let consultCate = []
  93. if (Number(res.status) === 1) {
  94. consultCate = res.data || []
  95. consultCate = consultCate.map(item => {
  96. let children = item.child_list.map(child => {
  97. return {
  98. value: child.f_name,
  99. label: child.name
  100. }
  101. })
  102. return {
  103. value: item.f_name,
  104. label: item.name,
  105. children: children
  106. }
  107. })
  108. // web 端,为所有二级分类添加 “全部”
  109. if (!this.mobile) {
  110. consultCate.forEach(item => {
  111. if (item.children) {
  112. let allItem = { value: item.value, label: '全部' }
  113. item.children.splice(0, 0, allItem)
  114. }
  115. })
  116. }
  117. }
  118. return consultCate
  119. }
  120. /** 获取技能服务列表 */
  121. async _getConsultList () {
  122. // 接口参数释义:https://www.yesdev.cn/apidocs-detail-20.html
  123. // const data = {
  124. // type: 2,
  125. // page: this.pagination.page,
  126. // page_size: this.pagination.pagesize,
  127. // cate_id: this.pagination.selectedCateIdTwo,
  128. // status: 2,
  129. // owner_type: 1
  130. // }
  131. const data = {
  132. page: this.pagination.page,
  133. page_size: this.pagination.pagesize,
  134. sale_zx_open: 1,
  135. cate_id_two_zx: this.pagination.selectedCateIdTwo || '',
  136. root_type: this.root_type
  137. }
  138. // 接口地址测试
  139. let res = await this.$axios.$post('/api/sale/consultList', data)
  140. let consultList = []
  141. if (Number(res.status) === 1) {
  142. consultList = res.data.list || []
  143. console.log(res.data.list)
  144. consultList = consultList.map(item => {
  145. let zxRating = item.zx_rating || ''
  146. let zxRatingText = ''
  147. if (zxRating >= 0.8) {
  148. zxRatingText = '高'
  149. } else if (zxRating >= 0.6) {
  150. zxRatingText = '较高'
  151. } else if (zxRating >= 0.4) {
  152. zxRatingText = '中'
  153. } else if (zxRating >= 0.2) {
  154. zxRatingText = '较低'
  155. } else {
  156. zxRatingText = '低'
  157. }
  158. // 最多展示3个头像
  159. let zxViewInfo = item.zx_view_info || []
  160. if (zxViewInfo.length > 4) {
  161. zxViewInfo = zxViewInfo.slice(0, 4)
  162. }
  163. let zxLastOrder = item.zx_last_order || {}
  164. if (zxLastOrder.buy_uid) {
  165. let nicknameFirst = zxLastOrder.nickname.substring(0, 1)
  166. let nicknameLast = zxLastOrder.nickname.substring(zxLastOrder.nickname.length - 1, zxLastOrder.nickname.length)
  167. zxLastOrder.nickname = `${nicknameFirst}****${nicknameLast}`
  168. }
  169. return {
  170. uid: item.uid || '',
  171. nickname: item.nickname || '',
  172. avatar: item.icon_url || '',
  173. lineStatus: item.lineStatus || '',
  174. company: item.company || '',
  175. title: item.title || '',
  176. saleList: item.sale_list || [],
  177. zxTotalNum: item.zx_total_num || 0,
  178. zxRating: item.zx_rating || '',
  179. zxPriceMin: item.zx_price_min || '0.00',
  180. zxRatingText: zxRatingText,
  181. zxViewNum: item.zx_view_num || 0,
  182. zxViewInfo: zxViewInfo,
  183. zxLastOrder: zxLastOrder,
  184. freework_level: item.freework_level || '',
  185. zx_sale_img: item.zx_sale_img || ''
  186. }
  187. })
  188. // consultList.forEach((item) => {
  189. // let imageList = item.image.split(',')
  190. // item.coverImage = imageList[0] || ''
  191. // imageList.splice(0, 1)
  192. // item.imageList = imageList
  193. // })
  194. this.pagination.total = res.data.total
  195. this.pagination.pageCount = res.data.pages
  196. // this.pagination.pagesize = res.data.page_size || 9
  197. // 当前页码 大于等于 页面总数:已加载所有数据
  198. if (this.pagination.page >= this.pagination.pageCount) {
  199. this.pagination.noMore = true
  200. } else {
  201. this.pagination.noMore = false
  202. }
  203. }
  204. return consultList
  205. }
  206. /** 获取最近成交数据 */
  207. async _getNewestTradeList () {
  208. let res = await this.$axios.$post('/api/sale/scrollList')
  209. let newestTradeList = []
  210. if (Number(res.status) === 1) {
  211. newestTradeList = res.data
  212. newestTradeList.forEach(item => {
  213. let nicknameFirst = item.nickname.substring(0, 1)
  214. let nicknameLast = item.nickname.substring(item.nickname.length - 1, item.nickname.length)
  215. item.nickname = `${nicknameFirst}****${nicknameLast}`
  216. })
  217. }
  218. return newestTradeList
  219. }
  220. dealThisMeta() {
  221. let head = {
  222. title: "",
  223. keyword: "",
  224. description: "",
  225. h1: "",
  226. canonical: "",
  227. metaLocation: ""
  228. }
  229. if (this.req) {
  230. const { headers: { host }, url } = this.req
  231. //拼接canonical
  232. if (host.indexOf('local') !== -1) {
  233. head.canonical = 'http://' + host + url
  234. } else {
  235. head.canonical = 'https://' + host + url
  236. }
  237. }
  238. if (this.cateNameTwo) {
  239. // 分类页
  240. head.title = `${this.cateNameTwo}技术咨询-${this.cateNameTwo}大牛-程序员客栈技术咨询`;
  241. head.keyword = `${this.cateNameTwo}技术咨询,${this.cateNameTwo}学习,${this.cateNameTwo}大牛,${this.cateNameTwo}高级开发工程师`;
  242. head.description = `程序员客栈技术培训提供海量${this.cateNameTwo}专家、${this.cateNameTwo}高级高级开发工程师为你提供一对一技术咨询服务,答疑解惑,出谋划策,定制服务,更多互联网专家请访问程序员客栈APP或官网技术咨询栏目`;
  243. } else {
  244. // 列表页,无筛选参数
  245. head.title = "领先的互联网知识技术咨询平台-【程序员客栈技术咨询】";
  246. head.keyword = "程序员大牛,架构师,高级开发工程师,开发技术咨询,开发经验,解决问题,一对一,面对面";
  247. head.description = "程序员客栈技术咨询是国内领先的互联网知识技术咨询平台。当你遇到任何互联网项目开发的问题或是个性化的服务需求,都可以直接找到行业专家,为你答疑解惑,出谋划策,定制服务,更多互联网专家请访问程序员客栈APP或官网技术咨询栏目";
  248. }
  249. return head
  250. }
  251. }