| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- export default class PersonalData {
- constructor({ $axios, req, app, redirect, error }) {
- this.$axios = $axios
- this.req = req
- this.app = app
- this.redirect = redirect
- this.error = error
- this.from = ''
- this.isExist = true
- this.pagesize = 10
- }
- async dealData() {
- let {
- name,
- path,
- params,
- fullPath,
- query
- } = this.app.context.route
- let [
- personalUserInfo,
- dynamicData,
- articleCount,
- courseCount,
- adList,
- isFollowing
- ] = await Promise.all([
- this._getPersonalUserInfo(),
- this._getDynamicCount(),
- this._getArticleCount(),
- this._getCourseCount(),
- this._getAdvert(),
- this._getFollowStatus()
- ])
- return {
- isExist: this.isExist,
- mobile: this.app.$deviceType.isMobile(),
- // head: this.dealThisMeta(),
- personalUserInfo,
- dynamicCount:dynamicData.dynamicCount,
- list:dynamicData.dynamicList,
- page:1,
- articleCount,
- courseCount,
- adList,
- isFollowing
- }
- }
- // 获取开发者个人信息
- async _getPersonalUserInfo() {
- let {
- name,
- path,
- params,
- fullPath,
- query
- } = this.app.context.route
- let res = await this.$axios.post('/uapi/user/info/action/other', {
- uid: params.uid
- })
- let personalUserInfo = {}
- if (Number(res.data.status) === 1) {
- personalUserInfo = {
- ...res.data.data
- }
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return personalUserInfo
- }
- async _getDynamicCount(){
- let {
- name,
- path,
- params,
- fullPath,
- query
- } = this.app.context.route
- let uid = params.uid
- let res = await this.$axios.post('/uapi/dynamic/get_dynamic_list_my', {
- to_uid: params.uid,
- page:1,
- pagesize:10
- })
- let count = 0
- let dynamicList = []
- if (Number(res.data.status) === 1) {
- count = res.data.data.user.dynamic_num
- dynamicList = res.data.data.list
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return {
- dynamicList,
- dynamicCount:count
- }
- }
- async _getArticleCount(){
- let {
- name,
- path,
- params,
- fullPath,
- query
- } = this.app.context.route
- let uid = params.uid
- let res = await this.$axios.post('/uapi/news/index/list', {
- uid: params.uid,
- page:1,
- pagesize:1
- })
- let count = 0
- if (Number(res.data.status) === 1) {
- count = res.data.data.total
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return count
- }
- async _getCourseCount(){
- let {
- name,
- path,
- params,
- fullPath,
- query
- } = this.app.context.route
- let uid = params.uid
- let res = await this.$axios.post('/uapi/goods/video/list', {
- to_uid: params.uid,
- page:1,
- pagesize:1
- })
- let count = 0
- if (Number(res.data.status) === 1) {
- count = res.data.data.total
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return count
- }
- // 获取广告位
- async _getAdvert() {
- let res = await this.$axios.post('/uapi/pub/adInfo', {
- position: 'personal'
- })
- let adList = []
- if (Number(res.data.status) === 1) {
- adList = {
- ...res.data.data.list
- }
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return adList
- }
- // 获取当前关注状态
- async _getFollowStatus() {
- let {
- name,
- path,
- params,
- fullPath,
- query
- } = this.app.context.route
- let uid = params.uid
- let res = await this.$axios.post('/uapi/dynamic/check_followers', {
- to_uid: uid
- })
- let isFollowing = false
- if (Number(res.data.status) === 1) {
- if(res.data.data.result == 1){
- isFollowing = true
- }
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return isFollowing
- }
- 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
- }
- }
|