| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- 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.from = ''
- this.isExist = true
- this.pagesize = 10
- }
- async dealData() {
- let {
- name,
- path,
- params,
- fullPath,
- query
- } = this.app.context.route
- // 重定向
- // if (path.indexOf('/frontend/consult/user') > -1) {
- // this.redirect(301, '/c/' + uid)
- // }
- let [
- userInfo,
- balanceInfo,
- workPlatInfo,
- typeList,
- hotInfo
- ] = await Promise.all([
- this._getUserInfo(),
- this._getUserBalance(),
- this._getWorkPlatInfo(),
- this._getTypeList(),
- this._getHotData()
- ])
- let firstType = typeList[0]
- let dynamicList = await this._getDynamicDetail(firstType.typeId)
- let isMore = dynamicList.length < this.pagesize ? false : true
- return {
- isExist: this.isExist,
- mobile: this.app.$deviceType.isMobile(),
- // head: this.dealThisMeta(),
- userInfo,
- balanceInfo,
- workPlatInfo,
- typeList,
- hotInfo,
- dynamicList,
- firstType,
- isMore
- }
- }
- // 获取用户信息
- async _getUserInfo() {
- let res = await this.$axios.$post('/uapi/user/info')
- // let res = await this.$axios.$post('/api/user/getInfo')
- let userInfo = {}
- if (Number(res.status) === 1) {
- let { info, login } = res.data
- // let info = {...res.data}
- // let login = {...res.data}
- userInfo['realname_re'] = info.realname_re;
- userInfo['realname_verify_status'] = info.realname_verify_status;
- userInfo['dynamic_rand'] = info.dynamic_rand
- userInfo['is_open_mall'] = info.is_open_mall
- userInfo['is_open_kill'] = info.is_open_kill
- userInfo['is_open_consult'] = info.is_open_consult
- userInfo['is_open_kc'] = info.is_open_kc
- userInfo['nickname'] = login.nickname
- userInfo['icon_url'] = login.icon_url
- userInfo['freework_level'] = login.freework_level
-
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return userInfo
- }
- // 获取账户余额
- async _getUserBalance() {
- let res = await this.$axios.$post('/api/account/getBalance')
- let balanceInfo = {}
- if (Number(res.status) === 1) {
- let info = res.data
- //账户余额
- balanceInfo['totalBalance'] = info['totalBalance']
- //总收入
- balanceInfo['historyTotalBalance'] = info['historyTotalBalance']
- //冻结余额
- balanceInfo['frozenBalance'] = info['frozenBalance']
- //薪资余额
- balanceInfo['gongMallBalance'] = info['gongMallBalance']
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return balanceInfo
- }
- // 获取工作台统计数据
- async _getWorkPlatInfo() {
- let res = await this.$axios.$post('/api/user/getWorkPlatformCount')
- let workPlatInfo = {}
- if (Number(res.status) === 1) {
- let info = res.data
- // 待办
- workPlatInfo['pendingNumber'] = info['pendingNumber']
- // 工作
- workPlatInfo['developerWorkNumber'] = info['developerWorkNumber']
- // 整包
- workPlatInfo['developerProjectNumber'] = info['developerProjectNumber']
- // 沟通
- workPlatInfo['recruitDeveloperCount'] = info['recruitDeveloperCount']
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return workPlatInfo
- }
- // 动态列表
- async _getDynamicDetail(type_id) {
- let res = await this.$axios.$post('/uapi/dynamic/get_dynamic_detail', {
- type_id,
- page: 1,
- pagesize: this.pagesize
- })
- let dynamicList = []
- if (Number(res.status) === 1) {
- let info = res.data.list
- info = info.map((item) => {
- let imgList = item.img
- imgList = imgList.map(item => {
- return item.img
- })
- return {
- ...item,
- imgList
- }
- })
- dynamicList = [...info]
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return dynamicList
- }
- // 圈子分类
- async _getTypeList() {
- let res = await this.$axios.$post('/uapi/dynamic/get_type_list')
- let typeList = []
- if (Number(res.status) === 1) {
- let info = res.data
- typeList = [...info]
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return typeList
- }
- // 热门资源
- async _getHotData(){
- let res = await this.$axios.$get('/sapi/index/index')
- let hotInfo = {
- 'works':[],
- 'learn':[]
- }
- if (Number(res.status) === 1) {
- let {works,learn} = res.data
- hotInfo['works'] = works.splice(0,5)
- hotInfo['learn'] = learn.splice(0,5)
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- return hotInfo
- }
- 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
- }
- }
|