| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- export default class DealSeoData {
- constructor({$axios, req, app, redirect, error}) {
- this.$axios = $axios
- this.req = req
- this.app = app
- this.redirect = redirect
- this.error = error
- this.skillDetail = {}
- this.isExist = true
- }
- async dealData() {
- let {
- name,
- query: { act },
- path,
- params,
- fullPath
- } = this.app.context.route
- const sale_id = params.id || ''
- // 重定向
- if (path.indexOf('/frontend/skill/detail') > -1) {
- this.redirect(301, '/s/' + sale_id)
- }
- const skillDetail = await this._getSkillDetail(sale_id)
- if (skillDetail && skillDetail.image && skillDetail.image.length) {
- let imageList = skillDetail.image.split(',')
- skillDetail.coverImage = imageList[0] || ''
- imageList.splice(0, 1)
- skillDetail.imageList = imageList
- }
- this.skillDetail = skillDetail
- return {
- isExist: this.isExist,
- sale_id,
- skillDetail,
- mobile: this.app.$deviceType.isMobile(),
- head: this.dealThisMeta(),
- act
- }
- }
- /** 获取技能详情 */
- async _getSkillDetail (sale_id) {
- let res = await this.$axios.$post('/api/sale/saleInfo', { sale_id })
- let skillDetail = {}
- if (Number(res.status) === 1) {
- skillDetail = res.data
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return skillDetail
- }
- dealThisMeta() {
- if (!this.isExist) {
- // 页面不存在时
- return {
- title: "页面不存在-程序员客栈",
- keyword: "",
- description: "",
- h1: "",
- canonical: "",
- metaLocation: ""
- }
- }
- let content = this.skillDetail.content.trim()
- let title = this.skillDetail.title.trim()
- const nickname = this.skillDetail.user.nickname
- if (content.length > 15) {
- content = content.substring(0, 15)
- }
- if (title.length > 15) {
- title = title.substring(0, 15)
- }
- let canonical = ''
- if (this.req) {
- const { headers: { host }, url } = this.req
- //拼接canonical
- if (host.indexOf('local') !== -1) {
- canonical = 'http://' + host + url
- } else {
- canonical = 'https://' + host + url
- }
- }
- let head = {
- title: `${this.skillDetail.title}-程序员客栈技能服务`,
- keyword: `${this.skillDetail.user.company},${this.skillDetail.direction_name},${this.skillDetail.title}`,
- description: `${nickname}可以为您提供:${title},技能服务是程序员客栈远程工作平台为企业和自由职业者提供的标准化数字服务,通过标准定价的模块化技能,帮助企业和自由职业者快速达成合作。`,
- h1: "",
- canonical: canonical,
- metaLocation: ""
- }
- return head
- }
- }
|