| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- export default class DynamicInfoData {
- constructor({$axios, req, app, redirect, error}) {
- this.$axios = $axios
- this.req = req
- this.app = app
- this.redirect = redirect
- this.error = error
- this.consultDetail= {}
- this.from = ''
- this.isExist = true
- }
- async dealData() {
- let {
- name,
- path,
- params,
- fullPath,
- query
- } = this.app.context.route
- const dynamicId = params.id || ''
- // 重定向
- // if (path.indexOf('/frontend/consult/user') > -1) {
- // this.redirect(301, '/c/' + uid)
- // }
- const dynamicDetail = await this._fetchData(dynamicId)
- return {
- isExist: this.isExist,
- dynamicDetail,
- mobile: this.app.$deviceType.isMobile(),
- // head: this.dealThisMeta(),
- }
- }
- async _fetchData(dynamicId){
- let res = await this.$axios.$post('/uapi/dynamic/get_dynamic_detail', {
- dynamic_id:dynamicId
- })
- let dynamicDetail = {}
- if (Number(res.status) === 1) {
- let dynamicList = res.data.list
- console.log(dynamicList)
- dynamicDetail = {...dynamicList[0]}
- }else{
- this.isExist = false
- }
- return dynamicDetail
- }
- dealThisMeta() {
- let title = ''
- let descriptionTitle = ''
- let description = ''
- let canonical = ''
- if (!this.isExist) {
- // 页面不存在时
- return {
- title: "页面不存在-程序员客栈",
- keyword: "",
- description: "",
- h1: "",
- canonical: "",
- metaLocation: ""
- }
- }
- const nickname = this.consultDetail.user.nickname
- this.consultDetail.sale_list.forEach((item, index) => {
- if (index === 0) {
- title = item.title.trim()
- description = item.content.trim()
- }
- // if (index !== this.consultDetail.sale_list.length - 1) {
- // description += `${item.title}、`
- // } else {
- // description += item.title
- // }
- })
- if (description.length > 15) {
- description = description.substring(0, 15)
- }
- if (title.length > 15) {
- descriptionTitle = title.substring(0, 15)
- } else {
- descriptionTitle = title
- }
- 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: `${title}-程序员客栈咨询服务`,
- keyword: `${this.consultDetail.user.company},${this.consultDetail.user.direction_name},${title}`,
- description: `${nickname}可以为您提供:${descriptionTitle},程序员客栈邀请到国内外互联网名企资深工作者,为您提供1对1技术咨询服务。`,
- h1: "",
- canonical: canonical,
- metaLocation: ""
- }
- return head
- }
- }
|